Midi.h

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2000-2001  The Exult Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (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 #ifndef _MIDI_H_
00020 #define _MIDI_H_
00021 
00022 #include <vector>
00023 #ifndef WIN32
00024 //#include "Mixer.h"
00025 #endif
00026 #include "xmidi.h"
00027 
00028 // The 'types' of midi drivers
00029 enum MidiDriverType {
00030   MIDI_DRIVER_NORMAL  = 0,  // We are outputting using Normal Midi Drivers
00031   MIDI_DRIVER_OGG,      // We are outputting using Oggs
00032 
00033 #ifdef USE_FMOPL_MIDI
00034   MIDI_DRIVER_FMSYNTH,    // We are outputting using FM Synth Driver
00035 #endif
00036 
00037 #ifdef USE_MT32EMU_MIDI
00038   MIDI_DRIVER_MT32EMU,    // We are outputting using MT32EMU Driver (Ha, you'll never see this!)
00039 #endif
00040 
00041   NUM_MIDI_DRIVER_TYPES   // Count of midi drivers
00042 };
00043 
00044 
00045 #include "SDL_mixer.h"
00046 
00047 #include <string>
00048 
00049 //---- MidiAbstract -----------------------------------------------------------
00050 
00051 class MidiAbstract
00052 {
00053 public:
00054   virtual void start_track(XMIDIEventList *, bool repeat) = 0;
00055   virtual void start_sfx(XMIDIEventList *) { }
00056   
00057   virtual void  stop_track(void)=0;
00058   virtual void  stop_sfx(void) { };
00059   virtual bool  is_playing(void)=0;
00060   virtual const char *copyright(void)=0;
00061 
00062   virtual void load_patches(bool force_xmidi) { }
00063   virtual bool is_fm_synth() { return false; }
00064   virtual bool use_gs127() { return false; }
00065 
00066   MidiAbstract() {};
00067   virtual ~MidiAbstract() {};
00068 };
00069 
00070 //Pseudo device, used purely to create the OGG_MIDI class with something
00071 class OGG_MIDI : virtual public MidiAbstract
00072 {
00073   static void   music_complete_callback(void);
00074 public:
00075   OGG_MIDI();
00076   virtual ~OGG_MIDI();
00077   virtual void  start_track(XMIDIEventList *, bool repeat);
00078   virtual void  stop_track(void);
00079   virtual bool  is_playing(void);
00080   virtual const char *copyright(void);
00081 };
00082 
00083 //---- MyMidiPlayer -----------------------------------------------------------
00084 
00085 class MyMidiPlayer
00086 {
00087 public:
00088 
00089   MyMidiPlayer();
00090   ~MyMidiPlayer();
00091   MyMidiPlayer(const char *flexfile);
00092   void  start_music(int num,bool continuous=false,int bank=0);
00093   void  start_music(const char *fname,int num,bool continuous=false);
00094   void  start_track(int num,bool continuous=false,int bank=0);
00095   void  start_track(const char *fname,int num,bool continuous=false);
00096   void  start_track(XMIDIEventList *eventlist, bool continuous=false);
00097   void  start_sound_effect(int num);
00098   void  stop_sound_effects();
00099   void  load_patches(bool force_xmidi=false) { if (midi_device) midi_device->load_patches(force_xmidi); }
00100 
00101   void  stop_music();
00102   
00103   bool  add_midi_bank(const char *s);
00104   void  set_music_conversion(int conv);
00105   int   get_music_conversion() { return music_conversion; }
00106   void  set_effects_conversion(int conv);
00107   int   get_effects_conversion() { return effects_conversion; }
00108 
00109   int   get_output_driver_type() { return output_driver_type; }
00110   void  set_output_driver_type(int);
00111 
00112   inline bool is_track_playing(int num) { 
00113     return midi_device && current_track==num && midi_device->is_playing();
00114   }
00115   inline int  get_current_track() { return (midi_device!=0)&&midi_device->is_playing()?current_track:-1; }
00116   inline int  is_repeating() { return repeating; }
00117 
00118   bool is_fm_synth() { return midi_device?midi_device->is_fm_synth():false; }
00119 
00120   
00121 private:
00122 
00123   MyMidiPlayer(const MyMidiPlayer &m) ; // Cannot call
00124   MyMidiPlayer &operator=(const MyMidiPlayer &); // Cannot call
00125   void    kmidi_start_track(int num,bool continuous=false);
00126   std::vector<std::string>  midi_bank;
00127   int current_track;
00128   bool  repeating;
00129   MidiAbstract  *midi_device;
00130   bool  initialized;
00131 
00132   bool  init_device(void);
00133 
00134   int   music_conversion;
00135   int   effects_conversion;
00136   int   output_driver_type;
00137 };
00138 
00139 #endif

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