patch_mod_ui_rigforge.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  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. self.connections,
  222. attempts_left=60
  223. )
  224. continue
  225. try:
  226. if resolved is not None:
  227. port_from_2, port_to_2 = resolved[1]
  228. else:
  229. port_from_2 = self._fix_host_connection_port(port_from)
  230. port_to_2 = self._fix_host_connection_port(port_to)
  231. except Exception:
  232. continue
  233. self.send_notmodified("connect %s %s" % (port_from_2, port_to_2))
  234. self.connections.append((port_from, port_to))
  235. self.msg_callback("connect %s %s" % (port_from, port_to))'''
  236. updated = text[:block_start] + replacement + text[block_end:]
  237. if " def _rigforge_restore_pipewire_boundary(" not in updated:
  238. marker = " def load_pb_connections("
  239. position = updated.find(marker)
  240. restore_method = ''' def _rigforge_restore_pipewire_boundary(
  241. self, pipewire_link, port_from, port_to, connection_list, attempts_left
  242. ):
  243. if self.connections is not connection_list:
  244. return
  245. if not (
  246. self.rigforge_capture_ports
  247. and self.rigforge_playback_ports
  248. and len(self.audioportsIn) == len(self.rigforge_capture_ports)
  249. and len(self.audioportsOut) == len(self.rigforge_playback_ports)
  250. ):
  251. ready = False
  252. else:
  253. result = subprocess.run(
  254. ["pw-link", "-o"],
  255. check=False,
  256. capture_output=True,
  257. text=True,
  258. )
  259. ready = result.returncode == 0 and all(
  260. port in result.stdout.splitlines()
  261. for port in (
  262. *self.rigforge_capture_ports.values(),
  263. *self.rigforge_playback_ports.values(),
  264. )
  265. )
  266. if ready and connect_link(*pipewire_link):
  267. edge = (port_from, port_to)
  268. if edge not in connection_list:
  269. connection_list.append(edge)
  270. self.msg_callback("connect %s %s" % (port_from, port_to))
  271. return
  272. if attempts_left <= 1:
  273. logging.error(
  274. "[host] PipeWire backend failed to restore ports: '%s' => '%s'",
  275. pipewire_link[0], pipewire_link[1]
  276. )
  277. return
  278. IOLoop.instance().call_later(
  279. 0.5,
  280. self._rigforge_restore_pipewire_boundary,
  281. pipewire_link,
  282. port_from,
  283. port_to,
  284. connection_list,
  285. attempts_left - 1
  286. )
  287. '''
  288. if position < 0:
  289. raise RuntimeError(f"could not insert PipeWire restore method in {host}")
  290. updated = updated[:position] + restore_method + updated[position:]
  291. if updated != original_text:
  292. host.write_text(updated, encoding="utf-8")
  293. def apply(source_root):
  294. app = Path(source_root)
  295. helper = Path(__file__).with_name("mod_ui_pipewire.py")
  296. (app / "mod" / "rigforge_pipewire.py").write_bytes(helper.read_bytes())
  297. replace_if_present(
  298. app / "mod" / "host.py",
  299. "from mod import (\n",
  300. "from mod.rigforge_pipewire import boundary_connection, connect_link, disconnect_link, pedalboard_connection\n"
  301. "from mod import (\n",
  302. )
  303. replace_if_present(
  304. app / "mod" / "host.py",
  305. "import os, json, socket, time, logging, sys\n",
  306. "import os, json, socket, time, logging, sys, subprocess\n",
  307. )
  308. replace_if_present(
  309. app / "mod" / "host.py",
  310. ''' self.jack_hw_capture_prefix = "mod-host:out" if self.descriptor.get('has_noisegate', False) else "system:capture_"
  311. ''',
  312. ''' self.jack_hw_capture_prefix = "mod-host:out" if self.descriptor.get('has_noisegate', False) else "system:capture_"
  313. self.rigforge_capture_ports = {
  314. "capture_%d" % (index + 1): port
  315. for index, port in enumerate(
  316. os.environ.get("MOD_RIGFORGE_CAPTURE_PORTS", "").split(",")
  317. )
  318. if port
  319. }
  320. self.rigforge_playback_ports = {
  321. "playback_%d" % (index + 1): port
  322. for index, port in enumerate(
  323. os.environ.get("MOD_RIGFORGE_PLAYBACK_PORTS", "").split(",")
  324. )
  325. if port
  326. }
  327. ''',
  328. )
  329. replace_if_present(
  330. app / "mod" / "host.py",
  331. ''' self.rigforge_capture_port = os.environ.get("MOD_RIGFORGE_CAPTURE_PORT")
  332. self.rigforge_playback_port = os.environ.get("MOD_RIGFORGE_PLAYBACK_PORT")
  333. ''',
  334. "",
  335. )
  336. replace_if_present(
  337. app / "mod" / "host.py",
  338. ''' if self.rigforge_capture_port and self.rigforge_playback_port:
  339. # These graph symbols map to Rigforge's stable virtual PipeWire boundary ports.
  340. self.audioportsIn = ["capture_1"]
  341. self.audioportsOut = ["playback_1"]
  342. ''',
  343. ''' if self.rigforge_capture_ports and self.rigforge_playback_ports:
  344. # These graph symbols map to Rigforge's stable virtual PipeWire boundary ports.
  345. self.audioportsIn = [
  346. "capture_%d" % index
  347. for index in range(1, len(self.rigforge_capture_ports) + 1)
  348. ]
  349. self.audioportsOut = [
  350. "playback_%d" % index
  351. for index in range(1, len(self.rigforge_playback_ports) + 1)
  352. ]
  353. ''',
  354. )
  355. replace_once(
  356. app / "mod" / "host.py",
  357. ''' for port in get_jack_hardware_ports(True, False):
  358. client_name, port_name = port.split(":",1)
  359. if client_name == "mod-spi2jack":
  360. cv_port_name = CV_PREFIX + port_name
  361. self.cvportsIn.append(cv_port_name)
  362. self.addressings.add_hw_cv_port('/cv/graph/' + cv_port_name)
  363. else:
  364. self.audioportsIn.append(port_name)
  365. for port in get_jack_hardware_ports(True, True):
  366. client_name, port_name = port.split(":",1)
  367. if client_name == "mod-jack2spi":
  368. self.cvportsOut.append(CV_PREFIX + port_name)
  369. else:
  370. self.audioportsOut.append(port_name)
  371. ''',
  372. ''' if self.rigforge_capture_ports and self.rigforge_playback_ports:
  373. # These graph symbols map to Rigforge's stable virtual PipeWire boundary ports.
  374. self.audioportsIn = [
  375. "capture_%d" % index
  376. for index in range(1, len(self.rigforge_capture_ports) + 1)
  377. ]
  378. self.audioportsOut = [
  379. "playback_%d" % index
  380. for index in range(1, len(self.rigforge_playback_ports) + 1)
  381. ]
  382. else:
  383. for port in get_jack_hardware_ports(True, False):
  384. client_name, port_name = port.split(":",1)
  385. if client_name == "mod-spi2jack":
  386. cv_port_name = CV_PREFIX + port_name
  387. self.cvportsIn.append(cv_port_name)
  388. self.addressings.add_hw_cv_port('/cv/graph/' + cv_port_name)
  389. else:
  390. self.audioportsIn.append(port_name)
  391. for port in get_jack_hardware_ports(True, True):
  392. client_name, port_name = port.split(":",1)
  393. if client_name == "mod-jack2spi":
  394. self.cvportsOut.append(CV_PREFIX + port_name)
  395. else:
  396. self.audioportsOut.append(port_name)
  397. ''',
  398. )
  399. replace_if_present(
  400. app / "mod" / "host.py",
  401. ''' if data[2] == "capture_1" and self.rigforge_capture_port:
  402. return self.rigforge_capture_port
  403. if data[2] == "playback_1" and self.rigforge_playback_port:
  404. return self.rigforge_playback_port
  405. ''',
  406. ''' if data[2] in self.rigforge_capture_ports:
  407. return self.rigforge_capture_ports[data[2]]
  408. if data[2] in self.rigforge_playback_ports:
  409. return self.rigforge_playback_ports[data[2]]
  410. ''',
  411. )
  412. replace_if_present(
  413. app / "mod" / "host.py",
  414. "import os, json, socket, time, logging, sys\n",
  415. "import os, json, socket, time, logging, sys, subprocess\n",
  416. )
  417. host_file = app / "mod" / "host.py"
  418. patch_load_connections(host_file)
  419. patch_host_connection_methods(host_file)
  420. replace_if_present(
  421. app / "mod" / "session.py",
  422. ''' # Set a plugin block position within the canvas
  423. ''',
  424. ''' def ws_rigforge_patch_set(self, request_id, instance, uri, valuetype, valuedata, ws):
  425. if valuetype != "p":
  426. ws.write_message("rigforge_patch_set_ack %s 0" % request_id)
  427. return
  428. def completed(ok):
  429. status = 1 if ok else 0
  430. if ok:
  431. self.msg_callback_broadcast(
  432. "patch_set %s 1 %s %c %s" % (instance, uri, valuetype, valuedata),
  433. ws,
  434. )
  435. ws.write_message("rigforge_patch_set_ack %s %d" % (request_id, status))
  436. self.host.patch_set(instance, uri, valuedata, completed)
  437. # Set a plugin block position within the canvas
  438. ''',
  439. )
  440. replace_if_present(
  441. app / "mod" / "webserver.py",
  442. ''' elif cmd == "plugin_pos":
  443. ''',
  444. ''' elif cmd == "rigforge_patch_set":
  445. data = data[1].split(" ", 4)
  446. if len(data) != 5:
  447. self.write_message("rigforge_patch_set_ack invalid 0")
  448. return
  449. request_id, inst, uri, vtype, value = data
  450. if not request_id.isalnum():
  451. self.write_message("rigforge_patch_set_ack invalid 0")
  452. return
  453. SESSION.ws_rigforge_patch_set(
  454. request_id, inst, uri, vtype, value, self
  455. )
  456. elif cmd == "plugin_pos":
  457. ''',
  458. )
  459. replace_if_present(
  460. app / "server.py",
  461. "os.environ['MOD_DEVICE_WEBSERVER_PORT'] = '8888'",
  462. "os.environ.setdefault('MOD_DEVICE_WEBSERVER_PORT', '8888')",
  463. )
  464. replace_if_present(
  465. app / "server.py",
  466. "os.environ['MOD_DEFAULT_PEDALBOARD'] = os.path.join(ROOT, 'default.pedalboard')",
  467. "os.environ.setdefault('MOD_DEFAULT_PEDALBOARD', os.path.join(ROOT, 'default.pedalboard'))",
  468. )
  469. replace_if_present(
  470. app / "html" / "js" / "pedalboard.js",
  471. ''' var captureTitles = {
  472. 1: 'Guitar - Mod-UI Input',
  473. 2: 'Bass - Mod-UI Input',
  474. 3: 'Micro - Mod-UI Input',
  475. 4: 'Synth - Mod-UI Input'
  476. }
  477. var captureTitle = captureTitles[i] || ('Hardware Capture ' + i)
  478. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  479. ''',
  480. ''' var captureTitles = {
  481. 1: 'Guitare - Entrée mod-ui',
  482. 2: 'Basse - Entrée mod-ui',
  483. 3: 'Micro - Entrée mod-ui',
  484. 4: 'Synthé - Entrée mod-ui'
  485. }
  486. var captureTitle = captureTitles[i] || ('Hardware Capture ' + i)
  487. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  488. ''',
  489. )
  490. replace_if_present(
  491. app / "html" / "js" / "pedalboard.js",
  492. ''' var playbackTitles = {
  493. 1: 'Guitar - Mod-UI Output',
  494. 2: 'Bass - Mod-UI Output',
  495. 3: 'Micro - Mod-UI Output',
  496. 4: 'Synth - Mod-UI Output'
  497. }
  498. var playbackTitle = playbackTitles[i] || ('Hardware Playback ' + i)
  499. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  500. ''',
  501. ''' var playbackTitles = {
  502. 1: 'Guitare - Sortie mod-ui',
  503. 2: 'Basse - Sortie mod-ui',
  504. 3: 'Micro - Sortie mod-ui',
  505. 4: 'Synthé - Sortie mod-ui'
  506. }
  507. var playbackTitle = playbackTitles[i] || ('Hardware Playback ' + i)
  508. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  509. ''',
  510. )
  511. replace_if_present(
  512. app / "html" / "js" / "pedalboard.js",
  513. ''' var captureTitle = (i === 1) ? 'Rigforge Mod-Host Input' : ('Hardware Capture ' + i)
  514. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  515. ''',
  516. ''' var captureTitles = {
  517. 1: 'Guitare - Entrée mod-ui',
  518. 2: 'Basse - Entrée mod-ui',
  519. 3: 'Micro - Entrée mod-ui',
  520. 4: 'Synthé - Entrée mod-ui'
  521. }
  522. var captureTitle = captureTitles[i] || ('Hardware Capture ' + i)
  523. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  524. ''',
  525. )
  526. replace_if_present(
  527. app / "html" / "js" / "pedalboard.js",
  528. ''' var playbackTitle = (i === 1) ? 'Rigforge Mod-Host Output' : ('Hardware Playback ' + i)
  529. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  530. ''',
  531. ''' var playbackTitles = {
  532. 1: 'Guitare - Sortie mod-ui',
  533. 2: 'Basse - Sortie mod-ui',
  534. 3: 'Micro - Sortie mod-ui',
  535. 4: 'Synthé - Sortie mod-ui'
  536. }
  537. var playbackTitle = playbackTitles[i] || ('Hardware Playback ' + i)
  538. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  539. ''',
  540. )
  541. replace_once(
  542. app / "html" / "js" / "pedalboard.js",
  543. ''' var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="Hardware Capture ' + i + '">')
  544. ''',
  545. ''' var captureTitles = {
  546. 1: 'Guitare - Entrée mod-ui',
  547. 2: 'Basse - Entrée mod-ui',
  548. 3: 'Micro - Entrée mod-ui',
  549. 4: 'Synthé - Entrée mod-ui'
  550. }
  551. var captureTitle = captureTitles[i] || ('Hardware Capture ' + i)
  552. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  553. ''',
  554. )
  555. replace_once(
  556. app / "html" / "js" / "pedalboard.js",
  557. ''' var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="Hardware Playback ' + i + '">')
  558. ''',
  559. ''' var playbackTitles = {
  560. 1: 'Guitare - Sortie mod-ui',
  561. 2: 'Basse - Sortie mod-ui',
  562. 3: 'Micro - Sortie mod-ui',
  563. 4: 'Synthé - Sortie mod-ui'
  564. }
  565. var playbackTitle = playbackTitles[i] || ('Hardware Playback ' + i)
  566. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  567. ''',
  568. )
  569. js_file = app / "html" / "js" / "pedalboard.js"
  570. if not js_file.read_bytes().endswith(b"\n"):
  571. js_file.write_bytes(js_file.read_bytes() + b"\n")
  572. if __name__ == "__main__":
  573. if len(sys.argv) != 2:
  574. raise SystemExit("Usage: patch_mod_ui_rigforge.py path/to/mod-ui/app")
  575. apply(Path(sys.argv[1]))