Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- on init
- make_perfview
- set_ui_height_px(328-68)
- set_script_title("A Dodgy Oh!")
- //set_control_par_str($INST_WALLPAPER_ID, $CONTROL_PAR_PICTURE, "skin")
- set_control_par($INST_ICON_ID, $CONTROL_PAR_HIDE, $HIDE_WHOLE_CONTROL)
- {#pragma save_compiled_source violins_ens_legato_compiled.txt}
- {**********************************************************************
- * CONSTANTS *
- **********************************************************************}
- declare const TRUE := 1
- declare const FALSE := 0
- declare const NULL := -999
- //declare const HOLDTIME := 250000 // legato interval hold time in microseconds
- {**********************************************************************
- * VARIABLES *
- **********************************************************************}
- declare i
- declare articulation := 0 // currently selected articulation
- declare last_note := -1
- {**********************************************************************
- * ARRAYS *
- **********************************************************************}
- declare %note_ids[2] // to hold the note IDs we'll need for true legato
- {**********************************************************************
- * FAMILIES *
- **********************************************************************}
- family App
- declare const HIGH_NOTE := 127
- declare const LOW_NOTE := 1
- declare const REAL_CC := 102
- end family
- family Sets // we organize related groups into sets
- declare %sustains[2] := (3, 4) // sustain group ids
- declare %intervals[3] := (0) //, 1, 2) // interval group ids
- // declare staccatos := 4 // staccato group id
- end family
- {**********************************************************************
- * GUI *
- **********************************************************************}
- // * POSITIONING KNOBS *
- {declare ui_knob $knb_x (0, 650, 1)
- move_control_px($knb_x, 400, 0)
- declare ui_knob $knb_y (0, 650, 1)
- move_control_px($knb_y, 500, 0)}
- // declare ui_menu pers $mnu_cc // dynamics cc selection menu
- // set_control_help($mnu_cc, "Select a CC number to control sustain dynamics.")
- // move_control_px($mnu_cc, 316, 50)
- // set_control_par(get_ui_id($mnu_cc), $CONTROL_PAR_HEIGHT, 144/6)
- // //set_control_par_str(get_ui_id($mnu_cc), $CONTROL_PAR_PICTURE, "menu")
- {* LEGATO CONTROLS *}
- declare ui_switch pers $swi_legato_bypass // legato toggle button
- move_control_px($swi_legato_bypass, 170, 3)
- set_control_help($swi_legato_bypass, "Toggles the legato.")
- //set_control_par_str(get_ui_id($swi_legato_bypass), $CONTROL_PAR_PICTURE, "switch")
- set_control_par_str(get_ui_id($swi_legato_bypass), $CONTROL_PAR_TEXT, "Disable Legato")
- set_control_par(get_ui_id($swi_legato_bypass), $CONTROL_PAR_WIDTH, 100)
- //set_control_par(get_ui_id($swi_legato_bypass), $CONTROL_PAR_HEIGHT, 312/6)
- declare ui_slider pers $sli_offset(0, 1000000) // sustain sample offset slider: 0-1000ms
- move_control_px($sli_offset, 67, 70)
- //set_control_par_str(get_ui_id($sli_offset), $CONTROL_PAR_PICTURE, "knob")
- //set_control_par(get_ui_id($sli_offset), $CONTROL_PAR_MOUSE_BEHAVIOUR, -2500)
- read_persistent_var($sli_offset)
- declare ui_label $lbl_offset(1, 1) // sustain offset control label
- move_control_px($lbl_offset, 118, 88)
- set_control_par(get_ui_id($lbl_offset), $CONTROL_PAR_WIDTH, 120)
- set_text($lbl_offset, "sustain offset: "&$sli_offset/1000)
- hide_part($lbl_offset, $HIDE_PART_BG) // hide label background
- set_control_par(get_ui_id($lbl_offset), $CONTROL_PAR_FONT_TYPE, 6)
- // declare ui_slider pers $sli_int_offset(0, 1000000) // interval sample offset slider: 0-1000ms
- // move_control_px($sli_int_offset, 67+150, 70)
- // //set_control_par_str(get_ui_id($sli_int_offset), $CONTROL_PAR_PICTURE, "knob")
- // //set_control_par(get_ui_id($sli_int_offset), $CONTROL_PAR_MOUSE_BEHAVIOUR, -2500)
- // read_persistent_var($sli_int_offset)
- // declare ui_label $lbl_int_offset(1, 1) // interval offset control label
- // move_control_px($lbl_int_offset, 118+150, 88)
- // set_control_par(get_ui_id($lbl_int_offset), $CONTROL_PAR_WIDTH, 120)
- // set_text($lbl_int_offset, "interval offset: "&$sli_int_offset/1000)
- // hide_part($lbl_int_offset, $HIDE_PART_BG) // hide label background
- // set_control_par(get_ui_id($lbl_int_offset), $CONTROL_PAR_FONT_TYPE, 6)
- declare ui_slider pers $sli_fade(100000, 700000) // legato fadein time slider
- move_control_px($sli_fade, 67, 121)
- //set_control_par_str(get_ui_id($sli_fade), $CONTROL_PAR_PICTURE, "knob")
- //set_control_par(get_ui_id($sli_fade), $CONTROL_PAR_MOUSE_BEHAVIOUR, -2500)
- read_persistent_var($sli_fade)
- declare ui_label $lbl_fade(1, 1) // legato fadein control label
- move_control_px($lbl_fade, 118, 138)
- set_control_par(get_ui_id($lbl_fade), $CONTROL_PAR_WIDTH, 120)
- set_text($lbl_fade, "fade in: "&$sli_fade/1000)
- hide_part($lbl_fade, $HIDE_PART_BG)
- set_control_par(get_ui_id($lbl_fade), $CONTROL_PAR_FONT_TYPE, 6)
- declare ui_slider pers $sli_fade_out(100000, 700000) // legato fadeout time slider
- move_control_px($sli_fade_out, 67, 121+50)
- //set_control_par_str(get_ui_id($sli_fade_out), $CONTROL_PAR_PICTURE, "knob")
- //set_control_par(get_ui_id($sli_fade_out), $CONTROL_PAR_MOUSE_BEHAVIOUR, -2500)
- read_persistent_var($sli_fade_out)
- declare ui_label $lbl_fade_out(1, 1) // legato fadeout control label
- move_control_px($lbl_fade_out, 118, 138+50)
- set_control_par(get_ui_id($lbl_fade_out), $CONTROL_PAR_WIDTH, 120)
- set_text($lbl_fade_out, "fade out: "&$sli_fade_out/1000)
- hide_part($lbl_fade_out, $HIDE_PART_BG)
- set_control_par(get_ui_id($lbl_fade_out), $CONTROL_PAR_FONT_TYPE, 6)
- declare ui_slider pers $sli_holdtime(0, 600000) // legato duration slider: 0-600ms
- move_control_px($sli_holdtime, 67, 121+100)
- //set_control_par_str(get_ui_id($sli_holdtime), $CONTROL_PAR_PICTURE, "knob")
- //set_control_par(get_ui_id($sli_holdtime), $CONTROL_PAR_MOUSE_BEHAVIOUR, -2500)
- read_persistent_var($sli_holdtime)
- declare ui_label $lbl_holdtime(1, 1) // legato duration control label
- move_control_px($lbl_holdtime, 118, 138+100)
- set_control_par(get_ui_id($lbl_holdtime), $CONTROL_PAR_WIDTH, 120)
- set_text($lbl_holdtime, "legato duration: "&$sli_holdtime/1000)
- hide_part($lbl_holdtime, $HIDE_PART_BG) // hide label background
- set_control_par(get_ui_id($lbl_holdtime), $CONTROL_PAR_FONT_TYPE, 6)
- // {* REVERB CONTROLS *}
- // declare ui_slider pers $sli_reverb(100000, 700000) // reverb amount slider
- // move_control_px($sli_reverb, 506, 86)
- // set_control_par_str(get_ui_id($sli_reverb), $CONTROL_PAR_PICTURE, "knob")
- // set_control_par(get_ui_id($sli_reverb), $CONTROL_PAR_MOUSE_BEHAVIOUR, -2500)
- // declare ui_label $lbl_reverb(1, 1) // reverb amount control label
- // move_control_px($lbl_reverb, 558, 103)
- // set_control_par(get_ui_id($lbl_reverb), $CONTROL_PAR_WIDTH, 60)
- // // set_text($lbl_reverb, $sli_reverb/1000)
- // hide_part($lbl_reverb, $HIDE_PART_BG)
- // set_control_par(get_ui_id($lbl_reverb), $CONTROL_PAR_FONT_TYPE, 6)
- {* OTHER CONTROLS *}
- // declare ui_switch pers $swi_reps_bypass // legato toggle button
- // move_control_px($swi_reps_bypass, 296, 124)
- // set_control_help($swi_reps_bypass, "Toggles round robins.")
- // //set_control_par_str(get_ui_id($swi_reps_bypass), $CONTROL_PAR_PICTURE, "switch")
- // set_control_par_str(get_ui_id($swi_reps_bypass), $CONTROL_PAR_TEXT, "")
- // set_control_par(get_ui_id($swi_reps_bypass), $CONTROL_PAR_WIDTH, 36)
- // set_control_par(get_ui_id($swi_reps_bypass), $CONTROL_PAR_HEIGHT, 312/6)
- // declare ui_label $lbl_articulation(1, 1) // articulation name label
- // set_text($lbl_articulation, "")
- // set_control_par($lbl_articulation, $CONTROL_PAR_WIDTH, 160)
- // set_control_par_str($lbl_articulation, $CONTROL_PAR_PICTURE, "articulation")
- // move_control_px($lbl_articulation, 66, 221)
- end on
- on ui_control($sli_offset)
- set_text($lbl_offset, "sustain offset: "&$sli_offset/1000)
- end on
- // on ui_control($sli_int_offset)
- // set_text($lbl_int_offset, "interval offset: "&$sli_int_offset/1000)
- // end on
- on ui_control($sli_fade)
- set_text($lbl_fade, "fade in: "&$sli_fade/1000)
- end on
- on ui_control($sli_fade_out)
- set_text($lbl_fade_out, "fade out: "&$sli_fade_out/1000)
- end on
- on ui_control($sli_holdtime)
- set_text($lbl_holdtime, "legato duration: "&$sli_holdtime/1000)
- end on
- on note
- disallow_group($ALL_GROUPS)
- if(in_range($EVENT_NOTE, App.LOW_NOTE, App.HIGH_NOTE)) // if note is in playable range,
- if(swi_legato_bypass = TRUE) // legato is bypassed
- select(articulation)
- case 0 // sustain
- for i := 0 to num_elements(Sets.sustains)-1
- allow_group(Sets.sustains[i])
- end for
- //case 1 // staccato
- // allow_group(Sets.staccatos)
- end select
- else
- // legato is on
- true_legato($EVENT_NOTE, $EVENT_VELOCITY, $sli_fade, $sli_fade_out, $sli_holdtime, $sli_offset)
- end if
- end if
- end on
- on release
- if($EVENT_NOTE = last_note and swi_legato_bypass = FALSE)
- last_note := -1 // reset last note
- end if
- end on
- {**********************************************************************
- * GUI CONTROL CALLBACKS *
- **********************************************************************}
- // * POSITIONING KNOBS *
- {on ui_control($knb_x)
- set_control_par(get_ui_id($sli_offset), $CONTROL_PAR_POS_X, $knb_x)
- end on
- on ui_control($knb_y)
- set_control_par(get_ui_id($sli_offset), $CONTROL_PAR_POS_Y, $knb_y)
- end on}
- {**********************************************************************
- * FUNCTIONS *
- **********************************************************************}
- function true_legato(note_num, note_vel, fadetime, fadeouttime, holdtime, offset)
- declare const WAIT_RES := 200 // resolution of legato hold loop
- declare interval // the interval to play
- declare is_legato // boolean flag
- // Loop iterators
- declare i
- declare pacer
- ignore_event($EVENT_ID)
- if(is_legato = TRUE) // legato hold loop is in progress
- pacer := holdtime // exit hold loop
- wait(WAIT_RES) // give it a moment to exit
- end if
- // Determine played interval
- if (last_note # -1) // check if last note exists
- interval := abs(note_num - last_note)
- end if
- if(last_note # -1 and interval <= 12) // if last note exists and interval is within legato range
- if(last_note > note_num) // this is a down interval
- interval := interval + 64
- end if
- // enable interval groups
- disallow_group($ALL_GROUPS)
- for i := 0 to num_elements(Sets.intervals)-1
- allow_group(Sets.intervals[i])
- end for
- note_off(%note_ids[1]) // end any already-playing intervals
- %note_ids[1] := play_note(last_note, interval, 0, -1) // play the interval note
- // crossfade: sustain to interval
- fade_out(%note_ids[0], fadetime, 1) // fade out sustain note and turn it off
- fade_in(%note_ids[1], fadetime/2) // fade in interval note
- is_legato := TRUE // mark legato flag as hold loop begins
- for pacer := 0 to holdtime/WAIT_RES // hold the interval sample until we want to fade in the new sustain
- if (%KEY_DOWN[note_num] = 0)
- note_off(%note_ids[0]) // turn off sustain
- note_off(%note_ids[1]) // turn off interval
- last_note := -1 // reset last note
- exit
- end if
- wait(WAIT_RES)
- end for
- is_legato := FALSE // reset legato flag because hold loop is complete
- // enable sustain groups
- disallow_group($ALL_GROUPS)
- for i := 0 to num_elements(Sets.sustains)-1
- allow_group(Sets.sustains[i])
- end for
- note_off(%note_ids[0]) // turn off old sustain
- %note_ids[0] := play_note(note_num, note_vel, offset, -1) // play sustain
- // crossfade: interval to sustain
- fade_out(%note_ids[1], fadeouttime, 1) // fade out interval note and turn it off
- fade_in(%note_ids[0], fadeouttime/2) // fade in sustain note
- else // if last note is -1
- // enable sustain groups
- disallow_group($ALL_GROUPS)
- for i := 0 to num_elements(Sets.sustains)-1
- allow_group(Sets.sustains[i])
- end for
- note_off(%note_ids[0]) // end any already-playing sustains
- %note_ids[0] := play_note(note_num, note_vel, 0, -1) // play sustain
- end if
- last_note := note_num // save the number of the last note played
- end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement