forked from YeshiNamkhai/ResonatingWithYou
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.py
More file actions
138 lines (117 loc) · 4.72 KB
/
start.py
File metadata and controls
138 lines (117 loc) · 4.72 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
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
#!/usr/bin/env python3
"""
Resonating With You — Script Launcher
======================================
Launch any of the quadraphonic generative audio scripts.
After a script finishes, the menu reappears. Press ESC or 0 to exit.
"""
import os
import sys
import subprocess
SCRIPTS = [
("beings_field2.py", "Living Beings Field"),
("entropic_field2.py", "Entropic Field — Generative Audio"),
("formalized_m2.py", "Formalized Music — Stochastic Audio"),
("gen_field2.py", "Generative Field — Walker Audio"),
("psychoa_test2.py", "Psychoacoustic Tests"),
("stochastic_field2.py", "Stochastic Field — Rhythmic Cells"),
("synth_harms2.py", "Quadraphonic Harmonic Synth"),
("chnn_scan2.py", "ChNN Sonic Image — Image Sonifier"),
("test_speakers2.py", "4-Channel Audio & Grid Test"),
]
# Resolve script directory (same folder as start.py)
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
# Auto-detect virtual environment Python interpreter
# (no need to "source activate" — we just use the venv's python directly)
def find_venv_python():
"""Find the Python interpreter inside .venv (macOS/Linux + Windows)."""
venv_dir = os.path.join(SCRIPT_DIR, '.venv')
if not os.path.isdir(venv_dir):
return sys.executable # No venv found, use system Python
# Windows: .venv\Scripts\python.exe
win_python = os.path.join(venv_dir, 'Scripts', 'python.exe')
if os.path.isfile(win_python):
return win_python
# macOS/Linux: .venv/bin/python
unix_python = os.path.join(venv_dir, 'bin', 'python')
if os.path.isfile(unix_python):
return unix_python
return sys.executable # Fallback
VENV_PYTHON = find_venv_python()
if VENV_PYTHON != sys.executable:
print(f" Using venv: {VENV_PYTHON}")
HEADER = """
╔══════════════════════════════════════════════════╗
║ Resonating With You ║
║ Quadraphonic Audio Suite ║
╚══════════════════════════════════════════════════╝
"""
def print_menu():
print(HEADER)
for i, (_, name) in enumerate(SCRIPTS, 1):
print(f" {i}. {name}")
print(f"\n 0. Exit")
print(f" ─────────────────────────────────────────")
def get_choice():
"""Cross-platform single-key input with ESC support."""
try:
# Try Windows first
import msvcrt
while True:
print("\n Select [1-9] or [0/ESC] to exit: ", end='', flush=True)
while True:
if msvcrt.kbhit():
ch = msvcrt.getch()
if ch == b'\x1b': # ESC
print("ESC")
return None
try:
val = int(ch.decode('utf-8', 'ignore'))
print(str(val))
return val
except (ValueError, UnicodeDecodeError):
pass
except ImportError:
# macOS / Linux: use simple input() — ESC handled as fallback
while True:
try:
raw = input("\n Select [1-9] or [0/ESC] to exit: ").strip()
if not raw or raw == '\x1b':
return None
val = int(raw)
return val
except (ValueError, EOFError, KeyboardInterrupt):
return None
def run_script(filename, extra_args=None):
"""Run a script as a subprocess, forwarding all CLI arguments."""
script_path = os.path.join(SCRIPT_DIR, filename)
if not os.path.isfile(script_path):
print(f"\n [ERROR] Script not found: {script_path}")
return
cmd = [VENV_PYTHON, script_path]
if extra_args:
cmd.extend(extra_args)
print(f"\n Launching: {filename}")
print(f" {'─' * 48}\n")
try:
subprocess.run(cmd, cwd=SCRIPT_DIR)
except KeyboardInterrupt:
pass
print(f"\n {'─' * 48}")
print(f" Script finished: {filename}")
def main():
# Collect any extra args (like -d 5, -c 4, -e) to forward to scripts
extra_args = sys.argv[1:]
while True:
print_menu()
choice = get_choice()
if choice is None or choice == 0:
print("\n Goodbye.\n")
break
if 1 <= choice <= len(SCRIPTS):
filename, name = SCRIPTS[choice - 1]
run_script(filename, extra_args)
else:
print(f"\n Invalid choice: {choice}")
if __name__ == "__main__":
main()