processBlock: what are valid sample numbers for newly-created MidiMessages?


#1

Hi,

I understand that processBlock has an associated time window, from (let’s call it) blockStartSampleNumber to blockEndSampleNumber.

  1. When calling addEvent on the MidiBuffer argument of processBlock, what happens if the timestamp argument lies outside this window? Is the corresponding message simply ignored?
  2. Is the time window inclusive or exclusive of blockStartSampleNumber? i.e. is it supposed to be the open interval [blockStartSampleNumber,blockEndSampleNumber] or the left-closed, right-open interval [blockStartSampleNumber,blockEndSampleNumber)? (See https://en.wikipedia.org/wiki/Interval_(mathematics)#Classification_of_intervals for terminology if needed).

Thanks,

Jerry.


#2

2 You have an Audio(Sample)Buffer as the first argument of processblock. The first sample of that buffer is the first sample of your “time” window, i.e.

*buffer->getWritePointer(channelNo) = 0.01f sets the first sample to 0.01f. 

buffer->getNumSamples() gives you the size of the window, so

buffer->getWritePointer(channelNo)[buffer->getNumSamples() - 1] = my_last_sample

sets the last sample.


#3

I don’t think this is what the OP is referring to.

If I understood it correctly, he is asking what range should be used for the sample numbers that are used to timestamp the MidiMessages that are emitted by the processBlock (i.e. those that are left in the MidiBuffer at the end of the method).

A suggestion to check that would be to see what range is used for the incoming messages that are in the MidiBuffer when the processBlock() is invoked.

My suspect/guess is that they all will be in the range [0, numSamples], but you should check with different plug-in formats and hosts to be sure.


#4

Valid values for the sampleNumber argument of addEvent would be 0 upto
buffer->getNumberOfSamples -1. Midi events added with sampleNumber outside this will simply be ignored AFAIK.