10381
|
1 |
/* $Id$ */
|
|
2 |
|
|
3 |
/** @file allegro_m.cpp Playing music via allegro. */
|
|
4 |
|
|
5 |
#ifdef WITH_ALLEGRO
|
|
6 |
|
|
7 |
#include "../stdafx.h"
|
|
8 |
#include "../debug.h"
|
|
9 |
#include "allegro_m.h"
|
|
10 |
#include <allegro.h>
|
|
11 |
|
|
12 |
static FMusicDriver_Allegro iFMusicDriver_Allegro;
|
|
13 |
static MIDI *_midi = NULL;
|
|
14 |
|
|
15 |
/** There are multiple modules that might be using Allegro and
|
|
16 |
* Allegro can only be initiated once. */
|
|
17 |
extern int _allegro_instance_count;
|
|
18 |
|
|
19 |
const char *MusicDriver_Allegro::Start(const char * const *param)
|
|
20 |
{
|
|
21 |
if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) return NULL;
|
|
22 |
_allegro_instance_count++;
|
|
23 |
|
|
24 |
/* Initialise the sound */
|
|
25 |
if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) return NULL;
|
|
26 |
|
|
27 |
/* Okay, there's no soundcard */
|
|
28 |
if (midi_card == MIDI_NONE) {
|
|
29 |
DEBUG(driver, 0, "allegro: no midi card found");
|
|
30 |
}
|
|
31 |
|
|
32 |
return NULL;
|
|
33 |
}
|
|
34 |
|
|
35 |
void MusicDriver_Allegro::Stop()
|
|
36 |
{
|
|
37 |
if (_midi != NULL) destroy_midi(_midi);
|
|
38 |
_midi = NULL;
|
|
39 |
|
|
40 |
if (--_allegro_instance_count == 0) allegro_exit();
|
|
41 |
}
|
|
42 |
|
|
43 |
void MusicDriver_Allegro::PlaySong(const char *filename)
|
|
44 |
{
|
|
45 |
if (_midi != NULL) destroy_midi(_midi);
|
|
46 |
_midi = load_midi(filename);
|
|
47 |
play_midi(_midi, false);
|
|
48 |
}
|
|
49 |
|
|
50 |
void MusicDriver_Allegro::StopSong()
|
|
51 |
{
|
|
52 |
stop_midi();
|
|
53 |
}
|
|
54 |
|
|
55 |
bool MusicDriver_Allegro::IsSongPlaying()
|
|
56 |
{
|
|
57 |
return midi_pos >= 0;
|
|
58 |
}
|
|
59 |
|
|
60 |
void MusicDriver_Allegro::SetVolume(byte vol)
|
|
61 |
{
|
|
62 |
set_volume(-1, vol);
|
|
63 |
}
|
|
64 |
|
|
65 |
#endif /* WITH_ALLEGRO */
|