Timidity_binary.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 #ifdef XWIN
00024 
00025 #ifndef ALPHA_LINUX_CXX
00026 #  include <unistd.h>
00027 #  include <csignal>
00028 #  include <sys/types.h>
00029 #  include <sys/stat.h>
00030 #  include <fcntl.h>
00031 #  include <iostream>
00032 #endif
00033 
00034 #include "fnames.h"
00035 
00036 using std::cerr;
00037 using std::endl;
00038 
00039 #if HAVE_TIMIDITY_BIN
00040 #include "Timidity_binary.h"
00041 
00042 static Mix_Music *mixermusic;
00043 
00044 //
00045 // Woohoo. This is easy with SDL_mixer! :)
00046 //
00047 
00048 Timidity_binary::Timidity_binary() 
00049 {
00050   //Point to music finish cleanup code
00051   Mix_HookMusicFinished(music_complete_callback);
00052 }
00053 
00054 Timidity_binary::~Timidity_binary()
00055 {
00056   // Stop any current player
00057   stop_track();
00058   stop_sfx();
00059 }
00060 
00061 void Timidity_binary::stop_track(void)
00062 {
00063   Mix_HaltMusic();
00064   if(mixermusic)
00065   {
00066     Mix_FreeMusic(mixermusic);
00067     mixermusic = NULL;
00068   }
00069 }
00070 //Clean up last track played, freeing memory each time
00071 void Timidity_binary::music_complete_callback(void)
00072 {
00073   if(mixermusic)
00074   {
00075     Mix_FreeMusic(mixermusic);
00076     mixermusic = NULL;
00077   }
00078 }
00079 
00080 bool  Timidity_binary::is_playing(void)
00081 {
00082   return Mix_PlayingMusic()!=0;
00083 }
00084 
00085 void  Timidity_binary::start_track(XMIDIEventList *event_list,bool repeat)
00086 {
00087   const char *name = MIDITMPFILE;
00088   event_list->Write(name);
00089 
00090 #if DEBUG
00091   cerr << "Starting midi sequence with Timidity_binary" << endl;
00092 #endif
00093   stop_track();
00094 
00095   mixermusic = Mix_LoadMUS(name);
00096   Mix_PlayMusic(mixermusic, repeat);
00097   Mix_VolumeMusic(MIX_MAX_VOLUME - 50); //Balance volume with other music types
00098 }
00099 
00100 void  Timidity_binary::start_sfx(XMIDIEventList *event_list)
00101 {
00102 }
00103 
00104 void  Timidity_binary::stop_sfx(void)
00105 {
00106 }
00107 
00108 const char *Timidity_binary::copyright(void)
00109 {
00110   return "Internal SDL_mixer timidity synthesiser";
00111 }
00112 
00113 #endif // HAVE_TIMIDITY_BIN
00114 
00115 #endif // XWIN

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