patch_mod_ui_rigforge.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. #!/usr/bin/env python3
  2. """Apply the small Rigforge integration patch to the pinned mod-ui source tree."""
  3. import sys
  4. from pathlib import Path
  5. def replace_once(path, original, replacement):
  6. text = path.read_text(encoding="utf-8")
  7. if replacement in text:
  8. return
  9. if text.count(original) != 1:
  10. raise RuntimeError(f"expected one upstream match in {path}")
  11. path.write_text(text.replace(original, replacement), encoding="utf-8")
  12. def replace_if_present(path, original, replacement):
  13. text = path.read_text(encoding="utf-8")
  14. if (replacement and replacement in text) or original not in text:
  15. return
  16. if text.count(original) != 1:
  17. raise RuntimeError(f"expected at most one upstream match in {path}")
  18. path.write_text(text.replace(original, replacement), encoding="utf-8")
  19. def replace_host_method(path, method_name, replacement):
  20. """Replace a complete Host method, independent of its upstream body variant."""
  21. text = path.read_text(encoding="utf-8")
  22. marker = f" def {method_name}("
  23. start = text.find(marker)
  24. if start < 0:
  25. raise RuntimeError(f"could not find Host.{method_name} in {path}")
  26. next_method = text.find("\n def ", start + len(marker))
  27. end = len(text) if next_method < 0 else next_method + 1
  28. replacement = replacement.rstrip() + "\n\n"
  29. updated = text[:start] + replacement + text[end:]
  30. if updated != text:
  31. path.write_text(updated, encoding="utf-8")
  32. def patch_host_connection_methods(host):
  33. """Normalize manual connection handling across old Rigforge patch variants."""
  34. replace_host_method(
  35. host,
  36. "connect",
  37. ''' def connect(self, port_from, port_to, callback):
  38. if (port_from, port_to) in self.connections:
  39. logging.info("[host] NOTE: Requested connection already exists")
  40. callback(True)
  41. return
  42. resolved = pedalboard_connection(
  43. port_from, port_to, self.rigforge_capture_ports,
  44. self.rigforge_playback_ports, self._fix_host_connection_port
  45. )
  46. if resolved is not None and resolved[0] == "pipewire":
  47. pipewire_link = resolved[1]
  48. ok = connect_link(*pipewire_link)
  49. callback(ok)
  50. if ok:
  51. self.connections.append((port_from, port_to))
  52. self.pedalboard_modified = True
  53. self.msg_callback("connect %s %s" % (port_from, port_to))
  54. else:
  55. logging.error(
  56. "[host] PipeWire backend failed to connect ports: '%s' => '%s'",
  57. pipewire_link[0], pipewire_link[1]
  58. )
  59. return
  60. def host_callback(ok):
  61. callback(ok)
  62. if ok:
  63. self.connections.append((port_from, port_to))
  64. self.msg_callback("connect %s %s" % (port_from, port_to))
  65. else:
  66. logging.error("[host] backend failed to connect ports: '%s' => '%s'", port_from, port_to)
  67. if resolved is not None:
  68. port_from_2, port_to_2 = resolved[1]
  69. else:
  70. port_from_2 = self._fix_host_connection_port(port_from)
  71. port_to_2 = self._fix_host_connection_port(port_to)
  72. self.send_modified(
  73. "connect %s %s" % (port_from_2, port_to_2),
  74. host_callback,
  75. datatype='boolean'
  76. )''',
  77. )
  78. text = host.read_text(encoding="utf-8")
  79. if " def _rigforge_pipewire_boundary(" in text:
  80. replace_host_method(
  81. host,
  82. "_rigforge_pipewire_boundary",
  83. ''' def _rigforge_pipewire_boundary(self, port_from, port_to):
  84. resolved = pedalboard_connection(
  85. port_from, port_to, self.rigforge_capture_ports,
  86. self.rigforge_playback_ports, self._fix_host_connection_port
  87. )
  88. if resolved is not None and resolved[0] == "pipewire":
  89. return resolved[1]
  90. return None''',
  91. )
  92. replace_host_method(
  93. host,
  94. "disconnect",
  95. ''' def disconnect(self, port_from, port_to, callback):
  96. resolved = pedalboard_connection(
  97. port_from, port_to, self.rigforge_capture_ports,
  98. self.rigforge_playback_ports, self._fix_host_connection_port
  99. )
  100. if resolved is not None and resolved[0] == "pipewire":
  101. pipewire_link = resolved[1]
  102. ok = disconnect_link(*pipewire_link)
  103. callback(ok)
  104. if ok:
  105. self.msg_callback("disconnect %s %s" % (port_from, port_to))
  106. self.pedalboard_modified = True
  107. try:
  108. self.connections.remove((port_from, port_to))
  109. except ValueError:
  110. logging.info(
  111. "[host] Requested '%s' => '%s' connection was not in the UI state",
  112. port_from, port_to
  113. )
  114. else:
  115. logging.error(
  116. "[host] PipeWire backend failed to disconnect ports: '%s' => '%s'",
  117. pipewire_link[0], pipewire_link[1]
  118. )
  119. return
  120. def host_callback(ok):
  121. # Upstream disconnect failures are not fatal to the UI state.
  122. callback(True)
  123. self.msg_callback("disconnect %s %s" % (port_from, port_to))
  124. if not ok:
  125. logging.error("[host] disconnect '%s' => '%s' failed", port_from, port_to)
  126. self.pedalboard_modified = True
  127. try:
  128. self.connections.remove((port_from, port_to))
  129. except ValueError:
  130. logging.info(
  131. "[host] NOTE: Requested '%s' => '%s' connection doesn't exist",
  132. port_from, port_to
  133. )
  134. if resolved is not None:
  135. port_from_2, port_to_2 = resolved[1]
  136. else:
  137. try:
  138. port_from_2 = self._fix_host_connection_port(port_from)
  139. except Exception:
  140. logging.info("[host] NOTE: Requested '%s' source port doesn't exist, assume disconnected", port_from)
  141. return host_callback(True)
  142. try:
  143. port_to_2 = self._fix_host_connection_port(port_to)
  144. except Exception:
  145. logging.info("[host] NOTE: Requested '%s' target port doesn't exist, assume disconnected", port_to)
  146. return host_callback(True)
  147. if len(self.connections) == 0:
  148. return host_callback(False)
  149. self.send_modified(
  150. "disconnect %s %s" % (port_from_2, port_to_2),
  151. host_callback,
  152. datatype='boolean'
  153. )''',
  154. )
  155. def patch_load_connections(host):
  156. """Make pedalboard restore use the same resolution as manual UI actions."""
  157. text = host.read_text(encoding="utf-8")
  158. original_text = text
  159. resolver_marker = " def _fix_host_connection_port(self, port):"
  160. resolver_start = text.find(resolver_marker)
  161. if resolver_start < 0:
  162. raise RuntimeError(f"could not locate Host._fix_host_connection_port in {host}")
  163. resolver_end = text.find(
  164. "\n def ", resolver_start + len(resolver_marker)
  165. )
  166. if resolver_end < 0:
  167. raise RuntimeError(f"could not locate end of Host._fix_host_connection_port in {host}")
  168. resolver_method = text[resolver_start:resolver_end]
  169. if (
  170. "# Rigforge bare boundary port alias; web_connect removes /graph/."
  171. not in resolver_method
  172. ):
  173. marker = ' data = port.split("/")\n'
  174. if resolver_method.count(marker) != 1:
  175. raise RuntimeError(f"could not identify port resolver body in {host}")
  176. updated_resolver = resolver_method.replace(
  177. marker,
  178. ''' # Rigforge bare boundary port alias; web_connect removes /graph/.
  179. if port in self.rigforge_capture_ports:
  180. return self.rigforge_capture_ports[port]
  181. if port in self.rigforge_playback_ports:
  182. return self.rigforge_playback_ports[port]
  183. data = port.split("/")
  184. if len(data) == 2 and data[0] == "" and (
  185. data[1] in self.rigforge_capture_ports
  186. or data[1] in self.rigforge_playback_ports
  187. ):
  188. symbol = data[1]
  189. return self.rigforge_capture_ports.get(
  190. symbol, self.rigforge_playback_ports.get(symbol)
  191. )
  192. ''',
  193. 1,
  194. )
  195. if updated_resolver == resolver_method:
  196. raise RuntimeError(f"could not add Rigforge alias to {host}")
  197. text = text[:resolver_start] + updated_resolver + text[resolver_end:]
  198. method_marker = " def load_pb_connections("
  199. method_start = text.find(method_marker)
  200. if method_start < 0:
  201. raise RuntimeError(f"could not find Host.load_pb_connections in {host}")
  202. block_start = text.find(" if doConnectionNow:", method_start)
  203. block_end = text.find(
  204. "\n elif aliasname1 is not None or aliasname2 is not None:",
  205. block_start,
  206. )
  207. if block_start < 0 or block_end < 0:
  208. raise RuntimeError(
  209. f"could not identify mod-ui pedalboard connection restoration block in {host}"
  210. )
  211. replacement = ''' if doConnectionNow:
  212. resolved = pedalboard_connection(
  213. port_from, port_to, self.rigforge_capture_ports,
  214. self.rigforge_playback_ports, self._fix_host_connection_port
  215. )
  216. if resolved is not None and resolved[0] == "pipewire":
  217. self._rigforge_restore_pipewire_boundary(
  218. resolved[1],
  219. port_from,
  220. port_to,
  221. attempts_left=60
  222. )
  223. continue
  224. try:
  225. if resolved is not None:
  226. port_from_2, port_to_2 = resolved[1]
  227. else:
  228. port_from_2 = self._fix_host_connection_port(port_from)
  229. port_to_2 = self._fix_host_connection_port(port_to)
  230. except Exception:
  231. continue
  232. self.send_notmodified("connect %s %s" % (port_from_2, port_to_2))
  233. self.connections.append((port_from, port_to))
  234. self.msg_callback("connect %s %s" % (port_from, port_to))'''
  235. updated = text[:block_start] + replacement + text[block_end:]
  236. restore_method = ''' def _rigforge_restore_pipewire_boundary(
  237. self, pipewire_link, port_from, port_to, attempts_left
  238. ):
  239. if not hasattr(self, "_rigforge_restore_attempts"):
  240. self._rigforge_restore_attempts = {}
  241. edge = (port_from, port_to)
  242. attempts_left = min(
  243. attempts_left, self._rigforge_restore_attempts.get(edge, 60)
  244. )
  245. if not (
  246. self.rigforge_capture_ports
  247. and self.rigforge_playback_ports
  248. and all(
  249. "capture_%d" % index in self.audioportsIn
  250. for index in range(1, len(self.rigforge_capture_ports) + 1)
  251. )
  252. and all(
  253. "playback_%d" % index in self.audioportsOut
  254. for index in range(1, len(self.rigforge_playback_ports) + 1)
  255. )
  256. ):
  257. ready = False
  258. else:
  259. result = subprocess.run(
  260. ["pw-link", "-o"],
  261. check=False,
  262. capture_output=True,
  263. text=True,
  264. )
  265. ready = result.returncode == 0 and all(
  266. port in result.stdout.splitlines()
  267. for port in (
  268. *self.rigforge_capture_ports.values(),
  269. *self.rigforge_playback_ports.values(),
  270. )
  271. )
  272. connections_now = self.connections
  273. if edge in connections_now:
  274. self._rigforge_restore_attempts.pop(edge, None)
  275. return
  276. if not ready and attempts_left == 60:
  277. logging.error(
  278. "[host] PipeWire boundary readiness failed: inputs=%r outputs=%r "
  279. "configured_capture=%r configured_playback=%r",
  280. self.audioportsIn,
  281. self.audioportsOut,
  282. sorted(self.rigforge_capture_ports),
  283. sorted(self.rigforge_playback_ports),
  284. )
  285. if ready and connect_link(*pipewire_link):
  286. self._rigforge_restore_attempts.pop(edge, None)
  287. if edge not in self.connections:
  288. self.connections.append(edge)
  289. self.msg_callback("connect %s %s" % (port_from, port_to))
  290. return
  291. if not ready and edge not in self._rigforge_restore_attempts:
  292. logging.error(
  293. "[host] PipeWire boundary ports are not ready for restore: '%s' => '%s' "
  294. "(capture ports: %s; playback ports: %s)",
  295. pipewire_link[0],
  296. pipewire_link[1],
  297. sorted(self.rigforge_capture_ports.values()),
  298. sorted(self.rigforge_playback_ports.values()),
  299. )
  300. if attempts_left <= 1:
  301. logging.error(
  302. "[host] PipeWire backend failed to restore ports: '%s' => '%s'",
  303. pipewire_link[0], pipewire_link[1]
  304. )
  305. return
  306. self._rigforge_restore_attempts[edge] = attempts_left - 1
  307. IOLoop.instance().call_later(
  308. 0.5,
  309. self._rigforge_restore_pipewire_boundary,
  310. pipewire_link,
  311. port_from,
  312. port_to,
  313. connections_now,
  314. attempts_left - 1
  315. )
  316. '''
  317. restore_marker = " def _rigforge_restore_pipewire_boundary("
  318. restore_start = updated.find(restore_marker)
  319. if restore_start >= 0:
  320. restore_end = updated.find("\n def ", restore_start + len(restore_marker))
  321. if restore_end < 0:
  322. raise RuntimeError(f"could not locate end of restore method in {host}")
  323. updated = updated[:restore_start] + restore_method.rstrip() + "\n\n" + updated[restore_end + 1:]
  324. else:
  325. marker = " def load_pb_connections("
  326. position = updated.find(marker)
  327. if position < 0:
  328. raise RuntimeError(f"could not insert PipeWire restore method in {host}")
  329. updated = updated[:position] + restore_method + updated[position:]
  330. if updated != original_text:
  331. host.write_text(updated, encoding="utf-8")
  332. def apply(source_root):
  333. app = Path(source_root)
  334. helper = Path(__file__).with_name("mod_ui_pipewire.py")
  335. (app / "mod" / "rigforge_pipewire.py").write_bytes(helper.read_bytes())
  336. replace_if_present(
  337. app / "mod" / "host.py",
  338. "from mod import (\n",
  339. "from mod.rigforge_pipewire import boundary_connection, connect_link, disconnect_link, pedalboard_connection\n"
  340. "from mod import (\n",
  341. )
  342. replace_if_present(
  343. app / "mod" / "host.py",
  344. "import os, json, socket, time, logging, sys\n",
  345. "import os, json, socket, time, logging, sys, subprocess\n",
  346. )
  347. replace_if_present(
  348. app / "mod" / "host.py",
  349. ''' self.jack_hw_capture_prefix = "mod-host:out" if self.descriptor.get('has_noisegate', False) else "system:capture_"
  350. ''',
  351. ''' self.jack_hw_capture_prefix = "mod-host:out" if self.descriptor.get('has_noisegate', False) else "system:capture_"
  352. self.rigforge_capture_ports = {
  353. "capture_%d" % (index + 1): port
  354. for index, port in enumerate(
  355. os.environ.get("MOD_RIGFORGE_CAPTURE_PORTS", "").split(",")
  356. )
  357. if port
  358. }
  359. self.rigforge_playback_ports = {
  360. "playback_%d" % (index + 1): port
  361. for index, port in enumerate(
  362. os.environ.get("MOD_RIGFORGE_PLAYBACK_PORTS", "").split(",")
  363. )
  364. if port
  365. }
  366. ''',
  367. )
  368. replace_if_present(
  369. app / "mod" / "host.py",
  370. ''' self.rigforge_capture_port = os.environ.get("MOD_RIGFORGE_CAPTURE_PORT")
  371. self.rigforge_playback_port = os.environ.get("MOD_RIGFORGE_PLAYBACK_PORT")
  372. ''',
  373. "",
  374. )
  375. replace_if_present(
  376. app / "mod" / "host.py",
  377. ''' if self.rigforge_capture_port and self.rigforge_playback_port:
  378. # These graph symbols map to Rigforge's stable virtual PipeWire boundary ports.
  379. self.audioportsIn = ["capture_1"]
  380. self.audioportsOut = ["playback_1"]
  381. ''',
  382. ''' if self.rigforge_capture_ports and self.rigforge_playback_ports:
  383. # These graph symbols map to Rigforge's stable virtual PipeWire boundary ports.
  384. self.audioportsIn = [
  385. "capture_%d" % index
  386. for index in range(1, len(self.rigforge_capture_ports) + 1)
  387. ]
  388. self.audioportsOut = [
  389. "playback_%d" % index
  390. for index in range(1, len(self.rigforge_playback_ports) + 1)
  391. ]
  392. ''',
  393. )
  394. replace_once(
  395. app / "mod" / "host.py",
  396. ''' for port in get_jack_hardware_ports(True, False):
  397. client_name, port_name = port.split(":",1)
  398. if client_name == "mod-spi2jack":
  399. cv_port_name = CV_PREFIX + port_name
  400. self.cvportsIn.append(cv_port_name)
  401. self.addressings.add_hw_cv_port('/cv/graph/' + cv_port_name)
  402. else:
  403. self.audioportsIn.append(port_name)
  404. for port in get_jack_hardware_ports(True, True):
  405. client_name, port_name = port.split(":",1)
  406. if client_name == "mod-jack2spi":
  407. self.cvportsOut.append(CV_PREFIX + port_name)
  408. else:
  409. self.audioportsOut.append(port_name)
  410. ''',
  411. ''' if self.rigforge_capture_ports and self.rigforge_playback_ports:
  412. # These graph symbols map to Rigforge's stable virtual PipeWire boundary ports.
  413. self.audioportsIn = [
  414. "capture_%d" % index
  415. for index in range(1, len(self.rigforge_capture_ports) + 1)
  416. ]
  417. self.audioportsOut = [
  418. "playback_%d" % index
  419. for index in range(1, len(self.rigforge_playback_ports) + 1)
  420. ]
  421. else:
  422. for port in get_jack_hardware_ports(True, False):
  423. client_name, port_name = port.split(":",1)
  424. if client_name == "mod-spi2jack":
  425. cv_port_name = CV_PREFIX + port_name
  426. self.cvportsIn.append(cv_port_name)
  427. self.addressings.add_hw_cv_port('/cv/graph/' + cv_port_name)
  428. else:
  429. self.audioportsIn.append(port_name)
  430. for port in get_jack_hardware_ports(True, True):
  431. client_name, port_name = port.split(":",1)
  432. if client_name == "mod-jack2spi":
  433. self.cvportsOut.append(CV_PREFIX + port_name)
  434. else:
  435. self.audioportsOut.append(port_name)
  436. ''',
  437. )
  438. replace_if_present(
  439. app / "mod" / "host.py",
  440. ''' if data[2] == "capture_1" and self.rigforge_capture_port:
  441. return self.rigforge_capture_port
  442. if data[2] == "playback_1" and self.rigforge_playback_port:
  443. return self.rigforge_playback_port
  444. ''',
  445. ''' if data[2] in self.rigforge_capture_ports:
  446. return self.rigforge_capture_ports[data[2]]
  447. if data[2] in self.rigforge_playback_ports:
  448. return self.rigforge_playback_ports[data[2]]
  449. ''',
  450. )
  451. replace_if_present(
  452. app / "mod" / "host.py",
  453. "import os, json, socket, time, logging, sys\n",
  454. "import os, json, socket, time, logging, sys, subprocess\n",
  455. )
  456. host_file = app / "mod" / "host.py"
  457. patch_load_connections(host_file)
  458. patch_host_connection_methods(host_file)
  459. replace_once(
  460. host_file,
  461. ''' if bundlepath and (bundlepath.startswith(LV2_PEDALBOARDS_DIR) or
  462. bundlepath.startswith(LV2_FACTORY_PEDALBOARDS_DIR)):
  463. save_last_bank_and_pedalboard(self.bank_id, bundlepath)
  464. else:
  465. save_last_bank_and_pedalboard(0, "")
  466. ''',
  467. ''' if bundlepath and (
  468. bundlepath.startswith(LV2_PEDALBOARDS_DIR)
  469. or bundlepath.startswith(LV2_FACTORY_PEDALBOARDS_DIR)
  470. or bundlepath.startswith(os.path.join(DATA_DIR, "references"))
  471. ):
  472. save_last_bank_and_pedalboard(self.bank_id, bundlepath)
  473. else:
  474. save_last_bank_and_pedalboard(0, "")
  475. ''',
  476. )
  477. replace_if_present(
  478. app / "mod" / "session.py",
  479. ''' # Set a plugin block position within the canvas
  480. ''',
  481. ''' def ws_rigforge_patch_set(self, request_id, instance, uri, valuetype, valuedata, ws):
  482. if valuetype != "p":
  483. ws.write_message("rigforge_patch_set_ack %s 0" % request_id)
  484. return
  485. def completed(ok):
  486. status = 1 if ok else 0
  487. if ok:
  488. self.msg_callback_broadcast(
  489. "patch_set %s 1 %s %c %s" % (instance, uri, valuetype, valuedata),
  490. ws,
  491. )
  492. ws.write_message("rigforge_patch_set_ack %s %d" % (request_id, status))
  493. self.host.patch_set(instance, uri, valuedata, completed)
  494. # Set a plugin block position within the canvas
  495. ''',
  496. )
  497. replace_if_present(
  498. app / "mod" / "webserver.py",
  499. ''' elif cmd == "plugin_pos":
  500. ''',
  501. ''' elif cmd == "rigforge_patch_set":
  502. data = data[1].split(" ", 4)
  503. if len(data) != 5:
  504. self.write_message("rigforge_patch_set_ack invalid 0")
  505. return
  506. request_id, inst, uri, vtype, value = data
  507. if not request_id.isalnum():
  508. self.write_message("rigforge_patch_set_ack invalid 0")
  509. return
  510. SESSION.ws_rigforge_patch_set(
  511. request_id, inst, uri, vtype, value, self
  512. )
  513. elif cmd == "plugin_pos":
  514. ''',
  515. )
  516. replace_if_present(
  517. app / "server.py",
  518. "os.environ['MOD_DEVICE_WEBSERVER_PORT'] = '8888'",
  519. "os.environ.setdefault('MOD_DEVICE_WEBSERVER_PORT', '8888')",
  520. )
  521. replace_if_present(
  522. app / "server.py",
  523. "os.environ['MOD_DEFAULT_PEDALBOARD'] = os.path.join(ROOT, 'default.pedalboard')",
  524. "os.environ.setdefault('MOD_DEFAULT_PEDALBOARD', os.path.join(ROOT, 'default.pedalboard'))",
  525. )
  526. replace_if_present(
  527. app / "html" / "js" / "pedalboard.js",
  528. ''' var captureTitles = {
  529. 1: 'Guitar - Mod-UI Input',
  530. 2: 'Bass - Mod-UI Input',
  531. 3: 'Micro - Mod-UI Input',
  532. 4: 'Synth - Mod-UI Input'
  533. }
  534. var captureTitle = captureTitles[i] || ('Hardware Capture ' + i)
  535. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  536. ''',
  537. ''' var captureTitles = {
  538. 1: 'Guitare - Entrée mod-ui',
  539. 2: 'Basse - Entrée mod-ui',
  540. 3: 'Micro - Entrée mod-ui',
  541. 4: 'Synthé - Entrée mod-ui'
  542. }
  543. var captureTitle = captureTitles[i] || ('Hardware Capture ' + i)
  544. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  545. ''',
  546. )
  547. replace_if_present(
  548. app / "html" / "js" / "pedalboard.js",
  549. ''' var playbackTitles = {
  550. 1: 'Guitar - Mod-UI Output',
  551. 2: 'Bass - Mod-UI Output',
  552. 3: 'Micro - Mod-UI Output',
  553. 4: 'Synth - Mod-UI Output'
  554. }
  555. var playbackTitle = playbackTitles[i] || ('Hardware Playback ' + i)
  556. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  557. ''',
  558. ''' var playbackTitles = {
  559. 1: 'Guitare - Sortie mod-ui',
  560. 2: 'Basse - Sortie mod-ui',
  561. 3: 'Micro - Sortie mod-ui',
  562. 4: 'Synthé - Sortie mod-ui'
  563. }
  564. var playbackTitle = playbackTitles[i] || ('Hardware Playback ' + i)
  565. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  566. ''',
  567. )
  568. replace_if_present(
  569. app / "html" / "js" / "pedalboard.js",
  570. ''' var captureTitle = (i === 1) ? 'Rigforge Mod-Host Input' : ('Hardware Capture ' + i)
  571. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  572. ''',
  573. ''' var captureTitles = {
  574. 1: 'Guitare - Entrée mod-ui',
  575. 2: 'Basse - Entrée mod-ui',
  576. 3: 'Micro - Entrée mod-ui',
  577. 4: 'Synthé - Entrée mod-ui'
  578. }
  579. var captureTitle = captureTitles[i] || ('Hardware Capture ' + i)
  580. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  581. ''',
  582. )
  583. replace_if_present(
  584. app / "html" / "js" / "pedalboard.js",
  585. ''' var playbackTitle = (i === 1) ? 'Rigforge Mod-Host Output' : ('Hardware Playback ' + i)
  586. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  587. ''',
  588. ''' var playbackTitles = {
  589. 1: 'Guitare - Sortie mod-ui',
  590. 2: 'Basse - Sortie mod-ui',
  591. 3: 'Micro - Sortie mod-ui',
  592. 4: 'Synthé - Sortie mod-ui'
  593. }
  594. var playbackTitle = playbackTitles[i] || ('Hardware Playback ' + i)
  595. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  596. ''',
  597. )
  598. replace_once(
  599. app / "html" / "js" / "pedalboard.js",
  600. ''' var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="Hardware Capture ' + i + '">')
  601. ''',
  602. ''' var captureTitles = {
  603. 1: 'Guitare - Entrée mod-ui',
  604. 2: 'Basse - Entrée mod-ui',
  605. 3: 'Micro - Entrée mod-ui',
  606. 4: 'Synthé - Entrée mod-ui'
  607. }
  608. var captureTitle = captureTitles[i] || ('Hardware Capture ' + i)
  609. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  610. ''',
  611. )
  612. replace_once(
  613. app / "html" / "js" / "pedalboard.js",
  614. ''' var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="Hardware Playback ' + i + '">')
  615. ''',
  616. ''' var playbackTitles = {
  617. 1: 'Guitare - Sortie mod-ui',
  618. 2: 'Basse - Sortie mod-ui',
  619. 3: 'Micro - Sortie mod-ui',
  620. 4: 'Synthé - Sortie mod-ui'
  621. }
  622. var playbackTitle = playbackTitles[i] || ('Hardware Playback ' + i)
  623. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  624. ''',
  625. )
  626. js_file = app / "html" / "js" / "pedalboard.js"
  627. if not js_file.read_bytes().endswith(b"\n"):
  628. js_file.write_bytes(js_file.read_bytes() + b"\n")
  629. if __name__ == "__main__":
  630. if len(sys.argv) != 2:
  631. raise SystemExit("Usage: patch_mod_ui_rigforge.py path/to/mod-ui/app")
  632. apply(Path(sys.argv[1]))