Midi - play, position, extract notes


#1

1) How is a midi file played in JUCE? (code?) 
2) How do I determine the current time position (being played)
3) How to use current time to obtain relevant notes for graphing? 

 


#2

1) Here's an example how to play a midi file with juce synthesizer. Rename, unzip and replace the file in the demo with this.

2) You can use samplePos from handleMidiFile() to obtain the current time position

3) MidiMessageSequence is a sorted list of the midi events in the track. Extract all note on and note off events. Use the time stamps of these to draw a graph of the notes. Then you can use samplePos from 2) to calculate the position of a pointer or line on the note(s) just being played


#3

There seems to be a problem around this line:
          midiFilePlayer.handleMidiFile(incomingMidi, bufferToFill.numSamples);

However, this is the most helpful code I've seen.

Thanks, J


#4

What happens? Can you play the keyboard as in the original demo?


#5

I initialized numMidiEvents = 0, that gets it past the problem below. It doesn't seem to work with all midi files, but it did work with one. I suspect that's because its basically picking the first track and the first track isn't always "interesting". So its probably working as intended.

In any case, this gets me pretty far down the path of where I want to go. Thanks!

------------------------ original issue....

I can't click to the synthesiser tab unless that line is commented out. It give a bad access error in juce_HeapBlock. Its trying to "handleMidiFile()":  midiMessages.addEvent(midiEvent->message, waitSamples);  ... Which since I haven't picked a file seems like that code should not execute.

I think its needs to do a check to see if a file has been selected or some such. I just haven't gotten to go through it to see why. If I comment it out I see the button with the midi selection button, but of course if I select a midi file it doesn't play it with the line gone.


#6

You're right, numMidiEvents should be initialized to zero in the constructor of MidiFileplayer. Forgot that...

getFirstNoteEvent() skips any track that doesn't contain any notes, so you really should here something for every midi file selected. Hopefully the debugger tells you why if you don't.

I attach a file that definitely should play. A rather minimalistic composition...


#7

It's just picking a track that has notes, just not interesting (ie. melody). I can remedy that.