DevMidF.h
gehe zur Dokumentation dieser Datei
00001 
00023 // ------------------------------------------------------------------
00024 // Mutabor 3, 1998, R.Krauße
00025 // MIDI-File als Device
00026 // ------------------------------------------------------------------
00027 
00028 #ifndef DEVMIDF_H
00029 #define DEVMIDF_H
00030 
00031 #include <fstream>
00032 
00033 #include "Device.h"
00034 
00035 #ifdef WX
00036 #include "mhArray.h"
00037 WX_DEFINE_ARRAY_INT(BYTE, TBYTEBase1);
00038 DEF_MHARRAY(BYTE, TByteArray, TBYTEBase1);
00039 #else
00040 #include <classlib/arrays.h>
00041 typedef TArray<BYTE> TByteArray;
00042 #endif
00043 
00044 // Track ------------------------------------------------------------
00045 
00046 class Track
00047 {
00048 
00049 public:
00050         DWORD Time;
00051         TByteArray *Data;
00052         Track()
00053         {
00054                 Time = 0;
00055                 Data = new TByteArray(100, 0, 100);
00056         }
00057 
00058         ~Track()
00059         {
00060                 delete Data;
00061         }
00062 
00063         void WriteDelta();
00064         void MidiOut3(BYTE c1, BYTE c2, BYTE c3)
00065         {
00066                 WriteDelta();
00067                 Data->Add(c1);
00068                 Data->Add(c2);
00069                 Data->Add(c3);
00070         }
00071 
00072         void MidiOut2(BYTE c1, BYTE c2)
00073         {
00074                 WriteDelta();
00075                 Data->Add(c1);
00076                 Data->Add(c2);
00077         }
00078 
00079         void Save(mutOFstream &os);
00080         void Add(BYTE c)
00081         {
00082                 Data->Add(c);
00083         }
00084 };
00085 
00086 typedef struct TAK1
00087 {
00088         int taste;
00089         int key;
00090         int fine;
00091         DWORD id;         // (channel << 24) +(Route->Id << 16) + (Box << 8) + Taste
00092         // zum Identifizieren fürs korrekte Ausschalten
00093 } TonAufKanal1;
00094 
00095 // OutMidiFile ------------------------------------------------------
00096 
00097 class OutMidiFile : public OutDevice
00098 {
00099         int bending_range;
00100 public:
00101 
00102         OutMidiFile(): OutDevice(), bending_range (2) {}
00103 
00104         OutMidiFile(const wxString &name, int devId, int bendingRange = 2)
00105                         : OutDevice(devId, name)
00106         {
00107                 bending_range = bendingRange;
00108         }
00109 
00110         virtual ~OutMidiFile()
00111         {};
00112         
00114 
00116         virtual void Save (tree_storage & config);
00117         
00119 
00124         virtual void Save (tree_storage & config, const Route * route);
00125         
00126         
00128 
00130         virtual void Load (tree_storage & config);
00131         
00133 
00138         virtual void Load (tree_storage & config, Route * route);
00139 
00140         
00141         virtual bool Open();
00142         virtual void Close();
00143         virtual void NoteOn(int box, int taste, int velo, Route *r, int channel, ChannelData *cd);
00144         virtual void NoteOff(int box, int taste, int velo, Route *r, int channel);
00145         virtual void NotesCorrect(int box);
00146         virtual void Sustain(char on, int channel);
00147         virtual int  GetChannel(int taste)
00148         {
00149                 return -1;
00150         } // hier kˆnnte man auch den richtigen Wett ausgeben, macht aber nixcht so viel Sinn
00151 
00152         virtual void Gis(GisToken *token, char turn)
00153         {};
00154 
00155         virtual void AddTime(frac time)
00156         {};
00157 
00158         virtual void MidiOut(DWORD data, char n);
00159         virtual void MidiOut(BYTE *p, char n);
00160         virtual void Quite(Route *r);
00161 
00162         void SetBendingRange(const int i)
00163         {
00164                 bending_range = i;
00165         }
00166 
00167         int GetBendingRange () const 
00168         {
00169                 return bending_range;
00170         }
00171 
00172         virtual DevType GetType() const
00173         {
00174                 return DTMidiFile;
00175         }
00176 
00177         
00178         virtual int GetMaxChannel() const { return 15; }
00179         virtual int GetMinChannel() const { return 0; }
00180         
00181         virtual mutString GetTypeName () const {
00182                 return _("MIDI output file");
00183         }
00184 
00185 #ifdef WX
00186         virtual wxString TowxString() const {
00187                 wxString s = OutDevice::TowxString() +
00188                 wxString::Format(_T("\n  Name = %s\n  DevId = %d\n  Bending Range = %d\n  nKeyOn"),
00189                                  Name.c_str(), DevId, bending_range, nKeyOn);
00190                 s.Printf(_T("\n  KeyDir = [ %d"), KeyDir[0]);
00191                 for (int i = 1; i<16; i++)
00192                         s.Printf(_T(", %d"),KeyDir[i]);
00193                 s.Printf(_T("]\n  ton_auf_kanal = [ t=%d,k=%d,f=%d"), 
00194                          ton_auf_kanal[0].taste, 
00195                          ton_auf_kanal[0].key, 
00196                          ton_auf_kanal[0].fine);
00197                 for (int i = 1; i<16; i++)
00198                         s.Printf(_T("; t=%d,k=%d,f=%d"), 
00199                                  ton_auf_kanal[i].taste, 
00200                                  ton_auf_kanal[i].key, 
00201                                  ton_auf_kanal[i].fine);
00202                 s+=_T("]");
00203                 return s;
00204         }
00205 #endif
00206         virtual void ReadData(wxConfigBase * config);
00207         virtual void WriteData(wxConfigBase * config);
00208         
00209 protected:
00210 
00211         Track Tracks;
00212         ChannelData Cd[16];
00213         char KeyDir[16];
00214         TonAufKanal1 ton_auf_kanal[16];
00215         int nKeyOn;
00216 };
00217 
00218 // InMidiFile -------------------------------------------------------
00219 
00220 
00221 
00222 class InMidiFile : public InDevice
00223 {
00224 
00225         class MidiTimer : public wxTimer
00226         {
00227                 InMidiFile * file;
00228 
00229         public:
00230                 MidiTimer(InMidiFile * f) : wxTimer(),file(f)
00231                 {}
00232 
00233                 void Notify()
00234                 {
00235                         file->IncDelta();
00236                 }
00237         };
00238 
00239         MidiTimer timer;
00240 public:
00241 
00242         InMidiFile(): InDevice(),timer (this),Track(NULL), TrackPos(NULL),curDelta(NULL),StatusByte(NULL) { }
00243 
00244         InMidiFile(wxString name, int devId): InDevice(devId, name),timer(this),Track(NULL),TrackPos(NULL),curDelta(NULL),StatusByte(NULL) {}
00245 
00246         virtual ~InMidiFile()
00247         {};
00248         
00250 
00252         virtual void Save (tree_storage & config);
00253         
00255 
00260         virtual void Save (tree_storage & config, const Route * route);
00261         
00262         
00264 
00266         virtual void Load (tree_storage & config);
00267 
00269 
00274         virtual void Load (tree_storage & config, Route * route);
00275 
00276         
00277         virtual bool Open();
00278         virtual void Close();
00279         virtual void Stop();
00280         virtual void Play();
00281         virtual void Pause();
00282 //         void Proceed(GisReadArtHead *h, char turn, Route *route) {};
00283 //         void ProceedRoute(GisReadArtHead *h, char turn) {};
00284         virtual frac ReadOn(frac time)
00285         {
00286                 return frac(0, 1);
00287         }
00288 
00289         virtual DevType GetType() const
00290         {
00291                 return DTMidiFile;
00292         }
00293 
00294 
00295         void IncDelta();
00296         
00297         virtual int GetMaxChannel() const { return 15; }
00298         virtual int GetMinChannel() const { return 0; }
00299         virtual int GetMaxTrack() const { return 0xFFFF; }
00300         virtual int GetMinTrack() const { return 0; }
00301 
00302         virtual mutString GetTypeName () const {
00303                 return _("MIDI input file");
00304         }
00305         
00306 #ifdef WX
00307         virtual wxString TowxString() const {
00308                 return InDevice::TowxString() +
00309                 wxString::Format(_T("\n  FileType = %d\n  nTrack = %d\n  Speed = %d\n  TrackPos = %d\n  curDelta = %ld"
00310                                     "\n  minDelta = %ld\n  actDelta = %ld\n  StatusByte = %x\n  Busy = %d"
00311                                     "\n  TicksPerQuater = %d\n  MMSPerQuater = %ld"),
00312                                  FileType, nTrack, Speed, (Track?(*Track?**Track:-1):-2), 
00313                                  (TrackPos?*TrackPos:-1), (curDelta?*curDelta:-1), 
00314                                  minDelta, actDelta, (StatusByte?*StatusByte:-1), Busy, TicksPerQuater, MMSPerQuater);
00315         }
00316 #endif
00317 protected:
00318         BYTE FileType;
00319         size_t nTrack;
00320         int Speed;
00321         BYTE **Track;
00322         DWORD *TrackPos;
00323         long *curDelta;
00324         long minDelta;
00325         long actDelta;
00326         BYTE *StatusByte;
00327         ChannelData Cd[16];
00328         //  UINT TimerId;
00329         BOOL Busy;
00330         DWORD TicksPerQuater;
00331         long MMSPerQuater;
00332         void Proceed(DWORD midiCode, int track);
00333         void ProceedRoute(DWORD midiCode, Route *route);
00334         long ReadMidiProceed(size_t nr, long time);
00335 };
00336 
00337 // Function ---------------------------------------------------------
00338 
00339 
00340 #endif
00341 
00342 /*
00343 timeSetEvent
00344 
00345 The timeSetEvent function starts a specified timer event. The multimedia timer runs in its own thread. After the event is activated, it calls the specified callback function or sets or pulses the specified event object.
00346 
00347 This function is obsolete. New applications should use CreateTimerQueueTimer to create a timer-queue timer.
00348 
00349 MMRESULT timeSetEvent(
00350   UINT           uDelay,
00351   UINT           uResolution,
00352   LPTIMECALLBACK lpTimeProc,
00353   DWORD_PTR      dwUser,
00354   UINT           fuEvent
00355 );
00356 
00357 Parameters
00358 
00359 uDelay
00360 
00361 Event delay, in milliseconds. If this value is not in the range of the minimum and maximum event delays supported by the timer, the function returns an error.
00362 
00363 uResolution
00364 
00365 Resolution of the timer event, in milliseconds. The resolution increases with smaller values; a resolution of 0 indicates periodic events should occur with the greatest possible accuracy. To reduce system overhead, however, you should use the maximum value appropriate for your application.
00366 
00367 lpTimeProc
00368 
00369 Pointer to a callback function that is called once upon expiration of a single event or periodically upon expiration of periodic events. If fuEvent specifies the TIME_CALLBACK_EVENT_SET or TIME_CALLBACK_EVENT_PULSE flag, then the lpTimeProc parameter is interpreted as a handle to an event object. The event will be set or pulsed upon completion of a single event or periodically upon completion of periodic events. For any other value of fuEvent, the lpTimeProc parameter is interpreted as a function pointer with the following signature: void (CALLBACK)(UINT uTimerID, UINT uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2);
00370 
00371 dwUser
00372 
00373 User-supplied callback data.
00374 
00375 fuEvent
00376 
00377 Timer event type. This parameter may include one of the following values.
00378 Value   Meaning
00379 TIME_ONESHOT    Event occurs once, after uDelay milliseconds.
00380 TIME_PERIODIC   Event occurs every uDelay milliseconds.
00381 
00382 The fuEvent parameter may also include one of the following values.
00383 Value   Meaning
00384 TIME_CALLBACK_FUNCTION  When the timer expires, Windows calls the function pointed to by the lpTimeProc parameter. This is the default.
00385 TIME_CALLBACK_EVENT_SET         When the timer expires, Windows calls the SetEvent function to set the event pointed to by the lpTimeProc parameter. The dwUser parameter is ignored.
00386 TIME_CALLBACK_EVENT_PULSE       When the timer expires, Windows calls the PulseEvent function to pulse the event pointed to by the lpTimeProc parameter. The dwUser parameter is ignored.
00387 TIME_KILL_SYNCHRONOUS   Passing this flag prevents an event from occurring after the timeKillEvent() function is called.
00388 
00389 Return Values
00390 
00391 Returns an identifier for the timer event if successful or an error otherwise. This function returns NULL if it fails and the timer event was not created. (This identifier is also passed to the callback function.)
00392 
00393 Remarks
00394 
00395 Each call to timeSetEvent for periodic timer events requires a corresponding call to the timeKillEvent function.
00396 
00397 Creating an event with the TIME_KILL_SYNCHRONOUS and the TIME_CALLBACK_FUNCTION flag prevents the event from occurring after the timeKillEvent function is called.
00398 
00399 Requirements
00400 
00401   Windows XP: Included in Windows XP only.
00402   Header: Declared in Mmsystem.h; include Windows.h.
00403   Library: Use Winmm.lib.
00404 
00405 
00406  */
00407 

Erzeugt am Sun Aug 21 2011 10:51:53 für Mutabor von doxygen 1.7.4