-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurses_fs_mixer.py
More file actions
232 lines (199 loc) · 6.79 KB
/
Copy pathcurses_fs_mixer.py
File metadata and controls
232 lines (199 loc) · 6.79 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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/usr/bin/env python3
"""
Flexible MIDI Message Translator with Templates
"""
import os
os.chdir(os.path.dirname(os.path.realpath(__file__))) # set cwd to where the script is
import rtmidi
import time
PORT = 9988
import subprocess
channel = [0,1]
keep_running = True
levels = []
import curses
from curses import wrapper
def concat(*args, sep=' '):
return sep.join(str(arg) for arg in args)
# [240, 67, 16, 127, 28, 12, 1, 16, 24, 1, 247]
# [240, 67, 16, 127, 28, 12, 1, 16, 46, 14, 247]
def cursable(stdscr):
curses.curs_set(0)
load_levels()
posns = []
stage = ''
i = 0 # switch to specific selection and while loop
key = "primed"
while True:
run = False
#stdscr.clear()
stdscr.addstr( 12, 32, "L", curses.A_REVERSE)
stdscr.addstr( 0,0, f"Main > MIDI > Mixer{stage}")
if key == "primed": # interpret key inputs
pass
elif key == curses.KEY_RIGHT:
i += 1
elif key == curses.KEY_LEFT:
i -= 1
elif key == ord('\n'):
run = True
if i < 0: # loop
i = 16
if i > 16:
i = 0
y,x = 1,0
for L, level in enumerate(levels):
if i == L:
stdscr.addstr(y,x, format(level,"3d"), curses.A_REVERSE)
else:
stdscr.addstr(y,x, format(level,"3d"))
if L == 7:
y,x = 2,0
else:
x += 3
posns.append((y,x))
if i == 16:
stdscr.addstr(3,0, "Back", curses.A_REVERSE)
else:
stdscr.addstr(3,0, "Back")
# stdscr.addstr(y,x, ' ')
# stdscr.addstr(y,x, cycle[i], curses.A_REVERSE)
if run: # wrap run action in conditional
if i == 16:
save()
return
else:
fuck_with(stdscr, posns[i-1], i)
stdscr.addstr( 0,0, f"Main > MIDI > Mixer ")
stdscr.refresh()
key = stdscr.getch() #refresh in loop, don't handle end feedback separately
def fuck_with(stdscr, pos:tuple, chan:int):
stage = f" > {chan+1}"
global levels
i = levels[chan] # switch to specific selection and while loop
key = "primed"
while True:
run = False
#stdscr.clear()
stdscr.addstr( 12, 32, "L", curses.A_REVERSE)
stdscr.addstr( 0,0, f"Main > MIDI > Mixer{stage}")
if key == "primed": # interpret key inputs
pass
elif key == curses.KEY_RIGHT:
i += 2
elif key == curses.KEY_LEFT:
i -= 2
elif key == ord('\n'):
run = True
if i <= 0: # loop
i = 0
if i >= 127:
i = 127
# for L, level in enumerate(levels):
# if i == L:
# stdscr.addstr(*pos, str(level), curses.A_REVERSE)
# else:
# stdscr.addstr(*pos, str(level))
# if L == 7:
# y,x = 2,0
# else:
# x += 3
stdscr.addstr(*pos, format(i,"3d"), curses.A_REVERSE)
levels[chan] = i
subprocess.check_output(f"echo 'cc {chan} 7 {i}' | nc -q 0 localhost {PORT}", shell=True)
# stdscr.addstr(y,x, ' ')
# stdscr.addstr(y,x, cycle[i], curses.A_REVERSE)
if run: # wrap run action in conditional
return
stdscr.refresh()
key = stdscr.getch()
def test_callback(message, data):
print(message)
match message[0]:
case [240, 67, 16, 127, 28, 12, 1, 16, 31, 1, 247]:
pass # undo
case [240, 67, 16, 127, 28, 12, 1, 16, 39, 1, 247]:
channel[0] = 0
case [240, 67, 16, 127, 28, 12, 1, 16, 39, 2, 247]:
channel[0] = 4
case [240, 67, 16, 127, 28, 12, 1, 16, 39, 5, 247]:
channel[0] = 8
case [240, 67, 16, 127, 28, 12, 1, 16, 39, 6, 247]:
channel[0] = 12
case [240, 67, 16, 127, 28, 12, 1, 16, 39, 7, 247]:
channel[1] = 1
case [240, 67, 16, 127, 28, 12, 1, 16, 39, 8, 247]:
channel[1] = 2
case [240, 67, 16, 127, 28, 12, 1, 16, 39, 8, 247]:
channel[1] = 3
case [240, 67, 16, 127, 28, 12, 1, 16, 39, 10, 247]:
channel[1] = 4
case [240, 67, 16, 127, 28, 12, 1, 16, 39, 0, 247]:
save()
global keep_running
keep_running = False
if message[0][:-1] == [176,105] and message[0][-1] != 0:
chan = sum(channel)
global levels
levels[chan-1] = message[0][-1]
subprocess.check_output(f"echo 'cc {chan-1} 7 {message[0][-1]}' | nc -q 0 localhost {PORT}", shell=True)
print(f"\rSetting channel {format(chan, '2')} to volume {format(message[0][-1], '3')}", end='')
def load_levels(apply=False):
global levels
try:
with open("current.sav") as current:
line = "primed"
while not line.startswith("levels") and line != "":
line = current.readline()
if line.startswith("levels"):
for chan in line.strip().split()[1:]:
levels.append( int(chan) )
except:
pass
if not levels:
for i in range(16):
levels.append(63)
if apply:
for chn, val in enumerate(levels):
print(f"echo 'cc {chn} 7 {val}'")
subprocess.check_output(f"echo 'cc {chn} 7 {val}' | nc -q 0 localhost {PORT}", shell=True)
def save():
other_data = []
try:
with open("current.sav") as save_file:
save_data = save_file.readlines()
except:
pass
else:
for line in save_data:
if not line.startswith("levels"):
other_data.append(line)
save_data = other_data
save_data.append('levels ' + ' '.join(str(i) for i in levels)+'\n')
with open("current.sav", 'w') as save_file:
save_file.writelines(save_data)
if __name__=='__main__':
wrapper(cursable)
# seqtrak_in = rtmidi.MidiIn()
# port_name = "SEQTRAK MIDI"
# ports = seqtrak_in.get_ports()
# port_index = next((i for i, name in enumerate(ports) if port_name in name), None)
# if port_index is not None:
# seqtrak_in.open_port(port_index)
# load_levels()
# seqtrak_in.ignore_types(sysex=False)
# seqtrak_in.set_callback(test_callback)
# print('Fluidsynth mixer is running')
# try:
# while keep_running:
# # input()
# # channel = -1
# # try:
# # ch = int( input('Will mix on channel: ') )
# # except:
# # pass
# # if not os.path.isfile('.keep_running_daemons'):
# # raise KeyboardInterrupt('doens\'t matter what i type here')
# time.sleep(0.5)
# except KeyboardInterrupt:
# print("\nShutting down...")