win_midiout.h

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2000, 2001, 2002  Ryan Nunn
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 #ifndef WIN_MIDIOUT_H
00020 #define WIN_MIDIOUT_H
00021 
00022 #if defined(WIN32) && !defined(UNDER_CE)
00023 
00024 #ifndef WIN32_LEAN_AND_MEAN
00025 #define WIN32_LEAN_AND_MEAN
00026 #endif
00027 
00028 // These will prevent inclusion of mmsystem sections
00029 #define MMNODRV         // Installable driver support
00030 #define MMNOSOUND       // Sound support
00031 #define MMNOWAVE        // Waveform support
00032 #define MMNOAUX         // Auxiliary audio support
00033 #define MMNOMIXER       // Mixer support
00034 #define MMNOTIMER       // Timer support
00035 #define MMNOJOY         // Joystick support
00036 #define MMNOMCI         // MCI support
00037 #define MMNOMMIO        // Multimedia file I/O support
00038 
00039 #include <windows.h>
00040 #include <mmsystem.h>
00041 
00042 #include "../Midi.h"
00043 #include "exceptions.h"
00044 
00045 class Windows_MidiOut : virtual public MidiAbstract
00046 {
00047 public:
00048   virtual void start_track(XMIDIEventList *, bool repeat);
00049   virtual void start_sfx(XMIDIEventList *);
00050   virtual void stop_track(void);
00051   virtual void stop_sfx(void);
00052   virtual bool is_playing(void);
00053   virtual const char *copyright(void);
00054 
00055   Windows_MidiOut();
00056   virtual ~Windows_MidiOut();
00057 
00058 private:
00059   UNREPLICATABLE_CLASS(Windows_MidiOut);
00060 
00061   struct mid_data {
00062     XMIDIEventList  *list;
00063     bool      repeat;
00064   };
00065 
00066   static const unsigned short centre_value;
00067   static const unsigned char  fine_value;
00068   static const unsigned char  coarse_value;
00069   static const unsigned short combined_value;
00070 
00071   signed int  dev_num;
00072   HMIDIOUT  midi_port;
00073   
00074   HANDLE    *thread_handle;
00075   DWORD   thread_id;
00076 
00077   // Thread communicatoins
00078   LONG    is_available;
00079   LONG    playing;
00080   LONG    s_playing;
00081   LONG    thread_com;
00082   LONG    sfx_com;
00083 
00084   mid_data *thread_data;
00085   mid_data *sfx_data;
00086 
00087   mid_data data;
00088   mid_data sdata;
00089 
00090   // Methods
00091   static DWORD __stdcall thread_start(void *data);
00092   void init_device();
00093   DWORD thread_main();
00094   void thread_play ();
00095   void reset_channel (int i);
00096 
00097   // Microsecond Clock
00098   unsigned long start;
00099   unsigned long sfx_start;
00100 
00101   inline void wmoInitClock ()
00102   { start = GetTickCount()*6; }
00103 
00104   inline void wmoAddOffset (unsigned long offset)
00105   { start += offset; }
00106 
00107   inline unsigned long wmoGetTime ()
00108   { return GetTickCount()*6 - start; }
00109 
00110   inline unsigned long wmoGetStart ()
00111   { return start; }
00112 
00113   inline unsigned long wmoGetRealTime ()
00114   { return GetTickCount()*6; }
00115 
00116   inline void wmoInitSFXClock ()
00117   { sfx_start = GetTickCount()*6; }
00118 
00119   inline void wmoAddSFXOffset (unsigned long offset)
00120   { sfx_start += offset; }
00121 
00122   inline unsigned long wmoGetSFXTime ()
00123   { return GetTickCount()*6 - sfx_start; }
00124 
00125   inline unsigned long wmoGetSFXStart ()
00126   { return sfx_start; }
00127 };
00128 
00129 #endif //WIN32
00130 
00131 #endif //WIN_MIDIOUT_H

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