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/>.
10 /** @file allegro_m.cpp Playing music via allegro. */
14 #include "../stdafx.h"
16 #include "allegro_m.h"
19 #include "../safeguards.h"
21 static FMusicDriver_Allegro iFMusicDriver_Allegro
;
22 static MIDI
*_midi
= NULL
;
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";
53 void MusicDriver_Allegro::Stop()
55 if (_midi
!= NULL
) destroy_midi(_midi
);
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()
73 bool MusicDriver_Allegro::IsSongPlaying()
78 void MusicDriver_Allegro::SetVolume(byte vol
)
83 #endif /* WITH_ALLEGRO */