# Play a Midi file? MidiMessageSequence -\> MidiBuffer

**URL:** <https://forum.juce.com/t/play-a-midi-file-midimessagesequence-midibuffer/13392>\
**Category:** General JUCE discussion\
**Created:** [August 16, 2014, 7:12pm UTC](https://forum.juce.com/t/play-a-midi-file-midimessagesequence-midibuffer/13392 "2014-08-16T19:12:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![joelt](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@joelt](https://forum.juce.com/u/joelt)\
**Post date:** [August 16, 2014, 7:12pm UTC](https://forum.juce.com/t/play-a-midi-file-midimessagesequence-midibuffer/13392/1 "2014-08-16T19:12:30Z")

</div>

I see MidiFile allows access to&nbsp;MidiMessageSequence, however to play midi it appears that a MidiBuffer is needed instead. I don't see a conversion from one to the other.

After that it appears I get the the default midi output from the AudioDeviceManager, and send it the midi buffer, but that part is particularly clear either. It seems like I would have found an example, but did not.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 20, 2014, 8:39am UTC](https://forum.juce.com/t/play-a-midi-file-midimessagesequence-midibuffer/13392/2 "2014-08-20T08:39:35Z")

</div>

The two classes have different purposes - MidiMessageSequence is a higher-level object, which knows about matching note on/off pairs and lets you edit the sequence. MidiBuffer is a low-level packed array, which can be iterated but not really modified.

---

<div class="post-metadata">

**Author:** ![joelt](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@joelt](https://forum.juce.com/u/joelt)\
**Post date:** [August 20, 2014, 1:35pm UTC](https://forum.juce.com/t/play-a-midi-file-midimessagesequence-midibuffer/13392/3 "2014-08-20T13:35:24Z")

</div>

MidFile loads MidiMessageSequence, I presume there is a convenience method to convert to MidiBuffer so it can be played?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 20, 2014, 1:48pm UTC](https://forum.juce.com/t/play-a-midi-file-midimessagesequence-midibuffer/13392/4 "2014-08-20T13:48:09Z")

</div>

You'd rarely ever need&nbsp;to convert a whole MidiMessageSequence into a single MidiBuffer, because you'd never want to play the entire file as one block. Generally you'll be given a MidiBuffer to fill by something like&nbsp;AudioProcessor::processBlock, and you'd only want to fill it with whatever small section of the MidiMessageSequence is being played. I don't have any helper methods to do that, I'm afraid, but it's easy enough to iterate it and add the messages.

---

<div class="post-metadata">

**Author:** ![joelt](https://avatars.discourse-cdn.com/v4/letter/j/9f8e36/32.png) [@joelt](https://forum.juce.com/u/joelt)\
**Post date:** [August 20, 2014, 3:32pm UTC](https://forum.juce.com/t/play-a-midi-file-midimessagesequence-midibuffer/13392/5 "2014-08-20T15:32:00Z")

</div>

I assumed if I call this...

AudioDeviceManager::getDefaultMediaOutput-\>sendBlockOfMessages(midiBuffer)

It would play the song, and prior to that an AudioProcessor could be registered&nbsp;to display the notes being played...&nbsp;

If I'm filling the processBlock(midibuffer), then I'm lost on how I would fill it with appropriate notes. Example anywhere?
