FileInputStream stream (File ("C:\\Users\\goldiman\\Desktop\\Midi0110\\ReadMidi\\music.mid"));
if (! stream.openedOk())
if (! midiFile.readFrom (stream))
const int numTracks = midiFile.getNumTracks();
if (numTracks <= 0)
const MidiMessageSequence& sequence = *midiFile.getTrack (0);
const int numEvents = sequence.getNumEvents();
if (numEvents <= 0)
ScopedPointer<MidiOutput> midiOutput (MidiOutput::openDevice (MidiOutput::getDefaultDeviceIndex()));
if (midiOutput == nullptr)
for (int i = 0; i < numEvents; ++i)
MidiMessageSequence::MidiEventHolder* eventHolder = sequence.getEventPointer (i);
if (eventHolder == nullptr)
const MidiMessage& message = eventHolder->message;
const int note = message.getNoteNumber();
const int velocity = message.getVelocity();
DBG ("Note on/off processed --- Note# " + String (note) + ", Velocity " + String (velocity));
DBG ("Skipped a message");
Above is a simplified version of what you've linked. Do note that "Sleep()" is not a standard function; you should be in the habit of using juce::Thread::sleep() to be able to conform to various platforms, not just Windows.
Also, you can use juce's multi-platform DBG() macro instead of std::cout and std::endl for outputting to the console. And juce::String handles converting all sorts of data types into String objects.
With that, it was obvious a couple things were leaking memory; your File object that was put on the heap, likewise for your MidiOutput instance. If you "new" something, you must "delete" something. So as to not forget or worry about it, use RAII, a juce::ScopedPointer is good in this case since it will handle that for you.
Edit: Right, I forgot to mention that you initially wrote "OuputMidi->MidiOutput->sendMessageNow". Not sure what the hell that was about, but seemed like a typo.
Have a look and see what I cleared up.