def test_connect(self):
        pedalboard = Pedalboard('Pedalboard name')
        pedalboard.observer = MagicMock()

        builder = MidiOutputTest.builder
        cctonode = builder.build(
            'http://gareus.org/oss/lv2/midifilter#cctonote')
        cctonode2 = builder.build(
            'http://gareus.org/oss/lv2/midifilter#cctonote')

        pedalboard.append(cctonode)
        pedalboard.append(cctonode2)

        self.assertEqual(0, len(pedalboard.connections))
        pedalboard.connect(cctonode.midi_outputs[0], cctonode2.midi_inputs[0])
        self.assertEqual(1, len(pedalboard.connections))

        new_connection = pedalboard.connections[0]
        pedalboard.observer.on_connection_updated.assert_called_with(
            new_connection, UpdateType.CREATED, pedalboard=pedalboard)

        pedalboard.connect(cctonode2.midi_outputs[0], cctonode.midi_inputs[0])
        self.assertEqual(2, len(pedalboard.connections))

        new_connection = pedalboard.connections[-1]
        pedalboard.observer.on_connection_updated.assert_called_with(
            new_connection, UpdateType.CREATED, pedalboard=pedalboard)
Exemple #2
0
    def test_disconnect(self):
        pedalboard = Pedalboard('Pedalboard name')

        builder = OutputTest.builder
        reverb = builder.build('http://calf.sourceforge.net/plugins/Reverb')
        reverb2 = builder.build('http://calf.sourceforge.net/plugins/Reverb')

        pedalboard.append(reverb)
        pedalboard.append(reverb2)

        pedalboard.connect(reverb.outputs[0], reverb2.inputs[0])
        pedalboard.connect(reverb.outputs[1], reverb2.inputs[0])
        self.assertEqual(2, len(pedalboard.connections))

        pedalboard.observer = MagicMock()

        disconnected = pedalboard.connections[-1]
        pedalboard.disconnect(reverb.outputs[1], reverb2.inputs[0])
        self.assertEqual(1, len(pedalboard.connections))
        pedalboard.observer.on_connection_updated.assert_called_with(disconnected, UpdateType.DELETED, pedalboard=pedalboard)

        disconnected = pedalboard.connections[-1]
        pedalboard.disconnect(reverb.outputs[0], reverb2.inputs[0])
        self.assertEqual(0, len(pedalboard.connections))
        pedalboard.observer.on_connection_updated.assert_called_with(disconnected, UpdateType.DELETED, pedalboard=pedalboard)
    def test_connections_effect_remove_your_connections(self):
        pedalboard = Pedalboard('Pedalboard name')

        builder = EffectTest.builder
        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(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])

        reverb_connections = (Connection(reverb.outputs[0], filter.inputs[0]),
                              Connection(reverb.outputs[1], filter.inputs[0]),
                              Connection(reverb.outputs[0], reverb2.inputs[0]))
        fuzz_connections = (Connection(reverb.outputs[0], filter.inputs[0]),
                            Connection(reverb.outputs[1], filter.inputs[0]),
                            Connection(filter.outputs[0], reverb2.inputs[0]))
        reverb2_connections = (Connection(filter.outputs[0],
                                          reverb2.inputs[0]),
                               Connection(reverb.outputs[0],
                                          reverb2.inputs[0]))

        self.assertCountEqual(reverb_connections, reverb.connections)
        self.assertCountEqual(fuzz_connections, filter.connections)
        self.assertCountEqual(reverb2_connections, reverb2.connections)
Exemple #4
0
    def test_connection_not_current_pedalboard(self):
        """Test only coverage"""
        manager = BanksManager()

        bank = Bank('Bank 1')
        manager.append(bank)

        mod_host = ModHost('localhost')
        mod_host.host = MagicMock()
        manager.register(mod_host)

        pedalboard = Pedalboard('test_set_pedalboard_1')
        pedalboard.append(
            self.builder.build('http://calf.sourceforge.net/plugins/Reverb'))

        pedalboard2 = Pedalboard('test_set_pedalboard_2')
        pedalboard2.append(
            self.builder.build('http://calf.sourceforge.net/plugins/Reverb'))
        pedalboard2.append(
            self.builder.build('http://calf.sourceforge.net/plugins/Reverb'))

        bank.append(pedalboard)
        bank.append(pedalboard2)

        mod_host.pedalboard = pedalboard

        pedalboard2.connect(pedalboard2.effects[0].outputs[0],
                            pedalboard2.effects[1].inputs[0])
