Midi generator creation

Hello Atom,

I do not understand why i would have to stop the audio thread to send a midi Message. 

Whatever, I can load my midifiles before running the plug in, but I do not understand your code and the link with the probleme I have.

I feel like dumb of not understanding how to play a simple midifile, but its not easy at all, and it seems no one can give me a simple and working exemple :S

Hi guys, I am still stuck at this simple task: read a midi file in the good tempo:

here is my code oxxyyd help me to write:

static double playTime;
void StereoWidthCtrlAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages) 
 static bool play = false;
 int numSamples = buffer.getNumSamples(); 
 double numSecondsInThisBlock = numSamples / 44100;
 double endTime = playTime + numSecondsInThisBlock; 
 static int nextEventID = 0;

 if (UserParams[generate] == 1.0) 
   play = true; UserParams[generate] = 0;
 if (play) 
   const MidiMessageSequence *midiSequence;
   MidiMessageSequence::MidiEventHolder *m;
   midiSequence = myMidiFile->getTrack(0);
   for (; m = midiSequence->getEventPointer(nextEventID); nextEventID++) 
    double timeStamp = m->message.getTimeStamp(); 
    if (timeStamp >= endTime)
    if (timeStamp >= playTime) 
     midiMessages.addEvent(m->message, timeStamp - playTime);
  playTime = endTime;

With what I understand the 'playTime' variable must be initialized at time time 't' when I clic the button to launch the midi clip. But how am I supposed to initialize it really ?

I am stuck on that since weeks and I do not get it, can you please help me. 

Waht is wrong qith this code ?



When you say, 'when i click...', I immediately think that you have to handle this from the gui editor for the plugin. Otherwise, what are you clicking on?

What you would do, is generate a button in the editor, and then on that button being clicked, set yourProcessor->playButtonClicked to TRUE. Then your processblock could check for that.

Even better, I would skip the button for now - can you start the file playing as soon as you load the plugin?

Try to eliminate as many variables that might be causing problems - hard code the filename and load only the same file everytime. Forget the click button and just try to start playing on bootup. Just simplify simplify simplify until you KNOW the various units are correct. Comment out code regularly to test out where the problems actually are.


You will get there eventually, but a lot of times what you THINK should be easy, is actually a bit more involved, as it can be done in many different ways. Hang in there, save often, and don't be afraid to break stuff! If you do actually set your computer on fire with your JUCE code, don't look at it as a failure, but a roaring success (and take pictures). ;]


Good luck and maybe post the entire source somewhere like bitbucket or github - I'd like to implement this too and I'm sure others would as well, then we could see ALL your code and help figure out what the issue is. No promises, but it is a better chance than use guessing at everything.


I set a Processor argument array in my editor when the button is clicked. My filename is hard in my code, I have no memory allocation, my program is really simple.

I read the documentation of midisequences, midimessages, timestamps, I std::cout all the values I have, to try to understand the way everything work, but I do not understand. I changed my all code many times to try new things, but, i can not figure it out, it does not work ... 

I can not understand why on the all forum, there is not even one exemple of a working sample of code for reading a midi file. 

I do not know what to try  or to change in my code anymore, i am stuck.


If you put a breakpoint in the debugger in processBlock, what do you find out?


I'll check how to use the debbuger,

on witch variable/codeligne do you want me to breakpoint ?

Thank you

The for clause would be an obvious candidate, don’t you think? From there you could single step and see if any midi event make it into the addEvent call.



I found this piece of code on the forum: https://gist.github.com/gaspard/6415937

It helped me to understand how the timer work, and I succed doing my midi generator. It is still bad, but i will make it better, now I have the sync notes :)


Thank you for you help guys, wich you the best