-
Notifications
You must be signed in to change notification settings - Fork 6
/
hinawa-focusrite-saffirepro-io-cli
executable file
·181 lines (165 loc) · 6.8 KB
/
hinawa-focusrite-saffirepro-io-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
170
171
172
173
174
175
176
177
178
179
180
181
#!/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.bebob.focusrite_saffirepro_io import FocusriteSaffireproIoUnit
def handle_mixer_input(unit, args):
ITEMS = {
'balance': (unit.set_mixer_input_balance,
unit.get_mixer_input_balance),
'gain': (unit.set_mixer_input_gain,
unit.get_mixer_input_gain),
}
CHS = (1, 2)
OPS = ('set', 'get')
targets = unit.get_mixer_input_labels()
if len(args) >= 1 and args[0] in targets:
target = args[0]
if len(args) >= 2 and args[1] in ITEMS:
set_func, get_func = ITEMS[args[1]]
if len(args) >= 3 and int(args[2]) in CHS:
ch = int(args[2])
if len(args) >= 4 and args[3] in OPS:
op = args[3]
if len(args) >= 5 and op == 'set':
val = float(args[4])
set_func(target, ch, val)
return True
elif op == 'get':
print(get_func(target, ch))
return True
print('Arguments for mixer-input command:')
print(' mixer-input TARGET ITEM CH OP [dB|BALANCE]')
print(' TARGET: [{0}]'.format('|'.join(targets)))
print(' ITEM: [{0}]'.format('|'.join(ITEMS)))
print(' CH: [{0}] (0=both)'.format('|'.join(map(str, CHS))))
print(' OP: [{0}]'.format('|'.join(OPS)))
print(' dB: [-128.0..128.0] if ITEM=gain and OP=set')
print(' BALANCE:[0..99] (left-to-right) if ITEM=balance and OP=set')
return False
def handle_output_params(unit, args):
ITEMS = {
'volume': (unit.set_output_volume, unit.get_output_volume),
'mute': (unit.set_output_mute, unit.get_output_mute),
'dim': (unit.set_output_dim, unit.get_output_dim),
'hwctl': (unit.set_output_hwctl, unit.get_output_hwctl),
'pad': (unit.set_output_pad, unit.get_output_pad),
}
OPS = ('set', 'get')
targets = unit.get_output_labels()
if len(args) >= 1 and args[0] in targets:
target = 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':
db = float(args[3])
set_func(target, db)
return True
elif op == 'get':
print(get_func(target))
return True
print('Arguments for output-params command:')
print(' output-params TARGET ITEM OP [dB|MUTE|DIM|HECTL|PAD]')
print(' TARGET: [{0}]'.format('|'.join(targets)))
print(' ITEM: [{0}]'.format('|'.join(ITEMS)))
print(' OP: [{0}]'.format('|'.join(OPS)))
print(' dB: [-128.00..128.00] if ITEM=volume and OP=set')
print(' MUTE: [0|1] if ITEM=mute and OP=set')
print(' DIM: [0|1] if ITEM=dim and OP=set')
print(' HWCTL: [0|1] if ITEM=hwctl and OP=set')
print(' PAD: [0|1] if ITEM=pad and OP=set')
return False
def handle_output_source(unit, args):
OPS = ('set', 'get')
targets = unit.get_output_destination_labels()
if len(args) >= 1 and args[0] in targets:
target = args[0]
if len(args) >= 2 and args[1] in OPS:
op = args[1]
sources = unit.get_output_source_labels(target)
if len(args) >= 3 and op == 'set' and args[2] in sources:
source = args[2]
unit.set_output_source(target, source)
return True
elif op == 'get':
print(unit.get_output_source(target))
return True
print('Arguments for output-source command:')
print(' output-source TARGET OP [SRC]')
print(' TARGET: [{0}]'.format('|'.join(targets)))
print(' OP: [{0}]'.format('|'.join(OPS)))
for target in targets:
sources = unit.get_output_source_labels(target)
print(' SRC: [{0}] if TARGET={1} and OP=set'.format(
'|'.join(sources), target))
return False
def handle_rate_mode(unit, args):
OPS = ('set', 'get')
modes = unit.get_supported_rate_modes()
if len(args) >= 1 and args[0] in OPS:
op = args[0]
if len(args) >= 2 and op == 'set' and args[1] in modes:
mode = args[1]
unit.set_rate_mode(mode)
return True
elif op == 'get':
print(unit.get_rate_mode())
return True
print('Arguments for rate-mode command:')
print(' rate-mode OP [MODE]')
print(' OP: [{0}]'.format('|'.join(OPS)))
print(' MODE: [{0}]'.format('|'.join(modes)))
print(' Packet streaming should be stopped.')
print(' The set operation corresponds to bus reset.')
return False
def handle_sampling_rate(unit, args):
OPS = ('set', 'get')
rates = unit.get_supported_sampling_rates()
if len(args) >= 1 and args[0] in OPS:
op = args[0]
if len(args) >= 2 and op == 'set' and int(args[1]) in rates:
rate = int(args[1])
unit.set_sampling_rate(rate)
return True
elif op == 'get':
print(unit.get_sampling_rate())
return True
print('Arguments for sampling-rate command:')
print(' sampling-rate OP [SOURCE]')
print(' OP: [{0}]'.format('|'.join(OPS)))
print(' SOURCE: [{0}]'.format('|'.join(map(str, rates))))
print(' Packet streaming should be stopped.')
return False
def handle_clock_source(unit, args):
OPS = ('set', 'get')
sources = unit.get_supported_clock_sources()
if len(args) > 0 and args[0] in OPS:
op = args[0]
if len(args) > 1 and op == 'set' and args[1] in sources:
source = args[1]
unit.set_clock_source(source)
return True
elif op == 'get':
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}] if OP=set'.format('|'.join(sources)))
print(' Packet streaming should be stopped.')
return False
cmds = {
'mixer-input': handle_mixer_input,
'output-params': handle_output_params,
'output-source': handle_output_source,
'rate-mode': handle_rate_mode,
'sampling-rate': handle_sampling_rate,
'clock-source': handle_clock_source,
}
fullpath = CliKit.seek_snd_unit_path()
if fullpath:
with FocusriteSaffireproIoUnit(fullpath) as unit:
CliKit.dispatch_command(unit, cmds)