Exemple #5
0
    def test_observers_mock(self):
        """Test only coverage"""
        sys_effect = SystemEffect('system', ('capture_1', 'capture_2'),
                                  ('playback_1', 'playback_2'))
        manager = BanksManager()

        bank = Bank('Bank 1')
        manager.append(bank)

        mod_host = ModHost('localhost')
        mod_host.host = MagicMock()
        manager.register(mod_host)

        pedalboard = Pedalboard('Rocksmith')

        mod_host.pedalboard = pedalboard

        bank.append(pedalboard)

        reverb = self.builder.build(
            'http://calf.sourceforge.net/plugins/Reverb')
        filter = self.builder.build(
            'http://calf.sourceforge.net/plugins/Filter')
        reverb2 = self.builder.build(
            'http://calf.sourceforge.net/plugins/Reverb')

        pedalboard.append(reverb)
        pedalboard.append(filter)
        pedalboard.append(reverb2)

        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])

        filter.toggle()
        filter.params[0].value = (filter.params[0].maximum -
                                  filter.params[0].minimum) / 2

        pedalboard.disconnect(filter.outputs[0], reverb2.inputs[0])
        filter.toggle()

        pedalboard.effects.remove(filter)

        pedalboard.connections.append(
            Connection(sys_effect.outputs[0], reverb.inputs[0]))
        pedalboard.connections.append(
            Connection(reverb2.outputs[0], sys_effect.inputs[0]))

        for connection in list(pedalboard.connections):
            pedalboard.connections.remove(connection)

        for effect in list(pedalboard.effects):
            pedalboard.effects.remove(effect)
Exemple #6
0
    def test_system_effect_connections(self):
        pedalboard = Pedalboard('A pedalboard')
        sys_effect = SystemEffect('system', ['capture_1'], ['playback_1', 'playback_2'])

        effect_output = sys_effect.outputs[0]
        effect_input = sys_effect.inputs[0]

        pedalboard.connect(effect_output, effect_input)
        self.assertEqual(len(pedalboard.connections), 1)

        pedalboard.disconnect(effect_output, effect_input)
        self.assertEqual(len(pedalboard.connections), 0)
    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))
    def read(self, json):
        pedalboard = Pedalboard(json['name'])

        effect_reader = EffectReader(self.system_effect)
        for effect_json in json['effects']:
            pedalboard.append(effect_reader.read(effect_json))

        connection_reader = ConnectionReader(pedalboard, self.system_effect)
        for connection_json in json['connections']:
            port_output, port_input = connection_reader.read(connection_json)
            pedalboard.connect(port_output, port_input)

        if 'data' in json:
            pedalboard.data = json['data']

        return pedalboard
Exemple #9
0
    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 bank(self, midi=True):
        sys_effect = self.system_effect

        bank = Bank('Bank 1')
        pedalboard = Pedalboard('Pedalboard 1')

        bank.append(pedalboard)
        bank.append(Pedalboard('Pedalboard is a Pedalboard?'))

        reverb = self.builder.build('http://calf.sourceforge.net/plugins/Reverb')
        filter = self.builder.build('http://calf.sourceforge.net/plugins/Filter')
        reverb2 = self.builder.build('http://calf.sourceforge.net/plugins/Reverb')

        pedalboard.append(reverb)
        pedalboard.append(filter)
        pedalboard.append(reverb2)

        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])

        if midi:
            cctonode = self.builder.build('http://gareus.org/oss/lv2/midifilter#cctonote')
            pedalboard.append(cctonode)
            pedalboard.connect(cctonode.midi_outputs[0], sys_effect.midi_inputs[0])
            pedalboard.connect(sys_effect.midi_outputs[0], cctonode.midi_inputs[0])

        pedalboard.connections.append(Connection(sys_effect.outputs[0], reverb.inputs[0]))
        pedalboard.connections.append(Connection(reverb2.outputs[0], sys_effect.inputs[0]))

        filter.toggle()
        filter.params[0].value = (filter.params[0].maximum - filter.params[0].minimum) / 3

        return bank
    def convert(self, pedalboard_path, system_effect=None):
        """
        :param Path pedalboard_path: Path that the pedalboard has been persisted.
                                     Generally is in format `path/to/pedalboard/name.pedalboard`
        :param SystemEffect system_effect: Effect that contains the audio interface outputs and inputs
                                           or None for **auto discover**
        :return Pedalboard: Pedalboard loaded
        """
        info = self.get_pedalboard_info(pedalboard_path)

        if system_effect is None:
            system_effect = self.discover_system_effect(info)

        pedalboard = Pedalboard(info['title'])

        effects_instance = {}

        for effect_data in info['plugins']:
            effect = self._generate_effect(effect_data)
            pedalboard.append(effect)
            effects_instance[effect_data['instance']] = effect

        try:
            for connection_data in info['connections']:
                output_port = self._get_port(connection_data['source'],
                                             effects_instance, system_effect)
                input_port = self._get_port(connection_data['target'],
                                            effects_instance, system_effect)

                pedalboard.connect(output_port, input_port)
        except PortNotFoundError as e:
            if self.ignore_errors:
                print("WARNING:", e)
            else:
                raise e

        return pedalboard
Exemple #12
0
    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)
Exemple #13
0
    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])