-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlauncher.py
More file actions
85 lines (69 loc) · 2.5 KB
/
Copy pathlauncher.py
File metadata and controls
85 lines (69 loc) · 2.5 KB
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
#!/usr/bin/env python3
"""
DreamScaler Launcher
Single entry point for all DreamScaler tools.
Modes
-----
osc Start the Bitwig OSC bridge (listens for scale changes, drives LEDs)
piano Start the interactive piano tool (visualisation, scales, chords, demos)
Usage
-----
python launcher.py # interactive menu
python launcher.py --mode osc
python launcher.py --mode piano
python launcher.py --mode osc --port COM5 --osc-port 9001
python launcher.py --mode piano --port COM5
python launcher.py --mode piano --port COM5 --jump 12 # jump to GUI selector
"""
import argparse
import subprocess
import sys
import os
from config import COM_PORT
HERE = os.path.dirname(os.path.abspath(__file__))
def _run(script, extra_args):
path = os.path.join(HERE, script)
subprocess.run([sys.executable, path] + extra_args)
def _menu():
print()
print('=' * 50)
print(' DreamScaler Launcher')
print('=' * 50)
print(' 1. OSC Bridge (Bitwig -> LED)')
print(' 2. Piano tool (interactive)')
print('=' * 50)
return input(' Choose [1/2]: ').strip()
def main():
parser = argparse.ArgumentParser(
description='DreamScaler Launcher',
formatter_class=argparse.RawDescriptionHelpFormatter,
)
parser.add_argument('--mode', choices=['osc', 'piano'],
help='Tool to launch (osc or piano)')
parser.add_argument('--port', default=COM_PORT,
help=f'Arduino serial port (default: {COM_PORT})')
parser.add_argument('--osc-port', type=int, default=9001,
help='UDP port for OSC messages (default: 9001, osc mode only)')
parser.add_argument('--jump', default=None,
help='Jump straight to a piano menu option, e.g. 12 for GUI (piano mode only)')
args = parser.parse_args()
mode = args.mode
if mode is None:
choice = _menu()
if choice == '1':
mode = 'osc'
elif choice == '2':
mode = 'piano'
else:
print('Invalid choice'); sys.exit(1)
if mode == 'osc':
print(f'\nStarting OSC Bridge on {args.port}, OSC port {args.osc_port}...')
_run('osc_bridge.py', ['--port', args.port, '--osc-port', str(args.osc_port)])
elif mode == 'piano':
extra = [args.port]
if args.jump:
extra.append(args.jump)
print(f'\nStarting Piano tool on {args.port}...')
_run('piano.py', extra)
if __name__ == '__main__':
main()