user_loser
user_loser

Reputation: 871

Mid not playing with Allegro 4 on Ubuntu 14.04

I am following along a book about programming in the C programming language with a game library called Allegro. If you Google "Allegro" you will know exactly what this is if you currently do not. Allegro basically makes writing a video game easier. I am already frustrated with the way this question is going.

Well, anyway I followed an example program from a book and the code sort of worked, opened a window and displayed some data, but did not play the Midi file, .mid. Does anyone know what could be going wrong? No errors were thrown when running this program. Plus, allegro says that the midi file was loaded successfully and that the Midi was playing. Though I did not hear any sound and did not see the progress of the MIDI file calculated in the GUI. There is some code to count the time, length and position, of the Midi file. However, the program did not count anything at all. I also tried the exmidi program under the examples folder of the Allegro installation and this did not work either. Allegro was able to play .wav files without any problems. Also, I was able to play the Mid file in question with a program called timidity. So I know I can play some Midi files on the Ubuntu laptop. I am just not sure why I cannot play Mid files with Allegro 4. 0_o

Any help is appreciated. Thank-you for reading this.

Here is the code:

#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, 0);

     //install the sound driver
     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("pinkpanther.mid");
     if(!music) {
       allegro_message("Error loading Midi file.");
       return 1;
     } else { 
       allegro_message("Music loaded");
     }

     //play the music
     if (play_mid(music, 0) != 0) { 
        allegro_message("Error playing Midi\n%s", allegro_error);
        return 1;
      } else { 
        allegro_message("No errors playing the Midi.");

      }

     //display status information
     length = get_midi_length(music);
     textprintf_ex(screen, font, 0, 20, WHITE, 0, "Length: %d:%02d", length/60, length % 60);

     do { 

         pos = midi_time;
         textprintf_ex(screen, font, 0, 30, WHITE, 0, "Position: %d:%02d", pos/60, pos % 60);
         rest(100);

     } while((pos <= length) && (!key[KEY_ESC]));

     stop_midi();
     destroy_midi(music);
     remove_sound();
     allegro_exit();
     return 0;
} 
END_OF_MAIN()

Upvotes: 0

Views: 136

Answers (0)

Related Questions