gehe zur Dokumentation dieser Datei00001
00079
00080
00081 #include "InputDeviceShape.h"
00082 #include "InputMidiDeviceShape.h"
00083 #include "InputMidiFileDeviceShape.h"
00084 #include "InputGuidoFileDeviceShape.h"
00085 #include "DevMidi.h"
00086 #include "BoxChannelShape.h"
00087
00088
00089
00090
00091
00092
00093
00094 #if defined(__WXMAC__) && defined(__WXMAC_CARBON__)
00095 # include "wx/mac/carbon/private.h"
00096 #endif
00097
00098 IMPLEMENT_DYNAMIC_CLASS(MutInputDeviceShape, MutDeviceShape)
00099
00100
00101 wxSizerFlags MutInputDeviceShape::sizerFlags;
00102
00103 bool MutInputDeviceShape:: Create (wxWindow * parent, wxWindowID id, InDevice * d)
00104 {
00105 device = d;
00106 if (!d) return false;
00107
00108 d->setUserData (this);
00109
00110 DEBUGLOG (other,_T ("Checking icon"));
00111 wxASSERT(MidiInputDevBitmap.IsOk());
00112
00113 return MutDeviceShape::Create (parent, id, d->GetName());
00114 }
00115
00116 MutInputDeviceShape * MutInputDeviceShape::CreateShape(wxWindow * parent,
00117 wxWindowID id,
00118 InDevice * d)
00119 {
00120 DEBUGLOGTYPE(other,MutInputDeviceShape,_T("Creating device shape"));
00121 wxASSERT (d);
00122 if (!d) return NULL;
00123
00124 DEBUGLOGTYPE(other,*d,_T("Device Type"));
00125 switch (d->GetType()) {
00126 case DTMidiPort:
00127 DEBUGLOGTYPE(other,MutInputDeviceShape,
00128 _T("Creating MIDI device shape"));
00129 return new MutInputMidiDeviceShape(parent,id,d);
00130 case DTMidiFile:
00131 DEBUGLOGTYPE(other,MutInputDeviceShape,
00132 _T("Creating MIDI file device shape"));
00133 return new MutInputMidiFileDeviceShape(parent,id,d);
00134 case DTGis:
00135 DEBUGLOGTYPE(other,MutInputDeviceShape,
00136 _T("Creating MIDI file device shape"));
00137 return new MutInputGuidoFileDeviceShape(parent,id,d);
00138 default:
00139 return NULL;
00140 }
00141 }
00142
00143 MutInputDeviceShape::~MutInputDeviceShape() {
00144 if (device) {
00145 wxASSERT (device -> getUserData() == this);
00146 device -> setUserData (NULL);
00147 }
00148 }
00149
00150 void MutInputDeviceShape::SetLabel(const wxString & st ) {
00151 MutDeviceShape::SetLabel(st);
00152 }
00153
00154 void MutInputDeviceShape::RemoveRoute(Route * route) {
00155 if (!route) return;
00156 Route * r = getRoutes();
00157 if (!r) return;
00158
00159 if (r == route) {
00160 device->SetRoute(route->GetNext());
00161 route->SetNext(NULL);
00162 return;
00163 }
00164
00165 do {
00166 if (r->GetNext() == route) {
00167 r->SetNext(route->GetNext());
00168 route->SetNext(NULL);
00169 return;
00170 }
00171 } while ((r = r->GetNext()));
00172 wxASSERT(!r);
00173 }
00174
00175 void MutInputDeviceShape::AddRoute(Route * route)
00176 {
00177 if (!device) return;
00178 if (!route) {
00179 UNREACHABLEC;
00180 return;
00181 }
00182 wxASSERT(!route->GetNext());
00183 route->SetNext(device->GetRoutes());
00184 device->SetRoute(route);
00185 }
00186
00187
00188 void MutInputDeviceShape::DoLeftDblClick() {
00189 InputDevDlg * in = ShowDeviceDialog();
00190 int Res = in->ShowModal();
00191 bool destroySelf = false;
00192
00193 if (Res == wxID_OK) {
00194 DevType type = in->GetType();
00195
00196 if (CanHandleType (type)) {
00197 readDialog (in);
00198 } else {
00199 InDevice * indev = InDevice::CreateDevice (type);
00200 if (indev) {
00201 MutInputDeviceShape * newdev =
00202 MutInputDeviceShape::CreateShape (indev);
00203 newdev -> readDialog (in);
00204 destroySelf = replaceSelfBy (newdev);
00205 m_parent->Layout();
00206 m_parent->FitInside();
00207 m_parent->SetVirtualSize(wxDefaultSize);
00208 m_parent->Refresh();
00209 }
00210 }
00211 } else if (Res == ::wxID_REMOVE) {
00212 destroySelf = DetachDevice();
00213 }
00214
00215 in->Destroy();
00216 DebugCheckRoutes();
00217
00218
00219
00220 if (destroySelf) DeleteSelf();
00221 }
00222
00223 InputDevDlg * MutInputDeviceShape::ShowDeviceDialog() {
00224 InputDevDlg * in = new InputDevDlg (m_parent);
00225 int nMidi = rtmidiin->getPortCount();
00226
00227 #ifdef RTMIDI
00228 nMidi = rtmidiin->getPortCount();
00229
00230 if ( nMidi ) {
00231 #ifdef __WXMSW__
00232 wxString portName;
00233 #else
00234 std::string portName;
00235 #endif
00236
00237 for (int i = 0; i < nMidi; i++) {
00238 try {
00239 portName = rtmidiin->getPortName(i);
00240 #ifdef __WXMSW__
00241 in->AppendPortChoice(portName);
00242 #else
00243 in->AppendPortChoice(muT(portName.c_str()));
00244 #endif
00245 } catch (RtError &error) {
00246 error.printMessage();
00247 break;
00248 }
00249 }
00250 } else
00251 in->AppendPortChoice(_("no device"));
00252 #else
00253 STUBC;
00254 #endif
00255
00256 in->SetMidiDevice(0);
00257 in->SetMidiFile(wxEmptyString);
00258 in->SetGUIDOFile(wxEmptyString);
00259
00260 InitializeDialog(in);
00261
00262 in->Fit();
00263
00264 return in;
00265 }
00266
00267 bool MutInputDeviceShape::DetachDevice ()
00268 {
00269
00270 for(Route * route = getRoutes();
00271 route; route = getRoutes())
00272 {
00273 void * p = route->getUserData();
00274 wxASSERT (wxDynamicCast (p,MutBoxChannelShape));
00275 MutBoxChannelShape * channel = (MutBoxChannelShape *) p;
00276
00277 wxASSERT (channel->GetInput() == this);
00278 channel->SetInput (NULL);
00279
00280 RemoveRoute(route);
00281 }
00282
00283 device->Destroy();
00284 device = NULL;
00285
00286 wxWindow * parent = m_parent;
00287 wxSizer * sizer = GetContainingSizer();
00288 if (sizer) {
00289 sizer -> Detach(this);
00290 }
00291 if (parent) {
00292 parent->Layout();
00293 parent->FitInside();
00294 parent->SetVirtualSize(wxDefaultSize);
00295 parent->Refresh();
00296 }
00297
00298
00299 return true;
00300 }
00301
00302
00303 bool MutInputDeviceShape::replaceSelfBy (MutInputDeviceShape * newshape)
00304 {
00305 wxASSERT (newshape);
00306 wxASSERT (newshape->device);
00307
00308 for(Route * route = newshape->device->ReplaceDevice (device);
00309 route; route = route->GetNext())
00310 {
00311 void * p = route->getUserData();
00312 wxASSERT (wxDynamicCast (p,MutBoxChannelShape));
00313 MutBoxChannelShape * channel = (MutBoxChannelShape *) p;
00314
00315 wxASSERT (channel->GetInput() == this);
00316 channel->SetInput (newshape);
00317
00318
00319 }
00320
00321 device->Destroy();
00322 device = NULL;
00323
00324 newshape->MoveBeforeInTabOrder (this);
00325
00326 wxSizer * sizer = GetContainingSizer();
00327 sizer -> Replace (this, newshape, false);
00328
00329 if (FindFocus()==this) {
00330 m_parent->Layout();
00331 m_parent->FitInside();
00332 m_parent->SetVirtualSize(wxDefaultSize);
00333 newshape->SetFocus();
00334 }
00335
00336 Hide();
00337 return true;
00338 }
00339
00340 void MutInputDeviceShape::ReadPanel(InputFilterPanel * panel, MutBoxChannelShape * channel)
00341 {
00342 wxASSERT(panel);
00343 wxASSERT(channel);
00344 if (!panel || !channel) return;
00345
00346 bool active = panel->IsShown();
00347
00348 MutInputDeviceShape * newShape = panel->GetCurrentSelection();
00349
00350 Route * route = channel->GetRoute();
00351 if (!active) {
00352 RemoveRoute(route);
00353 channel->SetInput(NULL);
00354 return;
00355 } else if (newShape != this) {
00356 RemoveRoute(route);
00357 channel->SetInput(newShape);
00358 if (newShape)
00359 newShape->AddRoute(route);
00360 }
00361 if (newShape) {
00362 wxWindow * FilterPanel = panel->GetCurrentDevicePage();
00363 if (!panel) {
00364 UNREACHABLEC;
00365 return;
00366 }
00367 newShape->ReadInputFilterPanel(FilterPanel,route);
00368 }
00369 }
00370
00371
00372
00373
00374
00375