Advertisement
esselfortium

Untitled

Dec 30th, 2020
3,425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. on init
  2.     make_perfview
  3.     set_ui_height_px(328-68)
  4.     set_script_title("A Dodgy Oh!")
  5.  
  6.     //set_control_par_str($INST_WALLPAPER_ID, $CONTROL_PAR_PICTURE, "skin")
  7.     set_control_par($INST_ICON_ID, $CONTROL_PAR_HIDE, $HIDE_WHOLE_CONTROL)
  8.  
  9.     {#pragma save_compiled_source violins_ens_legato_compiled.txt}
  10.  
  11.     {**********************************************************************
  12.     * CONSTANTS *
  13.     **********************************************************************}
  14.     declare const TRUE := 1
  15.     declare const FALSE := 0
  16.     declare const NULL := -999
  17.     //declare const HOLDTIME := 250000 // legato interval hold time in microseconds
  18.  
  19.     {**********************************************************************
  20.     * VARIABLES *
  21.     **********************************************************************}
  22.     declare i
  23.     declare articulation := 0 // currently selected articulation
  24.     declare last_note := -1
  25.  
  26.     {**********************************************************************
  27.     * ARRAYS *
  28.     **********************************************************************}
  29.     declare %note_ids[2] // to hold the note IDs we'll need for true legato
  30.  
  31.     {**********************************************************************
  32.     * FAMILIES *
  33.     **********************************************************************}
  34.     family App
  35.         declare const HIGH_NOTE := 127
  36.         declare const LOW_NOTE := 1
  37.         declare const REAL_CC := 102
  38.     end family
  39.  
  40.     family Sets // we organize related groups into sets
  41.         declare %sustains[2] := (3, 4) // sustain group ids
  42.         declare %intervals[3] := (0) //, 1, 2) // interval group ids
  43.         // declare staccatos := 4 // staccato group id
  44.     end family
  45.  
  46.     {**********************************************************************
  47.     * GUI *
  48.     **********************************************************************}
  49.     // * POSITIONING KNOBS *
  50.     {declare ui_knob $knb_x (0, 650, 1)
  51.     move_control_px($knb_x, 400, 0)
  52.     declare ui_knob $knb_y (0, 650, 1)
  53.     move_control_px($knb_y, 500, 0)}
  54.  
  55.  
  56.  
  57.     // declare ui_menu pers $mnu_cc // dynamics cc selection menu
  58.     // set_control_help($mnu_cc, "Select a CC number to control sustain dynamics.")
  59.     // move_control_px($mnu_cc, 316, 50)
  60.     // set_control_par(get_ui_id($mnu_cc), $CONTROL_PAR_HEIGHT, 144/6)
  61.     // //set_control_par_str(get_ui_id($mnu_cc), $CONTROL_PAR_PICTURE, "menu")
  62.  
  63.     {* LEGATO CONTROLS *}
  64.     declare ui_switch pers $swi_legato_bypass // legato toggle button
  65.     move_control_px($swi_legato_bypass, 170, 3)
  66.     set_control_help($swi_legato_bypass, "Toggles the legato.")
  67.     //set_control_par_str(get_ui_id($swi_legato_bypass), $CONTROL_PAR_PICTURE, "switch")
  68.     set_control_par_str(get_ui_id($swi_legato_bypass), $CONTROL_PAR_TEXT, "Disable Legato")
  69.     set_control_par(get_ui_id($swi_legato_bypass), $CONTROL_PAR_WIDTH, 100)
  70.     //set_control_par(get_ui_id($swi_legato_bypass), $CONTROL_PAR_HEIGHT, 312/6)
  71.  
  72.  
  73.  
  74.     declare ui_slider pers $sli_offset(0, 1000000) // sustain sample offset slider: 0-1000ms
  75.     move_control_px($sli_offset, 67, 70)
  76.     //set_control_par_str(get_ui_id($sli_offset), $CONTROL_PAR_PICTURE, "knob")
  77.     //set_control_par(get_ui_id($sli_offset), $CONTROL_PAR_MOUSE_BEHAVIOUR, -2500)
  78.     read_persistent_var($sli_offset)
  79.  
  80.     declare ui_label $lbl_offset(1, 1) // sustain offset control label
  81.     move_control_px($lbl_offset, 118, 88)
  82.     set_control_par(get_ui_id($lbl_offset), $CONTROL_PAR_WIDTH, 120)
  83.     set_text($lbl_offset, "sustain offset: "&$sli_offset/1000)
  84.     hide_part($lbl_offset, $HIDE_PART_BG) // hide label background
  85.     set_control_par(get_ui_id($lbl_offset), $CONTROL_PAR_FONT_TYPE, 6)
  86.  
  87.  
  88.  
  89.     // declare ui_slider pers $sli_int_offset(0, 1000000) // interval sample offset slider: 0-1000ms
  90.     // move_control_px($sli_int_offset, 67+150, 70)
  91.     // //set_control_par_str(get_ui_id($sli_int_offset), $CONTROL_PAR_PICTURE, "knob")
  92.     // //set_control_par(get_ui_id($sli_int_offset), $CONTROL_PAR_MOUSE_BEHAVIOUR, -2500)
  93.     // read_persistent_var($sli_int_offset)
  94.  
  95.     // declare ui_label $lbl_int_offset(1, 1) // interval offset control label
  96.     // move_control_px($lbl_int_offset, 118+150, 88)
  97.     // set_control_par(get_ui_id($lbl_int_offset), $CONTROL_PAR_WIDTH, 120)
  98.     // set_text($lbl_int_offset, "interval offset: "&$sli_int_offset/1000)
  99.     // hide_part($lbl_int_offset, $HIDE_PART_BG) // hide label background
  100.     // set_control_par(get_ui_id($lbl_int_offset), $CONTROL_PAR_FONT_TYPE, 6)
  101.  
  102.  
  103.  
  104.     declare ui_slider pers $sli_fade(100000, 700000) // legato fadein time slider
  105.     move_control_px($sli_fade, 67, 121)
  106.     //set_control_par_str(get_ui_id($sli_fade), $CONTROL_PAR_PICTURE, "knob")
  107.     //set_control_par(get_ui_id($sli_fade), $CONTROL_PAR_MOUSE_BEHAVIOUR, -2500)
  108.     read_persistent_var($sli_fade)
  109.  
  110.     declare ui_label $lbl_fade(1, 1) // legato fadein control label
  111.     move_control_px($lbl_fade, 118, 138)
  112.     set_control_par(get_ui_id($lbl_fade), $CONTROL_PAR_WIDTH, 120)
  113.     set_text($lbl_fade, "fade in: "&$sli_fade/1000)
  114.     hide_part($lbl_fade, $HIDE_PART_BG)
  115.     set_control_par(get_ui_id($lbl_fade), $CONTROL_PAR_FONT_TYPE, 6)
  116.  
  117.  
  118.  
  119.     declare ui_slider pers $sli_fade_out(100000, 700000) // legato fadeout time slider
  120.     move_control_px($sli_fade_out, 67, 121+50)
  121.     //set_control_par_str(get_ui_id($sli_fade_out), $CONTROL_PAR_PICTURE, "knob")
  122.     //set_control_par(get_ui_id($sli_fade_out), $CONTROL_PAR_MOUSE_BEHAVIOUR, -2500)
  123.     read_persistent_var($sli_fade_out)
  124.  
  125.     declare ui_label $lbl_fade_out(1, 1) // legato fadeout control label
  126.     move_control_px($lbl_fade_out, 118, 138+50)
  127.     set_control_par(get_ui_id($lbl_fade_out), $CONTROL_PAR_WIDTH, 120)
  128.     set_text($lbl_fade_out, "fade out: "&$sli_fade_out/1000)
  129.     hide_part($lbl_fade_out, $HIDE_PART_BG)
  130.     set_control_par(get_ui_id($lbl_fade_out), $CONTROL_PAR_FONT_TYPE, 6)
  131.  
  132.  
  133.  
  134.    
  135.  
  136.     declare ui_slider pers $sli_holdtime(0, 600000) // legato duration slider: 0-600ms
  137.     move_control_px($sli_holdtime, 67, 121+100)
  138.     //set_control_par_str(get_ui_id($sli_holdtime), $CONTROL_PAR_PICTURE, "knob")
  139.     //set_control_par(get_ui_id($sli_holdtime), $CONTROL_PAR_MOUSE_BEHAVIOUR, -2500)
  140.     read_persistent_var($sli_holdtime)
  141.  
  142.     declare ui_label $lbl_holdtime(1, 1) // legato duration control label
  143.     move_control_px($lbl_holdtime, 118, 138+100)
  144.     set_control_par(get_ui_id($lbl_holdtime), $CONTROL_PAR_WIDTH, 120)
  145.     set_text($lbl_holdtime, "legato duration: "&$sli_holdtime/1000)
  146.     hide_part($lbl_holdtime, $HIDE_PART_BG) // hide label background
  147.     set_control_par(get_ui_id($lbl_holdtime), $CONTROL_PAR_FONT_TYPE, 6)
  148.  
  149.  
  150.  
  151.     // {* REVERB CONTROLS *}
  152.     // declare ui_slider pers $sli_reverb(100000, 700000) // reverb amount slider
  153.     // move_control_px($sli_reverb, 506, 86)
  154.     // set_control_par_str(get_ui_id($sli_reverb), $CONTROL_PAR_PICTURE, "knob")
  155.     // set_control_par(get_ui_id($sli_reverb), $CONTROL_PAR_MOUSE_BEHAVIOUR, -2500)
  156.  
  157.     // declare ui_label $lbl_reverb(1, 1) // reverb amount control label
  158.     // move_control_px($lbl_reverb, 558, 103)
  159.     // set_control_par(get_ui_id($lbl_reverb), $CONTROL_PAR_WIDTH, 60)
  160.     // // set_text($lbl_reverb, $sli_reverb/1000)
  161.     // hide_part($lbl_reverb, $HIDE_PART_BG)
  162.     // set_control_par(get_ui_id($lbl_reverb), $CONTROL_PAR_FONT_TYPE, 6)
  163.  
  164.  
  165.     {* OTHER CONTROLS *}
  166.     // declare ui_switch pers $swi_reps_bypass // legato toggle button
  167.     // move_control_px($swi_reps_bypass, 296, 124)
  168.     // set_control_help($swi_reps_bypass, "Toggles round robins.")
  169.     // //set_control_par_str(get_ui_id($swi_reps_bypass), $CONTROL_PAR_PICTURE, "switch")
  170.     // set_control_par_str(get_ui_id($swi_reps_bypass), $CONTROL_PAR_TEXT, "")
  171.     // set_control_par(get_ui_id($swi_reps_bypass), $CONTROL_PAR_WIDTH, 36)
  172.     // set_control_par(get_ui_id($swi_reps_bypass), $CONTROL_PAR_HEIGHT, 312/6)
  173.  
  174.     // declare ui_label $lbl_articulation(1, 1) // articulation name label
  175.     // set_text($lbl_articulation, "")
  176.     // set_control_par($lbl_articulation, $CONTROL_PAR_WIDTH, 160)
  177.     // set_control_par_str($lbl_articulation, $CONTROL_PAR_PICTURE, "articulation")
  178.     // move_control_px($lbl_articulation, 66, 221)
  179. end on
  180.  
  181. on ui_control($sli_offset)
  182.     set_text($lbl_offset, "sustain offset: "&$sli_offset/1000)
  183. end on
  184.  
  185. // on ui_control($sli_int_offset)
  186. //     set_text($lbl_int_offset, "interval offset: "&$sli_int_offset/1000)
  187. // end on
  188.  
  189. on ui_control($sli_fade)
  190.     set_text($lbl_fade, "fade in: "&$sli_fade/1000)
  191. end on
  192.  
  193. on ui_control($sli_fade_out)
  194.     set_text($lbl_fade_out, "fade out: "&$sli_fade_out/1000)
  195. end on
  196.  
  197. on ui_control($sli_holdtime)
  198.     set_text($lbl_holdtime, "legato duration: "&$sli_holdtime/1000)
  199. end on
  200.  
  201. on note
  202.     disallow_group($ALL_GROUPS)
  203.  
  204.     if(in_range($EVENT_NOTE, App.LOW_NOTE, App.HIGH_NOTE)) // if note is in playable range,
  205.  
  206.         if(swi_legato_bypass = TRUE) // legato is bypassed
  207.             select(articulation)
  208.                 case 0 // sustain
  209.                     for i := 0 to num_elements(Sets.sustains)-1
  210.                         allow_group(Sets.sustains[i])
  211.                     end for
  212.                 //case 1 // staccato
  213.                 //    allow_group(Sets.staccatos)
  214.             end select
  215.         else
  216.             // legato is on
  217.             true_legato($EVENT_NOTE, $EVENT_VELOCITY, $sli_fade, $sli_fade_out, $sli_holdtime, $sli_offset)
  218.         end if
  219.     end if
  220. end on
  221.  
  222. on release
  223.     if($EVENT_NOTE = last_note and swi_legato_bypass = FALSE)
  224.         last_note := -1 // reset last note
  225.     end if
  226. end on
  227.  
  228.  
  229. {**********************************************************************
  230. * GUI CONTROL CALLBACKS *
  231. **********************************************************************}
  232. // * POSITIONING KNOBS *
  233. {on ui_control($knb_x)
  234.     set_control_par(get_ui_id($sli_offset), $CONTROL_PAR_POS_X, $knb_x)
  235. end on
  236.  
  237. on ui_control($knb_y)
  238.     set_control_par(get_ui_id($sli_offset), $CONTROL_PAR_POS_Y, $knb_y)
  239. end on}
  240.  
  241. {**********************************************************************
  242. * FUNCTIONS *
  243. **********************************************************************}
  244. function true_legato(note_num, note_vel, fadetime, fadeouttime, holdtime, offset)
  245.     declare const WAIT_RES := 200 // resolution of legato hold loop
  246.  
  247.     declare interval // the interval to play
  248.     declare is_legato // boolean flag
  249.  
  250.     // Loop iterators
  251.     declare i
  252.     declare pacer
  253.  
  254.     ignore_event($EVENT_ID)
  255.  
  256.     if(is_legato = TRUE) // legato hold loop is in progress
  257.         pacer := holdtime // exit hold loop
  258.         wait(WAIT_RES) // give it a moment to exit
  259.     end if
  260.  
  261.     // Determine played interval
  262.     if (last_note # -1) // check if last note exists
  263.         interval := abs(note_num - last_note)
  264.     end if
  265.  
  266.     if(last_note # -1 and interval <= 12) // if last note exists and interval is within legato range
  267.         if(last_note > note_num) // this is a down interval
  268.             interval := interval + 64
  269.         end if
  270.  
  271.         // enable interval groups
  272.         disallow_group($ALL_GROUPS)
  273.         for i := 0 to num_elements(Sets.intervals)-1
  274.             allow_group(Sets.intervals[i])
  275.         end for
  276.  
  277.         note_off(%note_ids[1]) // end any already-playing intervals
  278.         %note_ids[1] := play_note(last_note, interval, 0, -1) // play the interval note
  279.  
  280.         // crossfade: sustain to interval
  281.         fade_out(%note_ids[0], fadetime, 1) // fade out sustain note and turn it off
  282.         fade_in(%note_ids[1], fadetime/2) // fade in interval note
  283.  
  284.         is_legato := TRUE // mark legato flag as hold loop begins
  285.         for pacer := 0 to holdtime/WAIT_RES // hold the interval sample until we want to fade in the new sustain
  286.             if (%KEY_DOWN[note_num] = 0)
  287.                 note_off(%note_ids[0]) // turn off sustain
  288.                 note_off(%note_ids[1]) // turn off interval
  289.                 last_note := -1 // reset last note
  290.                 exit
  291.             end if
  292.  
  293.             wait(WAIT_RES)
  294.         end for
  295.         is_legato := FALSE // reset legato flag because hold loop is complete
  296.  
  297.         // enable sustain groups
  298.         disallow_group($ALL_GROUPS)
  299.         for i := 0 to num_elements(Sets.sustains)-1
  300.             allow_group(Sets.sustains[i])
  301.         end for
  302.  
  303.         note_off(%note_ids[0]) // turn off old sustain
  304.         %note_ids[0] := play_note(note_num, note_vel, offset, -1) // play sustain
  305.  
  306.         // crossfade: interval to sustain
  307.         fade_out(%note_ids[1], fadeouttime, 1) // fade out interval note and turn it off
  308.         fade_in(%note_ids[0], fadeouttime/2) // fade in sustain note
  309.  
  310.  
  311.     else // if last note is -1
  312.  
  313.         // enable sustain groups
  314.         disallow_group($ALL_GROUPS)
  315.         for i := 0 to num_elements(Sets.sustains)-1
  316.             allow_group(Sets.sustains[i])
  317.         end for
  318.  
  319.         note_off(%note_ids[0]) // end any already-playing sustains
  320.         %note_ids[0] := play_note(note_num, note_vel, 0, -1) // play sustain
  321.     end if
  322.  
  323.     last_note := note_num // save the number of the last note played
  324. end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement