PedalPi - Application - Controller¶
Notification scope¶
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.
A quick review will be given ahead. For more details, see the pluginsmanager observer documentation.
pluginsmanager has a solution to this problem. Defining a observer:
class MyAwesomeObserver(UpdatesObserver):
def __init__(self, message):
self.message = message
def on_bank_updated(self, bank, update_type, **kwargs):
print(self.message)
# Defining others abstract methods
...
Using:
>>> 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"
Using application, the process changes a bit. Because pluginsmanager does not support the current
pedalboard change notifications, clients should extend from ApplicationObserver
,
a specialization that adds this functionality:
class MyAwesomeObserver(ApplicationObserver):
def __init__(self, message):
self.message = message
def on_current_pedalboard_changed(self, pedalboard, **kwargs):
print('Pedalboard changed!')
def on_bank_updated(self, bank, update_type, **kwargs):
print(self.message)
# Defining others abstract methods
...
To correctly register ApplicationObserver, you must use Application.register_observer()
(or Component.register_observer()
):
>>> observer1 = MyAwesomeObserver("Hi! I am observer1")
>>> observer2 = MyAwesomeObserver("Hi! I am observer2")
>>>
>>> application.register_observer(observer1)
>>> application.register_observer(observer2)
Note
Registering directly to the pluginsmanager will result in not receiving updates
defined by ApplicationObserver
Using:
>>> manager = application.manager
>>>
>>> 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"
Warning
The operations performed by PluginsManager are not atomic. This architectural constraint was based on the experienced experience that one user will use the system at a time. In this way, try not to abuse the concurrence.
If you are having problems while doing this, let us know.
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