# Release groups and Sustain Pedal (or CC64) on and off events



## KrisY (Jan 19, 2019)

I got a piano instrument in the making and the release groups are supposed to play at both *sustain pedal* _on _and _off_ signals (also triggered by CC64 programmed into a daw).

To handle release groups I have separate groups for sustain pedal off (CC64 < 63) and on (CC64 > 64). This is because of that the sounds are the same but the lengths of the sustain samples are not. So the Release Trigger Counter modulator is on all groups, just using different release "t/ms" values. In other words, there is one set of (release-) groups for triggering when no sustain pedal is pressed or programmed into the DAW, and then another set of groups set to trigger when the sustain pedal has been pressed (really for note events triggered when sustain pedal is pressed / CC64 is over 64). All events are note-off events. So I guess, "*on release*".

Now I have set them to be release triggered and also set the group start options to *CC64 0-63* (_for release groups corresponding to notes triggered without sustain pedal pressed_) - and *CC64 64-127* (_for release groups corresponding to notes triggered with sustain pedal pressed_).

But only the groups with CC64 *0-63* (sustain pedal off) is triggered on release. I guess the problem is that when the sustain pedal or CC64 is reset to 0, the release is triggered, and then sustain pedal is no longer on. So how could it trigger a layer that is set to only trigger if sustain pedal is on? Haha. You can´t win. Clear cut case of catch 22 .

So by programming this it would look like something like this, I guess:


```
on release

  if CC64 is 0 AND [was just] > 63

    play THESE groups

  elseif

    play THOSE groups

  end if
 
end on
```


The other option would be to use on controller, and just disallow groups upon CC64 basis. (_using my own crafted on controller message CC112 on-off script that uses group start options to work, as release groups cannot be "disallow_group":ed. :/ Courtesy of NI_).

The other issues here on VI-control about this (or adjacent/similar) are usually solved using completely re-written release trigger scripts. I am not about to do any of that.

Any help with what callback and scripting can be used or even workarounds are much welcomed.


----------



## EvilDragon (Jan 20, 2019)

KrisY said:


> _as release groups cannot be "disallow_group":ed. :/ Courtesy of NI_).



They can but not if you use internal release triggering. You would have to script your own release triggering, then you can allow or disallow whichever groups you want. But since you're not gonna do that, not much else you can do there...


----------



## KrisY (Jan 20, 2019)

EvilDragon said:


> ... You would have to script your own release triggering, then you can allow or disallow whichever groups you want.



Indeed, I think you may have helped me with that specific info before . Thanks for the info. I solved that bit by using group start options set to controller 111-115, unused in most applications. These are then manipulated with UI buttons or pedal actions. That is the best approach for shutting off release groups if you do not write your own release triggering. I want to stick to the built in functionality as long as I can. Cause I don´t have the necessary skills to do math libraries or advanced programming.

Thanks for the info. 

I need to trigger different groups based on if the CC64 is (was just ago) held or not upon the time of note-off. So, I need ideas on how to make a release sample trigger on groups set to start on "CC64 = 64-127". The programming would have to use "on release". But how does KSP acknowledge a difference between release triggering _as a result of_ a _note-off message_ due to a _key being released_, *as opposed* to a note-off message _due to a controller message_ going from *CC64 > 63* to *CC64 < 64* ?? 

I mean programatically that´s a catch 22. Upon note-off Kontakt is going: 
Is the value of controller 64 above 63? No. 
Is it below? Yes. 
Was it the reason for the note-off message? what?

It´s a bit of a logical pickle. Unless there is an option to review the state of CC64 upon release. Like perhaps this one:


```
... if (%CC[64]<64 and lastcc64value>=64) ...
```

The code is from another thread here:
https://vi-control.net/community/threads/about-sustain-pedal-script.52398/#post-3945067

"lastcc64value" is most likely a stored value, a custom variable. Not sure yet.


----------



## EvilDragon (Jan 20, 2019)

It's really not a problem. You just do this:


```
on release
    if (%CC[64] < 64)
        <allow/disallow stuff, in your case send a particular CC value>
    else
        <allow/disallow different stuff, in your case send a particular other CC value>
    end if
end on
```

No?


----------



## KrisY (Jan 20, 2019)

That is the code I would put, except for the problem at hand. How does the note off messages get from being a note on? Yes, from a CC64 message. Going to 0. But the issue is that it has to be a different group now than if the sustain pedal was not held at all. 

See my problem? Different groups based on wether or not there was just recently a CC64 message of 64 or more, that then went to 63 or less.  

The note off messages are perhaps not different, but they have been triggered based on different events. 


```
on release
    if (%CC[64] < 64)   { this is the case always, no? }

    end if
end on
```

The CC64 is always at 0 when the "on release" was called, no? Or is the controller triggered after the note-off events? That would be unlikely. 

So, "if (%CC[64] < 64)" needs to be including some form of value stating that it was the reason for the "on release" being called back, for the release events. Or the difference is none. The cc64 is at 0. 

One solution is perhaps to delay the CC64 event that goes from above 64 to below 63, and release the notes, while the CC64 is at 64+, but that will not produce any note-off messages. Right? 

_The CC64 is the trigger here. So... catch 22. I dont see the logic in this feature with cc64 on release triggered groups. It can only work where CC64 is on 0 or less than 63. _


----------



## KrisY (Jan 20, 2019)

However.. 

this might be the key, structure wise:


```
on release
    if (%CC[64] < 64  and lastcc64value >= 64)
        <for the note in question, that was triggered after sustain pedal was triggered: play events from group 2>
    else
        <play events from group 1 (my release group for notes played without sustain pedal being pressed down)>
    end if
end on
```


----------

