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

Manually implemented arp/seq release

Discussion in 'Scripting Workshop' started by soyfabi, Sep 9, 2021.

  1. soyfabi

    soyfabi NI Product Owner

    Messages:
    26
    Hey Guys,
    so I managed to implement a release for a simple seq/arp/pattern...

    What works: If you press a key, the pattern starts. When you release the key, the pattern volume/velocity decreases until it stops, for a natural release feeling.

    What I want: When you press a key again while the pattern-release is still running, it should stop the release-pattern and the pattern should start again, as if you would press the key the first time.

    I somehow managed to make it work for every second key-press and I just dont figure out why it does not always work.

    Maybe someone wants to take a look at the code and try it out :) I guess everything is named in a way that it is
    self-describing.

    Note: In the code the pattern is only made for the note C3 (note 60 in ksp)

    Code:
    on init
    
        declare %pressed[128]
    
        declare $key_again:=-1
    
        declare $my_id1
        declare $my_id2
    
        declare $hold_pattern1:=0
        declare $hold_pattern2:=0
    
        declare $release_trig1:=0
        declare $release_trig2:=0
    
        declare $release_count1:=0
        declare $release_count2:=0
    
        declare $release_vol1:=19
        declare $release_vol2:=19
    
    end on
    
    
    on note
    
    if($EVENT_NOTE=60)
    
            %pressed[$EVENT_NOTE] := $EVENT_ID
    
            ignore_event($EVENT_ID)
    
            $hold_pattern1:=1
            $hold_pattern2:=1
    
            $release_trig1:=0
            $release_trig2:=0
    
            $release_count1:=0
            $release_count2:=0
    
            $release_vol1:=19
            $release_vol2:=19
    
    
            $key_again:= ($key_again+1) mod 2
    
        {---------while loop for pattern/seq----------------}
    
            while($hold_pattern1=1 and $key_again=0)   
    
                $my_id1 := play_note($EVENT_NOTE+12,100-$release_vol1,0,$DURATION_EIGHTH)
                wait($DURATION_QUARTER)
    
                if($release_trig1=1 and $release_count1<11)
    
                    inc($release_count1)
                    $release_vol1:=$release_vol1+8
    
                end if
                if($release_count1=10)
                    $hold_pattern1:=0
                    $release_count1:=0
                    $release_vol1:=19
                    $release_trig1:=0
    
                end if
    
            end while
            
            {--------same while loop but with key_again=1---------------}
    
            while($hold_pattern2=1 and $key_again=1)
    
                $my_id2 := play_note($EVENT_NOTE+12,100-$release_vol2,0,$DURATION_EIGHTH)
                wait($DURATION_QUARTER)
    
                if($release_trig2=1 and $release_count2<11)
                    
                    inc($release_count2)
                    $release_vol2:=$release_vol2+8
    
                end if
                if($release_count2=10)
    
                    $hold_pattern2:=0
                    $release_count2:=0
                    $release_vol2:=19
                    $release_trig2:=0
                    
                end if
    
            end while
    end if
    
    end on
    
    
    on release
    
        if (%pressed[$EVENT_NOTE]= $EVENT_ID)
            %pressed[$EVENT_NOTE] := 0
    
            if(%pressed[60]=0 and $EVENT_NOTE=60)
                $release_trig1:=1
                $release_trig2:=1
            end if
            
        end if
    
    end on
    
    help is much appreciated :)

    fabi
     
  2. ericchesek

    ericchesek New Member

    Messages:
    11
    Hello! I came up with something that might work for you. I tried to simplify the process a bit.

    Code:
    on init
        declare %pressed[128]
        declare $release_vol := 18
        declare $i
        message("")
    end on
    
    on note
        if($EVENT_NOTE=60)
            $i := 11
            {this will break out of the while loop below to stop the notes from repeating}
    
            %pressed[$EVENT_NOTE] := $EVENT_ID
            {store the note on event ID}
    
            ignore_event($EVENT_ID)
            {ignore it for the rest of this if statement}
    
            while($NOTE_HELD = 1)
                play_note($EVENT_NOTE+12,100-$release_vol,0,$DURATION_EIGHTH)
                wait($DURATION_QUARTER)
            end while
            {this repeats notes indefinitely while event note 60 is held}
    
            if($NOTE_HELD = 0)
                $i := 1
                while($i < 10)
                    play_note($EVENT_NOTE+12,100-($release_vol+$i*8),0,$DURATION_EIGHTH)
                    wait($DURATION_QUARTER)
                    inc($i)
                end while
            end if
    
        end if
    end on
     
    • Like Like x 1
  3. soyfabi

    soyfabi NI Product Owner

    Messages:
    26
    Hey Eric, thanks for your reply!
    I intentionally avoided working with NOTE_HELD to be able to work with the sustain pedal and holding the pattern with it. Should have mentioned that. But I managed to adapt your code and it worked! I still have to implement a code to ignore the pattern while the pattern is already playing due to "sustain pedal down". But I will have a try on that soon.

    Thank you for pushing me in the right direction :) I really made my life hard by trying to complicate it haha.
    Maybe ill come back if I'am stuck with the rest of the code;)

    fabi