Confused by sample numbers vs midi timestamps in midibuffers


#1

Total newbie so my reasoning may be completely wrong:

  • I have a plugin that needs to send out midi and the timing needs to be pretty precise - the plugin does not have any audio.
  • I figured out I can create midi events in the future, and dump those in a MidiBuffer. I set the midi timestamp in the MidiMessage
  • But when I add the MidiMessage to the buffer, I also need to provide a samplenumber
  • And if I understand correctly, it’s the samplenumber that will determine the timing of the MidiEvent going out

Is the above correct? If so, it seems like the timing is controlled by both the timestamp and the sample number? Am I correct? That does not seem to make much sense - there can only be one correct time, so which is it? From the class documentation I get the impression the timing will be controlled by the sample number.

Then how do I calculate the sample number? There is no audio device. From the MIDI message tutorial I get the impression I can choose my own sample rate, in the tutorial they choose 44.1k. And then the tutorial calculates the sample number by multiplying the midi timestamp by samplerate (give or take the difference between midimessage timing units and sample rate of course).

So the timestamps in the midimessage are in milliseconds, the “timestamp” in the midibuffer is in samples; conversion between the 2 is by means of sample rate.

Is the above reasoning correct? If so, is the timestamp in the midi message even important? Of would that depend on the receiver of the midimessages?

Thx for confirming or pointing me to my mistakes!