# allegro_m.cpp

Go to the documentation of this file.

    00001 /* $Id: allegro_m.cpp 16704 2009-06-30 20:11:36Z rubidium $ */
    00002
    00005 #ifdef WITH_ALLEGRO
    00006
    00007 #include "../stdafx.h"
    00008 #include "../debug.h"
    00009 #include "allegro_m.h"
    00010 #include <allegro.h>
    00011
    00012 static FMusicDriver_Allegro iFMusicDriver_Allegro;
    00013 static MIDI *_midi = NULL;
    00014
    00017 extern int _allegro_instance_count;
    00018
    00019 const char *MusicDriver_Allegro::Start(const char * const *param)
    00020 {
    00021   if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) return "Failed to set up Allegro";
    00022   _allegro_instance_count++;
    00023
    00024   /* Initialise the sound */
    00025   if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) return "Failed to set up Allegro sound";
    00026
    00027   /* Okay, there's no soundcard */
    00028   if (midi_card == MIDI_NONE) {
    00029     DEBUG(driver, 0, "allegro: no midi card found");
    00030     return "No sound card found";
    00031   }
    00032
    00033   return NULL;
    00034 }
    00035
    00036 void MusicDriver_Allegro::Stop()
    00037 {
    00038   if (_midi != NULL) destroy_midi(_midi);
    00039   _midi = NULL;
    00040
    00041   if (--_allegro_instance_count == 0) allegro_exit();
    00042 }
    00043
    00044 void MusicDriver_Allegro::PlaySong(const char *filename)
    00045 {
    00046   if (_midi != NULL) destroy_midi(_midi);
    00047   _midi = load_midi(filename);
    00048   play_midi(_midi, false);
    00049 }
    00050
    00051 void MusicDriver_Allegro::StopSong()
    00052 {
    00053   stop_midi();
    00054 }
    00055
    00056 bool MusicDriver_Allegro::IsSongPlaying()
    00057 {
    00058   return midi_pos >= 0;
    00059 }
    00060
    00061 void MusicDriver_Allegro::SetVolume(byte vol)
    00062 {
    00063   set_volume(-1, vol);
    00064 }
    00065
    00066 #endif /* WITH_ALLEGRO */