allegro_m.cpp

Go to the documentation of this file.
00001 /* $Id: allegro_m.cpp 17787 2009-10-17 14:39:43Z rubidium $ */
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 
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   /* Initialise the sound */
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   /* Okay, there's no soundcard */
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 /* WITH_ALLEGRO */

Generated on Fri Apr 30 21:55:21 2010 for OpenTTD by  doxygen 1.6.1