Go Down

Topic: Library for playing MIDI files from the Arduino (Read 6 times) previous topic - next topic

marco_c

#5
Dec 30, 2012, 08:50 pm Last Edit: Dec 30, 2012, 08:52 pm by marco_c Reason: 1
Thanks robtillart for taking the time to look and comment.

Quote
starnges that an destructor calls initialize

Initially I had some memory allocation going on and I had to free memory (that was being done in close()), so the destructor needed to call close(). I have renamed initialise() to resetTrack() which may give us all less of an uncomfortable feeling.

Quote
saw you have a dump mode (but it is a cooked dump not a raw dump)

There is a sketch that does a raw dump of the data in the chunks after the header, without using the library. I also use a utility called "MIDI File Analyzer" (picked up somewhere off a Google link) that basically agrees with my own dump(s) of the files, so I am have a high confidence the dumps are correct.

Quote
not handling all values between 0xf1 ... 0xff:

Yes, correct. These values are real time valuies that appear in a MIDI live stream as control messages but are not valid in a file - 0xf1 is undefined, 0xf2 is Start a sequence, 0xf3 is Continue sequence. 0xf4 is Stop sequence, 0xf5 is undefined, 0xf6 is Active Sense (like a watchdog timer), 0xff is Reset System. All others in this range should be processed.

Quote
x not used

A leftover from when I had an intermediate result being calculated.

Quote
syntactically wrong as you should use the boolean && not the bitwise &
and it can be faster

Agree. Suggested version also saves 1 byte of stack space :-)

Quote
many loops use int i;   you could check if uint8_t is enough ?

Good point, will check.

Quote
So many #if 's makes me wonder if you could not better

Great point here. I have done what you suggested before and I don't know why I didn't do it here as well. This will also make the code more maintanable, as an alternative output stream is easier to implement if needed.

I'll post an updated version of the library once implemented and tested.
Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

robtillaart

Quote
not handling all values between 0xf1 ... 0xff:
Yes, correct. These values are real time valuies that appear in a MIDI live stream as control messages but are not valid in a file - 0xf1 is undefined, 0xf2 is Start a sequence, 0xf3 is Continue sequence. 0xf4 is Stop sequence, 0xf5 is undefined, 0xf6 is Active Sense (like a watchdog timer), 0xff is Reset System. All others in this range should be processed.

but that still means that when you encounter them in a stream you should handle them appropriately (skip/resync stream etc).
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

marco_c

#7
Dec 30, 2012, 10:27 pm Last Edit: Dec 30, 2012, 11:12 pm by marco_c Reason: 1
I take your point, but they are actually not allowed to exist in the stream according to the Standard MIDI File documentation. If they are in there then either the file should be considered invalid (ie, abandon it) or the sync has to be to the next byte with a top bit not set, which should be the next deltaT.

The problem with MIDI files is that they are sequential - each note or event is defined in a time offset (deltaT) from the previous one and if you sync forward you get out of time sequence with respect to the other tracks. I actually had this happening early in the piece and it sounds awful.

I'll need to think about this one.

Edit - on reflection, the most straightforward way is to make the track invalid (ie, mark it as end of track) and stop playing it. This allows the other tracks to play on and the file is not totally lost.
Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

marco_c

#8
Dec 30, 2012, 11:17 pm Last Edit: Jan 05, 2013, 12:55 am by marco_c Reason: 1
Updated version of the library is attached. This implements points discussed above plus some additional tidy up of the debug messages.
Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

robtillaart

Quote
I take your point, but they are actually not allowed to exist in the stream according to the Standard MIDI File documentation.

There are many things in the world not allowed that still happen ...

if you encounter forbidden codes you should close the file immediately. In the big switch this should be the default: option to catch all non supported







Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up