patch_mod_ui_rigforge.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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. if edge in self.connections:
  273. self._rigforge_restore_attempts.pop(edge, None)
  274. return
  275. if not ready and attempts_left == 60:
  276. logging.error(
  277. "[host] PipeWire boundary readiness failed: inputs=%r outputs=%r "
  278. "configured_capture=%r configured_playback=%r",
  279. self.audioportsIn,
  280. self.audioportsOut,
  281. sorted(self.rigforge_capture_ports),
  282. sorted(self.rigforge_playback_ports),
  283. )
  284. if ready and connect_link(*pipewire_link):
  285. self._rigforge_restore_attempts.pop(edge, None)
  286. if edge not in self.connections:
  287. self.connections.append(edge)
  288. self.msg_callback("connect %s %s" % (port_from, port_to))
  289. return
  290. if not ready and edge not in self._rigforge_restore_attempts:
  291. logging.error(
  292. "[host] PipeWire boundary ports are not ready for restore: '%s' => '%s' "
  293. "(capture ports: %s; playback ports: %s)",
  294. pipewire_link[0],
  295. pipewire_link[1],
  296. sorted(self.rigforge_capture_ports.values()),
  297. sorted(self.rigforge_playback_ports.values()),
  298. )
  299. if attempts_left <= 1:
  300. logging.error(
  301. "[host] PipeWire backend failed to restore ports: '%s' => '%s'",
  302. pipewire_link[0], pipewire_link[1]
  303. )
  304. return
  305. self._rigforge_restore_attempts[edge] = attempts_left - 1
  306. IOLoop.instance().call_later(
  307. 0.5,
  308. self._rigforge_restore_pipewire_boundary,
  309. pipewire_link,
  310. port_from,
  311. port_to,
  312. attempts_left - 1
  313. )
  314. '''
  315. restore_marker = " def _rigforge_restore_pipewire_boundary("
  316. restore_start = updated.find(restore_marker)
  317. if restore_start >= 0:
  318. restore_end = updated.find("\n def ", restore_start + len(restore_marker))
  319. if restore_end < 0:
  320. raise RuntimeError(f"could not locate end of restore method in {host}")
  321. updated = updated[:restore_start] + restore_method.rstrip() + "\n\n" + updated[restore_end + 1:]
  322. else:
  323. marker = " def load_pb_connections("
  324. position = updated.find(marker)
  325. if position < 0:
  326. raise RuntimeError(f"could not insert PipeWire restore method in {host}")
  327. updated = updated[:position] + restore_method + updated[position:]
  328. if updated != original_text:
  329. host.write_text(updated, encoding="utf-8")
  330. def apply(source_root):
  331. app = Path(source_root)
  332. helper = Path(__file__).with_name("mod_ui_pipewire.py")
  333. (app / "mod" / "rigforge_pipewire.py").write_bytes(helper.read_bytes())
  334. replace_if_present(
  335. app / "mod" / "host.py",
  336. "from mod import (\n",
  337. "from mod.rigforge_pipewire import boundary_connection, connect_link, disconnect_link, pedalboard_connection\n"
  338. "from mod import (\n",
  339. )
  340. replace_if_present(
  341. app / "mod" / "host.py",
  342. "import os, json, socket, time, logging, sys\n",
  343. "import os, json, socket, time, logging, sys, subprocess\n",
  344. )
  345. replace_if_present(
  346. app / "mod" / "host.py",
  347. ''' self.jack_hw_capture_prefix = "mod-host:out" if self.descriptor.get('has_noisegate', False) else "system:capture_"
  348. ''',
  349. ''' self.jack_hw_capture_prefix = "mod-host:out" if self.descriptor.get('has_noisegate', False) else "system:capture_"
  350. self.rigforge_capture_ports = {
  351. "capture_%d" % (index + 1): port
  352. for index, port in enumerate(
  353. os.environ.get("MOD_RIGFORGE_CAPTURE_PORTS", "").split(",")
  354. )
  355. if port
  356. }
  357. self.rigforge_playback_ports = {
  358. "playback_%d" % (index + 1): port
  359. for index, port in enumerate(
  360. os.environ.get("MOD_RIGFORGE_PLAYBACK_PORTS", "").split(",")
  361. )
  362. if port
  363. }
  364. ''',
  365. )
  366. replace_if_present(
  367. app / "mod" / "host.py",
  368. ''' self.rigforge_capture_port = os.environ.get("MOD_RIGFORGE_CAPTURE_PORT")
  369. self.rigforge_playback_port = os.environ.get("MOD_RIGFORGE_PLAYBACK_PORT")
  370. ''',
  371. "",
  372. )
  373. replace_if_present(
  374. app / "mod" / "host.py",
  375. ''' if self.rigforge_capture_port and self.rigforge_playback_port:
  376. # These graph symbols map to Rigforge's stable virtual PipeWire boundary ports.
  377. self.audioportsIn = ["capture_1"]
  378. self.audioportsOut = ["playback_1"]
  379. ''',
  380. ''' if self.rigforge_capture_ports and self.rigforge_playback_ports:
  381. # These graph symbols map to Rigforge's stable virtual PipeWire boundary ports.
  382. self.audioportsIn = [
  383. "capture_%d" % index
  384. for index in range(1, len(self.rigforge_capture_ports) + 1)
  385. ]
  386. self.audioportsOut = [
  387. "playback_%d" % index
  388. for index in range(1, len(self.rigforge_playback_ports) + 1)
  389. ]
  390. ''',
  391. )
  392. replace_once(
  393. app / "mod" / "host.py",
  394. ''' for port in get_jack_hardware_ports(True, False):
  395. client_name, port_name = port.split(":",1)
  396. if client_name == "mod-spi2jack":
  397. cv_port_name = CV_PREFIX + port_name
  398. self.cvportsIn.append(cv_port_name)
  399. self.addressings.add_hw_cv_port('/cv/graph/' + cv_port_name)
  400. else:
  401. self.audioportsIn.append(port_name)
  402. for port in get_jack_hardware_ports(True, True):
  403. client_name, port_name = port.split(":",1)
  404. if client_name == "mod-jack2spi":
  405. self.cvportsOut.append(CV_PREFIX + port_name)
  406. else:
  407. self.audioportsOut.append(port_name)
  408. ''',
  409. ''' if self.rigforge_capture_ports and self.rigforge_playback_ports:
  410. # These graph symbols map to Rigforge's stable virtual PipeWire boundary ports.
  411. self.audioportsIn = [
  412. "capture_%d" % index
  413. for index in range(1, len(self.rigforge_capture_ports) + 1)
  414. ]
  415. self.audioportsOut = [
  416. "playback_%d" % index
  417. for index in range(1, len(self.rigforge_playback_ports) + 1)
  418. ]
  419. else:
  420. for port in get_jack_hardware_ports(True, False):
  421. client_name, port_name = port.split(":",1)
  422. if client_name == "mod-spi2jack":
  423. cv_port_name = CV_PREFIX + port_name
  424. self.cvportsIn.append(cv_port_name)
  425. self.addressings.add_hw_cv_port('/cv/graph/' + cv_port_name)
  426. else:
  427. self.audioportsIn.append(port_name)
  428. for port in get_jack_hardware_ports(True, True):
  429. client_name, port_name = port.split(":",1)
  430. if client_name == "mod-jack2spi":
  431. self.cvportsOut.append(CV_PREFIX + port_name)
  432. else:
  433. self.audioportsOut.append(port_name)
  434. ''',
  435. )
  436. replace_if_present(
  437. app / "mod" / "host.py",
  438. ''' if data[2] == "capture_1" and self.rigforge_capture_port:
  439. return self.rigforge_capture_port
  440. if data[2] == "playback_1" and self.rigforge_playback_port:
  441. return self.rigforge_playback_port
  442. ''',
  443. ''' if data[2] in self.rigforge_capture_ports:
  444. return self.rigforge_capture_ports[data[2]]
  445. if data[2] in self.rigforge_playback_ports:
  446. return self.rigforge_playback_ports[data[2]]
  447. ''',
  448. )
  449. replace_if_present(
  450. app / "mod" / "host.py",
  451. "import os, json, socket, time, logging, sys\n",
  452. "import os, json, socket, time, logging, sys, subprocess\n",
  453. )
  454. host_file = app / "mod" / "host.py"
  455. patch_load_connections(host_file)
  456. patch_host_connection_methods(host_file)
  457. replace_once(
  458. host_file,
  459. ''' if bundlepath and (bundlepath.startswith(LV2_PEDALBOARDS_DIR) or
  460. bundlepath.startswith(LV2_FACTORY_PEDALBOARDS_DIR)):
  461. save_last_bank_and_pedalboard(self.bank_id, bundlepath)
  462. else:
  463. save_last_bank_and_pedalboard(0, "")
  464. ''',
  465. ''' if bundlepath and (
  466. bundlepath.startswith(LV2_PEDALBOARDS_DIR)
  467. or bundlepath.startswith(LV2_FACTORY_PEDALBOARDS_DIR)
  468. or bundlepath.startswith(os.path.join(DATA_DIR, "references"))
  469. ):
  470. save_last_bank_and_pedalboard(self.bank_id, bundlepath)
  471. else:
  472. save_last_bank_and_pedalboard(0, "")
  473. ''',
  474. )
  475. replace_if_present(
  476. app / "mod" / "session.py",
  477. ''' # Set a plugin block position within the canvas
  478. ''',
  479. ''' def ws_rigforge_patch_set(self, request_id, instance, uri, valuetype, valuedata, ws):
  480. if valuetype != "p":
  481. ws.write_message("rigforge_patch_set_ack %s 0" % request_id)
  482. return
  483. def completed(ok):
  484. status = 1 if ok else 0
  485. if ok:
  486. self.msg_callback_broadcast(
  487. "patch_set %s 1 %s %c %s" % (instance, uri, valuetype, valuedata),
  488. ws,
  489. )
  490. ws.write_message("rigforge_patch_set_ack %s %d" % (request_id, status))
  491. self.host.patch_set(instance, uri, valuedata, completed)
  492. # Set a plugin block position within the canvas
  493. ''',
  494. )
  495. replace_if_present(
  496. app / "mod" / "webserver.py",
  497. ''' elif cmd == "plugin_pos":
  498. ''',
  499. ''' elif cmd == "rigforge_patch_set":
  500. data = data[1].split(" ", 4)
  501. if len(data) != 5:
  502. self.write_message("rigforge_patch_set_ack invalid 0")
  503. return
  504. request_id, inst, uri, vtype, value = data
  505. if not request_id.isalnum():
  506. self.write_message("rigforge_patch_set_ack invalid 0")
  507. return
  508. SESSION.ws_rigforge_patch_set(
  509. request_id, inst, uri, vtype, value, self
  510. )
  511. elif cmd == "plugin_pos":
  512. ''',
  513. )
  514. replace_if_present(
  515. app / "server.py",
  516. "os.environ['MOD_DEVICE_WEBSERVER_PORT'] = '8888'",
  517. "os.environ.setdefault('MOD_DEVICE_WEBSERVER_PORT', '8888')",
  518. )
  519. replace_if_present(
  520. app / "server.py",
  521. "os.environ['MOD_DEFAULT_PEDALBOARD'] = os.path.join(ROOT, 'default.pedalboard')",
  522. "os.environ.setdefault('MOD_DEFAULT_PEDALBOARD', os.path.join(ROOT, 'default.pedalboard'))",
  523. )
  524. replace_if_present(
  525. app / "html" / "js" / "pedalboard.js",
  526. ''' var captureTitles = {
  527. 1: 'Guitar - Mod-UI Input',
  528. 2: 'Bass - Mod-UI Input',
  529. 3: 'Micro - Mod-UI Input',
  530. 4: 'Synth - Mod-UI Input'
  531. }
  532. var captureTitle = captureTitles[i] || ('Hardware Capture ' + i)
  533. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  534. ''',
  535. ''' var captureTitles = {
  536. 1: 'Guitare - Entrée mod-ui',
  537. 2: 'Basse - Entrée mod-ui',
  538. 3: 'Micro - Entrée mod-ui',
  539. 4: 'Synthé - Entrée mod-ui'
  540. }
  541. var captureTitle = captureTitles[i] || ('Hardware Capture ' + i)
  542. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  543. ''',
  544. )
  545. replace_if_present(
  546. app / "html" / "js" / "pedalboard.js",
  547. ''' var playbackTitles = {
  548. 1: 'Guitar - Mod-UI Output',
  549. 2: 'Bass - Mod-UI Output',
  550. 3: 'Micro - Mod-UI Output',
  551. 4: 'Synth - Mod-UI Output'
  552. }
  553. var playbackTitle = playbackTitles[i] || ('Hardware Playback ' + i)
  554. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  555. ''',
  556. ''' var playbackTitles = {
  557. 1: 'Guitare - Sortie mod-ui',
  558. 2: 'Basse - Sortie mod-ui',
  559. 3: 'Micro - Sortie mod-ui',
  560. 4: 'Synthé - Sortie mod-ui'
  561. }
  562. var playbackTitle = playbackTitles[i] || ('Hardware Playback ' + i)
  563. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  564. ''',
  565. )
  566. replace_if_present(
  567. app / "html" / "js" / "pedalboard.js",
  568. ''' var captureTitle = (i === 1) ? 'Rigforge Mod-Host Input' : ('Hardware Capture ' + i)
  569. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  570. ''',
  571. ''' var captureTitles = {
  572. 1: 'Guitare - Entrée mod-ui',
  573. 2: 'Basse - Entrée mod-ui',
  574. 3: 'Micro - Entrée mod-ui',
  575. 4: 'Synthé - Entrée mod-ui'
  576. }
  577. var captureTitle = captureTitles[i] || ('Hardware Capture ' + i)
  578. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  579. ''',
  580. )
  581. replace_if_present(
  582. app / "html" / "js" / "pedalboard.js",
  583. ''' var playbackTitle = (i === 1) ? 'Rigforge Mod-Host Output' : ('Hardware Playback ' + i)
  584. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  585. ''',
  586. ''' var playbackTitles = {
  587. 1: 'Guitare - Sortie mod-ui',
  588. 2: 'Basse - Sortie mod-ui',
  589. 3: 'Micro - Sortie mod-ui',
  590. 4: 'Synthé - Sortie mod-ui'
  591. }
  592. var playbackTitle = playbackTitles[i] || ('Hardware Playback ' + i)
  593. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  594. ''',
  595. )
  596. replace_once(
  597. app / "html" / "js" / "pedalboard.js",
  598. ''' var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="Hardware Capture ' + i + '">')
  599. ''',
  600. ''' var captureTitles = {
  601. 1: 'Guitare - Entrée mod-ui',
  602. 2: 'Basse - Entrée mod-ui',
  603. 3: 'Micro - Entrée mod-ui',
  604. 4: 'Synthé - Entrée mod-ui'
  605. }
  606. var captureTitle = captureTitles[i] || ('Hardware Capture ' + i)
  607. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  608. ''',
  609. )
  610. replace_once(
  611. app / "html" / "js" / "pedalboard.js",
  612. ''' var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="Hardware Playback ' + i + '">')
  613. ''',
  614. ''' var playbackTitles = {
  615. 1: 'Guitare - Sortie mod-ui',
  616. 2: 'Basse - Sortie mod-ui',
  617. 3: 'Micro - Sortie mod-ui',
  618. 4: 'Synthé - Sortie mod-ui'
  619. }
  620. var playbackTitle = playbackTitles[i] || ('Hardware Playback ' + i)
  621. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  622. ''',
  623. )
  624. js_file = app / "html" / "js" / "pedalboard.js"
  625. if not js_file.read_bytes().endswith(b"\n"):
  626. js_file.write_bytes(js_file.read_bytes() + b"\n")
  627. if __name__ == "__main__":
  628. if len(sys.argv) != 2:
  629. raise SystemExit("Usage: patch_mod_ui_rigforge.py path/to/mod-ui/app")
  630. apply(Path(sys.argv[1]))