EDevice.cpp
gehe zur Dokumentation dieser Datei
00001 
00028 // ------------------------------------------------------------------
00029 // Mutabor 3, 1998, R.Krauße
00030 // Oberflächen Devices
00031 // ------------------------------------------------------------------
00032 
00033 #include <stdio.h>
00034 #include <stdlib.h>
00035 
00036 #include "EDevice.h"
00037 #include "DevMidi.h"
00038 
00039 
00040 
00041 EDevice *InEDevices = 0;
00042 EDevice *OutEDevices = 0;
00043 
00044 // EDevice ----------------------------------------------------------
00045 
00046 ERoute *EDevice::GetRoute(int nr)   // Nummern beginnen mit 0
00047 {
00048         for (ERoute *R = Routes; R; R = R->Next) {
00049                 if ( !nr ) return R;
00050                 nr--;
00051         }
00052         return 0;
00053 }
00054 
00055 // Anzahl der Routen
00056 int EDevice::nRoutes()
00057 {
00058         int n = 0;
00059         for (ERoute *R = Routes; R; R = R->Next)
00060                 n++;
00061         return n;
00062 }
00063 
00064 // Neue Route am Ende anh‰ngen (damit RTelse O.K. geht)
00065 void EDevice::AddRoute(ERoute *route)
00066 {
00067         ERoute **R = &Routes;
00068         while ( *R )
00069                 R = &(*R)->Next;
00070         *R = route;
00071 }
00072 
00073 wxString EDevice::GetName()
00074 {
00075         wxString s = Name;
00076         s.Replace(_T(" "), _T("_"));
00077         return s;
00078 }
00079 
00080 // Hilfe f¸r Verkettung: Wenn Outger‰t gekillt wird,
00081 // sollten die Verweise in den Routen verbogen werden
00082 
00083 void ChangeOutReferences(EDevice *from, EDevice *to)
00084 {
00085         for (EDevice *In = InEDevices; In; In = In->Next)
00086                 for (ERoute *R = In->Routes; R; R = R->Next)
00087                         if ( R->Out == from )
00088                                 R->Out = to;
00089 }
00090 
00091 // Verkettung in den Listen -----------------------------------------
00092 
00093 // fügt neues Device in Liste,
00094 // wenn Device schon existiert, dann wird nicht neu eingefügt
00095 // oldPos wird entfernt
00096 // einfügen auf newPos
00097 // bei dt == -1 und keinem newPlace wird nur gelöscht
00098 EDevice* NewDevice(EDevice **List,
00099                    DevType dt,
00100                    
00101                    const wxString& name,
00102                    int devId,
00103                    EDevice *oldPos,
00104                    EDevice *newPos)
00105 {
00106         DEBUGLOG2(routing,_T("(%x, %d, %s, %x, %x)"), List, dt, (name.c_str()), oldPos,  newPos);
00107         // Position finden zum Daten abladen
00108         EDevice *Pos = 0;
00109         ERoute *R = 0;
00110         
00111         if ( oldPos == newPos && oldPos ) {
00112                 Pos = oldPos;
00113                 Pos->DT = dt;
00114 #ifdef WX
00115                 Pos->Name = name;
00116 #else
00117                 strcpy(Pos->Name, name);
00118 #endif
00119                 Pos->DevId = devId;
00120                 Pos->Mode = MutaborDeviceUnregistered;
00121         } else {
00122                 if ( oldPos ) {
00123                         // Position von oldPos als Adresse finden
00124                         EDevice **PreOldPos = List;
00125                         
00126                         for (;*PreOldPos; PreOldPos = &((*PreOldPos)->Next))
00127                                 if ( *PreOldPos == oldPos )
00128                                         break;
00129                         
00130                         // oldPos löschen, Routen retten
00131                         R = oldPos->Routes;
00132 
00133                         oldPos->Routes = 0;
00134                         
00135                         *PreOldPos = (*PreOldPos)->Next;
00136                         
00137                         oldPos->Next = 0;
00138                         
00139                         delete oldPos;
00140                 }
00141 
00142                 // evtl. nur löschen
00143                 if ( dt == -1 ) {
00144                         if ( R )
00145                                 delete R;
00146 
00147                         return 0;
00148                 }
00149 
00150                 // Position von newPos als Adresse finden
00151                 EDevice **PreNewPos = List;
00152 
00153                 for (;*PreNewPos; PreNewPos = &((*PreNewPos)->Next))
00154                         if ( *PreNewPos == newPos )
00155                                 break;
00156 
00157                 // Device einfügen
00158                 Pos = new EDevice(dt, name, devId);
00159                 Pos->Routes = R;
00160                 Pos->Next = *PreNewPos;
00161                 *PreNewPos = Pos;
00162         }
00163         
00164         // Testen, ob Device schon so existiert
00165         for (EDevice **Dev = List ; *Dev; Dev = &((*Dev)->Next))
00166                 if ( *Dev != Pos &&
00167                     (*Dev)->DT == dt && (
00168 #ifdef WX
00169                                          ( !(*Dev)->Name.Cmp(name) ) ||
00170 #else
00171                                          ( !strcmp((*Dev)->Name, name) ) ||
00172 #endif
00173                                          ( dt == DTMidiPort && (*Dev)->DevId == devId ) ) ) {
00174                         // doppeltes Device gefunden, Routen ¸bertragen und lˆschen
00175                         EDevice *Dev1 = *Dev;
00176                         
00177                         if ( Dev1->Routes ) {
00178                                 Pos->AddRoute(Dev1->Routes);
00179                                 Dev1->Routes = 0;
00180                         }
00181                     
00182                         *Dev = Dev1->Next;
00183 
00184                         Dev1->Next = 0;
00185                         ChangeOutReferences(Dev1, Pos);
00186                         delete Dev1;
00187                         break;
00188                 }
00189         return Pos;
00190 }
00191 
00192 // Scannen und schreiben der Routen als Streams ---------------------
00193 
00194 // Hilfsfunktionen --------------------------------------------------
00195 
00196 #ifndef WX
00197 DevType Str2DT(char *type)
00198 {
00199         char *DTName[] =  { "", "MIDIPORT", "MIDIFILE", "GMN" };
00200         int i;
00201 
00202         for (i = 3; i > 0; i--)
00203                 if ( !strncmp(type, DTName[i], strlen(DTName[i])) )
00204                         break;
00205         
00206         return (DevType)i;
00207 }
00208 
00209 #else
00210 DevType Str2DT(const wxString& type)
00211 {
00212         wxString DTName[] =  { _T(""), _T("MIDIPORT"), _T("MIDIFILE"), _T("GMN") };
00213         int i;
00214         DEBUGLOG2(other,_T("Comparing %s"),type.c_str());
00215         
00216         for (i = 3; i > 0; i--) {
00217                 DEBUGLOG2(other,_T("Testing %s"), DTName[i].c_str() );
00218                 
00219                 if ( type.StartsWith(DTName[i]) )
00220                         break;
00221         }
00222         
00223         return (DevType)i;
00224 }
00225 
00226 #endif
00227 
00228 
00229 
00231 
00235 RouteType Str2RT(mutChar *type)
00236 {
00237         int i;
00238         
00239         for (i = 3; i > 0; i--)
00240                 if
00241 #ifndef WX
00242                         ( !strncmp(type, RTName[i], strlen(RTName[i])) )
00243 #else
00244                         ( !wxStricmp(type, RTName[i])) //, strlen(RTName[i])) )
00245 #endif
00246                         break;
00247 
00248         return (RouteType) i;
00249 }
00250 
00251 EDevice *GetEOut(int nr)
00252 {
00253         if ( nr < 0 )
00254                 return 0;
00255 
00256         EDevice *Out = OutEDevices;
00257         while ( Out && nr ) {
00258                 Out = Out->Next;
00259                 nr--;
00260                     }
00261         return Out;
00262 }
00263 
00264 #if defined(WX)
00265 
00266 // aus p eine Zeile in s lesen, i wird verschoben
00267 
00268 bool GetELine(const wxString& p, size_t& i, wxString &s)
00269 {
00270         size_t l = p.Length();
00271 start:
00272         if ( i >= l )
00273                 return false;
00274         while ( i < l && wxString(_T(" \t\n\r")).Find(p.GetChar(i)) != -1 )
00275                 i++;
00276         if ( i >= l )
00277                 return false;
00278         size_t i1 = i;
00279         int i2 = p.find(_T("\n"), i1);
00280         if ( i2 == -1 ) {
00281                 i = l;
00282                 s = p.Mid(i1);
00283         } else {
00284                 s = p.Mid(i1, i2-i1);
00285                 i = (size_t) i2;
00286         }
00287 
00288         s = s.Trim();
00289         if ( s.Length() == 0 || s.StartsWith(_T("#")) )
00290                 goto start;
00291 
00292         return true;
00293 }
00294 
00295 #define GETLINE \
00296 if ( !GetELine(config, i, s) ) \
00297 return
00298 
00299 // Routen scannen
00300 void ScanRoutes(const wxString& config)
00301 {
00303         DEBUGLOG2(routing,_T(""));
00304         STUB;
00305         return;
00306         
00307         // emty lists
00308         if ( InEDevices ) {
00309                 delete InEDevices;
00310                 InEDevices = 0;
00311         }
00312         if ( OutEDevices ) {
00313                 delete OutEDevices;
00314                 OutEDevices = 0;
00315         }
00316 
00317         // Zerlegen von config
00318         wxString s;
00319         size_t i = 0;
00320         GETLINE;
00321         
00322         DEBUGLOG2(routing,_T("+%s"),s.c_str());
00323         
00324         while ( !s.StartsWith(_T("OUTPUT")) ) {
00325                 GETLINE;
00326                 DEBUGLOG2(other,_T("+%s"),s.c_str());
00327         }
00328         
00329         GETLINE;
00330         DEBUGLOG2(routing,_T("+%s"),s.c_str());
00331         // Output lesen
00332         while ( !s.StartsWith(_T("INPUT")) ) {
00333                 wxChar Type[80], Name[400];
00334                 //wxString Type, Name;
00335                 int DevId, BendingRange;
00336 
00337                 DEBUGLOG2(routing,_T("a%s"),s.c_str());
00338 #if (wxUSE_UNICODE || wxUSE_WCHAR_T)
00339                 int test = SSCANF(s.c_str(), _T("%ls \"%l[^\"]\" %d %d"),
00340                                   Type, Name, &DevId, &BendingRange);
00341                 if ( test < 2 )
00342                         test = SSCANF(s.c_str(), _T("%ls %ls %d %d"),
00343                                       Type, Name, &DevId, &BendingRange);
00344                 if ( test < 2 ) {
00345                         //3 ??
00346                 }
00347 #else
00348                 int test = SSCANF(s.c_str(), _T("%s \"%[^\"]\" %d %d"),
00349                                   Type, Name, &DevId, &BendingRange);
00350                 if ( test < 2 )
00351                         test = SSCANF(s.c_str(), _T("%s %s %d %d"),
00352                                       Type, Name, &DevId, &BendingRange);
00353                 if ( test < 2 ) {
00354                         //3 ??
00355                 }
00356 #endif
00357                 DEBUGLOG2(routing,_T("Name = '%s'"),(wxString(Name).c_str()));
00358                 EDevice *Out = NewDevice(&OutEDevices, Str2DT(muT(Type)), Name, DevId);
00359 
00360                 if ( test == 4 )
00361                         Out->BendingRange = BendingRange;
00362                 GETLINE;
00363                 DEBUGLOG2(other,_T("+%s"),s.c_str());
00364         }
00365 
00366         GETLINE;
00367         DEBUGLOG2(routing,_T("+%s"),s.c_str());
00368         // Input lesen
00369 
00370         while ( 1 ) {
00371                 // Device lesen
00372                 wxChar Type[40], Name[400];
00373                 //wxString Type, Name;
00374                 int DevId = -1;
00375 #if (wxUSE_UNICODE || wxUSE_WCHAR_T)
00376                 int test = SSCANF(s, _T("%ls \"%l[^\"]\" %d"),
00377                                   Type, Name, &DevId);
00378                 if ( test < 2 )
00379                         test = SSCANF(s, _T("%ls %ls %d"),
00380                                       Type, Name, &DevId);
00381                 if ( test < 2 ) {
00382                         //3 ??
00383                 }
00384 
00385 #else
00386                 int test = SSCANF(s, _T("%s \"%[^\"]\" %d"),
00387                                   Type, Name, &DevId);
00388                 if ( test < 2 )
00389                         test = SSCANF(s, _T("%s %s %d"),
00390                                       Type, Name, &DevId);
00391                 if ( test < 2 ) {
00392                         //3 ??
00393                 }
00394 
00395 #endif
00396                     EDevice *In = NewDevice(&InEDevices, Str2DT(muT(Type)), Name, DevId);
00397                 GETLINE;
00398                 DEBUGLOG2(routing,_T("+%s"),s.c_str());
00399 
00400                 // Routen lesen
00401                 while ( Str2DT(s) == DTUnknown ) {
00402                         // Route lesen
00403                         wxChar Type[40];
00404                         int IFrom = 0, ITo = 0, Box = 0, BoxActive = 0,
00405                                                       OutDev = -1, OFrom = -1, OTo = -1, ONoDrum = 1;
00406 #if (wxUSE_UNICODE || wxUSE_WCHAR_T)
00407                         test = SSCANF(s.c_str(),
00408                                       _T("%ls %d %d %d %d %d %d %d %d"),
00409                                       Type, &IFrom, &ITo, &Box, &BoxActive,
00410                                       &OutDev, &OFrom, &OTo, &ONoDrum);
00411 
00412                         if ( test < 2 ) {
00413                                 //3 ??
00414                         }
00415 
00416 #else
00417                         test = SSCANF(s.c_str(),
00418                                       _T("%s %d %d %d %d %d %d %d %d"),
00419                                       Type, &IFrom, &ITo, &Box,
00420                                       &BoxActive, &OutDev, &OFrom, &OTo,
00421                                       &ONoDrum);
00422 
00423                         if ( test < 2 ) {
00424                                 //3 ??
00425                         }
00426 
00427 #endif
00428                         In->AddRoute(new ERoute(Str2RT(Type),
00429                                                 IFrom, ITo, Box,
00430                                                 BoxActive, GetEOut(OutDev),
00431                                                 OFrom, OTo, ONoDrum));
00432                         GETLINE;
00433                         DEBUGLOG2(routing,_T("+%s"),s.c_str());
00434                 }
00435         }
00436 }
00437 
00438 
00439 /* old default routing file:
00440 OUTPUT
00441   MIDIPORT MIDIPORT_OUT 0 2
00442 INPUT
00443   MIDIPORT MIDIPORT_IN 0
00444     ALL 0 0 0 1 0 0 15
00445  */
00446 // Routen scannen
00447 void ScanERoutes(wxConfigBase * config)
00448 {
00449         if (! config->HasGroup(_T("Input"))) return;
00450 
00451         // clear device lists
00452         if ( InEDevices ) {
00453                 delete InEDevices;
00454                 InEDevices = 0;
00455         }
00456 
00457         if ( OutEDevices ) {
00458                 delete OutEDevices;
00459                 OutEDevices = 0;
00460         }
00461 
00462         // Zerlegen von config
00463 
00464         wxString group;
00465 
00466         wxString defaultPortName = rtmidiout->getPortCount()?
00467                                    muT(rtmidiout->getPortName(0).c_str()):wxString(_("Unknown"));
00468 
00469         long group_number;
00470 
00471         // read output devices
00472         config->SetPath(_T("Output"));
00473 
00474         config->GetFirstGroup(group,group_number);
00475 
00476         for (bool test = true; // we have a default output device
00477                         test; test = config->GetNextGroup(group,group_number)) {
00478                 config->SetPath(group);
00479                 wxString name;
00480                 long type, id;
00481                 config->Read(_T("Name"), &name, defaultPortName);
00482 
00483                 config->Read(_T("Type"), &type, 1);
00484 
00485                 if (type <= 0 || type >= DeviceMaxType) {
00486                         // Bad device type; try to recover
00487                         wxString type_name;
00488                         config->Read(_T("Type_Name"), &type_name, _("Midi Port"));
00489 
00490                         int i;
00491 
00492                         for (i = 1; i < DeviceMaxType; i++)
00493                                 if (wxGetTranslation(DevTypeName[i]) == type_name) break;
00494 
00495                         if (i == DeviceMaxType) type = 0;
00496                         else type = i;
00497                 }
00498 
00499                 config->Read(_("Device_Id"), &id, 0);
00500 
00501                 EDevice *out = NewDevice(&OutEDevices, (DevType) type, name, id);
00502                 if (!out) abort();
00503                 out->BendingRange = config->Read(_("Bending_Range"),
00504                                                  (long)out->BendingRange);
00505 
00506                 config->SetPath(_T(".."));
00507         }
00508 
00509         config->SetPath(_T(".."));
00510 
00511         // read input devices
00512         config->SetPath(_T("Input"));
00513         config->GetFirstGroup(group,group_number);
00514 
00515         for (bool test = true; // we have a default output device
00516                         test; test = config->GetNextGroup(group,group_number)) {
00517                 config->SetPath(group);
00518 
00519                 wxString name;
00520                 long type, id;
00521                 config->Read(_T("Name"), &name, defaultPortName);
00522 
00523                 config->Read(_T("Type"), &type, 1);
00524 
00525                 if (type <= DTUnknown || type >= DeviceMaxType) {
00526                         // Bad device type; try to recover
00527                         wxString type_name;
00528                         config->Read(_T("Type_Name"), &type_name, _("Midi Port"));
00529 
00530                         int i;
00531 
00532                         for (i = 1; i < DeviceMaxType; i++)
00533                                 if (wxGetTranslation(DevTypeName[i]) == type_name) break;
00534 
00535                         if (i == DeviceMaxType) i = 0;
00536                 }
00537 
00538                 config->Read(_("Device_Id"), &id, 0);
00539 
00540                 EDevice *in = NewDevice(&InEDevices, (DevType) type, name, id);
00541 
00542                 config->SetPath(_T("Routes"));
00543                 wxString route_group;
00544                 long route_iterator;
00545                 config->GetFirstGroup(route_group,route_iterator);
00546 
00547                 for (bool test2 = true; // we need a default route
00548                                 test2; test2 = config->GetNextGroup(route_group,route_iterator)) {
00549                         config->SetPath(route_group);
00550 
00551                         long type;
00552 
00553                         config->Read(_T("Type"), &type, 0);
00554 
00555                         if (type < 0 || type > 3) {
00556 
00557                                 // Route type; try to recover
00558                                 wxString type_name;
00559                                 config->Read(_T("Type_Name"), &type_name, _("Midi Port"));
00560                                 int i;
00561 
00562                                 for (i = 1; i < 4; i++)
00563                                         if (muT(RTName[i]) == type_name) break;
00564 
00565                                 if (i == 4) type = 0;
00566                                 else type = i;
00567                         }
00568 
00569                         long IFrom, ITo, Box, Active, OutDev, OFrom, OTo, ONoDrum;
00570 
00571                         config->Read(_T("Input_from"), &IFrom, 0);
00572                         config->Read(_T("Input_to"), &ITo, 0);
00573                         config->Read(_T("Box"), &Box, 0);
00574                         config->Read(_T("Active"), &Active, 1);
00575                         config->Read(_T("Output_device"), &OutDev, 0);
00576                         config->Read(_T("Output_from"), &OFrom, 0);
00577                         config->Read(_T("Output_to"), &OTo, 15);
00578                         config->Read(_T("No_Drum"), &ONoDrum, 1);
00579 
00580                         in->AddRoute(new ERoute((RouteType) type, IFrom, ITo, Box, Active,
00581                                                 GetEOut(OutDev), OFrom, OTo, ONoDrum));
00582 
00583                         config->SetPath(_T(".."));
00584                 }
00585 
00586                 config->SetPath(_T("../.."));
00587         }
00588 
00589         config->SetPath(_T(".."));
00590 
00591         ScanDevices();
00592 }
00593 
00594 #else // no WX
00595 
00596 // aus p eine Zeile in s lesen, p wird verschoben
00597 char GetELine(char **p, char *s)
00598 {
00599 
00600 start:
00601 
00602         if ( !p || !(*p)[0] )
00603                 return 0;
00604 
00605         while ( (*p)[0] == ' ' || (*p)[0] == '\n' || (*p)[0] == '\r' )
00606                 *p = &(*p)[1];
00607 
00608         if ( !(*p)[0] )
00609                 return 0;
00610 
00611         char *p1 = *p;
00612 
00613         *p = strchr(p1, '\n');
00614 
00615         if ( !p )
00616                 *p = &p1[strlen(p1)];
00617 
00618         while ( *p1 && strchr("\n\r\t ", *p1) )
00619                 p1 = &p1[1];
00620 
00621         int i = (*p)-p1;
00622 
00623         strncpy(s, p1, i);
00624 
00625         s[i] = 0;
00626 
00627         while ( i > 0 && strchr("\n\r\t ", s[i-1]) )
00628                 s[--i] = 0;
00629 
00630         if ( !s[0] || s[0] == '#' )
00631                 goto start;
00632 
00633         return 1;
00634 }
00635 
00636 #define GETLINE \
00637   if ( !GetELine(&p1, s) ) \
00638     return
00639 
00640 // Routen scannen
00641 void ScanRoutes(char *config)
00642 {
00643         // Listen s‰ubern
00644 
00645         if ( InEDevices ) {
00646                 delete InEDevices;
00647                 InEDevices = 0;
00648         }
00649 
00650         if ( OutEDevices ) {
00651                 delete OutEDevices;
00652                 OutEDevices = 0;
00653         }
00654 
00655         // Zerlegen von config
00656         char s[200], *p1 = config;
00657 
00658         GETLINE;
00659 
00660         while ( strncmp(s, "OUTPUT", 6) ) {
00661                 GETLINE;
00662         }
00663 
00664         GETLINE;
00665 
00666         // Output lesen
00667 
00668         while ( strncmp(s, "INPUT", 5) ) {
00669                 char Type[20], Name[200];
00670                 int DevId, BendingRange;
00671                 //    int test = sscanf (s, "%s %s %d %d", Type, Name,
00672                 //                     &DevId, &BendingRange);
00673                 int test = sscanf (s, "%s \"%[^\"]^^\" %d %d", Type, Name,
00674                                    &DevId, &BendingRange);
00675 
00676                 if ( test < 2 )
00677                         test = sscanf (s, "%s %s %d %d", Type, Name, &DevId, &BendingRange);
00678 
00679                 if ( test < 2 ) {
00680                         //3 ??
00681                 }
00682 
00683                 EDevice *Out = NewDevice(&OutEDevices, Str2DT(Type), Name, DevId);
00684 
00685                 if ( test == 4 )
00686                         Out->BendingRange = BendingRange;
00687 
00688                 GETLINE;
00689         }
00690 
00691         GETLINE;
00692 
00693         // Input lesen
00694 
00695         while ( 1 ) {
00696                 // Device lesen
00697                 char Type[20], Name[200];
00698                 int DevId = -1;
00699                 int test = sscanf (s, "%s \"%[^\"]\" %d", Type, Name, &DevId);
00700 
00701                 if ( test < 2 )
00702                         test = sscanf (s, "%s %s %d", Type, Name, &DevId);
00703 
00704                 if ( test < 2 ) {
00705                         //3 ??
00706                 }
00707 
00708                 EDevice *In = NewDevice(&InEDevices, Str2DT(Type), Name, DevId);
00709 
00710                 GETLINE;
00711                 // Routen lesen
00712 
00713                 while ( Str2DT(s) == DTUnknown ) {
00714                         // Route lesen
00715                         char Type[20];
00716                         int IFrom = 0, ITo = 0, Box = 0, BoxActive = 0, OutDev = -1, OFrom = -1, OTo = -1, ONoDrum = 1;
00717                         test = sscanf(s, "%s %d %d %d %d %d %d %d %d",
00718                                       Type, &IFrom, &ITo, &Box, &BoxActive, &OutDev, &OFrom, &OTo, &ONoDrum);
00719 
00720                         if ( test < 2 ) {
00721                                 //3 ??
00722                         }
00723 
00724                         In->AddRoute(new ERoute(Str2RT(Type), IFrom, ITo, Box, BoxActive, GetEOut(OutDev), OFrom, OTo, ONoDrum));
00725 
00726                         GETLINE;
00727                 }
00728         }
00729 }
00730 
00731 #endif
00732 
00733 #ifdef WX
00734 
00735 // Routen schreiben
00736 void WriteRoutes(wxString &config)
00737 {
00739         STUB;
00740         return;
00741         
00742         // clean config
00743         config = wxEmptyString;
00744         // remove unused output devices
00745         EDevice *Out;
00746         EDevice *In;
00747 
00748         for (Out = OutEDevices; Out; Out = Out->Next)
00749                 Out->Nr = 0;
00750 
00751         for (In = InEDevices; In; In = In->Next)
00752                 for (ERoute *R = In->Routes; R; R = R->Next)
00753                         if ( R->Out )
00754                                 R->Out->Nr = 1;
00755 
00756         Out = OutEDevices;
00757 
00758         while ( Out ) {
00759                 if ( !Out->Nr ) {
00760                         NewDevice(&OutEDevices, DTNotSet, _T(""), 0, Out, 0);
00761                         Out = OutEDevices;
00762                         continue;
00763                 }
00764 
00765                 Out = Out->Next;
00766         }
00767 
00768         // Output schreiben
00769         config << _T("OUTPUT\n");
00770 
00771         int nr = 0;
00772 
00773         for ( Out = OutEDevices; Out; Out = Out->Next) {
00774                 Out->Nr = nr++; // Nummerierung zur bequemen Referenzierung
00775                 // beim Input schreiben
00776                 wxString sName = Out->Name;
00777 
00778                 if ( sName.Find(_T(" ")) )
00779                         sName.Prepend(_T("\"")) << _T("\"");
00780 
00781                 switch ( Out->DT ) {
00782 
00783                 case DTUnknown:
00784                         config << wxString::Format(_T("  UNKNOWN %s\n"),
00785                                                    sName.c_str());
00786 
00787                         break;
00788 
00789                 case DTMidiPort:
00790                         config << wxString::Format(_T("  MIDIPORT %s %d %d\n"),
00791                                                    sName.c_str(), Out->DevId,
00792                                                    Out->BendingRange);
00793 
00794                         break;
00795 
00796                 case DTMidiFile:
00797                         config << wxString::Format(_T("  MIDIFILE %s %d %d\n"),
00798                                                    sName.c_str(), 0,
00799                                                    Out->BendingRange);
00800 
00801                         break;
00802 
00803                 case DTGis:
00804                         config << wxString::Format(_T("  GMN %s\n"), sName.c_str());
00805 
00806                         break;
00807 
00808                 case DTNotSet:
00809                         wxLogWarning(_("Device found, but device type not set."));
00810                 }
00811         }
00812 
00813         DEBUGLOG2(routing,_T("WriteConfig: %s"), (config.c_str()));
00814 
00815         // Input schreiben
00816         nr = 0;
00817         config << _T("INPUT\n");
00818 
00819         for ( In = InEDevices; In; In = In->Next) {
00820                 // Device schreiben
00821                 In->Nr = nr++; // Nummern zur Referenz bei Play/Stop
00822                 In->Mode = MutaborDeviceStop; // Mode auf "registriert" setzen
00823                 wxString sName = In->Name;
00824 
00825                 if ( sName.Find(_T(" ")) )
00826                         sName.Prepend(_T("\"")) << _T("\"");
00827 
00828                 switch ( In->DT ) {
00829 
00830                 case DTUnknown:
00831                         config << wxString::Format(_T("  UNKNOWN %s\n"), sName.c_str());
00832 
00833                         break;
00834 
00835                 case DTGis:
00836                         config << wxString::Format(_T("  GMN %s\n"), sName.c_str());
00837 
00838                         break;
00839 
00840                 case DTMidiPort:
00841                         config << wxString::Format(_T("  MIDIPORT %s %d\n"), sName.c_str(), In->DevId);
00842 
00843                         break;
00844 
00845                 case DTMidiFile:
00846                         config << wxString::Format(_T("  MIDIFILE %s\n"), sName.c_str());
00847 
00848                         break;
00849 
00850                 case DTNotSet:
00851                         wxLogWarning(_("Device found but device type not set."));
00852 
00853                         break;
00854                 }
00855 
00856                 // Routen schreiben
00857                 for (ERoute *R = In->Routes; R; R = R->Next) {
00858                         int OutNr = ( R->Out ) ?  R->Out->Nr : -1;
00859                         config << wxT("    ") << muT(RTName[R->Type]) <<
00860                         wxString::Format(_T(" %d %d  %d %d  %d  %d %d %d\n"),
00861                                          R->IFrom, R->ITo, R->Box, R->Active, OutNr,
00862                                          R->OFrom, R->OTo, R->ONoDrum ? 1 : 0);
00863                 }
00864         }
00865 
00866         DEBUGLOG2(routing,_T("WriteRoutes: %s"), (config.c_str()));
00867 }
00868 
00869 // Routen schreiben
00870 void WriteERoutes(wxConfigBase *config)
00871 {
00873         STUB;
00874         return;
00875         
00876         // clean configuration
00877         // delete unused output devices
00878         EDevice *Out;
00879         EDevice *In;
00880 
00881         for (Out = OutEDevices; Out; Out = Out->Next)
00882                 Out->Nr = 0;
00883 
00884         for (In = InEDevices; In; In = In->Next)
00885                 for (ERoute *R = In->Routes; R; R = R->Next)
00886                         if ( R->Out )
00887                                 R->Out->Nr = 1;
00888 
00889         Out = OutEDevices;
00890 
00891         while ( Out ) {
00892                 if ( !Out->Nr ) {
00893                         NewDevice(&OutEDevices, DTNotSet, _T(""), 0, Out, 0);
00894                         Out = OutEDevices;
00895                         continue;
00896                 }
00897 
00898                 Out = Out->Next;
00899         }
00900 
00901         config -> DeleteGroup(_T("Input"));
00902 
00903         config -> DeleteGroup(_T("Output"));
00904         // Output schreiben
00905         config -> SetPath(_T("Output"));
00906         int nr = 0;
00907 
00908         for ( Out = OutEDevices; Out; Out = Out->Next) {
00909                 Out->Nr = nr++;
00910                 // Nummerierung zur bequemen Referenzierung beim Input schreiben
00911                 DEBUGLOG2(other,_T("Trying to save output device Nr. %d"), Out->Nr);
00912                 config->SetPath(wxString(_T("")) << Out->Nr);
00913 
00914                 config->Write(_T("Name"), Out->Name);
00915 
00916                 mutAssertMsg((Out->DT >= 0) && (Out->DT < DeviceMaxType),
00917                              wxString(_("Internal Error: Forbidden output device type: ")) << Out->DT);
00918 
00919                 config->Write(_T("Type"), Out->DT);
00920                 config->Write(_T("Type_Name"), wxGetTranslation(DevTypeName[Out->DT]));
00921 
00922                 switch ( Out->DT ) {
00923 
00924                 case DTNotSet:
00925 
00926                 case DTUnknown:
00927 
00928                 case DTGis:
00929                         break;
00930 
00931                 case DTMidiPort:
00932                         config -> Write(_T("Device_Id"), Out->DevId);
00933 
00934                         config -> Write(_T("Bending_Range"), Out->BendingRange);
00935 
00936                         break;
00937 
00938                 case DTMidiFile:
00939                         config -> Write(_T("Device_Id"), 0);
00940 
00941                         config -> Write(_T("Bending_Range"), Out->BendingRange);
00942 
00943                         break;
00944                 }
00945 
00946                 config -> SetPath(_T(".."));
00947         }
00948 
00949         // Input schreiben
00950         nr = 0;
00951 
00952         config -> SetPath(_T("../Input"));
00953 
00954         for ( In = InEDevices; In; In = In->Next) {
00955                 // Device schreiben
00956                 In->Nr = nr++; // Nummern zur Referenz bei Play/Stop
00957 
00958                 DEBUGLOGBASE(other,"",
00959                              _T("Trying to save input device Nr. %d"),
00960                              In->Nr);
00961                 In->Mode = MutaborDeviceStop; // Mode auf "registriert" setzen
00962                 config->SetPath(wxString(_T("")) << In->Nr);
00963 
00964                 config->Write(_T("Name"), In->Name);
00965 
00966                 mutAssertMsg((In->DT >= 0) && (In->DT <= DeviceMaxType),
00967                              _("Internal Error: Forbidden input device type."));
00968 
00969                 config->Write(_T("Type"), In->DT);
00970                 DEBUGLOG2(other,_T("Type Name, "));
00971                 config->Write(_T("Type_Name"), wxGetTranslation(DevTypeName[In->DT]));
00972 
00973                 switch ( In->DT ) {
00974 
00975                 case DTNotSet:
00976 
00977                 case DTMidiFile:
00978 
00979                 case DTGis:
00980 
00981                 case DTUnknown:
00982                         break;
00983 
00984                 case DTMidiPort:
00985                         DEBUGLOG2(other,_T("Device Id "));
00986 
00987                         config -> Write(_T("Device_Id"), In->DevId);
00988 
00989                         break;
00990 
00991                 default:
00992                         wxLogError(_("Undefined device type %d."), In->DT);
00993                 }
00994 
00995                 config -> SetPath(_T("Routes"));
00996 
00997                 // Routen schreiben
00998                 int routenr=0;
00999 
01000                 for (ERoute *R = In->Routes; R; R = R->Next, routenr++) {
01001                         DEBUGLOG2(other,_T("Trying to save Route Nr: %d"), routenr);
01002                         config -> SetPath(wxString(_T("")) << routenr);
01003                         config -> Write(_T("Type"), R->Type);
01004                         config -> Write(_T("Type_Name"), muT(RTName[R->Type]));
01005                         config -> Write(_T("Input_from"),R->IFrom);
01006                         config -> Write(_T("Input_to"), R->ITo);
01007                         config -> Write(_T("Box"), R->Box);
01008                         config -> Write(_T("Active"), R->Active);
01009                         config -> Write(_T("Output_device"),
01010                                         ( R->Out ) ?  R->Out->Nr : -1 );
01011                         config -> Write(_T("Output_from"), R->OFrom);
01012                         config -> Write(_T("Output_to"), R->OTo);
01013                         config -> Write(_T("No_Drum"), R->ONoDrum);
01014                         config -> SetPath(_T(".."));
01015                 }
01016 
01017                 config -> SetPath(_T("..")); // Routes
01018 
01019                 config -> SetPath(_T("..")); // Input dev Counter
01020         }
01021 
01022         config -> SetPath(_T(".."));
01023 
01024         DEBUGLOG2(other,_T("Done."));
01025 }
01026 
01027 #else // no WX
01028 
01029 // Routen schreiben
01030 void WriteRoutes(char **config)
01031 {
01032         char *s = (char*) malloc(30000), s1[200];
01033         s[0] = 0;
01034         // config s‰ubern
01035 
01036         if ( *config )
01037                 free(*config);
01038 
01039         // Unbenˆtigte Out Devices entfernen
01040         EDevice *Out;
01041 
01042         EDevice *In;
01043 
01044         for (Out = OutEDevices; Out; Out = Out->Next)
01045                 Out->Nr = 0;
01046 
01047         for (In = InEDevices; In; In = In->Next)
01048                 for (ERoute *R = In->Routes; R; R = R->Next)
01049                         if ( R->Out )
01050                                 R->Out->Nr = 1;
01051 
01052         Out = OutEDevices;
01053 
01054         while ( Out ) {
01055                 if ( !Out->Nr ) {
01056                         NewDevice(&OutEDevices, DTNotSet, "", 0, Out, 0);
01057                         Out = OutEDevices;
01058                         continue;
01059                 }
01060 
01061                 Out = Out->Next;
01062         }
01063 
01064         // Output schreiben
01065         strcat(s, "OUTPUT\n");
01066 
01067         int nr = 0;
01068 
01069         for ( Out = OutEDevices; Out; Out = Out->Next) {
01070                 Out->Nr = nr++; // Nummerierung zur bequemen Referenzierung beim Input schreiben
01071                 char s2[200];
01072 
01073                 if ( strchr(Out->Name, ' ') )
01074                         sprintf(s2, "\"%s\"", Out->Name);
01075                 else
01076                         strcpy(s2, Out->Name);
01077 
01078                 switch ( Out->DT ) {
01079 
01080                 case DTUnknown:
01081                         sprintf(s1, "  UNKNOWN %s\n", s2);
01082 
01083                         break;
01084 
01085                 case DTMidiPort:
01086                         sprintf(s1, "  MIDIPORT %s %d %d\n", s2, Out->DevId, Out->BendingRange);
01087 
01088                         break;
01089 
01090                 case DTMidiFile:
01091                         sprintf(s1, "  MIDIFILE %s %d %d\n", s2, 0, Out->BendingRange);
01092 
01093                         break;
01094 
01095                 case DTGis:
01096                         sprintf(s1, "  GMN %s\n", s2);
01097 
01098                         break;
01099                 }
01100 
01101                 strcat(s, s1);
01102         }
01103 
01104         // Input schreiben
01105         nr = 0;
01106 
01107         strcat(s, "INPUT\n");
01108 
01109         for ( In = InEDevices; In; In = In->Next) {
01110                 // Device schreiben
01111                 In->Nr = nr++; // Nummern zur Referenz bei Play/Stop
01112                 In->Mode = 0; // Mode auf "registriert" setzen
01113                 char s2[200];
01114 
01115                 if ( strchr(In->Name, ' ') )
01116                         sprintf(s2, "\"%s\"", In->Name);
01117                 else
01118                         strcpy(s2,In->Name);
01119 
01120                 switch ( In->DT ) {
01121 
01122                 case DTUnknown:
01123                         sprintf(s1, "  UNKNOWN %s\n", s2);
01124 
01125                         break;
01126 
01127                 case DTGis:
01128                         sprintf(s1, "  GMN %s\n", s2);
01129 
01130                         break;
01131 
01132                 case DTMidiPort:
01133                         sprintf(s1, "  MIDIPORT %s %d\n", s2, In->DevId);
01134 
01135                         break;
01136 
01137                 case DTMidiFile:
01138                         sprintf(s1, "  MIDIFILE %s\n", s2);
01139 
01140                         break;
01141                 }
01142 
01143                 strcat(s, s1);
01144 
01145                 // Routen schreiben
01146 
01147                 for (ERoute *R = In->Routes; R; R = R->Next) {
01148                         int OutNr = ( R->Out ) ?  R->Out->Nr : -1;
01149                         sprintf(s1, "    %s  %d %d  %d %d  %d  %d %d %d\n",
01150                                 RTName[R->Type], R->IFrom, R->ITo, R->Box, R->Active, OutNr,
01151                                 R->OFrom, R->OTo, R->ONoDrum ? 1 : 0);
01152                         strcat(s, s1);
01153                 }
01154         }
01155 
01156         *config = strdup(s);
01157 
01158         free(s);
01159 }
01160 
01161 #endif
01162 
01163 // Boxes used
01164 
01165 bool BoxUsed[MAX_BOX];
01166 
01167 void CheckBoxesUsed()
01168 {
01169         for (int i = 0; i < MAX_BOX; i++)
01170                 BoxUsed[i] = false;
01171 
01172         for (EDevice *In = InEDevices; In; In = In->Next)
01173                 for (ERoute *R = In->Routes; R; R = R->Next)
01174                         if ( R->Box >= 0 )
01175                                 BoxUsed[R->Box] = true;
01176 }
01177 
01178 
01179 int SmallestBoxUsed()
01180 
01181 {
01182         int Box = 256;
01183 
01184         for (EDevice *In = InEDevices; In; In = In->Next)
01185                 for (ERoute *R = In->Routes; R; R = R->Next)
01186                         if ( R->Box >= 0 )
01187 #ifdef VC8
01188                                 Box = min(Box, R->Box);
01189 
01190 #else
01191                                 Box = STD_PRE::min(Box, R->Box);
01192 
01193 #endif
01194         if ( Box == 256 )
01195                 return 0;
01196         else
01197                 return Box;
01198 }
01199 
01200 void ScanDevices()
01201 {
01207         // clean device lists
01208         DEBUGLOG2(routing,_T(""));
01209 
01210         if ( InDevice::GetDeviceList() ) {
01211                 delete InDevice::GetDeviceList();
01212         }
01213 
01214         if ( OutDevice::GetDeviceList() ) {
01215                 delete OutDevice::GetDeviceList();
01216         }
01217 
01218         // handle output devices
01219         {
01220                 OutDevice *Out = OutDevice::GetDeviceList();
01221                 EDevice * oute = OutEDevices;
01222                 if (oute) {
01223                         Out = oute->newOutDevice();
01224                         for (oute = oute -> Next; oute ; oute = oute->Next) {
01225                                 DEBUGLOG2(other,_T("oute: %x"), oute);
01226                                 Out -> SetNext(oute->newOutDevice());
01227                                 Out = Out->GetNext();
01228                         }
01229                 }
01230         }
01231 
01232         // handle input devices
01233         for (EDevice * ine = InEDevices; ine ; ine = ine->Next) {
01234 
01235                 InDevice *In = ine->newInDevice();
01236                 DEBUGLOG2(other,_T("ine: %x; In: %x"), ine, In);
01237 
01238                 if (!In) continue; // Permit unknown devices
01239 
01241 
01242                 wxASSERT(In);
01243 
01244                 // handle routes
01245                 for (ERoute * routee = ine->Routes; routee; routee = routee->Next) {
01246                         DEBUGLOG2(other,_T("routee: %x"), routee);
01247                         Route * r = routee->newRoute();
01248                         wxASSERT(r);
01249                         DEBUGLOG2(other,_T("route: %x"), r);
01250                         In->AddRoute(r);
01251                 }
01252         }
01253 }
01254 

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