| 1 |
#!/usr/bin/env python3 |
| 2 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 3 |
# Copyright (C) 2018 Takashi Sakamoto |
| 4 |
|
| 5 |
from hinawa_utils.misc.cli_kit import CliKit |
| 6 |
from hinawa_utils.dg00x.dg003_unit import Dg003Unit |
| 7 |
|
| 8 |
|
| 9 |
def handle_mixer_state(unit, args): |
| 10 |
ops = ('set', 'get') |
| 11 |
states = ('Disabled', 'Enabled') |
| 12 |
if len(args) >= 1 and args[0] in ops: |
| 13 |
op = args[0] |
| 14 |
if len(args) >= 2 and op == 'set' and args[1] in states: |
| 15 |
enabled = bool(args[1] == 'Enabled') |
| 16 |
unit.set_mixer_status(enabled) |
| 17 |
return True |
| 18 |
else: |
| 19 |
state = unit.get_mixer_status() |
| 20 |
index = 1 if state else 0 |
| 21 |
print(states[index]) |
| 22 |
return True |
| 23 |
print('Argumetns for mixer-state command:') |
| 24 |
print(' mixer-enable OP [ENABLED]') |
| 25 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 26 |
print(' ENABLED:[{0}]'.format('|'.join(states))) |
| 27 |
return False |
| 28 |
|
| 29 |
|
| 30 |
def handle_mixer_source(unit, args): |
| 31 |
srcs = unit.get_mixer_src_labels() |
| 32 |
items = { |
| 33 |
'pan': { |
| 34 |
'set': unit.set_mixer_src_balance, |
| 35 |
'get': unit.get_mixer_src_balance, |
| 36 |
}, |
| 37 |
'gain': { |
| 38 |
'set': unit.set_mixer_src_gain, |
| 39 |
'get': unit.get_mixer_src_gain, |
| 40 |
}, |
| 41 |
} |
| 42 |
ops = ('set', 'get') |
| 43 |
chs = ('0', '1') |
| 44 |
if len(args) >= 4: |
| 45 |
src, item, op, ch = args[0:4] |
| 46 |
if src in srcs and item in items and op in ops and ch in chs: |
| 47 |
ch = int(ch) |
| 48 |
if op == 'set' and len(args) >= 5: |
| 49 |
val = float(args[4]) |
| 50 |
items[item][op](src, ch, val) |
| 51 |
return True |
| 52 |
elif op == 'get': |
| 53 |
val = items[item][op](src, ch) |
| 54 |
print('{:.3f}'.format(val)) |
| 55 |
return True |
| 56 |
print('Arguments for mixer-source command:') |
| 57 |
print(' mixer-source SRC ITEM OP CH [dB|BALANCE]') |
| 58 |
print(' SRC: [{0}]'.format('|'.join(srcs))) |
| 59 |
print(' ITEMS: [{0}]'.format('|'.join(items))) |
| 60 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 61 |
print(' CH: [{0}]'.format('|'.join(chs))) |
| 62 |
print(' dB: [-inf, -175.000...0.000]') |
| 63 |
print(' BALANCE:[0.000...100.000]') |
| 64 |
return False |
| 65 |
|
| 66 |
|
| 67 |
cmds = { |
| 68 |
'mixer-state': handle_mixer_state, |
| 69 |
'mixer-source': handle_mixer_source, |
| 70 |
} |
| 71 |
|
| 72 |
fullpath = CliKit.seek_snd_unit_path() |
| 73 |
if fullpath: |
| 74 |
with Dg003Unit(fullpath) as unit: |
| 75 |
CliKit.dispatch_command(unit, cmds) |