Tutorial: Handling MIDI events - updating Pitchwheel


#1

Hi

Ive added a pitchwheel slider to the example in the “Tutorial:Handling MIDI events”. I have incoming midi and i added a slider that gets updated with the incoming pitchwheel changes via the timerCallback() method:

void timerCallback() override
	
	if (midiMessage.isPitchWheel())
		{
			pitchWheel.setValue(midiMessage.getPitchWheelValue(),dontSendNotification);
		}

i’ve set the Timer::startTimer(20); … i can move the hardware pitchwheel for a while and it works fine but after a while it gets stuck and slow. I have tried with lower startTimer values and it’s the same.

what are my unexperienced eyes, missing ?

im guessing, it is a miss aligned timing of the midi message callback and the timercallback … ? any hint is appreciated !!!

@jules or @timur is it possible to update the zip file with the last exercise “add modwheel and pitchwheel” as a _2 or _3 source code … this would be very educational !


#2

I think it may be @martinrobinson who wrote the tutorial.


#3

Yes I wrote that one. I’ll have a think, but for that exercise I was probably expecting you to use a CallbackMessage to get stuff back onto the message thread (as that technique was used in the IncomingMessageCallback class within the tutorial).

Looking at your code excerpt above using the Timer: if you’re storing the MIDI message in midiMessge, which looks like it’s a member variable (?), then if other MIDI is arriving within the 20ms (or even 1ms if you set the minimum Timer interval), then the value is likely to get overwritten before you get into the timer callback. Using the CallbackMessage will mean all the messages are queued.

The longer answer is that in a real audio application (where you are using an audio callback and generating or processing audio) then you probably wouldn’t do any of this as you’d be using the audio callback to deal with the MIDI too. Then you’d need something else to send the MIDI to the message thread (as the CallbackMessage technique can’t be used as it allocates memory).


#4

thanks a lot @martinrobinson for your explanation … i will try it with both ( message thread & audio callback ) so i can learn both concepts.