OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

allegro_m.cpp
Go to the documentation of this file.
1 /* $Id: allegro_m.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
2
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 */
9
12 #ifdef WITH_ALLEGRO
13
14 #include "../stdafx.h"
15 #include "../debug.h"
16 #include "allegro_m.h"
17 #include <allegro.h>
18
19 #include "../safeguards.h"
20
21 static FMusicDriver_Allegro iFMusicDriver_Allegro;
22 static MIDI *_midi = NULL;
23
28 extern int _allegro_instance_count;
29
30 const char *MusicDriver_Allegro::Start(const char * const *param)
31 {
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";
35 }
36 _allegro_instance_count++;
37
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";
42 }
43
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";
48 }
49
50 return NULL;
51 }
52
53 void MusicDriver_Allegro::Stop()
54 {
55 if (_midi != NULL) destroy_midi(_midi);
56 _midi = NULL;
57
58 if (--_allegro_instance_count == 0) allegro_exit();
59 }
60
61 void MusicDriver_Allegro::PlaySong(const char *filename)
62 {
63 if (_midi != NULL) destroy_midi(_midi);
64 _midi = load_midi(filename);
65 play_midi(_midi, false);
66 }
67
68 void MusicDriver_Allegro::StopSong()
69 {
70 stop_midi();
71 }
72
73 bool MusicDriver_Allegro::IsSongPlaying()
74 {
75 return midi_pos >= 0;
76 }
77
78 void MusicDriver_Allegro::SetVolume(byte vol)
79 {
80 set_volume(-1, vol);
81 }
82
83 #endif /* WITH_ALLEGRO */