mixer_midiout.cc

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2000  Dancer A.L Vesperman
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #ifdef HAVE_CONFIG_H
00020 #  include <config.h>
00021 #endif
00022 
00023 //#ifndef ALPHA_LINUX_CXX
00024 //#  include <unistd.h>
00025 //#  include <csignal>
00026 //#  include <sys/types.h>
00027 //#  include <sys/stat.h>
00028 //#  include <fcntl.h>
00029 //#endif
00030 
00031 #include <iostream>
00032 
00033 #include "fnames.h"
00034 
00035 using std::cerr;
00036 using std::endl;
00037 
00038 #include "mixer_midiout.h"
00039 
00040 static Mix_Music *mixermusic;
00041 
00042 //
00043 // Woohoo. This is easy with SDL_mixer! :)
00044 //
00045 
00046 Mixer_MidiOut::Mixer_MidiOut() 
00047 {
00048   //Point to music finish cleanup code
00049   Mix_HookMusicFinished(music_complete_callback);
00050 }
00051 
00052 Mixer_MidiOut::~Mixer_MidiOut()
00053 {
00054   // Stop any current player
00055   stop_track();
00056   stop_sfx();
00057 }
00058 
00059 void Mixer_MidiOut::stop_track(void)
00060 {
00061   Mix_HaltMusic();
00062   if(mixermusic)
00063   {
00064     Mix_FreeMusic(mixermusic);
00065     mixermusic = NULL;
00066   }
00067 }
00068 
00069 //Clean up last track played, freeing memory each time
00070 void Mixer_MidiOut::music_complete_callback(void)
00071 {
00072   if(mixermusic)
00073   {
00074     Mix_FreeMusic(mixermusic);
00075     mixermusic = NULL;
00076   }
00077 }
00078 
00079 bool  Mixer_MidiOut::is_playing(void)
00080 {
00081   return Mix_PlayingMusic()!=0;
00082 }
00083 
00084 void  Mixer_MidiOut::start_track(XMIDIEventList *event_list,bool repeat)
00085 {
00086   const char *name = MIDITMPFILE;
00087   event_list->Write(name);
00088 
00089 #if DEBUG
00090   cerr << "Starting midi sequence with Mixer_MidiOut" << endl;
00091 #endif
00092   stop_track();
00093 
00094   mixermusic = Mix_LoadMUS(name);
00095   Mix_PlayMusic(mixermusic, repeat);
00096   Mix_VolumeMusic(MIX_MAX_VOLUME);  //Balance volume with other music types
00097 }
00098 
00099 void  Mixer_MidiOut::start_sfx(XMIDIEventList *event_list)
00100 {
00101 //Defunct?
00102 }
00103 
00104 void  Mixer_MidiOut::stop_sfx(void)
00105 {
00106 //Defunct?
00107 }
00108 
00109 const char *Mixer_MidiOut::copyright(void)
00110 {
00111   return "Internal SDL_mixer midi out";
00112 }

Generated on Mon Jul 9 14:42:42 2007 for ExultEngine by  doxygen 1.5.1