Skip to content

Commit

Permalink
Example program that makes a MIDI echo/looper.
Browse files Browse the repository at this point in the history
  • Loading branch information
sixohsix committed May 15, 2012
1 parent 0282b21 commit dff36b6
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions simplecoremidi/examples/repeater.py
@@ -0,0 +1,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()

0 comments on commit dff36b6

Please sign in to comment.