Device.h
gehe zur Dokumentation dieser Datei
00001 // -*- C++ -*-
00002 
00099 #ifndef DEVICE_H
00100 #define DEVICE_H
00101 
00102 #include "Defs.h"
00103 
00104 #define DRUMCHANNEL 9  // Schlagzeugkanal bei General Midi (Kanal 9, bzw. 10)
00105 
00106 enum MutaborModeType {
00107         MutaborDeviceUnregistered = -1,
00108         MutaborDeviceStop,
00109         MutaborDevicePlay,
00110         MutaborDevicePause,
00111         MutaborDeviceCompileError,
00112         MutaborDeviceTimingError
00113 };
00114 
00115 #include "GIS.h"
00116 #include "Route.h"
00117 #include "wx/stopwatch.h"
00118 
00119 
00120 
00121 class OutDevice;
00122 
00123 class InDevice;
00124 
00125 extern char InDevChanged;
00126 
00127 // Device Typen
00128 enum DevType
00129 {
00130         DTNotSet = -1, DTUnknown, DTMidiPort, DTMidiFile, DTGis
00131 };
00132 
00133 #define DeviceMaxType DTGis+1
00134 
00135 // channel data -----------------------------------------------------
00136 
00137 class ChannelData
00138 {
00139 
00140 public:
00141         int Sound;          // -1 = noch nicht verwendet
00142         char Sustain;
00143         int BankSelectMSB;  // -1 .. noch nicht benutzt
00144         int BankSelectLSB;  // -1 .. noch nicht benutzt
00145         long Pitch;         // 0 = ungepitcht, kann durchaus auch negativ sein
00146         ChannelData(int sound = -1, char sustain = 0)
00147         {
00148                 Sound = sound;
00149                 Sustain = sustain;
00150                 BankSelectMSB = -1;
00151                 BankSelectLSB = -1;
00152                 Pitch = 0;
00153         }
00154 
00155         void Reset()
00156         {
00157                 Sound = -1;
00158                 Sustain = 0;
00159                 BankSelectMSB = -1;
00160                 BankSelectLSB = -1;
00161         }
00162 
00163         bool operator ==(ChannelData &cd)
00164         {
00165                 return ( Sound == -1 || cd.Sound == -1 || Sound == cd.Sound ) &&
00166                        ( Sustain == -1 || cd.Sustain == -1 || Sustain == cd.Sustain ) &&
00167                        ( BankSelectMSB == -1 || cd.BankSelectMSB == -1 || BankSelectMSB == cd.BankSelectMSB ) &&
00168                        ( BankSelectLSB == -1 || cd.BankSelectLSB == -1 || BankSelectLSB == cd.BankSelectLSB );
00169         }
00170 };
00171 
00172 
00173 class Device
00174 {
00175 private:
00176         void * userdata;
00177         int Id;
00178 protected:
00179         int DevId;
00180         mutString Name;
00181 public:
00182         
00183         Device():userdata(NULL),Id(-1),DevId(-1),Name(mutEmptyString) { }
00184         
00185         Device(int id, int devid, mutString name = mutEmptyString):userdata(NULL),Id(id),DevId(devid),Name(name) {}
00186         
00187         virtual ~Device() {     }
00188         
00190 
00192         virtual void Save (tree_storage & config) = 0;
00193         
00195 
00200         virtual void Save (tree_storage & config, const Route * route) = 0;
00201         
00203 
00205         virtual void Load (tree_storage & config) = 0;
00206         
00208 
00213         virtual void Load (tree_storage & config, Route * route) = 0;
00214         
00215         
00216         void setUserData (void * data) {
00217                 userdata = data; 
00218         }
00219         void * getUserData() const { return userdata; }
00220 
00221         const wxString & GetName() const
00222         {
00223                 return Name;
00224         }
00225         
00226         virtual void SetName(const wxString & s) 
00227         {
00228                 Name = s;
00229         }
00230         
00231         int GetDevId() const
00232         {
00233                 return DevId;
00234         }
00235         
00236         virtual void SetDevId(int id)
00237         {
00238                 DevId = id;
00239         }
00240         
00241         int GetId() const
00242         {
00243                 return Id;
00244         }
00245 
00246         virtual void ReadData(wxConfigBase * config) {};
00247         virtual void WriteData(wxConfigBase * config) {};       
00248         
00249         virtual mutString GetTypeName () const {
00250                 return _("Device base class");
00251         }
00252 
00253 #ifdef WX
00254         virtual wxString TowxString() const {
00255                 return wxString::Format(_T("Device base class. userdata = %p"), userdata);
00256         }
00257 #endif
00258 protected:
00259         void SetId(int id)
00260         {
00261                 Id = id;
00262         }
00263 };
00264 
00265 // Output devices ---------------------------------------------------
00266 
00267 class OutDevice: public Device
00268 {
00269         // private members: access only via access functions for debugging purposes
00270         /*
00271         OutDevice *Next;
00272         static OutDevice * deviceList;
00273          */
00274         WATCHEDPTR(OutDevice,routing,OutDevice) Next;
00275         static WATCHEDPTR(OutDevice,routing,OutDevice) deviceList;
00276 
00277 public:
00278         OutDevice():Device(),Next(this,_T("Next"))      
00279         {
00280                 AppendToDeviceList(this);
00281         }
00282 
00283         OutDevice(int devId, mutString name, int id = -1):Device(id, devId, name),Next(this,_T("Next")) 
00284         {
00285                 AppendToDeviceList(this);
00286         }
00287 
00288         virtual ~OutDevice()
00289         {
00290                 DEBUGLOG(routing,_T("this = %p"),this);
00291                 TruncateDeviceList (this);
00292                 OutDevice * root = deviceList;
00293                 deviceList = NULL;
00294                 
00295                 if ( Next ) delete Next;
00296                 
00297                 deviceList = root;
00298         }
00299 
00300         static OutDevice * CreateDevice (DevType type);
00301         static OutDevice * CreateDevice(DevType type, const mutString & name, int id);
00302         
00303         virtual bool Open() = 0;
00304         virtual void Close() = 0;
00305         
00306         virtual void NoteOn(int box, int taste, int velo, Route *r,
00307                             int channel, ChannelData *cd) = 0;
00308         virtual void NoteOff(int box, int taste, int velo, Route *r,
00309                              int channel) = 0;
00310         virtual void NotesCorrect(int box) = 0;
00311         virtual void Sustain(char on, int channel) = 0;
00312         virtual int  GetChannel(int taste) = 0;
00313         virtual void Gis(GisToken *token, char turn) = 0;
00314         virtual void AddTime(frac time) = 0;
00315         virtual void MidiOut(DWORD data, char n) = 0;
00316         virtual void MidiOut(BYTE *p, char n) = 0;
00317         virtual void Quite(Route *r) = 0;
00318         virtual void Panic() {};
00319 
00320         virtual bool NeedsRealTime()
00321         {
00322                 return false;
00323         }
00324 
00325         virtual DevType GetType() const
00326         {
00327                 return DTUnknown;
00328         }
00329 
00330         static OutDevice * GetDeviceList() { return deviceList ; }
00331 
00332         void SetNext(OutDevice * N) {
00333                 Next = N;               
00334         }
00335 
00336         OutDevice * GetNext() const {
00337                 return Next;
00338         }
00339 
00340         virtual mutString GetTypeName () const {
00341                 return _("Undefined output device");
00342         }
00343 #ifdef WX
00344         virtual wxString TowxString() const {
00345                 return wxString::Format(_T("Output device: %s (Id: %d)\n  userdata = %p\n  Next = %p"),
00346                                         GetTypeName().c_str(),DevId,(void *)getUserData(),(OutDevice *)Next);
00347         }
00348 #endif
00349         
00350         void Destroy() {
00351                 RemoveFromDeviceList(this);
00352                 delete this;
00353         }
00354 
00355         
00356         static OutDevice * Get(int devid) { return GetInDeviceList(devid); }
00357 
00359 
00363         static void InitializeIds();
00364         
00365         static void SaveDevices(tree_storage & config);
00366 
00368 
00371         static void LoadDevices(tree_storage & config);
00372 
00374 
00377         static OutDevice * GetDevice(int id);
00378 
00379 protected:
00380         static void AppendToDeviceList (OutDevice * dev);
00381         static void RemoveFromDeviceList (OutDevice * dev);
00382         static void TruncateDeviceList (OutDevice * dev);
00383         static OutDevice * GetInDeviceList(int devid);
00384         
00385 };
00386 
00387 // Input devices -------------------------------------------------
00388 class InDevice: public Device
00389 {
00390         // private members: access only via access functions for debugging purposes
00391         /*
00392         InDevice *Next;
00393         static InDevice * deviceList;
00394         Route *Routes;
00395          */
00396         WATCHEDPTR(InDevice, routing, InDevice) Next;
00397         static WATCHEDPTR(InDevice,routing,InDevice) deviceList;
00398         WATCHEDPTR(Route,routing,InDevice) Routes;
00399 protected:
00400         enum MutaborModeType Mode;
00401 
00402 public:
00403         InDevice():Device(), Next(this,_T("Next")), Routes(this,_T("Routes")), Mode(MutaborDeviceStop)
00404         {
00405                 AppendToDeviceList (this);
00406         }
00407         
00408         InDevice(int devId, mutString name = mutEmptyString, MutaborModeType mode = MutaborDeviceStop, int id = -1):
00409         Device(id, devId, name), Next(this,_T("Next")), Routes(this,_T("Routes")), Mode(mode)
00410         {
00411                 AppendToDeviceList(this);
00412         }
00413 
00414         virtual ~InDevice()
00415         {
00416                 DEBUGLOG(routing,_T("%p deleting route %p"),this,(Route *)Routes);
00417                 if ( Routes ) delete Routes;
00418 
00419                 TruncateDeviceList (this);
00420                 InDevice * root = deviceList;
00421                 deviceList = NULL;
00422 
00423                 DEBUGLOG(routing,_T("%p deleting Next %p"),this,(InDevice *)Next);
00424                 if ( Next ) delete Next;
00425 
00426                 deviceList = root;
00427                 DEBUGLOG(routing,_T("deleting %p"),this);
00428         }
00429 
00430         static InDevice * CreateDevice (DevType type);
00431         static InDevice * CreateDevice(DevType type, const mutStringRef name, int id);
00432         
00433         Route *GetMoveRoutes();
00434         Route *GetRoute(int nr);   // counting starts with 0
00435         int nRoutes();
00436         virtual bool Open() = 0;
00437         virtual void Close() = 0;
00438         virtual void Stop() = 0;
00439         virtual void Play() = 0;
00440         virtual void Pause() = 0;
00441         //        virtual frac ReadOn(frac time) = 0;
00442         virtual void AddRoute(Route *route);
00443 
00444         virtual void SetRoute(Route * route) 
00445         { 
00446                 Routes = route; 
00447                 if (route)
00448                         route->SetInDevice(this);
00449         }
00450 
00451         Route *GetRoutes()
00452         {
00453                 return Routes;
00454         }
00455 
00456         void Quite(); // all Routes quite
00457         virtual bool NeedsRealTime()
00458         {
00459                 return false;
00460         }
00461 
00462         virtual DevType GetType() const
00463         {
00464                 return DTUnknown;
00465         }
00466         
00467         virtual Route * ReplaceDevice (InDevice * dev);
00468         
00469   void SetMode(MutaborModeType m) { Mode = m; }
00470 
00471         MutaborModeType GetMode()
00472         {
00473                 return Mode;
00474         }
00475         
00476         static InDevice * GetDeviceList() { return deviceList ; }
00477         
00478         InDevice * GetNext() const 
00479         { 
00480                 return Next; 
00481         }
00482         
00483         void SetNext(InDevice * n) 
00484         {
00485                 Next = n;
00486         }
00487 
00488         virtual mutString GetTypeName () const {
00489                 return _("Undefined input device");
00490         }
00491 
00492 #ifdef WX
00493         virtual wxString TowxString() const {
00494                 return wxString::Format(_T("Input device: %s (Id: %d)\n  userdata = %x\n  Next = %x\n  Mode = %d"),
00495                                         GetTypeName().c_str(),DevId,getUserData(),GetNext(),Mode);
00496         }
00497 #endif
00498         void Destroy() {
00499                 RemoveFromDeviceList(this);
00500                 delete this;
00501         }
00502         
00504 
00508         static void InitializeIds();
00509 
00510         
00512 
00515         static void SaveDevices(tree_storage & config);
00516         
00518 
00521         static void LoadDevices(tree_storage & config);
00522         
00524 
00527         static InDevice * GetDevice(int id);
00528         
00529 protected:
00530         static void AppendToDeviceList (InDevice * dev);
00531         static void RemoveFromDeviceList (InDevice * dev);
00532         static void TruncateDeviceList (InDevice * dev);
00533 };
00534 
00535 class CurrentTimer: public wxStopWatch
00536 {
00537 public:
00538         CurrentTimer(long t = 0):wxStopWatch()
00539         {
00540                 Start(t);
00541         }
00542         
00543         virtual ~CurrentTimer() {}
00544 
00545         void Set(long t = 0)
00546         {
00547                 Start(t);
00548         }
00549 
00550         CurrentTimer& operator = (long t)
00551         {
00552                 Start(t);
00553                 return * this;
00554         }
00555 
00556         virtual void  Notify() 
00557         {
00558                 STUBC;
00559         }
00560 
00561         operator unsigned int ()
00562         {
00563                 return (unsigned int) Time();
00564         }
00565         
00566         operator long ()
00567         {
00568                 return Time();
00569         }
00570 };
00571 
00572 extern CurrentTimer CurrentTime;
00573 
00574 void StartCurrentTime();
00575 
00576 void StopCurrentTime();
00577 
00578 // functions --------------------------------------------------------
00579 
00580 
00581 
00582 void OutNotesCorrect(int box);
00583 
00584 bool OutOpen();
00585 
00586 void OutClose();
00587 
00588 void OutAddTime(frac time);
00589 
00590 bool InOpen();
00591 
00592 void InClose();
00593 
00594 bool NeedsRealTime();
00595 
00596 //frac InReadOn(frac time);
00597 
00598 void MidiOut(int box, DWORD data, char n = -1);
00599 
00600 void NotesCorrect(int box);
00601 
00602 int GetChannel(int box, int taste);
00603 
00604 #endif
00605 
00606 /*
00607  * \}
00608  */

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