0

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()
user_loser
  • 881
  • 1
  • 13
  • 27
  • Q: Can you play a specific file (e.g. "pinkpanther.mid") from your Ubuntu desktop, but not from your Allegro program? FYI, here are some similar links: https://ubuntuforums.org/showthread.php?t=1421888, https://github.com/adventuregamestudio/ags/issues/367, etc. Note the comment about explicitly specifying a sound device in `/etc/allegro.cfg`. – paulsm4 Aug 13 '17 at 23:31
  • Yes, I can play the pinkpanther.mid from a program called `Timidity`. I will have to look at the configuration file you point out `/etc/allegro.cfg`. Thank-you for the reply @paulsm4 :) – user_loser Aug 13 '17 at 23:39
  • I am not sure about the syntax of the configuration file in the `/etc/allegro.cfg` that someone posted an example of in your hyperlink. That looks like some strange alien language to me. :/ :D Hmmm Maybe I do not need Midi anyway. – user_loser Aug 13 '17 at 23:50
  • 1
    IIRC Timidity doesn't play the midi via a *midi* device, so it might behave differently from Allegro – Antti Haapala -- Слава Україні Aug 14 '17 at 00:22
  • What MIDI synthesizer do you want to use? Do you actually have one? – CL. Aug 14 '17 at 06:56
  • To be frank I could care less which MIDI synth is used. :) I must have one because I can play the dot mid files with Timidity. This sounds like a midi file too because it has that unique sound that Midi has. It sounds like an 8bit game from the 80s or 70s or something. – user_loser Aug 20 '17 at 22:13
  • @AnttiHaapala Interesting. I saw this problem for a few other Allegro users. I am just going to ignore this problem and not use Midi at the present time. – user_loser Aug 20 '17 at 22:15

0 Answers0