allegro_m.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifdef WITH_ALLEGRO
00013
00014 #include "../stdafx.h"
00015 #include "../debug.h"
00016 #include "allegro_m.h"
00017 #include <allegro.h>
00018
00019 static FMusicDriver_Allegro iFMusicDriver_Allegro;
00020 static MIDI *_midi = NULL;
00021
00024 extern int _allegro_instance_count;
00025
00026 const char *MusicDriver_Allegro::Start(const char * const *param)
00027 {
00028 if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) {
00029 DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error);
00030 return "Failed to set up Allegro";
00031 }
00032 _allegro_instance_count++;
00033
00034
00035 if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) {
00036 DEBUG(driver, 0, "allegro: install_sound failed '%s'", allegro_error);
00037 return "Failed to set up Allegro sound";
00038 }
00039
00040
00041 if (midi_card == MIDI_NONE) {
00042 DEBUG(driver, 0, "allegro: no midi card found");
00043 return "No sound card found";
00044 }
00045
00046 return NULL;
00047 }
00048
00049 void MusicDriver_Allegro::Stop()
00050 {
00051 if (_midi != NULL) destroy_midi(_midi);
00052 _midi = NULL;
00053
00054 if (--_allegro_instance_count == 0) allegro_exit();
00055 }
00056
00057 void MusicDriver_Allegro::PlaySong(const char *filename)
00058 {
00059 if (_midi != NULL) destroy_midi(_midi);
00060 _midi = load_midi(filename);
00061 play_midi(_midi, false);
00062 }
00063
00064 void MusicDriver_Allegro::StopSong()
00065 {
00066 stop_midi();
00067 }
00068
00069 bool MusicDriver_Allegro::IsSongPlaying()
00070 {
00071 return midi_pos >= 0;
00072 }
00073
00074 void MusicDriver_Allegro::SetVolume(byte vol)
00075 {
00076 set_volume(-1, vol);
00077 }
00078
00079 #endif