-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from PedalPi/issue-78-lv2-effect-builder-error
Issue #78 Improve lv2 effect builder error message
- Loading branch information
Showing
13 changed files
with
284 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# Copyright 2017 SrMouraSilva | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import sys | ||
from pathlib import Path | ||
|
||
from pluginsmanager.model.pedalboard import Pedalboard | ||
from pluginsmanager.model.system.system_effect import SystemEffect | ||
|
||
|
||
class ModPedalboardConverter(object): | ||
""" | ||
ModPedalboardConverter is a utility to convert MOD pedalboards structure | ||
in plugins manager pedalboard. | ||
`MOD`_, an awesome music enterprise, create the `mod-ui`_, a visual interface | ||
that enable create pedalboards in a simple way. | ||
.. _MOD: http://moddevices.com/ | ||
.. _mod-ui: https://github.com/moddevices/mod-ui | ||
""" | ||
|
||
def __init__(self, mod_ui_path, builder): | ||
""" | ||
:param Path mod_ui_path: path that mod_ui has in the computer. | ||
:param Lv2EffectBuilder builder: Builder for generate the lv2 effects | ||
""" | ||
self._load_mod_ui_libraries(mod_ui_path) | ||
self.builder = builder | ||
|
||
def _load_mod_ui_libraries(self, path): | ||
""" | ||
:param Path path: | ||
""" | ||
path = path / Path('mod') | ||
sys.path.append(str(path)) | ||
|
||
def get_pedalboard_info(self, path): | ||
""" | ||
:param Path path: Path that the pedalboard has been persisted. | ||
Generally is in format `path/to/pedalboard/name.pedalboard` | ||
:return dict: pedalboard persisted configurations | ||
""" | ||
from utils import get_pedalboard_info | ||
|
||
return get_pedalboard_info(str(path)) | ||
|
||
def convert(self, pedalboard_path, system_effect): | ||
""" | ||
: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 | ||
:return Pedalboard: Pedalboard loaded | ||
""" | ||
info = self.get_pedalboard_info(pedalboard_path) | ||
|
||
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 | ||
|
||
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) | ||
|
||
return pedalboard | ||
|
||
def _generate_effect(self, effect_data): | ||
effect = self.builder.build(effect_data['uri']) | ||
effect.active = not effect_data['bypassed'] | ||
|
||
for param_data in effect_data['ports']: | ||
effect.params[param_data['symbol']].value = param_data['value'] | ||
|
||
return effect | ||
|
||
def _get_port(self, name, effects_instance, system_effect): | ||
effect, port = None, None | ||
|
||
if name.startswith('capture_') or name.startswith('playback_'): | ||
effect = system_effect | ||
port = name | ||
else: | ||
instance, port = name.split('/') | ||
effect = effects_instance[instance] | ||
|
||
possible_ports = (effect.outputs, effect.inputs, effect.midi_outputs, effect.midi_inputs) | ||
filtered = filter(lambda ports: port in ports, possible_ports) | ||
|
||
ports = list(filtered)[0] | ||
return ports[port] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2017 SrMouraSilva | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2017 SrMouraSilva | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright 2017 SrMouraSilva | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import unittest | ||
|
||
from pluginsmanager.model.lv2.lv2_effect_builder import Lv2EffectBuilder | ||
from pluginsmanager.model.lv2.lv2_effect_builder import Lv2EffectBuilderError | ||
|
||
|
||
class Lv2EffecBuilderTest(unittest.TestCase): | ||
|
||
def test_load_nonexistent_effect(self): | ||
builder = Lv2EffectBuilder() | ||
with self.assertRaises(Lv2EffectBuilderError): | ||
builder.build('nonexistent_effect') |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Copyright 2017 SrMouraSilva | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import unittest | ||
|
||
from pluginsmanager.util.dict_tuple import DictTuple | ||
|
||
|
||
class DictTupleTest(unittest.TestCase): | ||
|
||
def test__get_item__(self): | ||
elements = ('123', '456', '789') | ||
data = DictTuple(elements, lambda e: e) | ||
|
||
for index, element in enumerate(elements): | ||
self.assertEqual(element, data[index]) | ||
self.assertEqual(element, data[element]) | ||
|
||
def test_in(self): | ||
elements = ('abc', 'cde', 'def') | ||
data = DictTuple(elements, lambda e: e.upper()) | ||
|
||
self.assertTrue('ABC' in data) | ||
self.assertFalse('abc' in data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2017 SrMouraSilva | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import os | ||
import unittest | ||
from pathlib import Path | ||
|
||
from pluginsmanager.model.lv2.lv2_effect_builder import Lv2EffectBuilder | ||
from pluginsmanager.model.system.system_effect import SystemEffect | ||
from pluginsmanager.util.mod_pedalboard_converter import ModPedalboardConverter | ||
|
||
|
||
class ModPedalboardConverterTest(unittest.TestCase): | ||
|
||
@unittest.skipIf('TRAVIS' in os.environ, 'Mod-ui not configured in Travis build') | ||
def test_all(self): | ||
path = Path('/home/paulo/git/mod/mod_ui/') | ||
builder = Lv2EffectBuilder() | ||
#builder.reload(builder.lv2_plugins_data()) | ||
|
||
converter = ModPedalboardConverter(path, builder) | ||
|
||
pedalboard_path = Path('/home/paulo/.pedalboards/teste.pedalboard') | ||
system_effect = SystemEffect('system', ['capture_1', 'capture_2'], ['playback_1', 'playback_2']) | ||
|
||
print(converter.get_pedalboard_info(pedalboard_path)) | ||
pedalboard = converter.convert(pedalboard_path, system_effect) | ||
print(pedalboard.json) |