Fade out and numPressedKeys



  • I'm experimenting and I think that fading out a note to -100 doesn't reduce the numPressedKeys counter - I'm trying to put together a simple example to demonstrate it at the mo.



  • Ok I've got an example that demonstrates the issue. It's a bit of a weird one. If you play a legato phrase and then release all the keys you'll see the numPressedKeys() in the console go up and it will keep going up everytime you do this, even though you're releasing all the keys. If you change the line of code in the first script from a fade out to Synth.noteOffByEventId() the problem is fixed.

    If you Console.print() the number of pressed keys in the first script the value is correct, it's only the second script that isn't correct and only seems to occur when the first script is in a container that is the parent of the second scripts synth - confusing!

    Also if you change the Synth.noteOffByEventId() in the noteOff callback of the first script to a volume fade out to -100 nothing is output by the seconds script at all.

    <?xml version="1.0" encoding="UTF-8"?>
    
    <Processor Type="SynthChain" ID="releaseTest" Bypassed="0" Gain="1" Balance="0"
               VoiceLimit="128" KillFadeTime="20" IconColour="0" packageName=""
               views="32.rk1bzA..........................vro1Qzc...." currentView="-1">
      <EditorStates BodyShown="0" Visible="1" Solo="0" Folded="0" InterfaceShown="0"/>
      <ChildProcessors>
        <Processor Type="MidiProcessorChain" ID="Midi Processor" Bypassed="0">
          <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
          <ChildProcessors/>
        </Processor>
        <Processor Type="ModulatorChain" ID="GainModulation" Bypassed="0" Intensity="1">
          <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
          <ChildProcessors/>
        </Processor>
        <Processor Type="ModulatorChain" ID="PitchModulation" Bypassed="1" Intensity="0">
          <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
          <ChildProcessors/>
        </Processor>
        <Processor Type="EffectChain" ID="FX" Bypassed="0">
          <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="0"/>
          <ChildProcessors>
            <Processor Type="SimpleGain" ID="Balcony" Bypassed="0" Gain="0" Delay="0"
                       Width="100" Balance="0">
              <EditorStates BodyShown="1" Visible="1" Solo="0"/>
              <ChildProcessors>
                <Processor Type="ModulatorChain" ID="Gain Modulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
                <Processor Type="ModulatorChain" ID="Delay Modulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
                <Processor Type="ModulatorChain" ID="Width Modulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
                <Processor Type="ModulatorChain" ID="Pan Modulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
              </ChildProcessors>
              <RoutingMatrix NumSourceChannels="12" Channel0="0" Send0="-1" Channel1="1" Send1="-1"
                             Channel2="-1" Send2="-1" Channel3="-1" Send3="-1" Channel4="-1"
                             Send4="-1" Channel5="-1" Send5="-1" Channel6="-1" Send6="-1"
                             Channel7="-1" Send7="-1" Channel8="-1" Send8="-1" Channel9="-1"
                             Send9="-1" Channel10="-1" Send10="-1" Channel11="-1" Send11="-1"/>
            </Processor>
            <Processor Type="SimpleGain" ID="Close" Bypassed="0" Gain="0" Delay="0"
                       Width="100" Balance="0">
              <EditorStates BodyShown="1" Visible="1" Solo="0" Folded="0"/>
              <ChildProcessors>
                <Processor Type="ModulatorChain" ID="Gain Modulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
                <Processor Type="ModulatorChain" ID="Delay Modulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
                <Processor Type="ModulatorChain" ID="Width Modulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
                <Processor Type="ModulatorChain" ID="Pan Modulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
              </ChildProcessors>
              <RoutingMatrix NumSourceChannels="12" Channel0="-1" Send0="-1" Channel1="-1"
                             Send1="-1" Channel2="2" Send2="-1" Channel3="3" Send3="-1" Channel4="-1"
                             Send4="-1" Channel5="-1" Send5="-1" Channel6="-1" Send6="-1"
                             Channel7="-1" Send7="-1" Channel8="-1" Send8="-1" Channel9="-1"
                             Send9="-1" Channel10="-1" Send10="-1" Channel11="-1" Send11="-1"/>
            </Processor>
            <Processor Type="SimpleGain" ID="Decca Centre" Bypassed="0" Gain="0" Delay="0"
                       Width="100" Balance="0">
              <EditorStates BodyShown="1" Visible="1" Solo="0" Folded="0"/>
              <ChildProcessors>
                <Processor Type="ModulatorChain" ID="Gain Modulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
                <Processor Type="ModulatorChain" ID="Delay Modulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
                <Processor Type="ModulatorChain" ID="Width Modulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
                <Processor Type="ModulatorChain" ID="Pan Modulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
              </ChildProcessors>
              <RoutingMatrix NumSourceChannels="12" Channel0="-1" Send0="-1" Channel1="-1"
                             Send1="-1" Channel2="-1" Send2="-1" Channel3="-1" Send3="-1"
                             Channel4="4" Send4="-1" Channel5="5" Send5="-1" Channel6="-1"
                             Send6="-1" Channel7="-1" Send7="-1" Channel8="-1" Send8="-1"
                             Channel9="-1" Send9="-1" Channel10="-1" Send10="-1" Channel11="-1"
                             Send11="-1"/>
            </Processor>
            <Processor Type="SimpleGain" ID="Decca Stereo" Bypassed="0" Gain="0" Delay="0"
                       Width="100" Balance="0">
              <EditorStates BodyShown="1" Visible="1" Solo="0" Folded="0"/>
              <ChildProcessors>
                <Processor Type="ModulatorChain" ID="Gain Modulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
                <Processor Type="ModulatorChain" ID="Delay Modulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
                <Processor Type="ModulatorChain" ID="Width Modulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
                <Processor Type="ModulatorChain" ID="Pan Modulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
              </ChildProcessors>
              <RoutingMatrix NumSourceChannels="12" Channel0="-1" Send0="-1" Channel1="-1"
                             Send1="-1" Channel2="-1" Send2="-1" Channel3="-1" Send3="-1"
                             Channel4="-1" Send4="-1" Channel5="-1" Send5="-1" Channel6="6"
                             Send6="-1" Channel7="7" Send7="-1" Channel8="-1" Send8="-1" Channel9="-1"
                             Send9="-1" Channel10="-1" Send10="-1" Channel11="-1" Send11="-1"/>
            </Processor>
            <Processor Type="SimpleGain" ID="Wide" Bypassed="0" Gain="0" Delay="0" Width="100"
                       Balance="0">
              <EditorStates BodyShown="1" Visible="1" Solo="0" Folded="0"/>
              <ChildProcessors>
                <Processor Type="ModulatorChain" ID="Gain Modulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
                <Processor Type="ModulatorChain" ID="Delay Modulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
                <Processor Type="ModulatorChain" ID="Width Modulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
                <Processor Type="ModulatorChain" ID="Pan Modulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
              </ChildProcessors>
              <RoutingMatrix NumSourceChannels="12" Channel0="-1" Send0="-1" Channel1="-1"
                             Send1="-1" Channel2="-1" Send2="-1" Channel3="-1" Send3="-1"
                             Channel4="-1" Send4="-1" Channel5="-1" Send5="-1" Channel6="-1"
                             Send6="-1" Channel7="-1" Send7="-1" Channel8="8" Send8="-1" Channel9="9"
                             Send9="-1" Channel10="-1" Send10="-1" Channel11="-1" Send11="-1"/>
            </Processor>
          </ChildProcessors>
        </Processor>
        <Processor Type="SynthChain" ID="Container" Bypassed="0" Gain="1" Balance="0"
                   VoiceLimit="128" KillFadeTime="20" IconColour="0">
          <EditorStates BodyShown="0" Visible="1" Solo="0" Folded="0"/>
          <ChildProcessors>
            <Processor Type="MidiProcessorChain" ID="Midi Processor" Bypassed="0">
              <EditorStates BodyShown="1" Visible="1" Solo="0" Folded="0"/>
              <ChildProcessors>
                <Processor Type="ScriptProcessor" ID="Script Processor3" Bypassed="0" Script="reg noteNumber = -1;&#10;reg eventId = -1;&#10;&#10;function onNoteOn()&#10;{&#10;&#9;Message.ignoreEvent(true);&#10;&#10;&#9;if (eventId != -1)&#10;&#9;{&#13;&#10;&#9;&#9;//Synth.noteOffByEventId(eventId);&#10;&#9;&#9;Synth.addVolumeFade(eventId, 60, -100); //Fade out old note&#10;&#9;}&#10;&#10;&#9;eventId = Synth.playNote(Message.getNoteNumber(), Message.getVelocity());&#10;&#10;&#9;noteNumber = Message.getNoteNumber();&#10;}&#10;&#10;function onNoteOff()&#10;{&#10;&#9;Message.ignoreEvent(true);&#10;&#10;&#9;if (Message.getNoteNumber() == noteNumber)&#10;&#9;{&#10;&#9;&#9;Synth.noteOffByEventId(eventId);&#10;&#9;&#9;//Synth.addVolumeFade(eventId, 60, -100);&#10;&#9;&#9;noteNumber = -1;&#10;&#9;&#9;eventId = -1;&#10;&#9;}&#10;}&#10;&#10;function onController()&#10;{&#10;&#9;&#10;}&#10;function onTimer()&#10;{&#10;&#9;&#10;}&#10;function onControl(number, value)&#10;{&#10;&#9;&#10;}&#10;">
                  <EditorStates BodyShown="1" Visible="1" Solo="0" contentShown="1" onInitOpen="0"
                                onNoteOnOpen="1" onNoteOffOpen="0" onControllerOpen="0" onTimerOpen="0"
                                onControlOpen="0"/>
                  <ChildProcessors/>
                  <Content/>
                </Processor>
              </ChildProcessors>
            </Processor>
            <Processor Type="ModulatorChain" ID="GainModulation" Bypassed="0" Intensity="1">
              <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
              <ChildProcessors/>
            </Processor>
            <Processor Type="ModulatorChain" ID="PitchModulation" Bypassed="1" Intensity="0">
              <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
              <ChildProcessors/>
            </Processor>
            <Processor Type="EffectChain" ID="FX" Bypassed="0">
              <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
              <ChildProcessors/>
            </Processor>
            <Processor Type="SineSynth" ID="Sine Wave Generator" Bypassed="0" Gain="0.017782794"
                       Balance="0" VoiceLimit="128" KillFadeTime="20" IconColour="0"
                       OctaveTranspose="0" SemiTones="0" UseFreqRatio="0" CoarseFreqRatio="1"
                       FineFreqRatio="0" SaturationAmount="0">
              <EditorStates BodyShown="1" Visible="1" Solo="0" GainModulationShown="1" Folded="1"/>
              <ChildProcessors>
                <Processor Type="MidiProcessorChain" ID="Midi Processor" Bypassed="0">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
                <Processor Type="ModulatorChain" ID="GainModulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0"/>
                  <ChildProcessors>
                    <Processor Type="SimpleEnvelope" ID="DefaultEnvelope" Bypassed="0" Intensity="1"
                               Attack="5" Release="10" LinearMode="1">
                      <EditorStates BodyShown="1" Visible="1" Solo="0"/>
                      <ChildProcessors>
                        <Processor Type="ModulatorChain" ID="Attack Time Modulation" Bypassed="0"
                                   Intensity="1">
                          <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                          <ChildProcessors/>
                        </Processor>
                      </ChildProcessors>
                    </Processor>
                  </ChildProcessors>
                </Processor>
                <Processor Type="ModulatorChain" ID="PitchModulation" Bypassed="0" Intensity="0">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
                <Processor Type="EffectChain" ID="FX" Bypassed="0">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
              </ChildProcessors>
              <RoutingMatrix NumSourceChannels="2" Channel0="0" Send0="-1" Channel1="1" Send1="-1"/>
            </Processor>
            <Processor Type="SineSynth" ID="Sine Wave Generator2" Bypassed="0" Gain="0.020417383"
                       Balance="0" VoiceLimit="128" KillFadeTime="20" IconColour="0"
                       OctaveTranspose="0" SemiTones="0" UseFreqRatio="0" CoarseFreqRatio="1"
                       FineFreqRatio="0" SaturationAmount="0">
              <EditorStates BodyShown="0" Visible="1" Solo="0" GainModulationShown="1"/>
              <ChildProcessors>
                <Processor Type="MidiProcessorChain" ID="Midi Processor" Bypassed="0">
                  <EditorStates BodyShown="1" Visible="1" Solo="0" Folded="0"/>
                  <ChildProcessors>
                    <Processor Type="ScriptProcessor" ID="numPressedKeys" Bypassed="0" Script="function onNoteOn()&#10;{&#10;&#9;Message.ignoreEvent(true);&#10;}&#10;function onNoteOff()&#10;{&#10;&#9;Message.ignoreEvent(true);&#13;&#10;&#9;&#13;&#10;&#9;Console.print(Synth.getNumPressedKeys());&#10;}&#10;function onController()&#10;{&#10;&#9;&#10;}&#10;function onTimer()&#10;{&#10;&#9;&#10;}&#10;function onControl(number, value)&#10;{&#10;&#9;&#10;}&#10;">
                      <EditorStates BodyShown="1" Visible="1" Solo="0" contentShown="1" onInitOpen="0"
                                    onNoteOnOpen="0" onNoteOffOpen="1" onControllerOpen="0" onTimerOpen="0"
                                    onControlOpen="0" Folded="0"/>
                      <ChildProcessors/>
                      <Content/>
                    </Processor>
                  </ChildProcessors>
                </Processor>
                <Processor Type="ModulatorChain" ID="GainModulation" Bypassed="0" Intensity="1">
                  <EditorStates BodyShown="1" Visible="0" Solo="0"/>
                  <ChildProcessors>
                    <Processor Type="SimpleEnvelope" ID="DefaultEnvelope" Bypassed="0" Intensity="1"
                               Attack="5" Release="10" LinearMode="1">
                      <EditorStates BodyShown="1" Visible="1" Solo="0"/>
                      <ChildProcessors>
                        <Processor Type="ModulatorChain" ID="Attack Time Modulation" Bypassed="0"
                                   Intensity="1">
                          <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                          <ChildProcessors/>
                        </Processor>
                      </ChildProcessors>
                    </Processor>
                  </ChildProcessors>
                </Processor>
                <Processor Type="ModulatorChain" ID="PitchModulation" Bypassed="0" Intensity="0">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
                <Processor Type="EffectChain" ID="FX" Bypassed="0">
                  <EditorStates BodyShown="1" Visible="0" Solo="0" Folded="1"/>
                  <ChildProcessors/>
                </Processor>
              </ChildProcessors>
              <RoutingMatrix NumSourceChannels="2" Channel0="0" Send0="-1" Channel1="1" Send1="-1"/>
            </Processor>
          </ChildProcessors>
          <RoutingMatrix NumSourceChannels="2" Channel0="0" Send0="-1" Channel1="1" Send1="-1"/>
        </Processor>
      </ChildProcessors>
      <RoutingMatrix NumSourceChannels="12" Channel0="0" Send0="-1" Channel1="1" Send1="-1"
                     Channel2="0" Send2="-1" Channel3="1" Send3="-1" Channel4="0"
                     Send4="-1" Channel5="1" Send5="-1" Channel6="0" Send6="-1" Channel7="1"
                     Send7="-1" Channel8="0" Send8="-1" Channel9="1" Send9="-1" Channel10="0"
                     Send10="-1" Channel11="1" Send11="-1"/>
      <macro_controls>
        <macro name="Macro 1" value="0" midi_cc="-1"/>
        <macro name="Macro 2" value="0" midi_cc="-1"/>
        <macro name="Macro 3" value="0" midi_cc="-1"/>
        <macro name="Macro 4" value="0" midi_cc="-1"/>
        <macro name="Macro 5" value="0" midi_cc="-1"/>
        <macro name="Macro 6" value="0" midi_cc="-1"/>
        <macro name="Macro 7" value="0" midi_cc="-1"/>
        <macro name="Macro 8" value="0" midi_cc="-1"/>
      </macro_controls>
      <MidiAutomation/>
    </Processor>
    


  • Hmm, this is not totally trivial, because I realize that calling Synth.addVolumeFade violates the "One Note off per Note On" rule (and the rising voice counter is just one of the many possible side effects).

    I may have to add an internal note off event when calling Synth.addVolumeFade, but then the same rules as with the Synth.noteOffFromEventId() applies (no mixing of artificial / real events). So if you want to fade out an event, you'll have to make it artificial.



  • I thought events created with Syth.playNote() are artificial by default...
    This may sound a bit dumb but when there are no keys pressed the on-screen keyboard shows no keys are pressed, couldn't the same mechanism behind this also work for Synth.getNumPressedKeys()?



  • You mean don't increase the counter for artificial notes? This could make sense, but I'll have to think a little bit about side effects.



  • Yeah I think that would make more sense since the only thing getNumPressedKeys() should care about is the number of physical keys that have been pressed. Perhaps another counter could be used for counting the number of note ons and offs.



  • As a temporary solution I'm using this script in the master container and checking the value of Globals.keyCount rather than using numPressedKeys().

    <?xml version="1.0" encoding="UTF-8"?>
    
    <Processor Type="ScriptProcessor" ID="KeyCounter" Bypassed="0" Script="Globals.keyCount = 0;function onNoteOn()&#10;{&#10;&#9;Globals.keyCount++;&#10;}&#10;function onNoteOff()&#10;{&#10;&#9;Globals.keyCount--;&#10;}&#10;function onController()&#10;{&#10;&#9;&#10;}&#10;function onTimer()&#10;{&#10;&#9;&#10;}&#10;function onControl(number, value)&#10;{&#10;&#9;&#10;}&#10;">
      <EditorStates BodyShown="1" Visible="1" Solo="0" contentShown="1" onInitOpen="0"
                    onNoteOnOpen="0" onNoteOffOpen="1" onControllerOpen="0" onTimerOpen="0"
                    onControlOpen="0"/>
      <ChildProcessors/>
      <Content/>
    </Processor>
    


  • I'll try to add a fix ASAP.


 

2
Online

353
Users

1.1k
Topics

7.5k
Posts