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)
def emitter(): source = MIDISource("random note emitter") sleep(4) frames = [] frame_time = time() heappush_all(frames, gen_all_off(frame_time)) while True: heappush_all(frames, maybe_gen_notes(frame_time)) while frames and (frames[0][0] < frame_time): midi_out = heappop(frames) print "emit {}".format(midi_out[1]) source.send(midi_out[1]) now = time() wait_time = -1 while wait_time <= 0: frame_time = frame_time + LOOP_WAIT wait_time = frame_time - now sleep(wait_time)