-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhinawa-tascam-fw-rack-cli
executable file
·169 lines (144 loc) · 5.68 KB
/
hinawa-tascam-fw-rack-cli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright (C) 2018 Takashi Sakamoto
from hinawa_utils.misc.cli_kit import CliKit
from hinawa_utils.tscm.tscm_rack_unit import TscmRackUnit
def handle_clock_source(unit, args):
ops = ('set', 'get')
if len(args) > 0 and args[0] in ops:
op = args[0]
if op == ops[0] and len(args) == 2:
if unit.get_property('is-locked'):
print('Packet is-locked started.')
return False
source = args[1]
unit.set_clock_source(source)
else:
print(unit.get_clock_source())
return True
print('Arguments for clock-source command:')
print(' clock-source OP [SRC]')
print(' OP: [{0}]'.format('|'.join(ops)))
print(' SRC: [{0}]'.format('|'.join(unit.supported_clock_sources)))
return False
def handle_sampling_rate(unit, args):
ops = ('set', 'get')
if len(args) > 0 and args[0] in ops:
op = args[0]
if op == ops[0] and len(args) == 2:
rate = int(args[1])
unit.set_sampling_rate(rate)
else:
print(unit.get_sampling_rate())
return True
print('Arguments for sampling-rate command:')
print(' sampling-rate OP [RATE]')
print(' OP: [{0}]'.format('|'.join(ops)))
rates = [str(r) for r in unit.supported_sampling_rates]
print(' RATE: [{0}]'.format('|'.join(rates)))
return False
def handle_firmware_versions(unit, args):
info = unit.get_firmware_versions()
for name, value in info.items():
print('{0}: {1}'.format(name, value))
return True
def handle_routing(unit, args, cmd, labels, set_func, get_func):
ops = ('set', 'get')
if len(args) > 0 and args[0] in ops:
op = args[0]
if op == ops[0] and len(args) == 2 and args[1] in labels:
src = args[1]
set_func(src)
return True
elif op == 'get':
print(get_func())
return True
print('Arguments for {0} command:'.format(cmd))
print(' {0} OP [SRC]'.format(cmd))
print(' OP: [{0}]'.format('|'.join(ops)))
print(' SRC: [{0}]'.format('|'.join(labels)))
return False
def handle_coax_out_src(unit, args):
return handle_routing(unit, args, 'coaxial-out-source',
unit.get_coax_out_src_labels(),
unit.set_coax_out_src,
unit.get_coax_out_src)
def handle_opt_out_src(unit, args):
return handle_routing(unit, args, 'optical-out-source',
unit.get_opt_out_src_labels(),
unit.set_opt_out_src,
unit.get_opt_out_src)
def handle_stream_spdif_in_src(unit, args):
return handle_routing(unit, args, 'stream-spdif-in-source',
unit.get_stream_spdif_in_src_labels(),
unit.set_stream_spdif_in_src,
unit.get_stream_spdif_in_src)
def handle_input_threshold(unit, args):
ops = ('set', 'get')
if len(args) >= 1 and args[0] in ops:
op = args[0]
if op == 'set' and len(args) >= 2:
level = float(args[1])
unit.set_input_threshold(level)
return True
elif op == 'get':
level = unit.get_input_threshold()
print('{:.3f}'.format(level))
return True
print('Arguments for input-threshold command:')
print(' input-threshold OP [LEVEL]')
print(' OP: [{0}]'.format('|'.join(ops)))
print(' LEVEL: [-inf, -90..0]')
return True
def handle_monitor_input(unit, args):
ops = ('set', 'get')
items = {
'gain': (unit.set_gain, unit.get_gain),
'mute': (unit.set_mute, unit.get_mute),
'balance': (unit.set_balance, unit.get_balance),
}
labels = unit.get_channel_labels()
if len(args) >= 1 and args[0] in labels:
ch = args[0]
if len(args) >= 2 and args[1] in items:
item = args[1]
set_func, get_func = items[item]
if len(args) >= 3 and args[2] in ops:
op = args[2]
if len(args) >= 4 and op == 'set':
val = None
if item == 'gain':
val = float(args[3])
elif item == 'mute':
val = bool(int(args[3]))
elif item == 'balance':
val = int(args[3])
if val != None:
set_func(ch, val)
return True
elif op == 'get':
print(get_func(ch))
return True
print('Arguments for monitor-input command:')
print(' monitor-input CH ITEM OP [dB|MUTE|BALANCE]')
print(' CH: [{0}]'.format('|'.join(labels)))
print(' ITEM: [{0}]'.format('|'.join(items)))
print(' OP: [{0}]'.format('|'.join(ops)))
print(' dB: [0-99] (percentage) if OP=set')
print(' MUTE: [0|1] if OP=set')
print(' BALANCE:[0-99] (left-to-right, percentage) if OP=set')
return False
cmds = {
'clock-source': handle_clock_source,
'sampling-rate': handle_sampling_rate,
'firmware-versions': handle_firmware_versions,
'coaxial-out-source': handle_coax_out_src,
'optical-out-source': handle_opt_out_src,
'stream-spdif-in-source': handle_stream_spdif_in_src,
'input-threshold': handle_input_threshold,
'monitor-input': handle_monitor_input,
}
fullpath = CliKit.seek_snd_unit_path()
if fullpath:
with TscmRackUnit(fullpath) as unit:
CliKit.dispatch_command(unit, cmds)