| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- import json
- import sys
- import tempfile
- import unittest
- from pathlib import Path
- import yaml
- ROOT = Path(__file__).resolve().parents[1]
- sys.path.insert(0, str(ROOT / "scripts"))
- from generate_mod_ui_pedalboard import generate_bundle_files, write_bundle
- from validate_desired_state import validate_state
- class ModUiPedalboardTests(unittest.TestCase):
- @classmethod
- def setUpClass(cls):
- cls.state = yaml.safe_load(
- (ROOT / "config" / "desired-state.yaml").read_text(encoding="utf-8")
- )
- def test_generated_bundle_has_nam_ir_state_and_boundary_cables(self):
- files = generate_bundle_files(self.state, ROOT)
- ttl = files["rigforge-guitar.ttl"].decode("utf-8")
- self.assertIn(
- 'doap:name "Rigforge - Guitare NAM/IR, Basse, Micro, Synthé"',
- ttl,
- )
- self.assertIn('lv2:name "Guitare - Entrée mod-ui"', ttl)
- self.assertIn('lv2:name "Guitare - Sortie mod-ui"', ttl)
- self.assertIn("<control_in>", ttl)
- self.assertIn("<control_out>", ttl)
- self.assertIn("<midi_separated_mode>", ttl)
- self.assertIn("state:state [", ttl)
- self.assertIn(
- f'<{self.state["routing"]["mod_host_chains"]["guitar"]["processors"][0]["file_property"]}>',
- ttl,
- )
- self.assertIn(
- '<http://lsp-plug.in/plugins/lv2/impulse_responses_mono/ports#ifn>',
- ttl,
- )
- self.assertIn("ingen:tail <rigforge_nam/output>", ttl)
- self.assertIn("ingen:head <rigforge_ir/in>", ttl)
- self.assertIn("ingen:tail <capture_1>", ttl)
- self.assertIn("ingen:head <rigforge_nam/input>", ttl)
- self.assertIn("ingen:tail <rigforge_ir/out>", ttl)
- self.assertIn("ingen:head <playback_1>", ttl)
- voice_chain = self.state["routing"]["mod_host_chains"]["voice"]
- voice_processors = voice_chain["processors"]
- self.assertIn("<rigforge_voice_high_pass>", ttl)
- self.assertIn("<rigforge_voice_compressor>", ttl)
- self.assertIn("<rigforge_voice_de_esser>", ttl)
- self.assertIn("<rigforge_voice_reverb>", ttl)
- self.assertIn('pedal:instanceLabel "Coupe-bas"', ttl)
- self.assertIn('pedal:instanceLabel "Compresseur voix"', ttl)
- self.assertIn('pedal:instanceLabel "De-esser"', ttl)
- self.assertIn('pedal:instanceLabel "Réverbération voix"', ttl)
- self.assertIn("ingen:tail <capture_3>", ttl)
- self.assertIn("ingen:head <rigforge_voice_high_pass/in>", ttl)
- self.assertIn(
- "ingen:tail <rigforge_voice_high_pass/out>", ttl
- )
- self.assertIn(
- "ingen:head <rigforge_voice_compressor/in>", ttl
- )
- self.assertIn(
- "ingen:tail <rigforge_voice_de_esser/out>", ttl
- )
- self.assertIn(
- "ingen:head <rigforge_voice_reverb/input_l>", ttl
- )
- self.assertIn(
- "a lv2:AudioPort, lv2:InputPort .",
- ttl[ttl.index("<rigforge_voice_reverb/input_r>") :],
- )
- self.assertIn("<rigforge_voice_reverb/output_r>", ttl)
- self.assertIn("ingen:head <playback_3>", ttl)
- for index, processor in enumerate(voice_processors):
- instance = processor["mod_ui_instance"].removeprefix("/graph/")
- self.assertIn(f"lv2:prototype <{processor['plugin_uri']}>", ttl)
- if index:
- previous = voice_processors[index - 1]
- previous_instance = previous["mod_ui_instance"].removeprefix("/graph/")
- previous_output = previous["output_port"].split(":", 1)[1]
- input_symbol = processor["input_port"].split(":", 1)[1]
- self.assertIn(
- f"ingen:tail <{previous_instance}/{previous_output}>", ttl
- )
- self.assertIn(f"ingen:head <{instance}/{input_symbol}>", ttl)
- nam = self.state["routing"]["mod_host_chains"]["guitar"]["processors"][0]
- ir = self.state["routing"]["mod_host_chains"]["guitar"]["processors"][1]
- nam_state = files[f"effect-{nam['instance']}/effect.ttl"].decode("utf-8")
- ir_state = files[f"effect-{ir['instance']}/effect.ttl"].decode("utf-8")
- self.assertIn(f"lv2:appliesTo <{nam['plugin_uri']}>", nam_state)
- self.assertIn(
- f'<{nam["file_property"]}> {json.dumps(str((ROOT / nam["asset_path"]).resolve()))}^^atom:Path',
- nam_state,
- )
- self.assertIn(f"lv2:appliesTo <{ir['plugin_uri']}>", ir_state)
- self.assertIn(
- f'<{ir["file_property"]}> {json.dumps(str((ROOT / ir["asset_path"]).resolve()))}^^atom:Path',
- ir_state,
- )
- self.assertIn(
- "<effect.ttl>\n\tlv2:appliesTo",
- files[f"effect-{nam['instance']}/manifest.ttl"].decode("utf-8").replace(
- " ", "\t"
- ),
- )
- for channel, label in ((2, "Basse"), (4, "Synthé")):
- self.assertIn(f'lv2:name "{label} - Entrée mod-ui"', ttl)
- self.assertIn(f'lv2:name "{label} - Sortie mod-ui"', ttl)
- self.assertIn(f"ingen:tail <capture_{channel}>", ttl)
- self.assertIn(f"ingen:head <playback_{channel}>", ttl)
- self.assertEqual(files["addressings.json"], b"{}\n")
- def test_generated_plugin_state_uses_target_model_path_with_spaces(self):
- with tempfile.TemporaryDirectory() as temporary:
- model = Path(temporary) / "NAM Models" / "Vox Crunch.nam"
- model.parent.mkdir()
- model.write_bytes(b"model")
- files = generate_bundle_files(
- self.state, ROOT, nam_model_path=model
- )
- nam = self.state["routing"]["mod_host_chains"]["guitar"]["processors"][0]
- nam_state = files[f"effect-{nam['instance']}/effect.ttl"].decode("utf-8")
- self.assertIn(f"{json.dumps(str(model.resolve()))}^^atom:Path", nam_state)
- def test_generated_bundle_tracks_current_desired_state(self):
- expected = generate_bundle_files(self.state, ROOT)
- with tempfile.TemporaryDirectory() as temporary:
- directory = Path(temporary) / "reference.pedalboard"
- write_bundle(directory, expected)
- actual = {
- path.relative_to(directory).as_posix(): path.read_bytes()
- for path in directory.rglob("*")
- if path.is_file()
- }
- self.assertEqual(actual, expected)
- self.assertEqual(validate_state(self.state), [])
- def test_generation_rejects_missing_asset(self):
- with tempfile.TemporaryDirectory() as directory:
- with self.assertRaisesRegex(FileNotFoundError, "missing or outside repository"):
- generate_bundle_files(self.state, Path(directory))
- if __name__ == "__main__":
- unittest.main()
|