{===========================} { fake round robin } { by SzcZ (c) 2014 } { www.fairlyconfusing.net } {===========================} on init {...................................................} { edit these value to match instrument's note range } { enter numbers for lowest and highest notes } {...................................................} declare const $LOW_note := 0 declare const $HIGH_note := 127 {...................................................} { this is starting seed for random number generator } { you can type in any number greater than zero } {...................................................} declare const $mother_seed := 101303404 {...................................................} set_script_title("Fake round robin") set_ui_height_px(100) set_listener ($NI_SIGNAL_TRANSP_START,1) {variables} declare $count declare $shadow_note_id declare $note_number declare $last_random := -1 declare const $KEY_RANGE := $HIGH_note - $LOW_note {ui coordinates} declare const $x_pos := 80 declare const $y_pos := 20 declare const $x_spc := 110 declare const $x_lab := 300 declare const $y_spc := 22 {knobs} declare ui_knob $fake_robin_range (0,$KEY_RANGE,1) set_text($fake_robin_range,"range") set_knob_unit($fake_robin_range,$KNOB_UNIT_ST) move_control_px($fake_robin_range, $x_pos, $y_pos + $y_spc) declare ui_knob $stereo_range (0,1000,10) set_text($stereo_range,"spread") set_knob_unit($stereo_range,$KNOB_UNIT_PERCENT) move_control_px($stereo_range, $x_pos + $x_spc, $y_pos + $y_spc) {labels} declare ui_label $l_robin (1,1) set_text ($l_robin," fake round robin") move_control_px($l_robin, $x_pos, $y_pos) declare ui_label $l_stereo (1,1) set_text ($l_stereo," fake stereo") move_control_px($l_stereo, $x_pos + $x_spc, $y_pos) declare ui_label $l_nfo1 (1,1) move_control_px($l_nfo1, $x_pos + $x_spc *2, $y_pos) declare ui_label $l_nfo2 (1,1) move_control_px($l_nfo2, $x_pos + $x_spc *2, $y_pos + $y_spc) declare ui_label $l_nfo3 (1,1) move_control_px($l_nfo3, $x_pos + $x_spc *2, $y_pos + $y_spc *2) hide_part ($l_nfo1,$HIDE_PART_BG) hide_part ($l_nfo2,$HIDE_PART_BG) hide_part ($l_nfo3,$HIDE_PART_BG) set_control_par(get_ui_id($l_nfo1), $CONTROL_PAR_WIDTH, $x_lab) set_control_par(get_ui_id($l_nfo2), $CONTROL_PAR_WIDTH, $x_lab) set_control_par(get_ui_id($l_nfo3), $CONTROL_PAR_WIDTH, $x_lab) set_control_par(get_ui_id($l_nfo1), $CONTROL_PAR_FONT_TYPE, 22) set_control_par(get_ui_id($l_nfo2), $CONTROL_PAR_FONT_TYPE, 2) set_control_par(get_ui_id($l_nfo3), $CONTROL_PAR_FONT_TYPE, 2) set_text ($l_nfo1,"FAKE RANDOM ROUND ROBIN") if($LOW_note =0 and $HIGH_note =127) set_text ($l_nfo2,"First edit LOW_note, HIGH_note values in the beginning of the script.") else set_text ($l_nfo2," ") end if set_text ($l_nfo3," ") {random generator const and variables} declare const $PMa := 16807 declare const $PMm := 2147483647 declare const $PMq := $PMm / $PMa declare const $PMr := $PMm mod $PMa declare $seed := $mother_seed declare $rnd declare $rnd_min declare $rnd_max := 1000000 {save settings} make_persistent ($fake_robin_range) make_persistent ($stereo_range) end on {random number generator} function generate_random $rnd := $PMa * ($seed mod $PMq) - $PMr * ($seed / $PMq) if ($rnd > 0) $seed := $rnd else $seed := $rnd + $PMm end if $rnd := ($rnd_max - $rnd_min) +1 $rnd := ($seed mod $rnd) + $rnd_min end function function draw_note call generate_random if($rnd = $last_random) inc($rnd) if($rnd > $rnd_max) $rnd := $rnd_min end if end if $last_random := $rnd end function {fake round robin functionality} on note set_text ($l_nfo3,"incoming note number: " & $EVENT_NOTE) if($fake_robin_range #0 and $EVENT_NOTE >= $LOW_note and $EVENT_NOTE <= $HIGH_note) $note_number := $EVENT_NOTE $rnd_min := $EVENT_NOTE - $fake_robin_range /2 $rnd_max := $EVENT_NOTE + $fake_robin_range /2 + $fake_robin_range mod 2 if($rnd_max > $HIGH_note) $count := $rnd_max - $HIGH_note $rnd_max := $rnd_max - $count $rnd_min := $rnd_min - $count end if if($rnd_min < $LOW_note) $count := $LOW_note - $rnd_min $rnd_max := $rnd_max + $count $rnd_min := $rnd_min + $count end if call draw_note $count := $EVENT_NOTE - $rnd change_note($EVENT_ID,$rnd) change_tune($EVENT_ID,$count *100000,1) {fake stereo functionality} if($stereo_range #0) change_pan($EVENT_ID,$stereo_range,1) call draw_note $count := $note_number - $rnd $shadow_note_id := play_note($rnd,$EVENT_VELOCITY,0,-1) change_tune($shadow_note_id,$count *100000,1) change_pan($shadow_note_id,-$stereo_range,1) end if end if end on {reset seed on transport start} on listener if($NI_SIGNAL_TYPE = $NI_SIGNAL_TRANSP_START) $seed := $mother_seed end if end on