I want to play music on my stepper motor (free standing) and cannot figure out how to open and view MIDI files. I can download them without issue but they only open with a music player application and I cannot open and view the source code to parse it to extract the note frequency and duration information necessary to drive my stepper motor to play music. I want to download the MIDI file for Star Trek Deep Space Nine and play it on my stepper motor. I downloaded a *.mid file and it plays in Realplayer but I cannot view the source code.
This thread talks about a library to do it:-
http://forum.arduino.cc/index.php?topic=139785.0
Basically there are three types of MIDI file, type 0,1 & 2 and they require different treatment.
A Format 0 file has a header chunk followed by one track chunk. It is the most interchangeable representation of data. It is very useful for a simple single-track player in a program which needs to make synthesisers make sounds, but which is primarily concerned with something else such as mixers or sound effect boxes. It is very desirable to be able to produce such a format, even if your program is track-based, in order to work with these simple programs.
A Format 1 or 2 file has a header chunk followed by one or more track chunks. programs which support several simultaneous tracks should be able to save and read data in format 1, a vertically one dimensional form, that is, as a collection of tracks. Programs which support several independent patterns should be able to save and read data in format 2, a horizontally one dimensional form. Providing these minimum capabilities will ensure maximum interchangeability.
My application is definitely a "Format 0 " application.
I downloaded this library but it's going to take me awhile to figure out how to use it .
The MIDI library you are using does not, as I understand it, process .MID files. It allows you to handle the receiving and sending of MIDI messages.
Library pointed to by Grumpy_Mike allows you to read a MID file and process the file at the right tempo.
Thanks for the heads up. I have a Midi file and a hex editer but can't figurevout how to extract the data because I don't know how many bytes are in each note packet. The only thing I can interpret is the name of the instruments.
MIDI works by sending messages, each message can be any length between one and three bytes long. You find out how long by looking at the first byte.
It does not give a note duration, it gives a note on message followed some time later by a note off message.
The note on message consists of three bytes
The note on message and what one of 16 MIDI channels to use.
The note number - the pitch a value of 0 to 127
The note velocity - how hard the note is struck - it can equate to volume and again has a value of 0 to 127
I'm working on figuring that out and when I have decyphered the entire MIDI file I want to play then I will be ready to start learning how to write the s/w to parse it. It could take me a month.
What I would do is to get an application on the PC that allows you to generate MIDI files. Use it to import the file you want and then use it to play out the MIDI to your Arduino.
Only when you have got that working make it stand alone.
As we say to beginners, take it one step at a time, it applies to us as well. ![]()
Playing a MIDI file to my arduino won't do me any good at the moment. I have a program that plays a simple midi file from memory as an array (Playtune) but that plays music using 3 outputs into one speaker. What I need is a program to read a MIDI file from an SD card and parse it for frequency information , noteON, & noteOFF commands because a MIDI file doesn't use a parameter called "duration". The program needs to take the frequency information and use it to output a STEP signal to a stepper motor driver starting at noteON and stopping at noteOFF.
Basically you could call it a "SD CARD MIDI file to stepper motor driver Music synthesizer."
I have a program that plays a simple midi file from memory as an array (Playtune) but that plays music using 3 outputs into one speaker.
No that is not what I mean.
I mean let it stream MIDI at the Arduino.
You don't need a duration parameter, just start the noise and stop it depending on when the appropriate command was received. Your sound generation will be asynchronous so there is no need ahead of time to know the note's duration.
That still won't help without a program to read the streaming MIDI and convert it to stepper motor STEP pulses (which can only be done by parsing the stream for the frequency and noteOn and noteOff. Streaming MIDI isn't going to drive a stepper motor. My only objective is to play a midi file on a stepper motor.
That still won't help without a program to read the streaming MIDI and convert it to stepper motor STEP pulses
Yes it will, it will give you a stream of information, which you can use to get note information.
The frequency is simply a note number, you can get the frequency from this table:-
Yes, I understand how to do that (manually). It's doing it with software that I was trying to accomplish. I know you can look up the frequency of any note in the 88 note 8 octave scale. That's how I was able to make a synthesizer with a 6800 before MIDI existed. Now I'd like to make a program that parses the streaming midi or a file on an SD card and converts it to stepper motor commands.