allegro_m.cpp

Go to the documentation of this file.
00001 /* $Id: allegro_m.cpp 20286 2010-08-01 19:44:49Z frosch $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
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 
00026 extern int _allegro_instance_count;
00027 
00028 const char *MusicDriver_Allegro::Start(const char * const *param)
00029 {
00030   if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) {
00031     DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error);
00032     return "Failed to set up Allegro";
00033   }
00034   _allegro_instance_count++;
00035 
00036   /* Initialise the sound */
00037   if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) {
00038     DEBUG(driver, 0, "allegro: install_sound failed '%s'", allegro_error);
00039     return "Failed to set up Allegro sound";
00040   }
00041 
00042   /* Okay, there's no soundcard */
00043   if (midi_card == MIDI_NONE) {
00044     DEBUG(driver, 0, "allegro: no midi card found");
00045     return "No sound card found";
00046   }
00047 
00048   return NULL;
00049 }
00050 
00051 void MusicDriver_Allegro::Stop()
00052 {
00053   if (_midi != NULL) destroy_midi(_midi);
00054   _midi = NULL;
00055 
00056   if (--_allegro_instance_count == 0) allegro_exit();
00057 }
00058 
00059 void MusicDriver_Allegro::PlaySong(const char *filename)
00060 {
00061   if (_midi != NULL) destroy_midi(_midi);
00062   _midi = load_midi(filename);
00063   play_midi(_midi, false);
00064 }
00065 
00066 void MusicDriver_Allegro::StopSong()
00067 {
00068   stop_midi();
00069 }
00070 
00071 bool MusicDriver_Allegro::IsSongPlaying()
00072 {
00073   return midi_pos >= 0;
00074 }
00075 
00076 void MusicDriver_Allegro::SetVolume(byte vol)
00077 {
00078   set_volume(-1, vol);
00079 }
00080 
00081 #endif /* WITH_ALLEGRO */