What's new

Re-pedaling / pedal issues and using KEY_DOWN


Noob in frenzy loop
Hello dear KSP:ers.

I am trying to make sense of why the pedal function, the internal script, that is. I have made a pretty complete script turning off and on functions for release groups etc. Using the internal pedal script functionality I am still getting an error when releasing and then re-pedaling again. Here´s my issue:

My script checks if the keys are down, with KEY_DOWN, upon on controller (cc64) release. It assigns a number to an array I made. That all works like a charm. But when I keep one note on, after releasing the pedal, the next time I re-pedal again (still holding the same key down), the KEY_DOWN array (internal Kontakt native array) returns that the key is NOT down. "0". Why?

Here´s the full issue. (the "#1" is the key strike event in question)

1. pedal is off, I press a key (#1) down.
2. I press down the pedal.
3. I release the key (#1), keeping the pedal pressed.
4. I press the same key again (#2), still keeping pedal pressed.
5. I release the pedal only, whereupon the previous key is faded out.
6. Here I still got the key (#2) pressed down.
7. I press the pedal again, then release it again. Keeping the key pressed down.
(here the script is checking if the key is down, with KEY_DOWN)
8. the KEY_DOWN is returning "0", that it is not pressed still.

WHY? Is this something of a general issue?

I looked through the general old thread for custom scripts:

There is something about sustain pedaling issues being fixed in there, in SIPS, but I have yet to find anything for this issue. SIPS is for solo instruments, mine is a piano, so might be off.

Sips page:
(info is at "Version 1.50 May 19, 2007")

Any help here is greatly appreciated.


Noob in frenzy loop
Thread starter
  • Thread Starter
  • Thread Starter
  • #2
Ok, so after a lot of testing I have realised that the internal Pedal script is not working as it should in regards to KEY_DOWN. Not when pedaling up, holding the key, then pedaling down again, as stated above.

However, if you disable the internal sustain pedal script, you can get around this issue. The KEY_DOWN internal array will work as intended. But that includes putting the SET_CONDITION(NO_SYS_SCRIPT_PEDAL) in your on init. The solution to internal pedal script is as follows:

This is the basics of "making your own pedal script":

2. put note_off in on controller, CC64 < 64. (more on this later).
3. for pianos/key-instruments:
- - on release, put the following code:

if (%CC[64] > 63 and %KEY_DOWN[$EVENT_NOTE] = 0)

    play_note($EVENT_NOTE, $EVENT_VELOCITY, 0, 0)

end if

-- this first ignores_event for incoming note_off messages, then plays a release sound of your choosing. Only for release events of the key itself. The active note continues to play.
4. put note_off in on release. More stuff applies here of course. When dealing with pianos/rhodes etc there are multiple sound groups mostly.

Code for retrieving all events that are active upon release of the pedal:

This script looks at all active events, per key, and then releases the ones that where the key initiating the event is not pressed, using KEY_DOWN). This is because we cannot use EVENT_NOTE in on controller.

get_event_ids is used to get all active events for all notes not yet released.

on controller
    if ($CC_NUM = 64)
        if (%CC[64] < 64 and ($lastcc64value>=64))

            get_event_ids(%ids) {get all active IDs and put in to the array "ids"}
            $count := 0
            while (%ids[$count] # 0)

                {getting the EVENT_ID´s EVENT_NOTE}
                $idn := get_event_par(%ids[$count],$EVENT_PAR_NOTE)

                if (%KEY_DOWN[$idn]=0)
                end if

          end while
        end if

        {now pedaling down, cc64 above 64.}
        if (%CC[64] > 63 and ($lastcc64value <= 63))
            message("") {nothing needed here}
        end if
        $lastcc64value := %CC[64]
    end if
end on

This code is lightly edited and from another post here:
Last edited:
Top Bottom