OutputDeviceShape.cpp
gehe zur Dokumentation dieser Datei
00001 // -*-C++ -*-
00002 
00094 #include "OutputDeviceShape.h"
00095 #include "OutputMidiDeviceShape.h"
00096 #include "OutputMidiFileDeviceShape.h"
00097 #include "OutputGuidoFileDeviceShape.h"
00098 #include "BoxChannelShape.h"
00099 #include "DevMidi.h"
00100 
00101 #if defined(__WXMAC__) && defined(__WXMAC_CARBON__)
00102 #       include "wx/mac/carbon/private.h"
00103 #endif
00104 
00105 IMPLEMENT_ABSTRACT_CLASS(MutOutputDeviceShape, MutDeviceShape)
00106 //MutOutputDeviceShape::stringmaptype MutOutputDeviceShape::stringmap;
00107 wxSizerFlags MutOutputDeviceShape::sizerFlags;
00108 
00109 bool MutOutputDeviceShape:: Create (wxWindow * parent, wxWindowID id, OutDevice * d)
00110 {
00111         device = d;
00112         if (!d) return false;
00113 
00114         d->setUserData (this);
00115 
00116         DEBUGLOG (other,_T ("Checking icon"));
00117         wxASSERT(MidiOutputDevBitmap.IsOk());
00118         
00119         return MutDeviceShape::Create (parent, id, d->GetName());
00120 }
00121 
00122 MutOutputDeviceShape * MutOutputDeviceShape::CreateShape(wxWindow * parent,
00123                                                        wxWindowID id,
00124                                                        OutDevice * d)
00125 {
00126         DEBUGLOGTYPE(routing,MutOutputDeviceShape,_T("Creating device shape"));
00127         wxASSERT (d);
00128         if (!d) return NULL;
00129 
00130         DEBUGLOGTYPE(routing,*d,_T("Device Type for device %p"), d);
00131         switch (d->GetType()) {
00132         case DTMidiPort:
00133                 DEBUGLOGTYPE(routing,MutOutputDeviceShape,
00134                              _T("Creating MIDI device shape"));
00135                 return new MutOutputMidiDeviceShape(parent,id,d);
00136         case DTMidiFile:
00137                 DEBUGLOGTYPE(routing,MutOutputDeviceShape,
00138                              _T("Creating MIDI  file device shape"));
00139                 return new MutOutputMidiFileDeviceShape(parent,id,d);
00140         case DTGis:
00141                 DEBUGLOGTYPE(routing,MutOutputDeviceShape,
00142                              _T("Creating MIDI  file device shape"));
00143                 return new MutOutputGuidoFileDeviceShape(parent,id,d);
00144         default:
00145                 return NULL; 
00146         }
00147 }
00148 
00149 void MutOutputDeviceShape::SetLabel(const wxString & st ) 
00150 {
00151         MutDeviceShape::SetLabel(st);
00152 }
00153 
00154 void MutOutputDeviceShape::AddRoute(Route * route) 
00155 {
00156         wxASSERT(route);
00157         wxASSERT(device);
00158         wxASSERT(route->GetOutDevice() == device);
00159         MutBoxChannelShape * channel = (MutBoxChannelShape *) route->getUserData();
00160         wxASSERT(dynamic_cast<MutIconShape *>(channel));
00161 
00162         // Check for duplicate route insertion.
00163         for (MutBoxChannelShapeList::const_iterator i = routes.begin() ; i != routes.end() ; i++) {
00164                 if ((*i)->GetRoute() == route) {
00165                         UNREACHABLEC; // maybe just STUB?
00166                         return;
00167                 }
00168         }
00169 
00170         if (channel) {
00171                 wxASSERT(channel->GetRoute()==route);
00172                 channel->SetOutput(this);
00173                 routes.push_back(channel);
00174         }
00175 }
00176 
00177 void MutOutputDeviceShape::RemoveRoute(Route * route)
00178 {
00179         wxASSERT(route);
00180         MutBoxChannelShape * channel = (MutBoxChannelShape *)route->getUserData();
00181         wxASSERT(dynamic_cast<MutBoxChannelShape *>(channel));
00182         wxASSERT(channel->GetRoute() == route);
00183         wxASSERT(channel->GetOutput() == this);
00184         
00185         channel->SetOutput(NULL, channel->GetOutput()==this);
00186         MutBoxChannelShapeList::iterator i;
00187         for (i = routes.begin(); i != routes.end(); i++) if (*i == channel) break;
00188 //      if (i == routes.end()) return;
00189         routes.erase(i);
00190 }
00191 
00192 
00193 void MutOutputDeviceShape::DoLeftDblClick() 
00194 {
00195         OutputDevDlg * out = ShowDeviceDialog();
00196         int Res = out->ShowModal();
00197         bool destroySelf = false;
00198 
00199         if (Res == wxID_OK) {
00200                 DevType type = out->GetType();
00201 
00202                 if (CanHandleType (type)) {
00203                         readDialog (out);
00204                 } else {
00205                         OutDevice * outdev = OutDevice::CreateDevice (type);
00206                         if (outdev) {
00207                                 DEBUGLOG (dialog, _T("%s"),outdev->TowxString().c_str());
00208                                 MutOutputDeviceShape * newdev = CreateShape (outdev);
00209                                 DEBUGLOG (dialog, _T(""));
00210                                 newdev -> readDialog (out);
00211                                 DEBUGLOG (dialog, _T(""));
00212                                 destroySelf = replaceSelfBy (newdev);
00213                                 DEBUGLOG (dialog, _T(""));
00214 
00215                                 m_parent->Layout();
00216                                 m_parent->FitInside();
00217                                 m_parent->SetVirtualSize(wxDefaultSize);
00218                                 m_parent->Refresh();
00219                         }
00220                 }
00221         } else if (Res == ::wxID_REMOVE) {
00222                 destroySelf = DetachDevice();
00223         }
00224 
00225         out->Destroy();
00226         DebugCheckRoutes();
00227 
00228         // Signalize to delete this control
00229         // Unfortunately WXMAC segfaults if we use Destroy(), here.
00230         if (destroySelf) DeleteSelf();
00231 }
00232 
00233 OutputDevDlg * MutOutputDeviceShape::ShowDeviceDialog() 
00234 {
00235         OutputDevDlg * out = new OutputDevDlg (m_parent);
00236         int nMidi = rtmidiout->getPortCount();
00237         DEBUGLOG (other, _T("Midi ports %d"),nMidi);
00238 
00239 #ifdef RTMIDI
00240         nMidi = rtmidiout->getPortCount();
00241 
00242         if ( nMidi )  {
00243 #ifdef __WXMSW__
00244                 wxString portName;
00245 #else
00246                 std::string portName;
00247 #endif
00248 
00249                 for (int i = 0; i < nMidi; i++) {
00250                         try {
00251                                 portName = rtmidiout->getPortName(i);
00252                         } catch (RtError &error) {
00253                                 error.printMessage();
00254                                 break;
00255                         }
00256 #ifdef __WXMSW__
00257                         out->AppendPortChoice(portName);
00258 #else
00259                         out->AppendPortChoice(muT(portName.c_str()));
00260 #endif
00261                 }
00262         } else
00263                 out->AppendPortChoice(_("no device"));
00264 #else
00265         /*    nMidi = midiInGetNumDevs();
00266               if ( nMidi )
00267               {
00268               for (int i = 0; i < nMidi; i++)
00269               {
00270               MIDIINCAPS miin;
00271               midiInGetDevCaps(i, &miin, sizeof(MIDIINCAPS));
00272               DataR0.Device.AddString(miin.szPname);
00273               }
00274               }
00275               else
00276               DataR0.Device.AddString("no device");*/
00277 #endif
00278         //              in->SetType(DTUnknown);
00279         out->SetMidiDevice(0);
00280         out->SetMidiFile(wxEmptyString);
00281         out->SetGUIDOFile(wxEmptyString);
00282         out->SetMidiBendingRange(2);
00283         out->SetMidiFileBendingRange(2);
00284 
00285         InitializeDialog(out);
00286                 
00287         out->Fit();
00288 
00289         return out;
00290 }
00291 
00292 bool MutOutputDeviceShape::DetachDevice ()
00293 {
00294         
00295         for (MutBoxChannelShapeList::iterator i = routes.begin(); i!= routes.end(); i = routes.begin()) {
00296                 MutBoxChannelShape *channel = *i;
00297                 wxASSERT(channel);
00298                 RemoveRoute(channel->GetRoute());
00299         }
00300         
00301         device->Destroy();
00302         device = NULL;
00303         
00304         wxWindow * parent = m_parent;
00305         wxSizer * sizer = GetContainingSizer();
00306         if (sizer) {
00307                 sizer -> Detach(this);
00308         }
00309         if (parent) {
00310                 parent->Layout();
00311                 parent->FitInside();
00312                 parent->SetVirtualSize(wxDefaultSize);
00313                 parent->Refresh();
00314         }
00315         
00316         return true;
00317 }
00318 
00319 bool MutOutputDeviceShape::replaceSelfBy (MutOutputDeviceShape  * newshape)
00320 {
00321         wxASSERT (newshape);
00322         wxASSERT (newshape->device);
00323 
00324         DEBUGLOG (routing, _T(""));
00325         
00326         for(MutBoxChannelShapeList::iterator i = routes.begin(); i!=routes.end(); i = routes.begin())
00327         {
00328                 DEBUGLOG (routing, _T("this = %p ; newshape = %p ; device = %p ; newshape->device = %p ; boxchannel = %p"),
00329                           this,newshape,device, newshape->device, (*i));
00330                 MutBoxChannelShape * channel = *i;
00331                 wxASSERT(channel->GetRoute()->GetOutDevice() == device);
00332                 RemoveRoute(channel);
00333                 channel->SetOutput(newshape,true);
00334                 wxASSERT(channel->GetRoute()->GetOutDevice() == newshape->device);
00335                 wxASSERT(channel->GetRoute()->GetOutDevice()->getUserData() == newshape);
00336                 newshape->AddRoute(channel);
00337         }
00338 
00339         DEBUGLOG (routing, _T(""));
00340         device -> Destroy();
00341         device = NULL;
00342        
00343         newshape->MoveBeforeInTabOrder (this);
00344 
00345         wxSizer * sizer = GetContainingSizer();
00346         sizer -> Replace (this, newshape, false);
00347         
00348         if (FindFocus()==this) {
00349                 m_parent->Layout();
00350                 m_parent->FitInside();
00351                 m_parent->SetVirtualSize(wxDefaultSize);
00352                 newshape->SetFocus();
00353         }
00354 
00355         Hide();
00356         return true;
00357 }
00358 
00359 void MutOutputDeviceShape::ReadPanel(OutputFilterPanel * panel, MutBoxChannelShape * channel)
00360 {
00361         wxASSERT(panel);
00362         wxASSERT(channel);
00363         if (!panel || !channel) return;
00364         DEBUGLOG(dialog,_T("Reading output device dialog"));
00365         
00366         bool active = panel->IsShown();
00367         
00368         // newShape may be NULL if the route ends at the box
00369         MutOutputDeviceShape * newShape = panel->GetCurrentSelection();
00370         Route * route = channel->GetRoute();
00371         if (!active) {
00372                 RemoveRoute(route);
00373                 channel->SetOutput(NULL);
00374                 return;
00375         } else if (newShape != this) {
00376                 RemoveRoute(route);
00377                 channel->SetOutput(newShape,true);
00378                 if (newShape)
00379                         newShape->AddRoute(route);
00380         }
00381         if (newShape) {
00382                 wxWindow * FilterPanel = panel->GetCurrentDevicePage();
00383                 if (!panel) {
00384                         UNREACHABLEC;
00385                         return;
00386                 }
00387                 newShape->ReadOutputFilterPanel(FilterPanel,route);
00388         }
00389         
00390 }
00391 
00392 
00393 /*
00394  * \}
00395  */

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