1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

Key range

Discussion in 'Scripting Workshop' started by Alaa daly, Jul 29, 2018.

  1. Alaa daly

    Alaa daly New Member

    Messages:
    10
    Hello , I'm asking how to make Key range for glide Script ?

    Code:
    on init
    
        message("")
    
        set_ui_height(310)
        set_script_title("gilde")
    
      
        declare const $pitch_change_interval := 100
        declare $glide_on
        declare $currentnote_id
        declare $newnote_id
        declare $oldnote1_id
        declare $oldnote2_id
        declare $oldnote3_id
        declare $current_pitch
        declare $target_pitch
        declare $pitch_shift
        declare $actual_glide
        declare $interval_cents
        declare polyphonic $this_id
    
        declare ui_knob $Glide(1000, 1000000, 1000000)
        declare ui_knob $Start (0, 1000000, 1000000)
        declare ui_knob $Scaling(100, 200, 100)
        declare ui_value_edit $Threshold(0, 127, 1)
    
        $Glide := 120000
        $Start := 5000
        $Scaling := 125
        $Threshold := 12
    
        move_control($Glide, 1, 1)
        move_control($Start, 2, 1)
        move_control($Scaling, 3, 1)
        move_control($Threshold, 4, 1)
    
        make_persistent ($Start)
        make_persistent ($Glide)
        make_persistent ($Scaling)
        make_persistent ($Threshold)
    
        message("")
    end on
    
    on note
        if ($glide_on = 1)
            ignore_event($EVENT_ID)
            $newnote_id := play_note($EVENT_NOTE, $EVENT_VELOCITY, $Start, -1)
            $this_id := $newnote_id
            change_tune($newnote_id,$current_pitch - ($EVENT_NOTE*100000), 0)
            $target_pitch := $EVENT_NOTE * 100000
            $interval_cents := abs($target_pitch/1000 - $current_pitch/1000)
            if ($interval_cents > $Threshold * 100)
                $interval_cents := $Threshold * 100
            end if
            $actual_glide := $Glide + ($Glide * $interval_cents / 1200 * ($Scaling - 100) / 100)
    
            fade_out($newnote_id, 0, 1)
            fade_in ($newnote_id,$actual_glide)
            fade_out($currentnote_id, $actual_glide, 1)
    
            note_off($oldnote3_id)
            $oldnote3_id := $oldnote2_id
            $oldnote2_id := $oldnote1_id
            $oldnote1_id := $currentnote_id
            $currentnote_id := $newnote_id
    
            $pitch_shift := ($target_pitch - $current_pitch) / ($actual_glide / $pitch_change_interval)
            wait($pitch_change_interval)
            while(abs($target_pitch - $current_pitch) > abs($pitch_shift))
                if ($currentnote_id = $this_id)
                    change_tune($currentnote_id, $pitch_shift, 1)
                    change_tune($oldnote1_id, $pitch_shift, 1)
                    change_tune($oldnote2_id, $pitch_shift, 1)
                    change_tune($oldnote3_id, $pitch_shift, 1)
                    $current_pitch := $current_pitch + $pitch_shift
                    wait($pitch_change_interval)
                else
                    exit
                end if
            end while
            if ($currentnote_id = $this_id)
                $pitch_shift := $target_pitch - $current_pitch
                change_tune($currentnote_id, $pitch_shift, 1)
                change_tune($oldnote1_id, $pitch_shift, 1)
                change_tune($oldnote2_id, $pitch_shift, 1)
                change_tune($oldnote3_id, $pitch_shift, 1)
                $current_pitch := $target_pitch
            end if
        else
            $currentnote_id := $EVENT_ID
            $current_pitch := $EVENT_NOTE * 100000
            $glide_on := 1
        end if
    end on
    
    on release
        if($EVENT_ID = $currentnote_id)
            $glide_on := 0
            note_off($oldnote3_id)
            note_off($oldnote2_id)
            note_off($oldnote1_id)
            $current_pitch := $target_pitch
        end if
        if ($glide_on = 1 and $EVENT_ID # $oldnote3_id)
            ignore_event($EVENT_ID)
            wait($Glide)
            note_off($EVENT_ID)
        end if
    end on
     
  2. corbo-billy

    corbo-billy NI Product Owner

    Messages:
    652
    For example, the scripts provided by Native can be useful.

    [​IMG]
     
  3. Alaa daly

    Alaa daly New Member

    Messages:
    10
    hello, corbo-billy it won't work with glid i tried it brake when i put an other instrument in left Hand like Pad or Bass

    Bass From C-2 → B2
    Instrument (with Glide ) From C3 → G8
     
  4. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
    If you load that other instrument as actually a separate instrument (and not a new group), it will work just fine.