// http://forum.cockos.com/showthread.php?p=538046#post538046 // http://forum.cockos.com/showpost.php?p=546746&postcount=33 desc:simple MIDI clock generator slider1:0<0,3,1>BEAT slider2:0<0,1,1>RUN slider3:24<2,24,1>DIV slider4:0<0,100,1>time shift (ms) in_pin:none out_pin:none @init ext_noinit = 1; prev_count = 24; prev_play_state = 0; noteOnMsg = $x90; noteOffMsg = $x80; clockMsg = $xF8; startMsg = $xFA; stopMsg = $xFC; contMsg = $xFB; @slider time_div = slider3; pdc_delay = srate*slider4/1000; pdc_midi = 1; @block (beat_position%4 == 0) ? slider1 = 0; (beat_position%4 == 1) ? slider1 = 1; (beat_position%4 == 2) ? slider1 = 2; (beat_position%4 == 3) ? slider1 = 3; slider2 = play_state; my_beat_position = beat_position; /* save the current beat_position so we can extrapolate it */ beats_per_sample = (tempo/60)/srate; /* get the beats per sample so we can track the beat position at a given sample */ offset = 0; /* reset offset from current block start */ @sample (prev_count != (my_beat_position*time_div)%time_div) ? ( midisend(offset,clockMsg,0); prev_count = (my_beat_position*time_div)%time_div; ); (play_state != prev_play_state) ? ( (play_state == 0) ? midisend(offset,stopMsg,0); (play_state == 1 || play_state == 5) ? midisend(offset,startMsg,0); prev_play_state = play_state; ); my_beat_position += beats_per_sample; /* advance the beat with the current known tempo so we are tracking it sample accurate */ offset += 1; /* advance offset so we send the midi notes at the correct time */