| 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.oxfw.tascam_fireone import TascamFireone |
| 7 |
|
| 8 |
# Helper functions |
| 9 |
|
| 10 |
|
| 11 |
def handle_current_status(unit, args): |
| 12 |
print('Current status:') |
| 13 |
print(' Packet Streaming:') |
| 14 |
print(' running: {0}'.format(unit.get_property('is-locked'))) |
| 15 |
fmts = unit.get_current_stream_formats() |
| 16 |
print( |
| 17 |
' sampling-rate: {0}'.format(fmts['playback']['sampling-rate'])) |
| 18 |
print(' Control surface:') |
| 19 |
print(' display-mode: {0}'.format(unit.get_display_mode())) |
| 20 |
print(' control-mode: {0}'.format(unit.get_control_mode())) |
| 21 |
print(' input-mode: {0}'.format(unit.get_input_mode())) |
| 22 |
print('ASIC information:') |
| 23 |
print(' type: {0}'.format(unit.hw_info['asic-type'])) |
| 24 |
print(' ID: {0}'.format(unit.hw_info['asic-id'])) |
| 25 |
print(' firmware version: {0}'.format(unit.hw_info['firmware-version'])) |
| 26 |
print('TASCAM firmware information:') |
| 27 |
print(' version: {0}'.format(unit.get_firmware_version())) |
| 28 |
return True |
| 29 |
|
| 30 |
|
| 31 |
def handle_display_mode(unit, args): |
| 32 |
ops = ('set', 'get') |
| 33 |
modes = unit.get_display_mode_labels() |
| 34 |
if len(args) > 0 and args[0] in ops: |
| 35 |
op = args[0] |
| 36 |
if op == ops[0] and len(args) == 2 and args[1] in modes: |
| 37 |
mode = args[1] |
| 38 |
unit.set_display_mode(mode) |
| 39 |
else: |
| 40 |
print(unit.get_display_mode()) |
| 41 |
return True |
| 42 |
print('Arguments for display-mode command:') |
| 43 |
print(' display-mode OPERATION [MODE]') |
| 44 |
print(' OPERATION: {0}'.format(', '.join(ops))) |
| 45 |
print(' MODE: {0}'.format(', '.join(modes))) |
| 46 |
return False |
| 47 |
|
| 48 |
|
| 49 |
def handle_control_mode(unit, args): |
| 50 |
ops = ('set', 'get') |
| 51 |
modes = unit.get_control_mode_labels() |
| 52 |
if len(args) > 0 and args[0] in ops: |
| 53 |
op = args[0] |
| 54 |
if op == ops[0] and len(args) == 2 and args[1] in modes: |
| 55 |
mode = args[1] |
| 56 |
unit.set_control_mode(mode) |
| 57 |
else: |
| 58 |
print(unit.get_control_mode()) |
| 59 |
return True |
| 60 |
print('Arguments for control-mode command:') |
| 61 |
print(' control-mode OPERATION [MODE]') |
| 62 |
print(' OPERATION: {0}'.format(', '.join(ops))) |
| 63 |
print(' MODE: {0}'.format(', '.join(modes))) |
| 64 |
return False |
| 65 |
|
| 66 |
|
| 67 |
def handle_input_mode(unit, args): |
| 68 |
ops = ('set', 'get') |
| 69 |
modes = unit.get_input_mode_labels() |
| 70 |
if len(args) > 0 and args[0] in ops: |
| 71 |
op = args[0] |
| 72 |
if op == ops[0] and len(args) == 2 and args[1] in modes: |
| 73 |
mode = args[1] |
| 74 |
unit.set_input_mode(mode) |
| 75 |
else: |
| 76 |
print(unit.get_input_mode()) |
| 77 |
return True |
| 78 |
print('Arguments for input-mode command:') |
| 79 |
print(' input-mode OPERATION [MODE]') |
| 80 |
print(' OPERATION: {0}'.format(', '.join(ops))) |
| 81 |
print(' MODE: {0}'.format(', '.join(modes))) |
| 82 |
return False |
| 83 |
|
| 84 |
|
| 85 |
def handle_sampling_rate(unit, args): |
| 86 |
ops = ('set', 'get') |
| 87 |
if len(args) > 0 and args[0] in ops: |
| 88 |
op = args[0] |
| 89 |
if op == ops[0] and len(args) == 2: |
| 90 |
if unit.get_property('is-locked'): |
| 91 |
print('Packet is-locked started.') |
| 92 |
return False |
| 93 |
rate = int(args[1]) |
| 94 |
for fmt in unit.supported_stream_formats['playback']: |
| 95 |
if fmt['sampling-rate'] == rate: |
| 96 |
playback = fmt |
| 97 |
break |
| 98 |
else: |
| 99 |
print('Invalid argument for sampling rate') |
| 100 |
return False |
| 101 |
for fmt in unit.supported_stream_formats['capture']: |
| 102 |
if fmt['sampling-rate'] == rate: |
| 103 |
capture = fmt |
| 104 |
break |
| 105 |
else: |
| 106 |
print('Invalid argument for sampling rate') |
| 107 |
return False |
| 108 |
unit.set_stream_formats(playback, capture) |
| 109 |
else: |
| 110 |
fmts = unit.get_current_stream_formats() |
| 111 |
print(fmts['playback']['sampling-rate']) |
| 112 |
return True |
| 113 |
print('Arguments for sampling-rate command:') |
| 114 |
print(' input-mode OPERATION [RATE]') |
| 115 |
print(' OPERATION: {0}'.format(', '.join(ops))) |
| 116 |
fmts = unit.supported_stream_formats['playback'] |
| 117 |
rates = [str(fmt['sampling-rate']) for fmt in fmts] |
| 118 |
print(' MODE: {0}'.format(', '.join(rates))) |
| 119 |
return True |
| 120 |
|
| 121 |
|
| 122 |
cmds = { |
| 123 |
'current-status': handle_current_status, |
| 124 |
'display-mode': handle_display_mode, |
| 125 |
'control-mode': handle_control_mode, |
| 126 |
'input-mode': handle_input_mode, |
| 127 |
'sampling-rate': handle_sampling_rate, |
| 128 |
} |
| 129 |
|
| 130 |
fullpath = CliKit.seek_snd_unit_path() |
| 131 |
if fullpath: |
| 132 |
with TascamFireone(fullpath) as unit: |
| 133 |
CliKit.dispatch_command(unit, cmds) |