2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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 /** @file allegro_m.cpp Playing music via allegro. */
12 #include "../stdafx.h"
14 #include "allegro_m.h"
15 #include "midifile.hpp"
18 #include "../safeguards.h"
20 static FMusicDriver_Allegro iFMusicDriver_Allegro
;
21 static MIDI
*_midi
= nullptr;
24 * There are multiple modules that might be using Allegro and
25 * Allegro can only be initiated once.
27 extern int _allegro_instance_count
;
29 std::optional
<std::string_view
> MusicDriver_Allegro::Start(const StringList
&)
31 if (_allegro_instance_count
== 0 && install_allegro(SYSTEM_AUTODETECT
, &errno
, nullptr)) {
32 Debug(driver
, 0, "allegro: install_allegro failed '{}'", allegro_error
);
33 return "Failed to set up Allegro";
35 _allegro_instance_count
++;
37 /* Initialise the sound */
38 if (install_sound(DIGI_AUTODETECT
, MIDI_AUTODETECT
, nullptr) != 0) {
39 Debug(driver
, 0, "allegro: install_sound failed '{}'", allegro_error
);
40 return "Failed to set up Allegro sound";
43 /* Okay, there's no soundcard */
44 if (midi_card
== MIDI_NONE
) {
45 Debug(driver
, 0, "allegro: no midi card found");
46 return "No sound card found";
52 void MusicDriver_Allegro::Stop()
54 if (_midi
!= nullptr) destroy_midi(_midi
);
57 if (--_allegro_instance_count
== 0) allegro_exit();
60 void MusicDriver_Allegro::PlaySong(const MusicSongInfo
&song
)
62 std::string filename
= MidiFile::GetSMFFile(song
);
64 if (_midi
!= nullptr) destroy_midi(_midi
);
65 if (!filename
.empty()) {
66 _midi
= load_midi(filename
.c_str());
67 play_midi(_midi
, false);
73 void MusicDriver_Allegro::StopSong()
78 bool MusicDriver_Allegro::IsSongPlaying()
83 void MusicDriver_Allegro::SetVolume(uint8_t vol
)
88 #endif /* WITH_ALLEGRO */