2025-01-16 14:49:41 +00:00
|
|
|
import threading
|
|
|
|
from logging import config
|
|
|
|
|
|
|
|
import obsws_python as obsws
|
2024-02-08 13:45:55 +00:00
|
|
|
|
2022-09-20 15:12:50 +01:00
|
|
|
import xair_api
|
|
|
|
|
2025-01-16 14:49:41 +00:00
|
|
|
config.dictConfig(
|
|
|
|
{
|
|
|
|
'version': 1,
|
|
|
|
'formatters': {
|
|
|
|
'standard': {
|
|
|
|
'format': '%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'handlers': {
|
|
|
|
'stream': {
|
|
|
|
'level': 'DEBUG',
|
|
|
|
'class': 'logging.StreamHandler',
|
|
|
|
'formatter': 'standard',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'loggers': {
|
|
|
|
'xair_api.xair': {
|
|
|
|
'handlers': ['stream'],
|
|
|
|
'level': 'DEBUG',
|
|
|
|
'propagate': False,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'root': {'handlers': ['stream'], 'level': 'WARNING'},
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2022-09-20 15:12:50 +01:00
|
|
|
|
|
|
|
class Observer:
|
2025-01-16 14:49:41 +00:00
|
|
|
def __init__(self, mixer, stop_event):
|
2022-09-20 15:12:50 +01:00
|
|
|
self._mixer = mixer
|
2025-01-16 14:49:41 +00:00
|
|
|
self._stop_event = stop_event
|
|
|
|
self._client = obsws.EventClient()
|
|
|
|
self._client.callback.register(
|
|
|
|
(
|
|
|
|
self.on_current_program_scene_changed,
|
|
|
|
self.on_exit_started,
|
|
|
|
)
|
|
|
|
)
|
2024-02-08 13:45:55 +00:00
|
|
|
|
|
|
|
def __enter__(self):
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __exit__(self, exc_type, exc_value, exc_traceback):
|
|
|
|
self._client.disconnect()
|
2022-09-20 15:12:50 +01:00
|
|
|
|
|
|
|
def on_current_program_scene_changed(self, data):
|
|
|
|
scene = data.scene_name
|
2025-01-15 10:54:52 +00:00
|
|
|
print(f'Switched to scene {scene}')
|
2022-09-20 15:12:50 +01:00
|
|
|
match scene:
|
2025-01-15 10:54:52 +00:00
|
|
|
case 'START':
|
|
|
|
print('Toggling strip 01 on')
|
2022-09-20 15:12:50 +01:00
|
|
|
self._mixer.strip[0].mix.on = not self._mixer.strip[0].mix.on
|
2025-01-15 10:54:52 +00:00
|
|
|
case 'BRB':
|
|
|
|
print('Setting strip 08 fader')
|
2022-09-20 15:12:50 +01:00
|
|
|
self._mixer.strip[7].mix.fader = -12.8
|
2025-01-15 10:54:52 +00:00
|
|
|
case 'END':
|
|
|
|
print('Settings strip 02 color')
|
2022-09-20 15:12:50 +01:00
|
|
|
self._mixer.strip[1].config.color = 8
|
2025-01-15 10:54:52 +00:00
|
|
|
case 'LIVE':
|
2022-09-30 19:30:42 +01:00
|
|
|
self._mixer.config.mute_group[0].on = True
|
2025-01-15 10:54:52 +00:00
|
|
|
print(f'Mute Group 1 is {self._mixer.config.mute_group[0].on}')
|
2022-09-20 15:12:50 +01:00
|
|
|
|
2025-01-16 14:49:41 +00:00
|
|
|
def on_exit_started(self, _):
|
|
|
|
self._stop_event.set()
|
|
|
|
|
2022-09-20 15:12:50 +01:00
|
|
|
|
2022-10-28 21:07:14 +01:00
|
|
|
def main():
|
2025-01-15 10:54:52 +00:00
|
|
|
with xair_api.connect('MR18', ip='mixer.local') as mixer:
|
2025-01-16 14:49:41 +00:00
|
|
|
stop_event = threading.Event()
|
|
|
|
|
|
|
|
with Observer(mixer, stop_event):
|
|
|
|
stop_event.wait()
|
2022-10-28 21:07:14 +01:00
|
|
|
|
|
|
|
|
2025-01-15 10:54:52 +00:00
|
|
|
if __name__ == '__main__':
|
2022-10-28 21:07:14 +01:00
|
|
|
main()
|