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++ 188.8.131.52). 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:
std::ifstream MIDI("MIDI.mid"); //my created sequence (does not work)
std::ofstream test("txt.txt"); //(I like palindromes)
in file txt.txt:
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:
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!