| 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.fireface.ff_unit import FFUnit |
| 7 |
|
| 8 |
|
| 9 |
def handle_status(unit, args): |
| 10 |
print('Model name: {0}'.format(unit.get_model_name())) |
| 11 |
|
| 12 |
print('Current configuration:') |
| 13 |
for target in unit.get_single_option_labels(): |
| 14 |
print(' {0}'.format(target)) |
| 15 |
for item in unit.get_single_option_item_labels(target): |
| 16 |
print(' {0}: {1}'.format( |
| 17 |
item, unit.get_single_option(target, item))) |
| 18 |
for target in unit.get_multiple_option_labels(): |
| 19 |
print(' {0}: {1}'.format(target, unit.get_multiple_option(target))) |
| 20 |
|
| 21 |
print('Sync status:') |
| 22 |
for key, val in unit.get_sync_status().items(): |
| 23 |
if isinstance(val, dict): |
| 24 |
print(' {0}:'.format(key)) |
| 25 |
for name, state in val.items(): |
| 26 |
print(' {0}: {1}'.format(name, state)) |
| 27 |
else: |
| 28 |
print(' {0}: {1}'.format(key, val)) |
| 29 |
|
| 30 |
return True |
| 31 |
|
| 32 |
|
| 33 |
def handle_multiple_option(unit, args): |
| 34 |
ops = ('set', 'get') |
| 35 |
targets = unit.get_multiple_option_labels() |
| 36 |
if len(args) >= 2 and args[0] in targets and args[1] in ops: |
| 37 |
target = args[0] |
| 38 |
op = args[1] |
| 39 |
vals = unit.get_multiple_option_value_labels(target) |
| 40 |
if op == 'set' and len(args) >= 3 and args[2] in vals: |
| 41 |
val = args[2] |
| 42 |
unit.set_multiple_option(target, val) |
| 43 |
return True |
| 44 |
elif op == 'get': |
| 45 |
print(unit.get_multiple_option(target)) |
| 46 |
return True |
| 47 |
|
| 48 |
print('Arguments for multiple-option command:') |
| 49 |
print(' multiple-option TARGET OP [ITEM]') |
| 50 |
print(' TARGET: [{0}]'.format('|'.join(targets))) |
| 51 |
print(' OP [{0}]'.format('|'.join(ops))) |
| 52 |
for target in targets: |
| 53 |
vals = unit.get_multiple_option_value_labels(target) |
| 54 |
print(' ITEM [{0}] if TARGET={1} and OP=set'.format( |
| 55 |
'|'.join(vals), target)) |
| 56 |
return False |
| 57 |
|
| 58 |
|
| 59 |
def handle_single_option(unit, args): |
| 60 |
ops = ('set', 'get') |
| 61 |
targets = unit.get_single_option_labels() |
| 62 |
if len(args) >= 1 and args[0] in targets: |
| 63 |
target = args[0] |
| 64 |
items = unit.get_single_option_item_labels(target) |
| 65 |
if len(args) >= 3 and args[1] in items and args[2] in ops: |
| 66 |
item = args[1] |
| 67 |
op = args[2] |
| 68 |
if op == 'set' and len(args) >= 4: |
| 69 |
enable = True if args[3] == '1' else False |
| 70 |
unit.set_single_option(target, item, enable) |
| 71 |
return True |
| 72 |
elif op == 'get': |
| 73 |
print(unit.get_single_option(target, item)) |
| 74 |
return True |
| 75 |
print('Arguments for single-option command:') |
| 76 |
print(' single-option TARGET ITEM OP [ENABLE]') |
| 77 |
print(' TARGET: [{0}]'.format('|'.join(targets))) |
| 78 |
for target in targets: |
| 79 |
items = unit.get_single_option_item_labels(target) |
| 80 |
print(' ITEM [{0}] if TARGET={1}'.format( |
| 81 |
'|'.join(items), target)) |
| 82 |
print(' OP [{0}]'.format('|'.join(ops))) |
| 83 |
print(' ENABLE: [0|1]') |
| 84 |
return False |
| 85 |
|
| 86 |
|
| 87 |
def handle_mixer_src(unit, args): |
| 88 |
ops = ('set', 'get') |
| 89 |
targets = unit.get_mixer_labels() |
| 90 |
srcs = unit.get_mixer_src_labels() |
| 91 |
mute = unit.get_mixer_mute_db() |
| 92 |
minimum = unit.get_mixer_min_db() |
| 93 |
maximum = unit.get_mixer_max_db() |
| 94 |
if (len(args) >= 3 and args[0] in targets and args[1] in srcs |
| 95 |
and args[2] in ops): |
| 96 |
target = args[0] |
| 97 |
src = args[1] |
| 98 |
op = args[2] |
| 99 |
if op == 'set' and len(args) >= 4: |
| 100 |
db = float(args[3]) |
| 101 |
unit.set_mixer_src(target, src, db) |
| 102 |
return True |
| 103 |
elif op == 'get': |
| 104 |
print(unit.get_mixer_src(target, src)) |
| 105 |
return True |
| 106 |
print('Arguments for mixer-src command:') |
| 107 |
print(' mixer-src TARGET SRC OP [dB]') |
| 108 |
print(' TARGET: [{0}]'.format('|'.join(targets))) |
| 109 |
print(' SRC: [{0}]'.format('|'.join(srcs))) |
| 110 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 111 |
print(' dB: [{0}, {1:.1f}..{2:.1f}] if OP=set'.format( |
| 112 |
mute, minimum, maximum)) |
| 113 |
return False |
| 114 |
|
| 115 |
|
| 116 |
def handle_output(unit, args): |
| 117 |
ops = ('set', 'get') |
| 118 |
targets = unit.get_out_labels() |
| 119 |
mute = unit.get_mixer_mute_db() |
| 120 |
minimum = unit.get_mixer_min_db() |
| 121 |
maximum = unit.get_mixer_max_db() |
| 122 |
if len(args) >= 2 and args[0] in targets and args[1] in ops: |
| 123 |
target = args[0] |
| 124 |
op = args[1] |
| 125 |
if op == 'set' and len(args) >= 3: |
| 126 |
db = float(args[2]) |
| 127 |
unit.set_out_volume(target, db) |
| 128 |
return True |
| 129 |
elif op == 'get': |
| 130 |
print(unit.get_out_volume(target)) |
| 131 |
return True |
| 132 |
print('Arguments for output command:') |
| 133 |
print(' output TARGET [dB]') |
| 134 |
print(' TARGET: [{0}]'.format('|'.join(targets))) |
| 135 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 136 |
print(' dB: [{0}, {1:.1f}..{2:.1f}] if OP=set'.format( |
| 137 |
mute, minimum, maximum)) |
| 138 |
return False |
| 139 |
|
| 140 |
|
| 141 |
cmds = { |
| 142 |
'status': handle_status, |
| 143 |
'multiple-option': handle_multiple_option, |
| 144 |
'single-option': handle_single_option, |
| 145 |
'mixer-src': handle_mixer_src, |
| 146 |
'output': handle_output, |
| 147 |
} |
| 148 |
|
| 149 |
fullpath = CliKit.seek_snd_unit_path() |
| 150 |
if fullpath: |
| 151 |
with FFUnit(fullpath) as unit: |
| 152 |
CliKit.dispatch_command(unit, cmds) |