Route.cpp
gehe zur Dokumentation dieser Datei
00001 // -*- C++ -*-
00048 #ifdef HAVE_CONFIG_H
00049 #include "config.h"
00050 #endif
00051 
00052 #include "Route.h"
00053 #include "Device.h"
00054 
00055 // Route ------------------------------------------------------------
00056 
00057 int Route::maxRouteId = 1;
00058 
00059 WATCHEDPTR(Route,routing,Route) Route::routeList(NULL,_T("Route::routeList"));
00060 
00061 const mutString RTName[] =
00062 {
00063 _T("ALL"), _T("ELSE"), _T("CHANNEL"), _T("STAFF")
00064 };
00065 
00066 void Route::Save(tree_storage & config) 
00067 {
00068         config.Write(_T("Box"),Box);
00069         config.Write(_T("Active"),Active);
00070         if (In)
00071                 ((InDevice *)In)->Save(config,this);
00072         if (Out)
00073                 ((OutDevice *) Out)->Save(config,this);
00074 }
00075 
00076 void Route::Load(tree_storage & config) 
00077 {
00078         Box = config.Read(_T("Box"),NoBox);
00079         Active = config.Read(_T("Active"),true);
00080         if (In)
00081                 ((InDevice *) In)->Load(config,this);
00082         if (Out)
00083                 ((OutDevice *) Out)->Load(config,this);
00084 }
00085 
00086 
00087 void Route::InitializeIds() 
00088 {
00089         OutDevice::InitializeIds();
00090         int i = 0;
00091         Route * route = GetRouteList();
00092         while (route) {
00093                 route -> Id = i++;
00094                 route -> inputid = -1;
00095                 Device * d =  static_cast<Device *>(route->GetOutDevice());
00096                 route -> outputid = d ? d ->GetId(): -1 ;
00097                 route=route->GetGlobalNext();
00098         }
00099         InDevice::InitializeIds();
00100 }
00101 
00102 void Route::SaveRoutes(tree_storage & config) 
00103 {
00104         config.toLeaf(_T("Routes"));
00105         
00106         for (Route * route = GetRouteList(); route; route = route->GetGlobalNext()) {
00107                 config.toLeaf(_T("Route"),route->GetId());
00108                 config.Write(_T("Input Device"), route->inputid);
00109                 config.Write(_T("Output Device"), route->outputid);
00110                 route -> Save (config);
00111                 config.toParent();
00112         }
00113         
00114         config.toParent();      
00115 }
00116 
00117 void Route::LoadRoutes(tree_storage & config) 
00118 {
00119         config.toLeaf(_T("Routes"));
00120         
00121         int i = config.toFirstLeaf(_T("Route"));
00122         while (i != wxNOT_FOUND) {
00123                 DEBUGLOGTYPE(config,Route,_T("Loading route with id %d."), i);
00124                 // \todo replace -1 by a correct default
00125                 int inputid = config.Read(_T("Input Device"), -1);
00126                 int outputid = config.Read(_T("Output Device"), -1);
00127                 InDevice * in = InDevice::GetDevice(inputid);
00128                 OutDevice * out = OutDevice::GetDevice(outputid);
00129                 Route * route = new Route(in,out);
00130                 if (in && route)
00131                         in->AddRoute(route);
00132                 if (route)
00133                         route -> Load(config);
00134                 i = config.toNextLeaf(_T("Route"));
00135         }
00136         
00137         config.toParent(2);
00138 }
00139 
00140 
00141 void Route::AppendToRouteList (Route * route) 
00142 {
00143         if (!routeList) {
00144                 routeList = route; 
00145                 return;
00146         }
00147         
00148         Route * r = routeList ;
00149         Route * r2;
00150         while ((r2 = r->globalNext)) {
00151                 wxASSERT(r != route);
00152                 r = r2;
00153         }
00154         r->globalNext = route;
00155 }
00156 
00157 void Route::RemoveFromRouteList (Route * route) 
00158 {
00159         if (!routeList) return;
00160         
00161         if (routeList == route) {
00162                 routeList = route -> globalNext; 
00163                 route -> globalNext = NULL;
00164                 return;
00165         }
00166         
00167         Route * d = routeList;
00168         while (d -> globalNext != route && d -> globalNext) d = d -> globalNext;
00169         if (d -> globalNext) {
00170                 d -> globalNext = (route -> globalNext);
00171                 route -> globalNext = NULL;
00172         }
00173 }
00174 
00175 const mutString DevTypeName[] =
00176 {
00177 N_("Unknown"),
00178 N_("Midi Port"),
00179 N_("Midi File"),
00180 N_("GUIDO .gmn File")
00181 };
00182 
00183 #define READCONFIGSTR(config,name,variable,defval) \
00184         variable = config.Read(_T(name),defval); \
00185         DEBUGLOG2(config,_T("Read " name " = %s"),variable.c_str());
00186 
00187 #define READCONFIGINT(config,name,variable,defval) \
00188         variable = config.Read(_T(name),defval); \
00189         DEBUGLOG2(config,_T("Read " name " = %d"),variable);
00190 
00191 
00192 #if 0
00193 void LoadRoutes(tree_storage & config)
00194 {
00195         DEBUGLOG2(config,_T("Loading routes."));
00196         
00197         if (! config.HasGroup(_T("Input")) && !config.HasGroup(_T("Output"))) return;
00198         
00199         // clear device lists
00200         InDevice * InDevices = InDevice::GetDeviceList();
00201         if ( InDevices ) {
00202                 delete InDevices;
00203                 InDevices = NULL;
00204         }
00205         
00206         Route * Routes = Route :: GetRouteList();
00207         if (Routes) {
00208                 delete Routes;
00209                 Routes = NULL;
00210         }
00211         
00212         OutDevice * OutDevices = OutDevice::GetDeviceList();
00213         if ( OutDevices ) {
00214                 delete OutDevices;
00215                 OutDevices = NULL;
00216         }
00217         
00218         // Zerlegen von config
00219         
00220         wxString group;
00221         
00222         wxString defaultPortName = rtmidiout->getPortCount()?
00223         muT(rtmidiout->getPortName(0).c_str()):wxString(_("Unknown"));
00224         
00225         long group_number;
00226         
00227         // read output devices
00228         config.toLeaf(_T("Output"));
00229         DEBUGLOG2(config,_T("Path: %s"),config.GetPath().c_str());
00230         
00231         group_number = config.toFirstLeaf(_T("Device"));
00232         
00233         for (bool test = true; // we have a default output device
00234              test; test = wxNOT_FOUND != (group_number = config.toNextLeaf(_T("Device")))) {
00235                 DEBUGLOG2(config,_T("Path: %s"),config.GetPath().c_str());
00236                 wxString name;
00237                 long type, id;
00238                 READCONFIGSTR(config,"Name",name,defaultPortName);
00239 
00240                 READCONFIGINT(config,"Type",type,1);            
00241                 if (type <= 0 || type >= DeviceMaxType) {
00242                         // Bad device type; try to recover
00243                         wxString type_name;
00244                         READCONFIGSTR(config,"Type_Name",type_name, _("Midi Port"));
00245                         
00246                         int i;
00247                         
00248                         for (i = 1; i < DeviceMaxType; i++)
00249                                 if (wxGetTranslation(DevTypeName[i]) == type_name) break;
00250                         
00251                         if (i == DeviceMaxType) type = 0;
00252                         else type = i;
00253                 }
00254                 
00255                 READCONFIGINT(config,"Device_Id", id, 0);
00256                 
00257                 Device *out = OutDevice::CreateDevice((DevType) type, name, id);
00258                 if (!out) {
00260                         STUB;
00261                 }
00262                 wxString cwd = config.GetPath();
00263                 out->Load(config);
00264         }
00265         
00266         config.toParent(2);
00267         DEBUGLOG2(config,_T("Path: %s"),config.GetPath().c_str());
00268         
00269         // read input devices
00270         config.toLeaf(_T("Input"));
00271         DEBUGLOG2(config,_T("Path: %s"),config.GetPath().c_str());
00272         group_number = config.toFirstLeaf(_T("Device"));
00273         
00274         for (bool test = true; // we have a default output device
00275              test; test = wxNOT_FOUND != (group_number = config.toNextLeaf(_T("Device")))) {
00276                 DEBUGLOG2(config,_T("Path: %s"),config.GetPath().c_str());
00277                 
00278                 wxString name;
00279                 long type, id;
00280                 READCONFIGSTR(config,"Name",name, defaultPortName);
00281                 
00282                 READCONFIGINT(config,"Type",type, 1);
00283                 
00284                 
00285                 if (type <= DTUnknown || type >= DeviceMaxType) {
00286                         // Bad device type; try to recover
00287                         wxString type_name;
00288                         READCONFIGSTR(config,"Type_Name",type_name, _("Midi Port"));
00289                         
00290                         
00291                         int i;
00292                         
00293                         for (i = 1; i < DeviceMaxType; i++)
00294                                 if (wxGetTranslation(DevTypeName[i]) == type_name) break;
00295                         
00296                         if (i == DeviceMaxType) {
00297                                 i = 0;
00298                                 STUB;
00299                         }
00300                 }
00301                 
00302                 READCONFIGINT(config,"Device_Id",id, 0);
00303                 
00304                 InDevice *in = InDevice::CreateDevice((DevType) type, name, id);
00305                 
00306                 config.toLeaf(_T("Routes"));
00307                 DEBUGLOG2(config,_T("Path: %s"),config.GetPath().c_str());
00308                 wxString route_group;
00309                 long route_iterator;
00310                 route_iterator = config.toFirstLeaf(_T("Route"));
00311                 
00312                 for (bool test2 = true; // we need a default route
00313                      test2; test2 = wxNOT_FOUND != (route_iterator = config.toNextLeaf(_T("Route")))) {
00314                         DEBUGLOG2(config,_T("Path: %s"),config.GetPath().c_str());
00315                         
00316                         long type;
00317                         
00318                         READCONFIGINT(config,"Type",type, 0);
00319                         
00320                         if (type < 0 || type > 3) {
00321                                 
00322                                 // Route type; try to recover
00323                                 wxString type_name;
00324                                 READCONFIGSTR(config,"Type_Name", type_name, _("Midi Port"));
00325                                 int i;
00326                                 
00327                                 for (i = 1; i < 4; i++)
00328                                         if (muT(RTName[i]) == type_name) break;
00329                                 
00330                                 if (i == 4) type = 0;
00331                                 else type = i;
00332                         }
00333                         
00334                         long IFrom, ITo, Box, Active, OutDev, OFrom, OTo, ONoDrum;
00335                         
00336                         READCONFIGINT(config,"Input_from",IFrom, 0);
00337                         READCONFIGINT(config,"Input_to",ITo, 0);
00338                         READCONFIGINT(config,"Box",Box, 0);
00339                         READCONFIGINT(config,"Active",Active, 1);
00340                         READCONFIGINT(config,"Output_device",OutDev, 0);
00341                         READCONFIGINT(config,"Output_from",OFrom, 0);
00342                         READCONFIGINT(config,"Output_to",OTo, 15);
00343                         READCONFIGINT(config,"No_Drum",ONoDrum, 1);
00344                         
00345                         in->AddRoute(new Route((RouteType) type, IFrom, ITo, Box, Active,
00346                                                OutDevice::Get(OutDev), in, OFrom, OTo, ONoDrum));
00347                         
00348                         DEBUGLOG2(config,_T("Path: %s"),config.GetPath().c_str());
00349                 }
00350 
00351                 config.toParent(2);
00352                 DEBUGLOG2(config,_T("Path: %s"),config.GetPath().c_str());
00353         }
00354         
00355         config.toParent();
00356         DEBUGLOG2(config,_T("Path: %s"),config.GetPath().c_str());
00357         
00358 }
00359 #endif
00360 
00361 
00362 void LoadRoutes(tree_storage & config)
00363 {
00364         config.toLeaf(_T("Routing"));
00365         
00366         InDevice::LoadDevices(config);
00367         OutDevice::LoadDevices(config);
00368         Route::LoadRoutes(config);
00369         
00370         config.toParent();
00371 }
00372 
00373 void  SaveRoutes(tree_storage & config)
00374 {
00375         config.DeleteGroup(_T("Routing"));
00376         
00377         config.toLeaf(_T("Routing"));
00378         
00379         // clean configuration
00380         // delete unused output devices
00381         Route::InitializeIds();
00382         
00383         InDevice::SaveDevices(config);
00384         OutDevice::SaveDevices(config);
00385         Route::SaveRoutes(config);
00386         
00387         config.toParent();
00388 }
00389 
00390 
00391 /*
00392  * \}
00393  */
00394 

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