| 1 |
#!/usr/bin/env python3 |
| 2 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 3 |
# Copyright (C) 2018 Takashi Sakamoto |
| 4 |
|
| 5 |
import sys |
| 6 |
import signal |
| 7 |
from time import sleep |
| 8 |
|
| 9 |
from hinawa_utils.misc.cli_kit import CliKit |
| 10 |
from hinawa_utils.dice.alesis_io_unit import AlesisIoUnit |
| 11 |
|
| 12 |
|
| 13 |
def handle_mixer_source_gain(unit, args): |
| 14 |
dsts = unit.get_mixer_labels() |
| 15 |
srcs = unit.get_mixer_src_labels() |
| 16 |
ops = ('set', 'get') |
| 17 |
chs = ('0', '1') |
| 18 |
if len(args) >= 4: |
| 19 |
dst, src, op, src_ch = args[0:4] |
| 20 |
if dst in dsts and src in srcs and op in ops and src_ch in chs: |
| 21 |
src_ch = int(src_ch) |
| 22 |
if op == 'set' and len(args) >= 5: |
| 23 |
db = float(args[4]) |
| 24 |
unit.set_mixer_src_gain(dst, src, src_ch, db) |
| 25 |
return True |
| 26 |
elif op == 'get': |
| 27 |
db = unit.get_mixer_src_gain(dst, src, src_ch) |
| 28 |
print('{0:.3f}'.format(db)) |
| 29 |
return True |
| 30 |
print('Arguments for mixer-source-gain') |
| 31 |
print(' mixer-source-gain DST SRC OP SRC_CH [DB]') |
| 32 |
print(' DST: [{0}]'.format('|'.join(dsts))) |
| 33 |
print(' SRC: [{0}]'.format('|'.join(srcs))) |
| 34 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 35 |
print(' SRC_CH: [{0}]'.format('|'.join(chs))) |
| 36 |
print(' DB: [-60.00-0.00]') |
| 37 |
return False |
| 38 |
|
| 39 |
|
| 40 |
def handle_mixer_source_panning(unit, args): |
| 41 |
dsts = unit.get_mixer_labels() |
| 42 |
srcs = unit.get_mixer_src_labels() |
| 43 |
ops = ('set', 'get') |
| 44 |
chs = ('0', '1') |
| 45 |
if len(args) >= 4: |
| 46 |
dst, src, op, src_ch = args[0:4] |
| 47 |
if src in srcs and dst in dsts and src_ch in chs and op in ops: |
| 48 |
src_ch = int(src_ch) |
| 49 |
if op == 'set' and len(args) >= 5: |
| 50 |
balance = float(args[4]) |
| 51 |
unit.set_mixer_src_balance(dst, src, src_ch, balance) |
| 52 |
return True |
| 53 |
elif op == 'get': |
| 54 |
balance = unit.get_mixer_src_balance(dst, src, src_ch) |
| 55 |
print('{:.3f}'.format(balance)) |
| 56 |
return True |
| 57 |
print('Arguments for mixer-source-panning') |
| 58 |
print(' mixer-source-panning DST SRC OP SRC_CH [BALANCE]') |
| 59 |
print(' DST: [{0}]'.format('|'.join(dsts))) |
| 60 |
print(' SRC: [{0}]'.format('|'.join(srcs))) |
| 61 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 62 |
print(' SRC_CH: [{0}]'.format('|'.join(chs))) |
| 63 |
print(' BALANCE:[0.0-100.0]') |
| 64 |
return False |
| 65 |
|
| 66 |
|
| 67 |
def handle_mixer_source_link(unit, args): |
| 68 |
dsts = unit.get_mixer_labels() |
| 69 |
srcs = unit.get_mixer_src_labels() |
| 70 |
ops = ('set', 'get') |
| 71 |
links = ('False', 'True') |
| 72 |
if len(args) >= 3: |
| 73 |
dst, src, op = args[0:3] |
| 74 |
if dst in dsts and src in srcs and op in ops: |
| 75 |
if op == 'set' and len(args) >= 4: |
| 76 |
link = args[3] == 'True' |
| 77 |
unit.set_mixer_src_link(dst, src, link) |
| 78 |
return True |
| 79 |
elif op == 'get': |
| 80 |
print(unit.get_mixer_src_link(dst, src)) |
| 81 |
return True |
| 82 |
print('Arguments for mixer-source-link') |
| 83 |
print(' mixer-source-link DST SRC OP [LINK]') |
| 84 |
print(' DST: [{0}]'.format('|'.join(dsts))) |
| 85 |
print(' SRC: [{0}]'.format('|'.join(srcs))) |
| 86 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 87 |
print(' LINK: [{0}]'.format('|'.join(links))) |
| 88 |
return False |
| 89 |
|
| 90 |
|
| 91 |
def handle_mixer_source_mute(unit, args): |
| 92 |
dsts = unit.get_mixer_labels() |
| 93 |
srcs = unit.get_mixer_src_labels() |
| 94 |
ops = ('set', 'get') |
| 95 |
chs = ('0', '1') |
| 96 |
if len(args) >= 4: |
| 97 |
dst, src, op, src_ch = args[0:4] |
| 98 |
if src in srcs and dst in dsts and src_ch in chs and op in ops: |
| 99 |
src_ch = int(src_ch) |
| 100 |
if op == 'set' and len(args) >= 5: |
| 101 |
mute = args[4] == 'True' |
| 102 |
unit.set_mixer_src_mute(dst, src, src_ch, mute) |
| 103 |
return True |
| 104 |
elif op == 'get': |
| 105 |
print(unit.get_mixer_src_mute(dst, src, src_ch)) |
| 106 |
return True |
| 107 |
print('Arguments for mixer-source-mute') |
| 108 |
print(' mixer-source-mute DST SRC OP SRC_CH [MUTE]') |
| 109 |
print(' DST: [{0}]'.format('|'.join(dsts))) |
| 110 |
print(' SRC: [{0}]'.format('|'.join(srcs))) |
| 111 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 112 |
print(' SRC_CH: [{0}]'.format('|'.join(chs))) |
| 113 |
print(' MUTE: [False|True]') |
| 114 |
return False |
| 115 |
|
| 116 |
|
| 117 |
def handle_enable_spdif_source(unit, args): |
| 118 |
ops = ('set', 'get') |
| 119 |
enables = ('False', 'True') |
| 120 |
if len(args) >= 1: |
| 121 |
op = args[0] |
| 122 |
if op == 'set' and len(args) >= 2: |
| 123 |
enable = args[1] == 'True' |
| 124 |
unit.set_mixer_spdif_src(enable) |
| 125 |
return True |
| 126 |
elif op == 'get': |
| 127 |
print(unit.get_mixer_spdif_src()) |
| 128 |
return True |
| 129 |
print('Arguments for enable-spdif-source:') |
| 130 |
print(' enable-spdif-source OP [ENABLE]') |
| 131 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 132 |
print(' ENABLE: [{0}]'.format('|'.join(enables))) |
| 133 |
return False |
| 134 |
|
| 135 |
|
| 136 |
def handle_mixer_out_volume(unit, args): |
| 137 |
targets = unit.get_mixer_labels() |
| 138 |
ops = ('set', 'get') |
| 139 |
chs = ('0', '1') |
| 140 |
if len(args) >= 3: |
| 141 |
target, op, ch = args[0:3] |
| 142 |
if target in targets and op in ops and ch in chs: |
| 143 |
ch = int(ch) |
| 144 |
if len(args) >= 4 and op == 'set': |
| 145 |
db = float(args[3]) |
| 146 |
unit.set_mixer_out_volume(target, ch, db) |
| 147 |
return True |
| 148 |
elif op == 'get': |
| 149 |
db = unit.get_mixer_out_volume(target, ch) |
| 150 |
print('{:.3f}'.format(db)) |
| 151 |
return True |
| 152 |
print('Arguments for mixer-out-volume command:') |
| 153 |
print(' mixer-out-volume TARGET OP CH [GAIN]') |
| 154 |
print(' TARGET: [{0}]'.format('|'.join(targets))) |
| 155 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 156 |
print(' CH: [{0}]'.format('|'.join(chs))) |
| 157 |
print(' dB: [-60.00-0.00]') |
| 158 |
return False |
| 159 |
|
| 160 |
|
| 161 |
def handle_mixer_out_level(unit, args): |
| 162 |
targets = unit.get_mixer_labels() |
| 163 |
ops = ('set', 'get') |
| 164 |
chs = ('0', '1') |
| 165 |
levels = unit.get_level_labels() |
| 166 |
|
| 167 |
if len(args) >= 3: |
| 168 |
target, op, ch = args[0:3] |
| 169 |
if target in targets and op in ops and ch in chs: |
| 170 |
ch = int(ch) |
| 171 |
if len(args) >= 4 and op == 'set' and args[3] in levels: |
| 172 |
level = args[3] |
| 173 |
unit.set_mixer_out_level(target, ch, level) |
| 174 |
return True |
| 175 |
elif op == 'get': |
| 176 |
print(unit.get_mixer_out_level(target, ch)) |
| 177 |
return True |
| 178 |
print('Arguments for mixer-out-level command:') |
| 179 |
print(' mixer-out-level TARGET OP CH [LEVEL]') |
| 180 |
print(' TARGET: [{0}]'.format('|'.join(targets))) |
| 181 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 182 |
print(' CH: [{0}]'.format('|'.join(chs))) |
| 183 |
print(' LEVEL: [{0}]'.format('|'.join(unit.get_level_labels()))) |
| 184 |
return False |
| 185 |
|
| 186 |
|
| 187 |
def handle_mixer_out_mute(unit, args): |
| 188 |
targets = unit.get_mixer_labels() |
| 189 |
ops = ('set', 'get') |
| 190 |
chs = ('0', '1') |
| 191 |
mutes = ('False', 'True') |
| 192 |
levels = unit.get_level_labels() |
| 193 |
|
| 194 |
if len(args) >= 3: |
| 195 |
target, op, ch = args[0:3] |
| 196 |
if target in targets and op in ops and ch in chs: |
| 197 |
ch = int(ch) |
| 198 |
if len(args) >= 4 and op == 'set' and args[3] in mutes: |
| 199 |
mute = args[3] == 'True' |
| 200 |
unit.set_mixer_out_mute(target, ch, mute) |
| 201 |
return True |
| 202 |
elif op == 'get': |
| 203 |
print(unit.get_mixer_out_mute(target, ch)) |
| 204 |
return True |
| 205 |
print('Arguments for mixer-out-mute command:') |
| 206 |
print(' mixer-out-mute TARGET OP CH [MUTE]') |
| 207 |
print(' TARGET: [{0}]'.format('|'.join(targets))) |
| 208 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 209 |
print(' CH: [{0}]'.format('|'.join(chs))) |
| 210 |
print(' MUTE: [True|False]') |
| 211 |
return False |
| 212 |
|
| 213 |
|
| 214 |
def handle_output_source(unit, args): |
| 215 |
targets = unit.get_output_labels() |
| 216 |
ops = ('set', 'get') |
| 217 |
|
| 218 |
if len(args) >= 2: |
| 219 |
target, op = args[0:2] |
| 220 |
if target in targets and op in ops: |
| 221 |
srcs = unit.get_output_src_labels(target) |
| 222 |
if len(args) >= 3 and args[2] in srcs: |
| 223 |
src = args[2] |
| 224 |
unit.set_output_src(target, src) |
| 225 |
return True |
| 226 |
elif op == 'get': |
| 227 |
print(unit.get_output_src(target)) |
| 228 |
return True |
| 229 |
print('Arguments for output-source command:') |
| 230 |
print(' output-source TARGET OP [SRC]') |
| 231 |
print(' TARGET: [{0}]'.format('|'.join(targets))) |
| 232 |
print(' OP: [{0}]'.format('|'.join(ops))) |
| 233 |
for target in targets: |
| 234 |
labels = unit.get_output_src_labels(target) |
| 235 |
if len(labels) == 1: |
| 236 |
print(' SRC: {0} is fixed to TARGET={1}'.format( |
| 237 |
labels[0], target)) |
| 238 |
else: |
| 239 |
print(' SRC: [{0}] if TARGET={1} and OP=set'.format( |
| 240 |
'|'.join(labels), target)) |
| 241 |
return False |
| 242 |
|
| 243 |
|
| 244 |
def handle_listen_metering(unit, args): |
| 245 |
labels = unit.get_meter_labels() |
| 246 |
signal.signal(signal.SIGINT, lambda signum, frame: sys.exit()) |
| 247 |
while True: |
| 248 |
meters = unit.get_meters() |
| 249 |
for i, label in enumerate(labels): |
| 250 |
print('{0}: {1:.3f} dB'.format(label, meters[i])) |
| 251 |
print() |
| 252 |
sleep(0.5) |
| 253 |
return True |
| 254 |
|
| 255 |
|
| 256 |
cmds = { |
| 257 |
'mixer-source-gain': handle_mixer_source_gain, |
| 258 |
'mixer-source-panning': handle_mixer_source_panning, |
| 259 |
'mixer-source-link': handle_mixer_source_link, |
| 260 |
'mixer-source-mute': handle_mixer_source_mute, |
| 261 |
'mixer-out-volume': handle_mixer_out_volume, |
| 262 |
'mixer-out-level': handle_mixer_out_level, |
| 263 |
'mixer-out-mute': handle_mixer_out_mute, |
| 264 |
'output-source': handle_output_source, |
| 265 |
'listen-metering': handle_listen_metering, |
| 266 |
} |
| 267 |
|
| 268 |
fullpath = CliKit.seek_snd_unit_path() |
| 269 |
if fullpath: |
| 270 |
with AlesisIoUnit(fullpath) as unit: |
| 271 |
if unit.name == 'iO|26': |
| 272 |
cmds['use-spdif-source'] = handle_enable_spdif_source |
| 273 |
CliKit.dispatch_command(unit, cmds) |