PedalPi - Application - Controller¶
Token¶
pluginsmanager can notifies they changes. As an example, if a connection between effects is created, plugins manager notifies its observers about the change.
This is how ModHost
and Autosaver
know when a change occurs.
These observers work passively: they only receive updates, not using the pluginsmanager api to change the state of the application.
Man-Machine Interfaces are usually active: they need to change the state of the application. As an example, a button that leaves bypass an effect. They also need to receive notifications, so that the information presented to the user can be updated in accordance with changes made by other interfaces.
In these cases, is necessary in a change notifiers all except the one who caused the change.
As example, a multi-effects uses Raspberry-P1 for physical management and WebService for a controller with Apk controller. If they uses only pluginsmanager, a toggle status effect change in a Raspberry-P1 will informs WebService and unreasonably Raspberry-P1.
pluginsmanager has a solution to this problem:
>>> class MyAwesomeObserver(UpdatesObserver):
>>> def __init__(self, message):
>>> self.message = message
>>>
>>> def on_bank_updated(self, bank, update_type, **kwargs):
>>> print(self.message)
>>>
>>>
>>> observer1 = MyAwesomeObserver("Hi! I am observer1")
>>> observer2 = MyAwesomeObserver("Hi! I am observer2")
>>>
>>> manager = BanksManager()
>>> manager.register(observer1)
>>> manager.register(observer2)
>>>
>>> bank = Bank('Bank 1')
>>> manager.banks.append(bank)
"Hi! I am observer1"
"Hi! I am observer2"
>>> with observer1:
>>> del manager.banks[0]
"Hi! I am observer2"
>>> with observer2:
>>> manager.banks.append(bank)
"Hi! I am observer1"
However, it is not reliable since it is not thread safe.
Application uses an explicit way of reporting notifications via tokens - unique strings that identify observers. Your API provides methods that change the state of the application that receive a token as a parameter. A change with an informed token is not propagated to an observer who has this token:
>>> class MyAwesomeObserver(ApplicationObserver):
>>> def __init__(self, application, token, name):
>>> super(ActionsFacade, self).__init__()
>>> self._token = token
>>> self.name = name
>>>
>>> @property
>>> def token(self):
>>> return self._token
>>>
>>> def on_effect_status_toggled(self, effect, **kwargs):
>>> print(self.name)
>>>
>>> ...
>>>
>>> observer1 = MyAwesomeObserver('observer-1', 'Observer 1 method called!')
>>> observer2 = MyAwesomeObserver('observer-2', 'Observer 2 method called!')
>>>
>>> notification_controller = application.controller(NotificationController)
>>> notification_controller.register(observer1)
>>> notification_controller.register(observer2)
>>>
>>> effects_controller = application.controller(EffectController)
>>> effects_controller.toggle_status(reverb)
'Observer 1 method called!'
'Observer 2 method called!'
>>> effects_controller.toggle_status(reverb, observer1.token)
'Observer 2 method called!'
>>> effects_controller.toggle_status(reverb, observer2.token)
'Observer 1 method called!'
Controller¶
-
class
application.controller.controller.
Controller
(application)[source]¶ Abstract class for Application controllers.
Extends to offer functionalities for this API. Remember to manually register the extended class in
Application
(in private_load_controllers
method)Parameters: application (Application) – Application
instance-
__weakref__
¶ list of weak references to the object (if defined)
-
BanksController¶
ComponentDataController¶
-
class
application.controller.component_data_controller.
ComponentDataController
(application)[source]¶ Maybe the pedalboard data it’s not sufficient for management in a custom
Components
. For example, in a possible visual pedalboard manager is necessary persist the effects positions.ComponentDataController
offers a way to salve and restore data.For your component, create a unique identifier (key) and use it for manage all your Component data. For example:
>>> key = 'raspberry-p0' >>> controller = application.controller(ComponentDataController) >>> # If key not exists, returns {} >>> controller[key] {} >>> controller[key] = {'pedalboard': 0} >>> controller[key] {'pedalboard': 0} >>> # The new data overrides old data >>> controller[key] = {'pedalboards': []} >>> controller[key] {'pedalboards': []} >>> # Changes in returned object will not change the persisted data >>> data = controller[key] >>> data['component'] = 'Raspberry P0' >>> data {'pedalboards': [], 'component': 'Raspberry P0'} >>> controller[key] {'pedalboards': []} >>> # Remove all content for 'raspberry-p0' >>> del controller[key] >>> controller[key] {}
Warning
ComponentDataController
does not have access control, which means that any Component that eventually use ComponentDataController may interfere with the content (accessing, changing or removing).Warning
It’s a easy way for save simple data. Please, don’t save binaries or big content
CurrentController¶
DeviceController¶
EffectController¶
NotificationController¶
-
class
application.controller.notification_controller.
NotificationController
(app)[source]¶ Notifies request changes to all
ApplicationObserver
registered than not contains the same request _token_.-
bank_updated
(bank, update_type, index, origin, token=None)[source]¶ Notify changes in
Bank
.Parameters:
-
connection_updated
(connection, update_type, pedalboard, token=None)[source]¶ Notify
Connection
addictions and removals.Parameters: - connection (Connection) – Connection added or removed
- update_type (UpdateType) – Change type
- pedalboard (Pedalboard) – Pedalboard that the connection is (or has) contained
- token (string) – Request token identifier
-
current_pedalboard_changed
(pedalboard, token=None)[source]¶ Notify current pedalboard change.
Parameters: - pedalboard (Pedalboard) – New current pedalboard
- token (string) – Request token identifier
-
effect_status_toggled
(effect, token=None)[source]¶ Notify
Effect
status toggled.Parameters: - effect (Effect) – Effect when status has been toggled
- token (string) – Request token identifier
-
effect_updated
(effect, update_type, index, origin, token=None)[source]¶ Notify changes in
Effect
.Parameters:
-
is_requester
(observer, token)[source]¶ Verify if the observer is the requester change (if observer contains same token that token informed)
Parameters: - observer (ApplicationObserver) –
- token (string) – Request token identifier
Returns: The requisition is realized by observer?
-
param_value_changed
(param, token=None, **kwargs)[source]¶ Notify
Param
value change.Parameters: - param (Param) – Param with value changed
- token (string) – Request token identifier
-
pedalboard_updated
(pedalboard, update_type, index, origin, token=None)[source]¶ Notify changes in
Pedalboard
.Parameters:
-