hi all, i am an allegro(noob) and i'm trying to put some midi under my game. Now the problem is: this just doesn't work!!
This is my code:
| 1 | #include <allegro.h> |
| 2 | |
| 3 | MIDI *midi; // Instance to store our MIDI data. |
| 4 | |
| 5 | int main() |
| 6 | { |
| 7 | allegro_init(); |
| 8 | install_keyboard(); |
| 9 | |
| 10 | set_color_depth(16); // Adjust if necessary. |
| 11 | set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); // Windowed because it won't matter. |
| 12 | |
| 13 | detect_midi_driver(MIDI_AUTODETECT); |
| 14 | detect_digi_driver(DIGI_AUTODETECT); // Don't know if this is necessary if you only want midi. |
| 15 | install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL); |
| 16 | |
| 17 | midi = load_midi("ff1menu.mid"); |
| 18 | |
| 19 | play_midi(midi, 1); |
| 20 | |
| 21 | readkey(); // Wait until a key is pressed before we... |
| 22 | |
| 23 | // ... End the program. |
| 24 | stop_midi(); |
| 25 | destroy_midi(midi); // It is necessary to free memory allocated for creating the MIDI to prevent any memory leaks. |
| 26 | |
| 27 | // It isn't necessary to un-init Allegro since it does so for us. |
| 28 | return 0; |
| 29 | } |
| 30 | END_OF_MAIN(); |
Now, this just DOESN't work. My pc just can play midi normaly (i think, with windows media player and other players), i even can make midifiles with a composer program (sybelius), but allegro...
I mean the program runs normaly, but i can't hear anithing.
Can someone plz help me? i ve been searching for days without any result
You need install_timer() before install_sound(...), I think. Because the Allegro sound system depends on the Allegro timer.
detect_midi_driver(MIDI_AUTODETECT); detect_digi_driver(DIGI_AUTODETECT);
These are useless.
Some error checking would also be good, like
if (install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,NULL) != 0) { allegro_message("ERROR: Couldn't initialize sound hardware!"); }
And please leave the "AAAAAAARGH!!!" out if you start a thread again, even if you are frustrated. Instead you could write something like "can't get it to work", that would sound much better.
Imagine yourself walking along the street, suddenly a stranger jumps in your way and screams "I DON'T KNOW HOW TO GET TO <insert some place>! AAAAAARGH!". Would you help him?
i have put install_timer() in the file, but it still doesn't work.
sorry for the aargh btw
OK, then add some error checking!
if (install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,NULL) != 0) { allegro_message("ERROR: Couldn't initialize sound hardware!"); }
midi = load_midi("ff1menu.mid"); if (!midi) { allegro_message("ERROR loading MIDI!"); }
That way you see where it fails. And be sure to do install_timer() BEFORE install_sound().
I now have this code:
| 1 | #include <allegro.h> |
| 2 | |
| 3 | MIDI *midi; // Instance to store our MIDI data. |
| 4 | |
| 5 | int main() |
| 6 | { |
| 7 | allegro_init(); |
| 8 | install_keyboard(); |
| 9 | install_timer(); |
| 10 | |
| 11 | set_color_depth(16); // Adjust if necessary. |
| 12 | set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0); // Windowed because it won't matter. |
| 13 | |
| 14 | |
| 15 | if (install_sound(DIGI_AUTODETECT,MIDI_AUTODETECT,NULL) != 0) |
| 16 | { |
| 17 | allegro_message("ERROR: Couldn't initialize sound hardware!"); |
| 18 | }midi = load_midi("ff1menu.mid"); |
| 19 | |
| 20 | if (!midi) |
| 21 | { |
| 22 | allegro_message("ERROR loading MIDI!"); |
| 23 | } |
| 24 | |
| 25 | play_midi(midi, 1); |
| 26 | |
| 27 | readkey(); // Wait until a key is pressed before we... |
| 28 | |
| 29 | // ... End the program. |
| 30 | stop_midi(); |
| 31 | destroy_midi(midi); // It is necessary to free memory allocated for creating the MIDI to prevent any memory leaks. |
| 32 | |
| 33 | // It isn't necessary to un-init Allegro since it does so for us. |
| 34 | return 0; |
| 35 | } |
| 36 | END_OF_MAIN(); |
but i still can't hear nothing:-/. I just get a black window, like always, but i don't get any error messages.:o
can plz someone help me



I tested your code and it worked, strange... post some information about the hardware/software you use.
try it with another midi file
Do the allegro examples allegro/examples/exmidi.c and allegro/tests/testmidi.c work?