patch_mod_ui_rigforge.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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 apply(source_root):
  20. app = Path(source_root)
  21. helper = Path(__file__).with_name("mod_ui_pipewire.py")
  22. (app / "mod" / "rigforge_pipewire.py").write_bytes(helper.read_bytes())
  23. replace_if_present(
  24. app / "mod" / "host.py",
  25. "from mod import (\n",
  26. "from mod.rigforge_pipewire import boundary_connection, connect_link, disconnect_link, pedalboard_connection\n"
  27. "from mod import (\n",
  28. )
  29. replace_if_present(
  30. app / "mod" / "host.py",
  31. ''' self.jack_hw_capture_prefix = "mod-host:out" if self.descriptor.get('has_noisegate', False) else "system:capture_"
  32. ''',
  33. ''' self.jack_hw_capture_prefix = "mod-host:out" if self.descriptor.get('has_noisegate', False) else "system:capture_"
  34. self.rigforge_capture_ports = {
  35. "capture_%d" % (index + 1): port
  36. for index, port in enumerate(
  37. os.environ.get("MOD_RIGFORGE_CAPTURE_PORTS", "").split(",")
  38. )
  39. if port
  40. }
  41. self.rigforge_playback_ports = {
  42. "playback_%d" % (index + 1): port
  43. for index, port in enumerate(
  44. os.environ.get("MOD_RIGFORGE_PLAYBACK_PORTS", "").split(",")
  45. )
  46. if port
  47. }
  48. ''',
  49. )
  50. replace_if_present(
  51. app / "mod" / "host.py",
  52. ''' self.rigforge_capture_port = os.environ.get("MOD_RIGFORGE_CAPTURE_PORT")
  53. self.rigforge_playback_port = os.environ.get("MOD_RIGFORGE_PLAYBACK_PORT")
  54. ''',
  55. "",
  56. )
  57. replace_if_present(
  58. app / "mod" / "host.py",
  59. ''' if self.rigforge_capture_port and self.rigforge_playback_port:
  60. # These graph symbols map to Rigforge's stable virtual PipeWire boundary ports.
  61. self.audioportsIn = ["capture_1"]
  62. self.audioportsOut = ["playback_1"]
  63. ''',
  64. ''' if self.rigforge_capture_ports and self.rigforge_playback_ports:
  65. # These graph symbols map to Rigforge's stable virtual PipeWire boundary ports.
  66. self.audioportsIn = [
  67. "capture_%d" % index
  68. for index in range(1, len(self.rigforge_capture_ports) + 1)
  69. ]
  70. self.audioportsOut = [
  71. "playback_%d" % index
  72. for index in range(1, len(self.rigforge_playback_ports) + 1)
  73. ]
  74. ''',
  75. )
  76. replace_once(
  77. app / "mod" / "host.py",
  78. ''' for port in get_jack_hardware_ports(True, False):
  79. client_name, port_name = port.split(":",1)
  80. if client_name == "mod-spi2jack":
  81. cv_port_name = CV_PREFIX + port_name
  82. self.cvportsIn.append(cv_port_name)
  83. self.addressings.add_hw_cv_port('/cv/graph/' + cv_port_name)
  84. else:
  85. self.audioportsIn.append(port_name)
  86. for port in get_jack_hardware_ports(True, True):
  87. client_name, port_name = port.split(":",1)
  88. if client_name == "mod-jack2spi":
  89. self.cvportsOut.append(CV_PREFIX + port_name)
  90. else:
  91. self.audioportsOut.append(port_name)
  92. ''',
  93. ''' if self.rigforge_capture_ports and self.rigforge_playback_ports:
  94. # These graph symbols map to Rigforge's stable virtual PipeWire boundary ports.
  95. self.audioportsIn = [
  96. "capture_%d" % index
  97. for index in range(1, len(self.rigforge_capture_ports) + 1)
  98. ]
  99. self.audioportsOut = [
  100. "playback_%d" % index
  101. for index in range(1, len(self.rigforge_playback_ports) + 1)
  102. ]
  103. else:
  104. for port in get_jack_hardware_ports(True, False):
  105. client_name, port_name = port.split(":",1)
  106. if client_name == "mod-spi2jack":
  107. cv_port_name = CV_PREFIX + port_name
  108. self.cvportsIn.append(cv_port_name)
  109. self.addressings.add_hw_cv_port('/cv/graph/' + cv_port_name)
  110. else:
  111. self.audioportsIn.append(port_name)
  112. for port in get_jack_hardware_ports(True, True):
  113. client_name, port_name = port.split(":",1)
  114. if client_name == "mod-jack2spi":
  115. self.cvportsOut.append(CV_PREFIX + port_name)
  116. else:
  117. self.audioportsOut.append(port_name)
  118. ''',
  119. )
  120. replace_if_present(
  121. app / "mod" / "host.py",
  122. ''' if data[2] == "capture_1" and self.rigforge_capture_port:
  123. return self.rigforge_capture_port
  124. if data[2] == "playback_1" and self.rigforge_playback_port:
  125. return self.rigforge_playback_port
  126. ''',
  127. ''' if data[2] in self.rigforge_capture_ports:
  128. return self.rigforge_capture_ports[data[2]]
  129. if data[2] in self.rigforge_playback_ports:
  130. return self.rigforge_playback_ports[data[2]]
  131. ''',
  132. )
  133. replace_if_present(
  134. app / "mod" / "host.py",
  135. ''' if len(data) == 3:
  136. # Handle special cases
  137. if data[2] == "serial_midi_in":
  138. ''' + " \n",
  139. ''' if len(data) == 3:
  140. # Handle special cases
  141. if data[2] in self.rigforge_capture_ports:
  142. return self.rigforge_capture_ports[data[2]]
  143. if data[2] in self.rigforge_playback_ports:
  144. return self.rigforge_playback_ports[data[2]]
  145. if data[2] == "serial_midi_in":
  146. ''',
  147. )
  148. replace_if_present(
  149. app / "mod" / "host.py",
  150. ''' def connect(self, port_from, port_to, callback):
  151. if (port_from, port_to) in self.connections:
  152. ''',
  153. ''' def _rigforge_pipewire_boundary(self, port_from, port_to):
  154. return boundary_connection(
  155. port_from,
  156. port_to,
  157. self.rigforge_capture_ports,
  158. self.rigforge_playback_ports,
  159. self._fix_host_connection_port,
  160. )
  161. def connect(self, port_from, port_to, callback):
  162. if (port_from, port_to) in self.connections:
  163. ''',
  164. )
  165. replace_if_present(
  166. app / "mod" / "host.py",
  167. ''' def host_callback(ok):
  168. callback(ok)
  169. if ok:
  170. self.connections.append((port_from, port_to))
  171. self.msg_callback("connect %s %s" % (port_from, port_to))
  172. else:
  173. logging.error("[host] backend failed to connect ports: '%s' => '%s'", port_from, port_to)
  174. self.send_modified("connect %s %s" % (self._fix_host_connection_port(port_from),
  175. self._fix_host_connection_port(port_to)), host_callback)
  176. ''',
  177. ''' resolved = pedalboard_connection(
  178. port_from, port_to, self.rigforge_capture_ports,
  179. self.rigforge_playback_ports, self._fix_host_connection_port
  180. )
  181. if resolved is not None and resolved[0] == "pipewire":
  182. pipewire_link = resolved[1]
  183. ok = connect_link(*pipewire_link)
  184. callback(ok)
  185. if ok:
  186. self.connections.append((port_from, port_to))
  187. self.pedalboard_modified = True
  188. self.msg_callback("connect %s %s" % (port_from, port_to))
  189. else:
  190. logging.error(
  191. "[host] PipeWire backend failed to connect ports: '%s' => '%s'",
  192. pipewire_link[0], pipewire_link[1]
  193. )
  194. return
  195. def host_callback(ok):
  196. callback(ok)
  197. if ok:
  198. self.connections.append((port_from, port_to))
  199. self.msg_callback("connect %s %s" % (port_from, port_to))
  200. else:
  201. logging.error("[host] backend failed to connect ports: '%s' => '%s'", port_from, port_to)
  202. if resolved is not None:
  203. port_from_2, port_to_2 = resolved[1]
  204. else:
  205. port_from_2 = self._fix_host_connection_port(port_from)
  206. port_to_2 = self._fix_host_connection_port(port_to)
  207. self.send_modified("connect %s %s" % (port_from_2, port_to_2), host_callback)
  208. ''',
  209. )
  210. replace_once(
  211. app / "mod" / "host.py",
  212. ''' def disconnect(self, port_from, port_to, callback):
  213. def host_callback(ok):
  214. ''',
  215. ''' def disconnect(self, port_from, port_to, callback):
  216. pipewire_link = self._rigforge_pipewire_boundary(port_from, port_to)
  217. if pipewire_link is not None:
  218. ok = disconnect_link(*pipewire_link)
  219. callback(ok)
  220. if ok:
  221. self.msg_callback("disconnect %s %s" % (port_from, port_to))
  222. self.pedalboard_modified = True
  223. try:
  224. self.connections.remove((port_from, port_to))
  225. except ValueError:
  226. logging.info(
  227. "[host] Requested '%s' => '%s' connection was not in the UI state",
  228. port_from, port_to
  229. )
  230. else:
  231. logging.error(
  232. "[host] PipeWire backend failed to disconnect ports: '%s' => '%s'",
  233. pipewire_link[0], pipewire_link[1]
  234. )
  235. return
  236. def host_callback(ok):
  237. ''',
  238. )
  239. replace_if_present(
  240. app / "mod" / "host.py",
  241. ''' def load_pb_connections(self, connections, mappedOldMidiIns, mappedOldMidiOuts,
  242. mappedNewMidiIns, mappedNewMidiOuts):
  243. ''',
  244. ''' def _rigforge_restore_pipewire_boundary(
  245. self, pipewire_link, port_from, port_to, connection_list, attempts_left
  246. ):
  247. if self.connections is not connection_list:
  248. return
  249. if connect_link(*pipewire_link):
  250. edge = (port_from, port_to)
  251. if edge not in connection_list:
  252. connection_list.append(edge)
  253. self.msg_callback("connect %s %s" % (port_from, port_to))
  254. return
  255. if attempts_left <= 1:
  256. logging.error(
  257. "[host] PipeWire backend failed to restore ports: '%s' => '%s'",
  258. pipewire_link[0], pipewire_link[1]
  259. )
  260. return
  261. IOLoop.instance().call_later(
  262. 0.5,
  263. self._rigforge_restore_pipewire_boundary,
  264. pipewire_link,
  265. port_from,
  266. port_to,
  267. connection_list,
  268. attempts_left - 1
  269. )
  270. def load_pb_connections(self, connections, mappedOldMidiIns, mappedOldMidiOuts,
  271. mappedNewMidiIns, mappedNewMidiOuts):
  272. ''',
  273. )
  274. load_connections_original = ''' pipewire_link = self._rigforge_pipewire_boundary(port_from, port_to)
  275. if pipewire_link is not None:
  276. self._rigforge_restore_pipewire_boundary(
  277. pipewire_link,
  278. port_from,
  279. port_to,
  280. self.connections,
  281. attempts_left=60
  282. )
  283. continue
  284. self.send_notmodified("connect %s %s" % (port_from_2, port_to_2))
  285. self.connections.append((port_from, port_to))
  286. self.msg_callback("connect %s %s" % (port_from, port_to))
  287. '''
  288. load_connections_patched = ''' resolved = pedalboard_connection(
  289. port_from, port_to, self.rigforge_capture_ports,
  290. self.rigforge_playback_ports, self._fix_host_connection_port
  291. )
  292. if resolved is not None and resolved[0] == "pipewire":
  293. pipewire_link = resolved[1]
  294. self._rigforge_restore_pipewire_boundary(
  295. pipewire_link,
  296. port_from,
  297. port_to,
  298. self.connections,
  299. attempts_left=60
  300. )
  301. continue
  302. if resolved is not None:
  303. port_from_2, port_to_2 = resolved[1]
  304. self.send_notmodified("connect %s %s" % (port_from_2, port_to_2))
  305. self.connections.append((port_from, port_to))
  306. self.msg_callback("connect %s %s" % (port_from, port_to))
  307. '''
  308. load_connections_old = ''' pipewire_link = self._rigforge_pipewire_boundary(port_from, port_to)
  309. if pipewire_link is not None:
  310. self._rigforge_restore_pipewire_boundary(
  311. pipewire_link,
  312. port_from,
  313. port_to,
  314. self.connections,
  315. attempts_left=60
  316. )
  317. continue
  318. self.send_notmodified("connect %s %s" % (port_from_2, port_to_2))
  319. self.connections.append((port_from, port_to))
  320. '''
  321. text = (app / "mod" / "host.py").read_text(encoding="utf-8")
  322. if load_connections_patched not in text:
  323. if text.count(load_connections_original) == 1:
  324. original = load_connections_original
  325. elif text.count(load_connections_old) == 1:
  326. original = load_connections_old
  327. else:
  328. marker = " def load_pb_connections(self, connections, mappedOldMidiIns"
  329. start = text.find(marker)
  330. body = text.find(" pipewire_link = self._rigforge_pipewire_boundary(port_from, port_to)", start)
  331. if start < 0 or body < 0:
  332. raise RuntimeError("could not identify mod-ui pedalboard connection restoration block")
  333. end = text.find("\n\n elif aliasname1", body)
  334. if end < 0:
  335. raise RuntimeError("could not find end of mod-ui pedalboard connection restoration block")
  336. original = text[body:end]
  337. replace_once(
  338. app / "mod" / "host.py",
  339. original,
  340. load_connections_patched.rstrip("\n"),
  341. )
  342. replace_if_present(
  343. app / "mod" / "host.py",
  344. ''' if len(data) == 3:
  345. # Handle special cases
  346. if data[2] == "serial_midi_in":
  347. ''',
  348. ''' if len(data) == 3:
  349. # Handle special cases
  350. if data[2] in self.rigforge_capture_ports:
  351. return self.rigforge_capture_ports[data[2]]
  352. if data[2] in self.rigforge_playback_ports:
  353. return self.rigforge_playback_ports[data[2]]
  354. if data[2] == "serial_midi_in":
  355. ''',
  356. )
  357. replace_if_present(
  358. app / "mod" / "host.py",
  359. ''' def host_callback(ok):
  360. callback(ok)
  361. if ok:
  362. self.connections.append((port_from, port_to))
  363. self.msg_callback("connect %s %s" % (port_from, port_to))
  364. else:
  365. logging.error("[host] backend failed to connect ports: '%s' => '%s'", port_from, port_to)
  366. self.send_modified("connect %s %s" % (self._fix_host_connection_port(port_from),
  367. self._fix_host_connection_port(port_to)), host_callback)
  368. ''',
  369. ''' pipewire_link = self._rigforge_pipewire_boundary(port_from, port_to)
  370. if pipewire_link is not None:
  371. ok = connect_link(*pipewire_link)
  372. callback(ok)
  373. if ok:
  374. self.connections.append((port_from, port_to))
  375. self.pedalboard_modified = True
  376. self.msg_callback("connect %s %s" % (port_from, port_to))
  377. else:
  378. logging.error(
  379. "[host] PipeWire backend failed to connect ports: '%s' => '%s'",
  380. pipewire_link[0], pipewire_link[1]
  381. )
  382. return
  383. def host_callback(ok):
  384. callback(ok)
  385. if ok:
  386. self.connections.append((port_from, port_to))
  387. self.msg_callback("connect %s %s" % (port_from, port_to))
  388. else:
  389. logging.error("[host] backend failed to connect ports: '%s' => '%s'", port_from, port_to)
  390. self.send_modified("connect %s %s" % (self._fix_host_connection_port(port_from),
  391. self._fix_host_connection_port(port_to)), host_callback)
  392. ''',
  393. )
  394. replace_once(
  395. app / "mod" / "host.py",
  396. ''' def disconnect(self, port_from, port_to, callback):
  397. def host_callback(ok):
  398. ''',
  399. ''' def disconnect(self, port_from, port_to, callback):
  400. pipewire_link = self._rigforge_pipewire_boundary(port_from, port_to)
  401. if pipewire_link is not None:
  402. ok = disconnect_link(*pipewire_link)
  403. callback(ok)
  404. if ok:
  405. self.msg_callback("disconnect %s %s" % (port_from, port_to))
  406. self.pedalboard_modified = True
  407. try:
  408. self.connections.remove((port_from, port_to))
  409. except ValueError:
  410. logging.info(
  411. "[host] Requested '%s' => '%s' connection was not in the UI state",
  412. port_from, port_to
  413. )
  414. else:
  415. logging.error(
  416. "[host] PipeWire backend failed to disconnect ports: '%s' => '%s'",
  417. pipewire_link[0], pipewire_link[1]
  418. )
  419. return
  420. def host_callback(ok):
  421. ''',
  422. )
  423. replace_if_present(
  424. app / "mod" / "session.py",
  425. ''' # Set a plugin block position within the canvas
  426. ''',
  427. ''' def ws_rigforge_patch_set(self, request_id, instance, uri, valuetype, valuedata, ws):
  428. if valuetype != "p":
  429. ws.write_message("rigforge_patch_set_ack %s 0" % request_id)
  430. return
  431. def completed(ok):
  432. status = 1 if ok else 0
  433. if ok:
  434. self.msg_callback_broadcast(
  435. "patch_set %s 1 %s %c %s" % (instance, uri, valuetype, valuedata),
  436. ws,
  437. )
  438. ws.write_message("rigforge_patch_set_ack %s %d" % (request_id, status))
  439. self.host.patch_set(instance, uri, valuedata, completed)
  440. # Set a plugin block position within the canvas
  441. ''',
  442. )
  443. replace_if_present(
  444. app / "mod" / "webserver.py",
  445. ''' elif cmd == "plugin_pos":
  446. ''',
  447. ''' elif cmd == "rigforge_patch_set":
  448. data = data[1].split(" ", 4)
  449. if len(data) != 5:
  450. self.write_message("rigforge_patch_set_ack invalid 0")
  451. return
  452. request_id, inst, uri, vtype, value = data
  453. if not request_id.isalnum():
  454. self.write_message("rigforge_patch_set_ack invalid 0")
  455. return
  456. SESSION.ws_rigforge_patch_set(
  457. request_id, inst, uri, vtype, value, self
  458. )
  459. elif cmd == "plugin_pos":
  460. ''',
  461. )
  462. replace_if_present(
  463. app / "server.py",
  464. "os.environ['MOD_DEVICE_WEBSERVER_PORT'] = '8888'",
  465. "os.environ.setdefault('MOD_DEVICE_WEBSERVER_PORT', '8888')",
  466. )
  467. replace_if_present(
  468. app / "server.py",
  469. "os.environ['MOD_DEFAULT_PEDALBOARD'] = os.path.join(ROOT, 'default.pedalboard')",
  470. "os.environ.setdefault('MOD_DEFAULT_PEDALBOARD', os.path.join(ROOT, 'default.pedalboard'))",
  471. )
  472. replace_if_present(
  473. app / "html" / "js" / "pedalboard.js",
  474. ''' var captureTitles = {
  475. 1: 'Guitar - Mod-UI Input',
  476. 2: 'Bass - Mod-UI Input',
  477. 3: 'Micro - Mod-UI Input',
  478. 4: 'Synth - Mod-UI Input'
  479. }
  480. var captureTitle = captureTitles[i] || ('Hardware Capture ' + i)
  481. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  482. ''',
  483. ''' var captureTitles = {
  484. 1: 'Guitare - Entrée mod-ui',
  485. 2: 'Basse - Entrée mod-ui',
  486. 3: 'Micro - Entrée mod-ui',
  487. 4: 'Synthé - Entrée mod-ui'
  488. }
  489. var captureTitle = captureTitles[i] || ('Hardware Capture ' + i)
  490. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  491. ''',
  492. )
  493. replace_if_present(
  494. app / "html" / "js" / "pedalboard.js",
  495. ''' var playbackTitles = {
  496. 1: 'Guitar - Mod-UI Output',
  497. 2: 'Bass - Mod-UI Output',
  498. 3: 'Micro - Mod-UI Output',
  499. 4: 'Synth - Mod-UI Output'
  500. }
  501. var playbackTitle = playbackTitles[i] || ('Hardware Playback ' + i)
  502. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  503. ''',
  504. ''' var playbackTitles = {
  505. 1: 'Guitare - Sortie mod-ui',
  506. 2: 'Basse - Sortie mod-ui',
  507. 3: 'Micro - Sortie mod-ui',
  508. 4: 'Synthé - Sortie mod-ui'
  509. }
  510. var playbackTitle = playbackTitles[i] || ('Hardware Playback ' + i)
  511. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  512. ''',
  513. )
  514. replace_if_present(
  515. app / "html" / "js" / "pedalboard.js",
  516. ''' var captureTitle = (i === 1) ? 'Rigforge Mod-Host Input' : ('Hardware Capture ' + i)
  517. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  518. ''',
  519. ''' var captureTitles = {
  520. 1: 'Guitare - Entrée mod-ui',
  521. 2: 'Basse - Entrée mod-ui',
  522. 3: 'Micro - Entrée mod-ui',
  523. 4: 'Synthé - Entrée mod-ui'
  524. }
  525. var captureTitle = captureTitles[i] || ('Hardware Capture ' + i)
  526. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  527. ''',
  528. )
  529. replace_if_present(
  530. app / "html" / "js" / "pedalboard.js",
  531. ''' var playbackTitle = (i === 1) ? 'Rigforge Mod-Host Output' : ('Hardware Playback ' + i)
  532. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  533. ''',
  534. ''' var playbackTitles = {
  535. 1: 'Guitare - Sortie mod-ui',
  536. 2: 'Basse - Sortie mod-ui',
  537. 3: 'Micro - Sortie mod-ui',
  538. 4: 'Synthé - Sortie mod-ui'
  539. }
  540. var playbackTitle = playbackTitles[i] || ('Hardware Playback ' + i)
  541. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  542. ''',
  543. )
  544. replace_once(
  545. app / "html" / "js" / "pedalboard.js",
  546. ''' var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="Hardware Capture ' + i + '">')
  547. ''',
  548. ''' var captureTitles = {
  549. 1: 'Guitare - Entrée mod-ui',
  550. 2: 'Basse - Entrée mod-ui',
  551. 3: 'Micro - Entrée mod-ui',
  552. 4: 'Synthé - Entrée mod-ui'
  553. }
  554. var captureTitle = captureTitles[i] || ('Hardware Capture ' + i)
  555. var hw = $('<div class="ignore-arrive hardware-output" mod-port-index="' + i + '" title="' + captureTitle + '">')
  556. ''',
  557. )
  558. replace_once(
  559. app / "html" / "js" / "pedalboard.js",
  560. ''' var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="Hardware Playback ' + i + '">')
  561. ''',
  562. ''' var playbackTitles = {
  563. 1: 'Guitare - Sortie mod-ui',
  564. 2: 'Basse - Sortie mod-ui',
  565. 3: 'Micro - Sortie mod-ui',
  566. 4: 'Synthé - Sortie mod-ui'
  567. }
  568. var playbackTitle = playbackTitles[i] || ('Hardware Playback ' + i)
  569. var hw = $('<div class="ignore-arrive hardware-input" mod-port-index="' + i + '" title="' + playbackTitle + '">')
  570. ''',
  571. )
  572. js_file = app / "html" / "js" / "pedalboard.js"
  573. if not js_file.read_bytes().endswith(b"\n"):
  574. js_file.write_bytes(js_file.read_bytes() + b"\n")
  575. if __name__ == "__main__":
  576. if len(sys.argv) != 2:
  577. raise SystemExit("Usage: patch_mod_ui_rigforge.py path/to/mod-ui/app")
  578. apply(Path(sys.argv[1]))