Playing MIDI events


Hi everybody !

I have followed some instructions I have found in the forum about this subject… I have written some code for a metronome and I will need to develop a MIDI player. I want you to give me some comments about my code :

[code]void ThreadMetronome::run()
while (! (threadShouldExit()))

	theSynth->synth.noteOff(1, 74, false);

	if (beatCours == 0)
		theSynth->synth.noteOn(1, 74, 1.f);
		theSynth->synth.noteOn(1, 74, 0.4f);

	if (beatCours >= beatMax)
		beatCours = 0;

theSynth->synth.noteOff(1, 74, false);


As you can see, I have created a synth structure which reads the wav file of the click, and the playing is launched by a noteOn event. The timeToWait variable contains the time in ms between each clic…

But, I think this code is not so much versatile. First because it works with integer ms instead of ticks of float ms, and because the code between each clicks may bring a time offset… That works fine with the metronome, but that may be problematic with the MIDI file playing.

Before, I did an infinite loop and a test at each iteration with a high precision time function, to know if it’s time to act. but the CPU load was very high…

What solution do you advice to me ?

Thanks :wink:




Things are so great when they are so simple :lol:

Thanks Jules :wink: