I can't run 'pitchWheelMoved

Hello. I am a new JUCE user, and I’ve reached a point where I couldn’t find an answer to my problem no matter how much research I’ve done. It could be something simple that I’m overlooking. Am I doing something wrong with the following approaches?

void Sample::handlePitchWheel(int midiChannel, int wheelValue) {
MyPitchValue = wheelValue;

for (int j = voices.size(); --j >= 0; ) {
    juce::SynthesiserVoice* const voice = voices.getUnchecked(j);
    voice->pitchWheelMoved(wheelValue);
}

}
Apart from this, I have another piece of code that is not working:

float myPitchValue = mSample.MyPitchValue;
juce::MidiMessage pitchWheelMessage = juce::MidiMessage::pitchWheel(1, myPitchValue);
midiMessages.addEvent(pitchWheelMessage, buffer.getNumSamples());

mSample.renderNextBlock(buffer, midiMessages, 0, buffer.getNumSamples());

I would greatly appreciate your assistance.

for the 2nd piece of code not working: what is the range of your myPitchValue?

From the MidiMessage docs:

position - the wheel position, in the range 0 to 16383

So 8191 (I think? Or it might be 8192, check with Le Goog for MIDI specs!) is equivalent to no pitch bend applied, 0 is full negative pitch bend and 16383 is full positive pitch bend.

ps. please when putting code in forum messages surround the code with three back-ticks, eg.

```

std::cout << "your code goes here"
          << "and will be nicely formatted and highlighted"
          << std::endl;

```

Indeed, the value received here is between 0 and 16383. However, it seems like the pitchWheelMoved() function is empty. I’m currently researching this issue, but I haven’t been able to apply the pitch bend to my sample instrument yet. Below, I have two different approaches to tackle this issue.


void Sample::handlePitchWheel (int midiChannel,
                       int wheelValue){
    for ( int j = voices.size(); --j >= 0; )
    {
        juce::SynthesiserVoice* const voice = voices.getUnchecked (j);
        voice->pitchWheelMoved(wheelValue);
    }
}
void AnatolianWaveOudAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
{
    float myPitchValue = mSample.MyPitchValue;
    juce::MidiMessage pitchWheelMessage = juce::MidiMessage::pitchWheel(1, myPitchValue);
    midiMessages.addEvent(pitchWheelMessage, buffer.getNumSamples());
    
    mSample.renderNextBlock(buffer, midiMessages, 0, buffer.getNumSamples());
}

Note that the timestamp of the MidiMessages is from 0 to buffer.getNumSamples()-1, which means technically you are exceeding the possible sample positions.
I don’t know what happens, maybe it is discarded.

The addEvent() returns a bool, if the operation worked or not, maybe it is useful to evaluate that too, maybe in a DBG (but remove it right after, as DBG is not realtime safe, but handy to figure out what’s going on).

In this situations the most important is to figure out if your code is actually run or not.