allegro_m.cpp

Go to the documentation of this file.
00001 /* $Id: allegro_m.cpp 14632 2008-11-25 23:21:58Z rubidium $ */
00002 
00005 #ifdef WITH_ALLEGRO
00006 
00007 #include "../stdafx.h"
00008 #include "../debug.h"
00009 #include "allegro_m.h"
00010 #include <allegro.h>
00011 
00012 static FMusicDriver_Allegro iFMusicDriver_Allegro;
00013 static MIDI *_midi = NULL;
00014 
00017 extern int _allegro_instance_count;
00018 
00019 const char *MusicDriver_Allegro::Start(const char * const *param)
00020 {
00021   if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, NULL)) return NULL;
00022   _allegro_instance_count++;
00023 
00024   /* Initialise the sound */
00025   if (install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) != 0) return NULL;
00026 
00027   /* Okay, there's no soundcard */
00028   if (midi_card == MIDI_NONE) {
00029     DEBUG(driver, 0, "allegro: no midi card found");
00030   }
00031 
00032   return NULL;
00033 }
00034 
00035 void MusicDriver_Allegro::Stop()
00036 {
00037   if (_midi != NULL) destroy_midi(_midi);
00038   _midi = NULL;
00039 
00040   if (--_allegro_instance_count == 0) allegro_exit();
00041 }
00042 
00043 void MusicDriver_Allegro::PlaySong(const char *filename)
00044 {
00045   if (_midi != NULL) destroy_midi(_midi);
00046   _midi = load_midi(filename);
00047   play_midi(_midi, false);
00048 }
00049 
00050 void MusicDriver_Allegro::StopSong()
00051 {
00052   stop_midi();
00053 }
00054 
00055 bool MusicDriver_Allegro::IsSongPlaying()
00056 {
00057   return midi_pos >= 0;
00058 }
00059 
00060 void MusicDriver_Allegro::SetVolume(byte vol)
00061 {
00062   set_volume(-1, vol);
00063 }
00064 
00065 #endif /* WITH_ALLEGRO */

Generated on Wed Jun 3 19:05:11 2009 for OpenTTD by  doxygen 1.5.6