Need KSP Help: Small adjustments for a keyswitch note fade out/mute script for Kontakt

TheDoldrumer
TheDoldrumer Member Posts: 14 Member
edited October 22 in Scripting Workshop

There are two adjustments I've been looking to make to a keyswitch note fadeout script that I've been working on for an instrument.:


- I'd like for the keyswitch to ignore any notes that I still have my fingers held down on, and to only fade out/mute the notes that I've taken my fingers off of.


- I'd like for the keyswitch to activate essentially from the initial note on event only (if that makes any sense). So if I were to play a note, then release my finger, the keyswitch would effectively fade out/mute the released notes, yet if I were to keep the keyswitch held down, the script would still allow for me to play any consecutive notes without fading out. Essentially making the initial triggering of the keyswitch the gate in which the fadeout is activated, as oppose to it being during the entire duration that the keyswitch is held down.



Side Note: The keyswitch uses C-1 as its trigger to fade out any resonating notes while or after a note has been played. The ADSR release envelope should also be turned all the way up for the script to work as intended


The Code:


on init

    declare $count
    declare $fade_out

    declare ui_knob $fade_time(10000,1000000,100000)
    set_text($fade_time,"Length")
    make_persistent($fade_time)
    move_control($fade_time,1,1)

    declare const $KEY_SWITCH := 12

    set_key_color(12,$KEY_COLOR_RED)
end on


on note
    if ($EVENT_NOTE=$KEY_SWITCH)
        fade_out($ALL_EVENTS,$fade_time,0)
        $fade_out := 0
    end if
end on

...

I am not the best with scripting, so any help with this would be greatly appreciated!

Best Answers

  • medusa
    medusa Member Posts: 98 Helper
    edited March 2022 Answer ✓

    Actually maybe a better way would be set marks on the released IDs, in the on release callback. And then fade out by marks with your keyswitch, so only the released IDS will have the mark and be faded out.


    I'm not with Kontakt at the moment, but something like this in concept:

    on note
        if ($EVENT_NOTE=$KEY_SWITCH)
            fade_out(by_marks($MARK_1), $fade_time,0)
        end if
    end on
    
    on release
        set_mark($EVENT_ID, MARK_1)
    end on
    


  • EvilDragon
    EvilDragon Moderator Posts: 1,028 mod
    Answer ✓

    Missing $ before MARK_1.

Answers

  • medusa
    medusa Member Posts: 98 Helper

    Maybe use the %KEY_DOWN array to check if the notes are being held?

  • TheDoldrumer
    TheDoldrumer Member Posts: 14 Member
    edited March 2022

    Not sure if I'm thinking of this the right way? I've got something like this, but it doesn't seem to work:

    on note
        if ($EVENT_NOTE=$KEY_SWITCH)
    	fade_out($ALL_EVENTS, $fade_time,0)
            $fade_out := 0
        else
            ignore_event(%KEY_DOWN[13-127])
        end if
    end on
    
  • TheDoldrumer
    TheDoldrumer Member Posts: 14 Member
  • medusa
    medusa Member Posts: 98 Helper
    edited March 2022 Answer ✓

    Actually maybe a better way would be set marks on the released IDs, in the on release callback. And then fade out by marks with your keyswitch, so only the released IDS will have the mark and be faded out.


    I'm not with Kontakt at the moment, but something like this in concept:

    on note
        if ($EVENT_NOTE=$KEY_SWITCH)
            fade_out(by_marks($MARK_1), $fade_time,0)
        end if
    end on
    
    on release
        set_mark($EVENT_ID, MARK_1)
    end on
    


  • TheDoldrumer
    TheDoldrumer Member Posts: 14 Member

    For some reason I'm getting an "'end on' expected" error?


  • EvilDragon
    EvilDragon Moderator Posts: 1,028 mod
    Answer ✓

    Missing $ before MARK_1.

  • TheDoldrumer
    TheDoldrumer Member Posts: 14 Member
    edited March 2022

    This works! Heres the final script:

    on init


    declare $fade_out

    declare ui_knob $fade_time(10000,1000000,100000)

    set_text($fade_time,"Length")

    make_persistent($fade_time)

    move_control($fade_time,1,1)


      declare const $KEY_SWITCH := 12

    set_key_color(12,$KEY_COLOR_RED)


    end on

    on note

    if ($EVENT_NOTE=$KEY_SWITCH)

        fade_out(by_marks($MARK_1), $fade_time,0)

    $fade_out := 0

    end if


    end on


    on release

    set_event_mark($EVENT_ID, $MARK_1)


    end on

  • EvilDragon
    EvilDragon Moderator Posts: 1,028 mod

    Please use the code block feature when pasting code in... Select your text and press the paragraph symbol, then quotation mark button:


This discussion has been closed.
Back To Top