Skip to content

Commit

Permalink
Merge pull request #5 from PedalPi/data
Browse files Browse the repository at this point in the history
Support for custom data in pedalboard
  • Loading branch information
SrMouraSilva committed Dec 26, 2016
2 parents 5164b06 + 60d4f64 commit 92a9652
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pluginsmanager/model/effect.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class Effect(metaclass=ABCMeta):
:param Pedalboard pedalboard: Pedalboard where the effect lies.
"""

def __init__(self, pedalboard=None):
self.pedalboard = pedalboard
def __init__(self):
self.pedalboard = None
self._active = True

self._params = ()
Expand Down
7 changes: 7 additions & 0 deletions pluginsmanager/model/lv2/lv2_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ def minimum(self):
@property
def symbol(self):
return self._param['symbol']

@property
def __dict__(self):
dictionary = super(Lv2Param, self).__dict__
dictionary['index'] = self._param['index']

return dictionary
2 changes: 1 addition & 1 deletion pluginsmanager/model/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def json(self):
@property
def __dict__(self):
return {
'index': self._param['index'],
'index': self.effect.params.index(self),
'minimum': self.minimum,
'maximum': self.maximum,
'symbol': self.symbol,
Expand Down
14 changes: 12 additions & 2 deletions pluginsmanager/model/pedalboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@ class Pedalboard(object):
>>> reverb.outputs[1].connect(sys_effect.inputs[0])
ObservableList: [<Connection object as 'system.capture_1 -> GxFuzzFaceFullerMod.In' at 0x7f60f45f3f60>, <Connection object as 'GxFuzzFaceFullerMod.Out -> Calf Reverb.In L' at 0x7f60f45f57f0>, <Connection object as 'Calf Reverb.Out R -> system.playback_1' at 0x7f60f45dacc0>]
>>> pedalboard.data
{}
>>> pedalboard.data = {'my-awesome-component': True}
>>> pedalboard.data
{'my-awesome-component': True}
For load the pedalboard for play the songs with it::
>>> mod_host.pedalboard = pedalboard
All changes in the pedalboard will be reproduced in mod-host
All changes¹ in the pedalboard will be reproduced in mod-host.
¹ Except in data attribute, changes in this does not interfere with anything.
:param string name: Pedalboard name
"""
Expand All @@ -51,6 +58,8 @@ def __init__(self, name):

self.bank = None

self.data = {}

@property
def observer(self):
return self._observer
Expand Down Expand Up @@ -98,7 +107,8 @@ def __dict__(self):
return {
'name': self.name,
'effects': [effect.json for effect in self.effects],
'connections': [connection.json for connection in self.connections]
'connections': [connection.json for connection in self.connections],
'data': self.data
}

def append(self, effect):
Expand Down
21 changes: 13 additions & 8 deletions pluginsmanager/util/persistence_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def read(self, json):
for connection_json in json['connections']:
pedalboard.connections.append(connection_reader.read(connection_json))

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

return pedalboard


Expand Down Expand Up @@ -100,23 +103,25 @@ def read(self, json):
return Connection(connection_output, connection_input)

def read_output(self, json):
index = json['symbol']

effect_index = json['effect']
effect = self.pedalboard.effects[effect_index]

return effect.outputs[index]
return self.generic_system_output(effect, json['symbol'])

def read_input(self, json):
index = json['symbol']

effect_index = json['effect']
effect = self.pedalboard.effects[effect_index]

return effect.inputs[index]
return self.generic_system_input(effect, json['symbol'])

def read_system_output(self, json):
return self.system_effect.outputs[json['symbol']]
return self.generic_system_output(self.system_effect, json['symbol'])

def read_system_input(self, json):
return self.system_effect.inputs[json['symbol']]
return self.generic_system_input(self.system_effect, json['symbol'])

def generic_system_output(self, effect, symbol):
return effect.outputs[symbol]

def generic_system_input(self, effect, symbol):
return effect.inputs[symbol]
9 changes: 9 additions & 0 deletions test/model/patch_test.py → test/model/pedalboard_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,12 @@ def test_delete_effect_remove_your_connections(self):
self.assertEqual(1, len(pedalboard.connections))
for connection in fuzz_connections:
pedalboard.observer.on_connection_updated.assert_any_call(connection, UpdateType.DELETED)

def test_data(self):
pedalboard = Pedalboard('Bank 1')
pedalboard.observer = MagicMock()

self.assertEqual({}, pedalboard.data)
data = {'my-awesome-component': True}
pedalboard.data = data
self.assertEqual(data, pedalboard.data)
1 change: 1 addition & 0 deletions test/util/persistence_decoder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def test_read(self):
bank = self.bank
bank_readed = util.read(bank.json)

self.maxDiff = None
self.assertEqual(bank.json, bank_readed.json)

def test_read_unknown_technology(self):
Expand Down

0 comments on commit 92a9652

Please sign in to comment.