def test_move(self): builder = Lv2EffectBuilder() a = builder.build('http://calf.sourceforge.net/plugins/Reverb') b = builder.build('http://calf.sourceforge.net/plugins/Reverb') c = builder.build('http://calf.sourceforge.net/plugins/Reverb') d = builder.build('http://calf.sourceforge.net/plugins/Reverb') lista = RestrictionList() lista.append(a) lista.append(b) lista.append(c) lista.append(d) lista.observer = MagicMock() new_index = 2 old_index = lista.index(a) lista.move(a, new_index) self.assertEqual(lista.index(a), new_index) self.assertListEqual([b, c, a, d], list(lista)) expected = [ call(UpdateType.DELETED, a, old_index), call(UpdateType.CREATED, a, new_index) ] self.assertListEqual(expected, lista.observer.call_args_list)
def mod_converter(self): path = Path('/home/paulo/git/mod/mod_ui/') #builder = MagicMock() builder = Lv2EffectBuilder(ignore_unsupported_plugins=False) # builder.reload(builder.lv2_plugins_data()) return ModPedalboardConverter(path, builder, ignore_errors=True)
def test_json(self): bank = Bank('Bank 1') pedalboard = Pedalboard('Rocksmith') builder = Lv2EffectBuilder() system_effect = SystemEffect('system', ('capture_1', 'capture_2'), ('playback_1', 'playback_2')) reverb = builder.build('http://calf.sourceforge.net/plugins/Reverb') filter = builder.build('http://calf.sourceforge.net/plugins/Filter') reverb2 = builder.build('http://calf.sourceforge.net/plugins/Reverb') pedalboard.append(reverb) pedalboard.append(filter) pedalboard.append(reverb2) pedalboard.connect(system_effect.outputs[0], reverb.inputs[0]) pedalboard.connect(reverb.outputs[0], filter.inputs[0]) pedalboard.connect(reverb.outputs[1], filter.inputs[0]) pedalboard.connect(filter.outputs[0], reverb2.inputs[0]) pedalboard.connect(reverb.outputs[0], reverb2.inputs[0]) pedalboard.connect(reverb.outputs[0], system_effect.inputs[0]) bank.append(pedalboard) print(json.dumps(bank.json, sort_keys=True, indent=2))
class Test(unittest.TestCase): address = 'http://localhost:3000/v1/' SUCCESS = 200 CREATED = 201 UPDATED = 200 DELETED = 200 ERROR = 400 rest = RestFacade() plugins_builder = Lv2EffectBuilder() def setUp(self): try: self.rest.get('') except requests.exceptions.ConnectionError: self.fail("Server is down") @property def default_bank_mock(self): bank = BankMock('REST - Default Bank' + str(uuid.uuid4())) pedalboard = Pedalboard('REST - Default Pedalboard') reverb = self.plugins_builder.build('http://calf.sourceforge.net/plugins/Reverb') reverb2 = self.plugins_builder.build('http://calf.sourceforge.net/plugins/Reverb') bank.append(pedalboard) pedalboard.append(reverb) pedalboard.append(reverb2) reverb.outputs[0].connect(reverb2.inputs[0]) return bank
def test_delete_effect_remove_your_connections(self): pedalboard = Pedalboard('Pedalboard name') builder = Lv2EffectBuilder() reverb = builder.build('http://calf.sourceforge.net/plugins/Reverb') filter = builder.build('http://calf.sourceforge.net/plugins/Filter') reverb2 = builder.build('http://calf.sourceforge.net/plugins/Reverb') pedalboard.append(reverb) pedalboard.append(filter) pedalboard.append(reverb2) reverb.outputs[0].connect(filter.inputs[0]) reverb.outputs[1].connect(filter.inputs[0]) filter.outputs[0].connect(reverb2.inputs[0]) reverb.outputs[0].connect(reverb2.inputs[0]) self.assertEqual(4, len(pedalboard.connections)) pedalboard.observer = MagicMock() fuzz_connections = filter.connections pedalboard.effects.remove(filter) self.assertEqual(1, len(pedalboard.connections)) for connection in fuzz_connections: pedalboard.observer.on_connection_updated.assert_any_call( connection, UpdateType.DELETED, pedalboard=pedalboard)
def test_swap_not_equals_effects(self): builder = Lv2EffectBuilder() a = builder.build('http://calf.sourceforge.net/plugins/Reverb') b = builder.build('http://calf.sourceforge.net/plugins/Reverb') lista = RestrictionList() lista.append(a) listb = RestrictionList() listb.append(b) lista.observer = MagicMock() listb.observer = MagicMock() lista[0], listb[0] = listb[0], lista[0] self.assertEqual(b, lista[0]) self.assertEqual(a, listb[0]) lista.observer.assert_called_once_with(UpdateType.UPDATED, lista[0], 0, old=listb[0]) listb.observer.assert_called_once_with(UpdateType.UPDATED, listb[0], 0, old=lista[0])
def test_insert_repeated(self): builder = Lv2EffectBuilder() element = builder.build('http://calf.sourceforge.net/plugins/Reverb') lista = EffectsList() lista.insert(1, element) with self.assertRaises(AlreadyAddedError): lista.insert(1, element)
def test_append(self): builder = Lv2EffectBuilder() element = builder.build('http://calf.sourceforge.net/plugins/Reverb') lista = RestrictionList() lista.observer = MagicMock() lista.append(element) lista.observer.assert_called_once_with(UpdateType.CREATED, element, 0)
def test_del_not_repeated(self): builder = Lv2EffectBuilder() element1 = builder.build('http://calf.sourceforge.net/plugins/Reverb') lista = EffectsList() lista.append(element1) del lista[0] # Now will raises lista.append(element1)
def test_observers(self): mock = MagicMock() observer = Autosaver('data/test/') observer.save = mock observer.delete = mock manager = BanksManager() manager.register(observer) bank = Bank('Bank 1') manager.append(bank) observer.save.assert_called_with(bank) pedalboard = Pedalboard('Rocksmith') bank.append(pedalboard) observer.save.assert_called_with(bank) builder = Lv2EffectBuilder() reverb = builder.build('http://calf.sourceforge.net/plugins/Reverb') filter = builder.build('http://calf.sourceforge.net/plugins/Filter') reverb2 = builder.build('http://calf.sourceforge.net/plugins/Reverb') pedalboard.append(reverb) observer.save.assert_called_with(bank) pedalboard.append(filter) observer.save.assert_called_with(bank) pedalboard.append(reverb2) observer.save.assert_called_with(bank) reverb.outputs[0].connect(filter.inputs[0]) observer.save.assert_called_with(bank) reverb.outputs[1].connect(filter.inputs[0]) observer.save.assert_called_with(bank) filter.outputs[0].connect(reverb2.inputs[0]) observer.save.assert_called_with(bank) reverb.outputs[0].connect(reverb2.inputs[0]) observer.save.assert_called_with(bank) filter.toggle() observer.save.assert_called_with(bank) filter.params[0].value = (filter.params[0].maximum - filter.params[0].minimum) / 2 observer.save.assert_called_with(bank) del bank.pedalboards[0] observer.save.assert_called_with(bank) bank2 = Bank('Bank 2') manager.banks[0] = bank2 observer.delete.assert_called_with(bank2) observer.save.assert_called_with(bank2) manager.banks.remove(bank2) observer.delete.assert_called_with(bank2)
def test__setitem__repeated(self): builder = Lv2EffectBuilder() element1 = builder.build('http://calf.sourceforge.net/plugins/Reverb') element2 = builder.build('http://calf.sourceforge.net/plugins/Reverb') lista = EffectsList() lista.append(element1) lista.append(element2) lista[0] = element1 # Same effect - Ok with self.assertRaises(AlreadyAddedError): lista[1] = element1 # Different effect - Error
def test__setitem__repeated(self): builder = Lv2EffectBuilder() element1 = MagicMock() element2 = MagicMock() lista = ConnectionsList(MagicMock()) lista.append(element1) lista.append(element2) lista[0] = element1 # Same effect - Ok with self.assertRaises(AlreadyAddedError): lista[1] = element1 # Different effect - Error
def test_remove(self): builder = Lv2EffectBuilder() element1 = builder.build('http://calf.sourceforge.net/plugins/Reverb') element2 = builder.build('http://calf.sourceforge.net/plugins/Reverb') element3 = builder.build('http://calf.sourceforge.net/plugins/Reverb') lista = RestrictionList() lista.append(element1) lista.append(element2) lista.append(element3) lista.observer = MagicMock() lista.remove(element2) lista.observer.assert_called_once_with(UpdateType.DELETED, element2, 1)
def test__setitem_equal__(self): builder = Lv2EffectBuilder() a = builder.build('http://calf.sourceforge.net/plugins/Reverb') b = builder.build('http://calf.sourceforge.net/plugins/Reverb') c = builder.build('http://calf.sourceforge.net/plugins/Reverb') lista = RestrictionList() lista.append(a) lista.append(b) lista.append(c) lista.observer = MagicMock() lista[1] = b lista.observer.assert_not_called()
def test_swap(self): builder = Lv2EffectBuilder() a = builder.build('http://calf.sourceforge.net/plugins/Reverb') b = builder.build( 'http://guitarix.sourceforge.net/plugins/gx_flanger#_flanger') lista = EffectsList() lista.append(a) lista.append(b) lista.real_list.observer = MagicMock() with self.assertRaises(AlreadyAddedError): lista[0], lista[1] = lista[1], lista[0] return '''
def test_append_notaddable(self): builder = Lv2EffectBuilder() element1 = builder.build('http://calf.sourceforge.net/plugins/Reverb') element2 = builder.build('http://calf.sourceforge.net/plugins/Reverb') pedalboard = Pedalboard('name') connection = Connection(element1.outputs[0], element2.inputs[0]) with self.assertRaises(NotAddableError): pedalboard.connections.append(connection) pedalboard.append(element2) with self.assertRaises(NotAddableError): pedalboard.connections.append(connection) pedalboard.append(element1) pedalboard.connections.append(connection) # All effects added - OK
def test__delitem__(self): builder = Lv2EffectBuilder() a = builder.build('http://calf.sourceforge.net/plugins/Reverb') b = builder.build('http://calf.sourceforge.net/plugins/Reverb') c = builder.build('http://calf.sourceforge.net/plugins/Reverb') lista = RestrictionList() lista.append(a) lista.append(b) lista.append(c) lista.observer = MagicMock() index = 1 del lista[index] lista.observer.assert_called_once_with(UpdateType.DELETED, b, index)
def _configure_lv2_plugins_data(self): if not self._dao.exists_data: try: self.reload_lv2_plugins_data() self.app.log( "Lv2Plugins data - Loaded lv2 plugins data installed") except: self.app.log( "Lv2Plugins data - It's not possible reload lv2 plugins data" ) self.app.log(" Please install lilv") self.app.log( "Lv2Plugins data - Using PluginsManager default lv2 plugins data" ) print(self._dao.data_path, Lv2EffectBuilder.plugins_json_file) self._dao.save( Persistence.read(Path(Lv2EffectBuilder.plugins_json_file))) return Lv2EffectBuilder(plugins_json=self._dao.path)
def test_move_same_index(self): builder = Lv2EffectBuilder() a = builder.build('http://calf.sourceforge.net/plugins/Reverb') b = builder.build('http://calf.sourceforge.net/plugins/Reverb') c = builder.build('http://calf.sourceforge.net/plugins/Reverb') d = builder.build('http://calf.sourceforge.net/plugins/Reverb') lista = RestrictionList() lista.append(a) lista.append(b) lista.append(c) lista.append(d) lista.observer = MagicMock() same_index = lista.index(a) lista.move(a, same_index) lista.observer.assert_not_called()
def test_contains(self): builder = Lv2EffectBuilder() a = builder.build('http://calf.sourceforge.net/plugins/Reverb') b = builder.build('http://calf.sourceforge.net/plugins/Reverb') c = builder.build('http://calf.sourceforge.net/plugins/Reverb') d = builder.build('http://calf.sourceforge.net/plugins/Reverb') lista = RestrictionList() lista.append(a) lista.append(b) lista.append(c) self.assertTrue(a in lista) self.assertTrue(b in lista) self.assertTrue(c in lista) self.assertFalse(d in lista) self.assertTrue(d not in lista)
def test_system_midi_port(self): from pluginsmanager.observer.mod_host.mod_host import ModHost from pluginsmanager.model.pedalboard import Pedalboard from pluginsmanager.model.lv2.lv2_effect_builder import Lv2EffectBuilder from pluginsmanager.model.system.system_effect import SystemEffect jack_system = SystemEffect( 'system', [], # audio inputs ['playback_1', 'playback_2'], # audio output [], # midi inputs [] # midi outputs ) jack_ttymidi = SystemEffect( 'ttymidi', [], # audio inputs [], # audio output ['MIDI_in'], # midi inputs ['MIDI_out'] # midi outputs ) modhost = ModHost('localhost') modhost.connect() pedalboard = Pedalboard('MDA-EP') builder = Lv2EffectBuilder() ep = builder.build( 'http://guitarix.sourceforge.net/plugins/gx_oc_2_#_oc_2_') pedalboard.append(ep) # REMEMBER: FIRST OUTPUT, SECOND INPUT # EPiano contains two audio output ports and one midi input port pedalboard.connect(ep.outputs[0], jack_system.inputs[0]) pedalboard.connect(jack_ttymidi.midi_outputs[0], ep.midi_inputs[0]) # If not using banks manager, the changes will not be applied automatically # then, is necessary changes the pedalboard at the end modhost.pedalboard = pedalboard # Safe close modhost.close()
def test_pop_empty_parameter(self): builder = Lv2EffectBuilder() a = builder.build('http://calf.sourceforge.net/plugins/Reverb') b = builder.build('http://calf.sourceforge.net/plugins/Reverb') c = builder.build('http://calf.sourceforge.net/plugins/Reverb') d = builder.build('http://calf.sourceforge.net/plugins/Reverb') lista = RestrictionList() lista.append(a) lista.append(b) lista.append(c) lista.append(d) lista.observer = MagicMock() self.assertEqual(d, lista.pop()) self.assertEqual(3, len(lista)) lista.observer.assert_called_once_with(UpdateType.DELETED, d, len(lista))
def test_json(self): bank = Bank('Bank 1') pedalboard = Pedalboard('Rocksmith') builder = Lv2EffectBuilder() reverb = builder.build('http://calf.sourceforge.net/plugins/Reverb') filter = builder.build('http://calf.sourceforge.net/plugins/Filter') reverb2 = builder.build('http://calf.sourceforge.net/plugins/Reverb') pedalboard.append(reverb) pedalboard.append(filter) pedalboard.append(reverb2) reverb.outputs[0].connect(filter.inputs[0]) reverb.outputs[1].connect(filter.inputs[0]) filter.outputs[0].connect(reverb2.inputs[0]) reverb.outputs[0].connect(reverb2.inputs[0]) bank.append(pedalboard) print((json.dumps(bank.json, sort_keys=True, indent=2)))
def test__setitem__(self): builder = Lv2EffectBuilder() a = builder.build('http://calf.sourceforge.net/plugins/Reverb') b = builder.build('http://calf.sourceforge.net/plugins/Reverb') c = builder.build('http://calf.sourceforge.net/plugins/Reverb') d = builder.build('http://calf.sourceforge.net/plugins/Reverb') lista = RestrictionList() lista.append(a) lista.append(b) lista.append(c) lista.observer = MagicMock() index = 1 old_value = lista[index] new_value = d lista[index] = new_value lista.observer.assert_called_once_with(UpdateType.UPDATED, new_value, index, old=old_value)
def _load_preset(self, yaml_file, remove_previous=False): # Create graph with effect plugin objects graph = self._create_graph_from_config(yaml_file) # Cleanup existing pedalboard in mod-host if remove_previous and self._pedalboard is not None: for e in list(self._pedalboard.effects): for c in list(e.connections): self._pedalboard.disconnect(c.output, c.input) self._pedalboard.effects.remove(e) self._banks_manager.banks[0] = [] del self._pedalboard # Create PedalPi pedalboard and add to bank and mod-host pedalboard = Pedalboard(graph.settings['name']) pedalboard.graph = graph self._banks_manager.banks[0].append(pedalboard) # Add nodes (effects) to mod-host lv2_builder = Lv2EffectBuilder() for node in graph.nodes: # loop over Plugin objects self._log.info("mod-host: add effect " + str(node)) node.effect = lv2_builder.build(node.uri) pedalboard.effects.append(node.effect) sys_effect = SystemEffect('system', ['capture_1', 'capture_2'], ['playback_1', 'playback_2']) # Connect system capture to first effect pedalboard.connect(sys_effect.outputs[0], pedalboard.effects[0].inputs[0]) # Add edges (connections) to mod-host for node in graph.nodes: # looper over Plugin objects incoming = graph.get_incoming_edges(node) outgoing = graph.get_outgoing_edges(node) self._log.info( 'mod-host: add connection {!s} -> [{:d}] "{:s}" -> {!s}'. format(incoming, node.index, node.name, outgoing)) # Go through outgoing edges (indices) for e in outgoing: # loop over edge indices # Connect current effect to effect given by index e neighbor = graph.get_node_from_index(e) if node.has_stereo_output and neighbor.has_stereo_input: # stereo to stereo pedalboard.connect(node.effect.outputs[0], neighbor.effect.inputs[0]) pedalboard.connect(node.effect.outputs[1], neighbor.effect.inputs[1]) elif not node.has_stereo_output and neighbor.has_stereo_input: # split mono to stereo pedalboard.connect(node.effect.outputs[0], neighbor.effect.inputs[0]) pedalboard.connect(node.effect.outputs[0], neighbor.effect.inputs[1]) elif node.has_stereo_output and not neighbor.has_stereo_input: # sum stereo to mono pedalboard.connect(node.effect.outputs[0], neighbor.effect.inputs[0]) pedalboard.connect(node.effect.outputs[1], neighbor.effect.inputs[0]) else: # mono to mono pedalboard.connect(node.effect.outputs[0], neighbor.effect.inputs[0]) if outgoing == []: left_output = node.effect.outputs[0] right_output = node.effect.outputs[1 if node. has_stereo_output else 0] pedalboard.connect(left_output, sys_effect.inputs[0]) pedalboard.connect(right_output, sys_effect.inputs[1])
def setUpClass(cls): cls.builder = Lv2EffectBuilder()
modhost = SystemEffect('mod-host', ['midi_in'], []) autosaver = Autosaver('/root/pedalpi') manager = autosaver.load(sys_effect) #manager = BanksManager() # Mod-Host mod_host = ModHost('localhost') mod_host.connect() manager.register(mod_host) pedalboard = Pedalboard('MDA-EP') modhost.pedalboard = pedalboard builder = Lv2EffectBuilder() ep = builder.build('http://moddevices.com/plugins/mda/EPiano') pedalboard.connections.append(Connection(sys_effect.inputs[0], ep.outputs[0])) pedalboard.connections.append(Connection(sys_effect.inputs[1], ep.outputs[1])) pedalboard.connections.append(Connection(sys_effect.outputs[0], ep.inputs[0])) # Safe close from signal import pause try: pause() except KeyboardInterrupt: mod_host.close()
def test_observers_calls(self): observer = MagicMock() manager = BanksManager() manager.register(observer) bank = Bank('Bank 1') manager.append(bank) observer.on_bank_updated.assert_called_with(bank, UpdateType.CREATED, index=0, origin=manager) pedalboard = Pedalboard('Rocksmith') bank.append(pedalboard) observer.on_pedalboard_updated.assert_called_with(pedalboard, UpdateType.CREATED, index=0, origin=bank) builder = Lv2EffectBuilder() reverb = builder.build('http://calf.sourceforge.net/plugins/Reverb') filter = builder.build('http://calf.sourceforge.net/plugins/Filter') reverb2 = builder.build('http://calf.sourceforge.net/plugins/Reverb') pedalboard.append(reverb) observer.on_effect_updated.assert_called_with(reverb, UpdateType.CREATED, index=reverb.index, origin=pedalboard) pedalboard.append(filter) observer.on_effect_updated.assert_called_with(filter, UpdateType.CREATED, index=filter.index, origin=pedalboard) pedalboard.append(reverb2) observer.on_effect_updated.assert_called_with(reverb2, UpdateType.CREATED, index=reverb2.index, origin=pedalboard) pedalboard.connect(reverb.outputs[0], filter.inputs[0]) observer.on_connection_updated.assert_called_with( Connection(reverb.outputs[0], filter.inputs[0]), UpdateType.CREATED, pedalboard=pedalboard ) pedalboard.connect(reverb.outputs[1], filter.inputs[0]) observer.on_connection_updated.assert_called_with( Connection(reverb.outputs[1], filter.inputs[0]), UpdateType.CREATED, pedalboard=pedalboard ) pedalboard.connect(filter.outputs[0], reverb2.inputs[0]) observer.on_connection_updated.assert_called_with( Connection(filter.outputs[0], reverb2.inputs[0]), UpdateType.CREATED, pedalboard=pedalboard ) pedalboard.connect(reverb.outputs[0], reverb2.inputs[0]) observer.on_connection_updated.assert_called_with( Connection(reverb.outputs[0], reverb2.inputs[0]), UpdateType.CREATED, pedalboard=pedalboard ) filter.toggle() observer.on_effect_status_toggled.assert_called_with(filter) filter.params[0].value = (filter.params[0].maximum - filter.params[0].minimum) / 2 observer.on_param_value_changed.assert_called_with(filter.params[0]) del bank.pedalboards[0] observer.on_pedalboard_updated.assert_called_with(pedalboard, UpdateType.DELETED, index=0, origin=bank) bank2 = Bank('Bank 2') old_bank = manager.banks[0] manager.banks[0] = bank2 observer.on_bank_updated.assert_called_with(bank2, UpdateType.UPDATED, index=0, origin=manager, old=old_bank) manager.banks.remove(bank2) observer.on_bank_updated.assert_called_with(bank2, UpdateType.DELETED, index=0, origin=manager)
def setUpClass(cls): cls.builder = Lv2EffectBuilder() mock = 'TRAVIS' in os.environ mock = True cls.mod_host = cls.generate_mod_host(mock)
def test_load_nonexistent_effect(self): builder = Lv2EffectBuilder() with self.assertRaises(Lv2EffectBuilderError): builder.build('nonexistent_effect')