You've already forked RadioPlayer
mirror of
https://github.com/radio95-rnt/RadioPlayer.git
synced 2026-02-26 21:53:54 +01:00
module callbacks in the future?
This commit is contained in:
@@ -26,7 +26,7 @@ class PlayerModule:
|
||||
Receive an IMC object
|
||||
"""
|
||||
pass
|
||||
def imc_data(self, source: 'PlayerModule | ActiveModifier | PlaylistAdvisor', data: object) -> object:
|
||||
def imc_data(self, source: 'PlayerModule | ActiveModifier | PlaylistAdvisor', data: object, broadcast: bool) -> object:
|
||||
pass
|
||||
class PlaylistModifierModule:
|
||||
"""
|
||||
@@ -57,7 +57,7 @@ class PlaylistAdvisor:
|
||||
Receive an IMC object
|
||||
"""
|
||||
pass
|
||||
def imc_data(self, source: 'PlayerModule | ActiveModifier | PlaylistAdvisor', data: object) -> object:
|
||||
def imc_data(self, source: 'PlayerModule | ActiveModifier | PlaylistAdvisor', data: object, broadcast: bool) -> object:
|
||||
pass
|
||||
class ActiveModifier:
|
||||
"""
|
||||
@@ -84,7 +84,7 @@ class ActiveModifier:
|
||||
Receive an IMC object
|
||||
"""
|
||||
pass
|
||||
def imc_data(self, source: 'PlayerModule | ActiveModifier | PlaylistAdvisor', data: object) -> object:
|
||||
def imc_data(self, source: 'PlayerModule | ActiveModifier | PlaylistAdvisor', data: object, broadcast: bool) -> object:
|
||||
pass
|
||||
class InterModuleCommunication:
|
||||
def __init__(self, advisor: PlaylistAdvisor, active_modifier: ActiveModifier | None, simple_modules: list[PlayerModule]) -> None:
|
||||
@@ -94,15 +94,15 @@ class InterModuleCommunication:
|
||||
self.names_modules: dict[str, PlaylistAdvisor | ActiveModifier | PlayerModule] = {}
|
||||
def broadcast(self, source: PlaylistAdvisor | ActiveModifier | PlayerModule, data: object) -> None:
|
||||
"""
|
||||
Send data to all modules
|
||||
Send data to all modules, other than ourself
|
||||
"""
|
||||
self.advisor.imc_data(source, data)
|
||||
if self.active_modifier: self.active_modifier.imc_data(source, data)
|
||||
for module in self.simple_modules: module.imc_data(source, data)
|
||||
if source is not self.advisor: self.advisor.imc_data(source, data, True)
|
||||
if self.active_modifier and source is not self.active_modifier: self.active_modifier.imc_data(source, data, True)
|
||||
for module in [f for f in self.simple_modules if f is not source]: module.imc_data(source, data, True)
|
||||
def register(self, module: PlaylistAdvisor | ActiveModifier | PlayerModule, name: str):
|
||||
if name in self.names_modules.keys(): return False
|
||||
self.names_modules[name] = module
|
||||
return True
|
||||
def send(self, source: PlaylistAdvisor | ActiveModifier | PlayerModule, name: str, data: object) -> object:
|
||||
if not name in self.names_modules.keys(): raise Exception
|
||||
return self.names_modules[name].imc_data(source, data)
|
||||
return self.names_modules[name].imc_data(source, data, False)
|
||||
@@ -110,7 +110,7 @@ class Module(PlaylistAdvisor):
|
||||
def imc(self, imc: InterModuleCommunication):
|
||||
self.class_imc = imc
|
||||
imc.register(self, "advisor")
|
||||
def imc_data(self, source: PlayerModule | ActiveModifier | PlaylistAdvisor, data: object):
|
||||
def imc_data(self, source: PlayerModule | ActiveModifier | PlaylistAdvisor, data: object, broadcast: bool):
|
||||
return self.custom_playlist
|
||||
|
||||
advisor = Module()
|
||||
@@ -1,4 +1,4 @@
|
||||
Modules in the radio95 radio player are quite simple.
|
||||
Modules in the radioPlayer are quite simple.
|
||||
|
||||
First of all, ther are in total only 4 modules:
|
||||
- Observer (PlayerModule), this module is a passive observer, you can use this as a status api or to send the song metadata to your RDS encoder
|
||||
@@ -32,7 +32,7 @@ class PlayerModule:
|
||||
Receive an IMC object
|
||||
"""
|
||||
pass
|
||||
def imc_data(self, source: 'PlayerModule | ActiveModifier | PlaylistAdvisor', data: object) -> object:
|
||||
def imc_data(self, source: 'PlayerModule | ActiveModifier | PlaylistAdvisor', data: object, broadcast: bool) -> object:
|
||||
pass
|
||||
class PlaylistModifierModule:
|
||||
"""
|
||||
@@ -63,7 +63,7 @@ class PlaylistAdvisor:
|
||||
Receive an IMC object
|
||||
"""
|
||||
pass
|
||||
def imc_data(self, source: 'PlayerModule | ActiveModifier | PlaylistAdvisor', data: object) -> object:
|
||||
def imc_data(self, source: 'PlayerModule | ActiveModifier | PlaylistAdvisor', data: object, broadcast: bool) -> object:
|
||||
pass
|
||||
class ActiveModifier:
|
||||
"""
|
||||
@@ -90,7 +90,7 @@ class ActiveModifier:
|
||||
Receive an IMC object
|
||||
"""
|
||||
pass
|
||||
def imc_data(self, source: 'PlayerModule | ActiveModifier | PlaylistAdvisor', data: object) -> object:
|
||||
def imc_data(self, source: 'PlayerModule | ActiveModifier | PlaylistAdvisor', data: object, broadcast: bool) -> object:
|
||||
pass
|
||||
class InterModuleCommunication:
|
||||
def __init__(self, advisor: PlaylistAdvisor, active_modifier: ActiveModifier | None, simple_modules: list[PlayerModule]) -> None:
|
||||
@@ -100,18 +100,18 @@ class InterModuleCommunication:
|
||||
self.names_modules: dict[str, PlaylistAdvisor | ActiveModifier | PlayerModule] = {}
|
||||
def broadcast(self, source: PlaylistAdvisor | ActiveModifier | PlayerModule, data: object) -> None:
|
||||
"""
|
||||
Send data to all modules
|
||||
Send data to all modules, other than ourself
|
||||
"""
|
||||
self.advisor.imc_data(source, data)
|
||||
if self.active_modifier: self.active_modifier.imc_data(source, data)
|
||||
for module in self.simple_modules: module.imc_data(source, data)
|
||||
if source is not self.advisor: self.advisor.imc_data(source, data, True)
|
||||
if self.active_modifier and source is not self.active_modifier: self.active_modifier.imc_data(source, data, True)
|
||||
for module in [f for f in self.simple_modules if f is not source]: module.imc_data(source, data, True)
|
||||
def register(self, module: PlaylistAdvisor | ActiveModifier | PlayerModule, name: str):
|
||||
if name in self.names_modules.keys(): return False
|
||||
self.names_modules[name] = module
|
||||
return True
|
||||
def send(self, source: PlaylistAdvisor | ActiveModifier | PlayerModule, name: str, data: object) -> object:
|
||||
if not name in self.names_modules.keys(): raise Exception
|
||||
return self.names_modules[name].imc_data(source, data)
|
||||
return self.names_modules[name].imc_data(source, data, False)
|
||||
```
|
||||
|
||||
Each module shall have a python script in the modules directory. Each of the modules need to define one or more global variables in order to be seen by the core:
|
||||
|
||||
Reference in New Issue
Block a user