summaryrefslogtreecommitdiffstats
path: root/audiomixer.py
diff options
context:
space:
mode:
authorEdi Feschiyan <edi.feschiyan@konsulko.com>2020-06-08 13:43:13 +0300
committerEdi Feschiyan <edi.feschiyan@konsulko.com>2020-06-09 09:30:14 +0300
commit03471f59045bba8b61d1e3056d75178fe297b57a (patch)
tree86d6cac6b01975b5cba165e06cd2c35827aefef7 /audiomixer.py
parentc01603b57d97eba4aac9e62aca9f22da77a2ada0 (diff)
Completed audiomixer api
Diffstat (limited to 'audiomixer.py')
-rw-r--r--audiomixer.py94
1 files changed, 94 insertions, 0 deletions
diff --git a/audiomixer.py b/audiomixer.py
new file mode 100644
index 0000000..3d61c10
--- /dev/null
+++ b/audiomixer.py
@@ -0,0 +1,94 @@
+from aglbaseservice import AGLBaseService, AFBResponse
+import asyncio
+import os
+
+verbs = ['subscribe', 'unsubscribe', 'list_controls', 'volume', 'mute']
+events = ['volume_changed', 'mute_changed', 'controls_changed']
+
+
+class AudioMixerService(AGLBaseService):
+ service = 'agl-service-audiomixer'
+ parser = AGLBaseService.getparser()
+ parser.add_argument('--list_controls', default=True, help='Request list of controls', action='store_true')
+ parser.add_argument('--getmute', help='Get mute state', action='store_true')
+ parser.add_argument('--setmute', help='Set mute state', type=int, choices=[0, 1])
+ parser.add_argument('--setvolume', help='Set volume level', type=float)
+ parser.add_argument('--getvolume', help='Get volume level', action='store_true')
+
+
+ def __init__(self, ip, port=None, service='agl-service-audiomixer'):
+ super().__init__(api='audiomixer', ip=ip, port=port, service=service)
+
+ async def subscribe(self, event='volume_changed'): # audio mixer uses 'event' instead 'value',
+ return await self.request('subscribe', {'event': event})
+
+ async def unsubscribe(self, event='volume_changed'):
+ return await self.request('unsubscribe', {'event': event})
+
+ async def list_controls(self):
+ return await self.request('list_controls')
+
+ async def volume(self, value=None):
+ if value is not None:
+ return await self.request('volume', {'control': 'Master', 'value': value})
+ else:
+ return await self.request('volume', {'control': 'Master'})
+
+ async def mute(self, value=None):
+ return await self.request('mute', {'control': 'Master', 'value': value})
+
+
+async def main():
+ args = AudioMixerService.parser.parse_args()
+ ams = await AudioMixerService(ip=args.ipaddr, port=args.port)
+
+ if args.list_controls:
+ resp = await ams.list_controls()
+ print(f'Requesting list_controls with id {resp}')
+ r = AFBResponse(await ams.response())
+ print(r)
+
+ if args.setvolume is not None:
+ resp = await ams.volume(args.setvolume)
+ print(f'Setting volume to {args.setvolume} with id {resp}')
+ r = AFBResponse(await ams.response())
+ print(r)
+
+ if args.getvolume:
+ resp = await ams.volume()
+ print(f'Requesting volume with id {resp}')
+ r = AFBResponse(await ams.response())
+ print(r)
+
+ if args.setmute is not None:
+ resp = await ams.mute(args.setmute)
+ print(f'Setting mute to {args.setmute} with id {resp}')
+ r = AFBResponse(await ams.response())
+ print(r)
+
+ if args.getmute:
+ resp = await ams.mute()
+ r = AFBResponse(await ams.response())
+ print(r)
+
+ if args.subscribe:
+ for event in args.subscribe:
+ id = await ams.subscribe(event)
+ print(f'Subscribing to {event} with id {id}')
+ r = AFBResponse(await ams.response())
+ print(r)
+
+ if args.unsubscribe:
+ for event in args.unsubscribe:
+ id = await ams.unsubscribe(event)
+ print(f'Unsubscribing from {event} with id {id}')
+ r = AFBResponse(await ams.response())
+ print(r)
+
+ if args.listener:
+ async for response in ams.listener():
+ print(response)
+
+if __name__ == '__main__':
+ loop = asyncio.get_event_loop()
+ loop.run_until_complete(main())