Professional Documents
Culture Documents
Arpeggiator
Author: Native Instruments
Written by: Josef Natterer, Nicki Marinic
Modified: September 11, 2009
on init
set_script_title("ARP")
set_ui_height(5)
message("")
declare $latch_mode
make_persistent($latch_mode)
$latch_mode := 1
declare !note_class[12]
!note_class[0] := "C"
!note_class[1] := "Db"
!note_class[2] := "D"
!note_class[3] := "Eb"
!note_class[4] := "E"
!note_class[5] := "F"
!note_class[6] := "Gb"
!note_class[7] := "G"
!note_class[8] := "Ab"
!note_class[9] := "A"
!note_class[10] := "Bb"
!note_class[11] := "B"
declare @knob_name
@knob_name := "Rate"
declare !tempo_names[18]
!tempo_names[0] := "1/128"
!tempo_names[1] := "1/64"
!tempo_names[2] := "1/32"
!tempo_names[3] := "1/16 T"
!tempo_names[4] := "3/64"
!tempo_names[5] := "1/16"
!tempo_names[6] := "1/8 T"
!tempo_names[7] := "3/32"
!tempo_names[8] := "1/8"
!tempo_names[9] := "1/4 T"
!tempo_names[10] := "3/16"
!tempo_names[11] := "1/4"
!tempo_names[12] := "1/2 T"
!tempo_names[13] := "3/8"
!tempo_names[14] := "1/2"
!tempo_names[15] := "3/4"
!tempo_names[16] := "4/4"
!tempo_names[17] := "Bar"
declare %pressed_id[128]
declare %note_buffer[512]
declare %ordered[128]
declare %velo[128]
declare $cursor
declare $old_latch_time
declare $a
declare $aa
declare $sema
declare $rand
declare $bb
declare $b
declare $loop_cursor
declare %loop_buffer[512]
declare $id
declare $check_id
declare $min
declare $min_note
declare $max_note
declare $helper
declare %help_buffer[512]
declare $step_length
declare $strike_count
declare $duration
declare $note
declare $velo
declare $act_step
declare $last_order
declare $oct_cursor
declare $swing_cursor
declare %preset_arr[12*42]
make_persistent(%Preset_arr)
$a := 0
while($a < 12*42)
%preset_arr[$a] := %default_preset[$a mod 42]
inc($a)
end while
$a := 0
set_table_steps_shown(%rhythm, $steps)
_read_persistent_var($Sync_knob)
set_knob_label ($Sync_knob,!tempo_names[$Sync_knob])
move_control($Global_label,1,2)
move_control($Pitch_label,4,2)
move_control($Timing_label,1,7)
move_control($Rhythm_label,4,7)
move_control($note_order_label,4,3)
move_control(%rhythm,5,8)
move_control($swing,3,8)
move_control($steps,4,8)
move_control($Dur,2,8)
move_control($note_order,4,4)
move_control($strike,6,3)
move_control($Octave,5,3)
move_control($latch_knob,1,3)
move_control($edit_preset,0,0)
move_control($Velo_button,4,9)
move_control($midi_thru,3,4)
move_control($Rate_knob,1,8)
move_control($Sync_knob,0,0)
set_control_par_str(get_ui_id($Rate_Knob),
$CONTROL_PAR_AUTOMATION_NAME,"Arpeggiator Rate")
set_control_par_str(get_ui_id($Octave),
$CONTROL_PAR_AUTOMATION_NAME,"Arpeggiator Octave")
set_control_par_str(get_ui_id($Dur),$CONTROL_PAR_AUTOMATION_NAME,"Arpeggiator
Duration")
end on
on note
if ($latch_mode = 0)
exit
end if
%velo[$EVENT_NOTE] := $EVENT_VELOCITY
{only one event per Note}
set_event_par($EVENT_ID,0,2)
if ($midi_thru = 0)
ignore_event($EVENT_ID)
end if
if (%pressed_id[$EVENT_NOTE] > 0)
exit
else
%pressed_id[$EVENT_NOTE] := $EVENT_ID
end if
case 10 to 13
$loop_cursor := $cursor
$a := 0
while(($a*2) < $cursor)
%loop_buffer[($a*2)] := %ordered[$cursor -1 -
$a]
%loop_buffer[($a*2)+1] := %ordered[$a]
inc($a)
end while
$loop_cursor := $cursor
if ($note_order = 11 or $note_order = 13)
$a := 0
while($a < $loop_cursor)
%help_buffer[$loop_cursor - $a-1] :=
%loop_buffer[$a]
inc($a)
end while
$a := 0
while($a < $loop_cursor)
%loop_buffer[$a] := %help_buffer[$a]
inc($a)
end while
end if
if (($note_order = 12 or $note_order = 13) and
$cursor > 2)
select ($repeat)
case 1
$a := 0
while($a < $cursor-2)
%loop_buffer[($a)+
($cursor)] := %loop_buffer[$cursor-2-$a]
inc($a)
end while
$loop_cursor := $cursor*2 - 2
case 2
if ($note_order = 12)
$a := 0
while($a < $cursor-1)
%loop_buffer[($a)+
($cursor)] := %loop_buffer[$cursor-1-$a]
inc($a)
end while
$loop_cursor := $cursor*2 - 1
else
$a := 0
while($a < $cursor-1)
%loop_buffer[($a)+
($cursor)] := %loop_buffer[$cursor-2-$a]
inc($a)
end while
$loop_cursor := $cursor*2 - 1
end if
case 3
if ($note_order = 13)
$a := 0
while($a < $cursor-1)
%loop_buffer[($a)+
($cursor)] := %loop_buffer[$cursor-1-$a]
inc($a)
end while
$loop_cursor := $cursor*2 - 1
else
$a := 0
while($a < $cursor-1)
%loop_buffer[($a)+
($cursor)] := %loop_buffer[$cursor-2-$a]
inc($a)
end while
$loop_cursor := $cursor*2 - 1
end if
case 5
$a := 0
while($a < $cursor)
%loop_buffer[($a)+
($cursor)] := %loop_buffer[$cursor-1-$a]
inc($a)
end while
$loop_cursor := $cursor*2
end select
end if
case 14
$loop_cursor := 1
%loop_buffer[$aa+1] := %ordered[random(0,$cursor-1)]
%loop_buffer[0] := %ordered[random(0,$cursor-1)]
case 15
if ($aa < 2 or $last_order # $note_order)
$loop_cursor := $cursor
$a := 0
while($a < $cursor)
%help_buffer[$a] := %ordered[$a]
inc($a)
end while
$helper := $cursor
$a := 0
while ($a < $cursor)
%loop_buffer[$a] :=
%help_buffer[random(0,$helper-1)]
$bb := 0
while($bb < $helper)
if (%help_buffer[$bb] =
%loop_buffer[$a])
while($bb < $helper)
%help_buffer[$bb] :=
%help_buffer[$bb+1]
inc($bb)
end while
$bb := $helper+1
dec($helper)
end if
inc($bb)
end while
inc($a)
end while
end if
case 16
$loop_cursor := $cursor
$a := 0
while($a < $cursor )
%loop_buffer[$a] := %note_buffer[$a]
inc($a)
end while
end select
$last_order := $note_order
select ($Sync_knob)
case 0
$step_length := $DURATION_SIXTEENTH/8
case 1
$step_length := $DURATION_SIXTEENTH/4
case 2
$step_length := $DURATION_SIXTEENTH/2
case 3
$step_length := $DURATION_QUARTER/6
case 4
$step_length := ($DURATION_SIXTEENTH/4)*3
case 5
$step_length := $DURATION_SIXTEENTH
case 6
$step_length := $DURATION_QUARTER/3
case 7
$step_length := ($DURATION_SIXTEENTH/2)*3
case 8
$step_length := $DURATION_EIGHTH
case 9
$step_length := ($DURATION_QUARTER*2)/3
case 10
$step_length := $DURATION_SIXTEENTH*3
case 11
$step_length := $DURATION_QUARTER
case 12
$step_length := ($DURATION_QUARTER*4)/3
case 13
$step_length := $DURATION_EIGHTH*3
case 14
$step_length := $DURATION_QUARTER*2
case 15
$step_length := $DURATION_QUARTER*3
case 16
$step_length := $DURATION_QUARTER*4
case 17
$step_length := $DURATION_BAR
end select
if ($swing_cursor mod 2 = 0)
$step_length := $step_length + ($step_length*$Swing)/100
else
$step_length := $step_length + ($step_length*(-$Swing))/100
end if
inc($swing_cursor)
$duration := ($step_length/100)*$dur
if ($duration < 10000)
$duration := 10000
end if
if ($step_length < 5000)
$step_length := 5000
end if
$velo := 100
if (%rhythm[$act_step] # 0)
if ($loop_cursor # 0)
if ($note_order = 16)
$a := 0
while($a < $loop_cursor)
$note := %loop_buffer[$a] +
$oct_cursor*12
$velo := %velo[%loop_buffer[$a]]
if ($strike_count > 0)
$velo := ($velo * $Str_vel)/100
end if
if ($velo_button = 1)
$velo := 127
end if
$velo := ($velo * %rhythm[$act_step])/100
if ($velo > 127)
$velo := 127
end if
if ($velo < 1)
$velo := 1
end if
if ($note > 0 and $note < 128)
play_note($note,$velo,0,$duration)
end if
inc($a)
end while
if ($strike_count >= $strike-1)
$aa := $loop_cursor
end if
else
$note := %loop_buffer[$aa] + $oct_cursor*12
$velo := %velo[%loop_buffer[$aa]]
if ($strike_count > 0)
$velo := ($velo * $Str_vel)/100
end if
if ($velo_button = 1)
$velo := 127
end if
$velo := ($velo * %rhythm[$act_step])/100
if ($velo > 127)
$velo := 127
end if
if ($velo < 1)
$velo := 1
end if
if($note > 0 and $note < 128)
if ($fromPGS_nsteal = 1)
fade_out(%key_ID[$note],10000,1)
end if
$new_ID := play_note($note,$velo,0,$duration)
%key_ID[$note] := $new_ID
end if
end if
end if
if ($strike_count < $strike-1)
dec($aa)
dec($act_step)
inc($strike_count)
else
$strike_count := 0
end if
else
on release
{only one event per Note}
if (%EVENT_PAR[0] = 2)
{ignore_event($EVENT_ID)}
if (%pressed_id[$EVENT_NOTE] = 0)
exit
else
%pressed_id[$EVENT_NOTE] := 0
end if
else
exit
end if
if ($latch_mode = 0)
exit
end if
{which notes should be in the buffer}
select ($latch_mode)
case 1
$a := 0
$b := $cursor
$cursor := 0
while($a < $b)
if ($EVENT_NOTE # %note_buffer[$a])
%note_buffer[$cursor] := %note_buffer[$a]
inc($cursor)
end if
inc($a)
end while
case 2 to 3
exit
end select
end on
on ui_control ($latch_knob)
$latch_mode := $latch_knob
select ($latch_mode)
case 0
set_knob_label($latch_knob,"Off")
$a := 0
while($a < $cursor)
%note_buffer[$a] := 0
inc($a)
end while
$cursor := 0
case 1
set_knob_label($latch_knob,"On")
$b := $cursor
$cursor := 0
$a := 0
while($a < $b)
if (%pressed_id[%note_buffer[$a]] > 0)
%note_buffer[$cursor] := %note_buffer[$a]
inc($cursor)
end if
inc($a)
end while
case 2
set_knob_label($latch_knob,"Hold")
case 3
set_knob_label($latch_knob,"Hold +-")
end select
end on
on ui_control ($Sync_knob)
set_knob_label ($Sync_knob,!tempo_names[$Sync_knob])
end on
on ui_control($edit_Preset)
if ($edit_Preset < 99)
$a := 0
set_table_steps_shown(%rhythm, $steps)
$sync_knob := ($Rate_knob * 18) /1000001
set_knob_defval ($Rate_knob,(5 *1000001) / 17)
set_knob_label ($Rate_knob,!tempo_names[$sync_knob])
set_knob_unit($Rate_knob,$KNOB_UNIT_NONE)
end if
$edit_preset := 100
end on
on ui_control ($steps)
set_table_steps_shown(%rhythm, $steps)
end on
on ui_control ($note_order)
if ($note_order # 99)
$last_note_order := $note_order
else
$note_order:= $last_note_order
end if
end on
on ui_control ($rate_knob)
end on
on pgs_changed
if (pgs_key_exists(PGS_ARP_ON))
$latch_mode := pgs_get_key_val(PGS_ARP_ON,0)
$latch_knob := pgs_get_key_val(PGS_ARP_ON,0)
end if
$fromPGS_nsteal := pgs_get_key_val(PGS_NSTEAL,0)
$Sync_knob := pgs_get_key_val(PGS_ARP_RATE,0)
set_knob_label ($Sync_knob,!tempo_names[$Sync_knob])
$Dur := pgs_get_key_val(PGS_ARP_DURATION,0)
$Strike := pgs_get_key_val(PGS_ARP_STRIKE,0)
$Swing := pgs_get_key_val(PGS_ARP_SWING,0)
$Octave := pgs_get_key_val(PGS_ARP_OCTAVE,0)
$note_order := pgs_get_key_val(PGS_ARP_ORDER,0)
end on
{END OF SCRIPT}