on init
set_script_title("Double Re-trigger by Aaron Venture")
set_ui_height(2)
declare $last_note
declare $last_velocity
declare $is_playing := 0
declare ui_label $title(4, 1)
set_text($title,"Double Re-trigger by Aaron Venture")
move_control($title,2,1)
set_control_par(get_ui_id($title),$CONTROL_PAR_TEXT_ALIGNMENT,1)
declare ui_value_edit $Key(0, 127, $VALUE_EDIT_MODE_NOTE_NAMES)
$Key := 108
move_control($Key,2,3)
make_persistent($Key)
declare ui_value_edit $Key2(0, 127, $VALUE_EDIT_MODE_NOTE_NAMES)
$Key2 := 107
move_control($Key2,2,4)
make_persistent($Key2)
declare ui_value_edit $Delay(0, 200, 1)
$Delay := 15
move_control($Delay,3,4)
set_control_par_str(get_ui_id($Delay),$CONTROL_PAR_HELP,"Set the delay before the note is re-triggered.")
make_persistent($Delay)
declare ui_value_edit $dlyrandom(0, 50, 1)
$dlyrandom := 50
move_control($dlyrandom,4,4)
set_control_par_str(get_ui_id($dlyrandom),$CONTROL_PAR_TEXT,"Randomize")
set_control_par_str(get_ui_id($dlyrandom),$CONTROL_PAR_HELP,"Set the percentage for which the delay value can fluctuate up or down.")
make_persistent($dlyrandom)
declare ui_switch $rtnoff
set_control_par_str(get_ui_id($rtnoff),$CONTROL_PAR_TEXT,"Note-off")
set_control_par_str(get_ui_id($rtnoff),$CONTROL_PAR_HELP,"If this is enabled, releasing the re-trigger key will send a note-off and stop the re-triggered note.")
move_control($rtnoff,5,3)
make_persistent($rtnoff)
end on
on ui_control($Key)
if ($Key=$Key2 and ($Key2 # 0))
$Key := $Key2-1
else
if ($Key=$Key2 and ($Key2=0))
$Key := $Key2+1
end if
end if
end on
on ui_control($Key2)
if ($Key2=$Key and ($Key # 0))
$Key2 := $Key-1
else
if ($Key=$Key2 and ($Key2=0))
$Key2 := $Key+1
end if
end if
end on
on midi_in
if ($MIDI_COMMAND=$MIDI_COMMAND_NOTE_ON and ($MIDI_BYTE_1 # $Key) and ($MIDI_BYTE_1 # $Key2))
$last_note := $MIDI_BYTE_1
$last_velocity := $MIDI_BYTE_2
$is_playing := 1
else
if ($MIDI_COMMAND=$MIDI_COMMAND_NOTE_OFF and ($MIDI_BYTE_1=$last_note))
$is_playing := 0
else
if ($MIDI_COMMAND=$MIDI_COMMAND_NOTE_ON and ($MIDI_BYTE_1=$key or ($MIDI_BYTE_1=$Key2)) and ($is_playing=1))
set_midi($MIDI_CHANNEL,$MIDI_COMMAND_NOTE_OFF,$last_note,$last_velocity)
wait(($Delay+random(-$Delay*$dlyrandom/100,$Delay*$dlyrandom/100))*1000)
set_midi($MIDI_CHANNEL,$MIDI_COMMAND_NOTE_ON,$last_note,$last_velocity)
else
if ($MIDI_COMMAND=$MIDI_COMMAND_NOTE_OFF and ($MIDI_BYTE_1=$key or ($MIDI_BYTE_1=$Key2)) and ($rtnoff=1))
set_midi($MIDI_CHANNEL,$MIDI_COMMAND_NOTE_OFF,$last_note,$last_velocity)
end if
end if
end if
end if
end on