(svn r27729) -Codechange: Do not count static NewGRF when checking for the maximum...
[openttd.git] / src / music / allegro_m.cpp
blob77b488186a0c416d224bffe469146754cf97df95
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
10 /** @file allegro_m.cpp Playing music via allegro. */
12 #ifdef WITH_ALLEGRO
14 #include "../stdafx.h"
15 #include "../debug.h"
16 #include "allegro_m.h"
17 #include <allegro.h>
19 #include "../safeguards.h"
21 static FMusicDriver_Allegro iFMusicDriver_Allegro;
22 static MIDI *_midi = NULL;
24 /**
25 * There are multiple modules that might be using Allegro and
26 * Allegro can only be initiated once.
28 extern int _allegro_instance_count;
30 const char *MusicDriver_Allegro::Start(const char * const *param)
32 if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) {
33 DEBUG(driver, 0, "allegro: install_allegro failed '%s'", allegro_error);
34 return "Failed to set up Allegro";
36 _allegro_instance_count++;
38 /* Initialise the sound */
39 if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) {
40 DEBUG(driver, 0, "allegro: install_sound failed '%s'", allegro_error);
41 return "Failed to set up Allegro sound";
44 /* Okay, there's no soundcard */
45 if (midi_card == MIDI_NONE) {
46 DEBUG(driver, 0, "allegro: no midi card found");
47 return "No sound card found";
50 return NULL;
53 void MusicDriver_Allegro::Stop()
55 if (_midi != NULL) destroy_midi(_midi);
56 _midi = NULL;
58 if (--_allegro_instance_count == 0) allegro_exit();
61 void MusicDriver_Allegro::PlaySong(const char *filename)
63 if (_midi != NULL) destroy_midi(_midi);
64 _midi = load_midi(filename);
65 play_midi(_midi, false);
68 void MusicDriver_Allegro::StopSong()
70 stop_midi();
73 bool MusicDriver_Allegro::IsSongPlaying()
75 return midi_pos >= 0;
78 void MusicDriver_Allegro::SetVolume(byte vol)
80 set_volume(-1, vol);
83 #endif /* WITH_ALLEGRO */