Get the current value of the sustain pedal when you start playing the note in synthesizerVoice

I can get the value in each voice by overriding the controllerMoved method, but only when the note is active. Not at play time

Yes, it’s possible to get its on/off state with isSustainPedalDown(), but not its value (what if it’s half-pedal?).

Apparently the Synthesizer class only stores its on/off state.

I think I’m going to have to modify the class, but maybe there’s a less radical solution?

It might be possible to get this behaviour by deriving from Synthesiser and overriding handleController to keep a record of the sustain pedal value. Then, you can also override SynthesiserVoice::startNote to look up the sustain controller value on the voice’s currentPlayingMidiChannel.

Yes, override handleController to capture the state of the pedal seemed inevitable. Although I evaluated how to treat it later, I finally thought that this state should be included in the played note, so I finally did something quite ugly but effective, which is to combine the sustain with the velocity.

    void noteOn(int midiChannel, int midiNoteNumber, float velocity) 	override
    {

        float velocityAndSustain =  static_cast<float>((static_cast<int>(velocity * 127.f)) | (sustainValue << 8));
        juce::Synthesiser::noteOn(midiChannel, midiNoteNumber, velocityAndSustain);

    }

I think a new version of synthesizerVoice::starNote should be added with a structure with the current values of the sustain, sustenuto, soft, pitch wheel, (and maybe channel pressure), as well as any state or value that is currently required to be added, or in the future.