-
Notifications
You must be signed in to change notification settings - Fork 16
/
repeater.py
36 lines (29 loc) · 908 Bytes
/
repeater.py
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
from time import time, sleep
from simplecoremidi import MIDISource, MIDIDestination
LOOP_WAIT = 1.0 / 200 # 200 Hz
DELAY = 1 # 1 sec
def repeater():
dest = MIDIDestination("repeater input")
source = MIDISource("repeater output")
frames = []
last_frame_time = time()
while True:
midi_in = dest.recv()
if midi_in:
#source.send(midi_in)
frames.append((last_frame_time + DELAY, midi_in))
while frames:
midi_out = frames[0]
if midi_out[0] < last_frame_time:
source.send(midi_out[1])
frames.pop(0)
else:
break
now = time()
wait_time = -1
while wait_time <= 0:
last_frame_time = last_frame_time + LOOP_WAIT
wait_time = last_frame_time - now
sleep(wait_time)
if __name__=='__main__':
repeater()