Hi everybody,
I have some troubles with the well-known MIDI-protocol. I am trying to make some kind of program that is able to generically generate .midi music. It is not that complicated yet, so do not bother with it, in fact I am just running tests right now. I have this problem when I try to play a self generated MIDI-file with only one note. I was able to copy a existing midi in code (
rdbuf()), so it is not my compiler's fault (Dev-C++ 4.9.9.2). I would rather not work with MIDI-libraries so as to only use my own code.
After some hard work on the Internet i finally managed to get the information I needed about MIDI on byte level. I made the midi with
fstream and afterwards I wrote a few lines C++ to test if I could correctly apply my newly aquired knowledge. This is the program:
1 2 3 4 5 6 7 8 9 10
|
#include <fstream>
int main()
{
std::ifstream MIDI("MIDI.mid"); //my created sequence (does not work)
std::ofstream test("txt.txt"); //(I like palindromes)
test<<std::hex;
while(!MIDI.fail())
{
test<<MIDI.get()<<'\n';
}
|
in file txt.txt:
4d
54
68
64
0
0
0
6
0
0
0
1
0
60
4d
54\72
6b
0
0
0
b
1
91
3c
f
66
81
3c
f
ff
2f
0
ffffffff |
I started with the header chunk,
then a track chunk,
a note on and
a note off event,
and a end-of-track meta-event.
I have no idea where the large number at the end comes from, is it the cause of all the trouble? When i open MIDI.mid with Notepad, the number 0xffffffff is not represented in Unicode-character, so I cannot get it out of the file. I guess it is just a glitch. The problem occurs when I try to play the file. Windows Media Player starts complaining about insufficient memory so I guess I forgot some kind of EOF event. I also tried Synthesia, becuase I know Windows long enough, but it also refuses to play my file... For the interested, my knowledge originates form this lovely tutorial:
http://www.sonicspot.com/guide/midifiles.html
if you see the error, PLEASE contact me. C++ is my hobby, I learned C++ from a book, so I do not have a teacher to answer my questions. You people are my only hope...
Atleast thanks for reading!
Kind regards,
Niels Meijer