test_mod_ui_pedalboard.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import json
  2. import sys
  3. import tempfile
  4. import unittest
  5. from pathlib import Path
  6. import yaml
  7. ROOT = Path(__file__).resolve().parents[1]
  8. sys.path.insert(0, str(ROOT / "scripts"))
  9. from generate_mod_ui_pedalboard import generate_bundle_files, write_bundle
  10. from validate_desired_state import validate_state
  11. class ModUiPedalboardTests(unittest.TestCase):
  12. @classmethod
  13. def setUpClass(cls):
  14. cls.state = yaml.safe_load(
  15. (ROOT / "config" / "desired-state.yaml").read_text(encoding="utf-8")
  16. )
  17. def test_generated_bundle_has_nam_ir_state_and_boundary_cables(self):
  18. files = generate_bundle_files(self.state, ROOT)
  19. ttl = files["rigforge-guitar.ttl"].decode("utf-8")
  20. self.assertIn(
  21. 'doap:name "Rigforge - Guitare NAM/IR, Basse, Micro, Synthé"',
  22. ttl,
  23. )
  24. self.assertIn('lv2:name "Guitare - Entrée mod-ui"', ttl)
  25. self.assertIn('lv2:name "Guitare - Sortie mod-ui"', ttl)
  26. self.assertIn("<control_in>", ttl)
  27. self.assertIn("<control_out>", ttl)
  28. self.assertIn("<midi_separated_mode>", ttl)
  29. self.assertIn("state:state [", ttl)
  30. self.assertIn(
  31. f'<{self.state["routing"]["mod_host_chains"]["guitar"]["processors"][0]["file_property"]}>',
  32. ttl,
  33. )
  34. self.assertIn(
  35. '<http://lsp-plug.in/plugins/lv2/impulse_responses_mono/ports#ifn>',
  36. ttl,
  37. )
  38. self.assertIn("ingen:tail <rigforge_nam/output>", ttl)
  39. self.assertIn("ingen:head <rigforge_ir/in>", ttl)
  40. self.assertIn("ingen:tail <capture_1>", ttl)
  41. self.assertIn("ingen:head <rigforge_nam/input>", ttl)
  42. self.assertIn("ingen:tail <rigforge_ir/out>", ttl)
  43. self.assertIn("ingen:head <playback_1>", ttl)
  44. voice_chain = self.state["routing"]["mod_host_chains"]["voice"]
  45. voice_processors = voice_chain["processors"]
  46. self.assertIn("<rigforge_voice_high_pass>", ttl)
  47. self.assertIn("<rigforge_voice_compressor>", ttl)
  48. self.assertIn("<rigforge_voice_de_esser>", ttl)
  49. self.assertIn("<rigforge_voice_reverb>", ttl)
  50. self.assertIn('pedal:instanceLabel "Coupe-bas"', ttl)
  51. self.assertIn('pedal:instanceLabel "Compresseur voix"', ttl)
  52. self.assertIn('pedal:instanceLabel "De-esser"', ttl)
  53. self.assertIn('pedal:instanceLabel "Réverbération voix"', ttl)
  54. self.assertIn("ingen:tail <capture_3>", ttl)
  55. self.assertIn("ingen:head <rigforge_voice_high_pass/in>", ttl)
  56. self.assertIn(
  57. "ingen:tail <rigforge_voice_high_pass/out>", ttl
  58. )
  59. self.assertIn(
  60. "ingen:head <rigforge_voice_compressor/in>", ttl
  61. )
  62. self.assertIn(
  63. "ingen:tail <rigforge_voice_de_esser/out>", ttl
  64. )
  65. self.assertIn(
  66. "ingen:head <rigforge_voice_reverb/input_l>", ttl
  67. )
  68. self.assertIn(
  69. "a lv2:AudioPort, lv2:InputPort .",
  70. ttl[ttl.index("<rigforge_voice_reverb/input_r>") :],
  71. )
  72. self.assertIn("<rigforge_voice_reverb/output_r>", ttl)
  73. self.assertIn("ingen:head <playback_3>", ttl)
  74. for index, processor in enumerate(voice_processors):
  75. instance = processor["mod_ui_instance"].removeprefix("/graph/")
  76. self.assertIn(f"lv2:prototype <{processor['plugin_uri']}>", ttl)
  77. if index:
  78. previous = voice_processors[index - 1]
  79. previous_instance = previous["mod_ui_instance"].removeprefix("/graph/")
  80. previous_output = previous["output_port"].split(":", 1)[1]
  81. input_symbol = processor["input_port"].split(":", 1)[1]
  82. self.assertIn(
  83. f"ingen:tail <{previous_instance}/{previous_output}>", ttl
  84. )
  85. self.assertIn(f"ingen:head <{instance}/{input_symbol}>", ttl)
  86. nam = self.state["routing"]["mod_host_chains"]["guitar"]["processors"][0]
  87. ir = self.state["routing"]["mod_host_chains"]["guitar"]["processors"][1]
  88. nam_state = files[f"effect-{nam['instance']}/effect.ttl"].decode("utf-8")
  89. ir_state = files[f"effect-{ir['instance']}/effect.ttl"].decode("utf-8")
  90. self.assertIn(f"lv2:appliesTo <{nam['plugin_uri']}>", nam_state)
  91. self.assertIn(
  92. f'<{nam["file_property"]}> {json.dumps(str((ROOT / nam["asset_path"]).resolve()))}^^atom:Path',
  93. nam_state,
  94. )
  95. self.assertIn(f"lv2:appliesTo <{ir['plugin_uri']}>", ir_state)
  96. self.assertIn(
  97. f'<{ir["file_property"]}> {json.dumps(str((ROOT / ir["asset_path"]).resolve()))}^^atom:Path',
  98. ir_state,
  99. )
  100. self.assertIn(
  101. "<effect.ttl>\n\tlv2:appliesTo",
  102. files[f"effect-{nam['instance']}/manifest.ttl"].decode("utf-8").replace(
  103. " ", "\t"
  104. ),
  105. )
  106. for channel, label in ((2, "Basse"), (4, "Synthé")):
  107. self.assertIn(f'lv2:name "{label} - Entrée mod-ui"', ttl)
  108. self.assertIn(f'lv2:name "{label} - Sortie mod-ui"', ttl)
  109. self.assertIn(f"ingen:tail <capture_{channel}>", ttl)
  110. self.assertIn(f"ingen:head <playback_{channel}>", ttl)
  111. self.assertEqual(files["addressings.json"], b"{}\n")
  112. def test_generated_plugin_state_uses_target_model_path_with_spaces(self):
  113. with tempfile.TemporaryDirectory() as temporary:
  114. model = Path(temporary) / "NAM Models" / "Vox Crunch.nam"
  115. model.parent.mkdir()
  116. model.write_bytes(b"model")
  117. files = generate_bundle_files(
  118. self.state, ROOT, nam_model_path=model
  119. )
  120. nam = self.state["routing"]["mod_host_chains"]["guitar"]["processors"][0]
  121. nam_state = files[f"effect-{nam['instance']}/effect.ttl"].decode("utf-8")
  122. self.assertIn(f"{json.dumps(str(model.resolve()))}^^atom:Path", nam_state)
  123. def test_generated_bundle_tracks_current_desired_state(self):
  124. expected = generate_bundle_files(self.state, ROOT)
  125. with tempfile.TemporaryDirectory() as temporary:
  126. directory = Path(temporary) / "reference.pedalboard"
  127. write_bundle(directory, expected)
  128. actual = {
  129. path.relative_to(directory).as_posix(): path.read_bytes()
  130. for path in directory.rglob("*")
  131. if path.is_file()
  132. }
  133. self.assertEqual(actual, expected)
  134. self.assertEqual(validate_state(self.state), [])
  135. def test_generation_rejects_missing_asset(self):
  136. with tempfile.TemporaryDirectory() as directory:
  137. with self.assertRaisesRegex(FileNotFoundError, "missing or outside repository"):
  138. generate_bundle_files(self.state, Path(directory))
  139. if __name__ == "__main__":
  140. unittest.main()