home *** CD-ROM | disk | FTP | other *** search
- ////////////////////////////////////////////////////
- // Game Programming All In One, Third Edition
- // Chapter 6 - PlayMidi program
- ////////////////////////////////////////////////////
-
- #include <allegro.h>
-
- #define MODE GFX_AUTODETECT_WINDOWED
- #define WIDTH 640
- #define HEIGHT 480
- #define WHITE makecol(255,255,255)
-
- int main(void)
- {
- MIDI *music;
- int pos, length;
-
- //initialize the program
- allegro_init();
- install_keyboard();
- install_timer();
- set_gfx_mode(MODE, WIDTH, HEIGHT, 0, 0);
- textout_ex(screen, font, "PlayMidi Program (Hit ESC to quit)", 0, 0, WHITE, -1);
-
- if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) {
- allegro_message("Error initializing sound system\n%s\n", allegro_error);
- return 1;
- }
-
- //load the midi file
- music = load_midi("mach5.mid");
- if (!music) {
- allegro_message("Error loading Midi file");
- return 1;
- }
- if (play_midi(music, 0) != 0) {
- allegro_message("Error playing Midi\n%s", allegro_error);
- return 1;
- }
-
- length = get_midi_length(music);
- do {
- pos = midi_time;
- textprintf_ex(screen, font, 0, 20, WHITE, -1, "Length: %d:%02d", length / 60, length % 60);
- textprintf_ex(screen, font, 0, 30, WHITE, -1, "Position: %d:%02d", pos / 60, pos % 60);
- rest(20);
- } while((pos <= length) && (!key[KEY_ESC]));
-
- stop_midi();
- destroy_midi(music);
- allegro_exit();
- return 0;
- }
- END_OF_MAIN()
-