MidiBuffer::addEvent sampleNumber clarification


#1

I’m tidying my first plugin and came to realise I’ve never fully understood what sampleNumber parameter is in MidiBuffer::addEvent (and didn’t grasp the offset variable calculation in the arpeggiator example). I have been calling it with a value of 0, but am I correct in thinking that inside processBlock e.g.:

const int sampleFrames = buffer.getNumSamples(); // Say 512

Should addEvent’s sampleNumber be between 0 and 512 to tell the host the exact sample no the MIDI event should be triggered on?


#2

Simple answer: yes!


#3

The offset variable in the arpeggiator defines the exact sample within the audio buffer block where the current note should be stopped and the next one started based on the note duration/speed of the arpeggiator.


#4

Thanks both!

The offset takes the max of 3 things so I wasn’t entirely sure, but if conceptually that’s how it works then all good and I can do slight adjustments to ensure notes off/CCs before notes on.

Really enjoyed using the Juce framework by the way and found it very straight forward (coming from a C#/Delphi background).