00001
00024
00025
00026
00027
00028
00029
00030
00031
00033
00034
00035
00036
00037
00038
00039 #include "wx/wxprec.h"
00040
00041 #ifdef __BORLANDC__
00042 #pragma hdrstop
00043 #endif
00044
00045 #ifndef WX_PRECOMP
00046 #include "wx/wx.h"
00047
00048 #endif
00049
00050 #include "Defs.h"
00051 #include <stdio.h>
00052 #include "wx/list.h"
00053 #include "wx/ffile.h"
00054
00055 #include "Runtime.h"
00056
00057
00058 #include "mhDefs.h"
00059 #include "MutRouteWnd.h"
00060 #include "InputDevDlg.h"
00061
00062 #include "BoxDlg.h"
00063
00064 #include "OutputDevDlg.h"
00065 #include "NewInputDeviceShape.h"
00066 #include "NewBoxShape.h"
00067 #include "NewOutputDeviceShape.h"
00068 #include "DebugRoute.h"
00069 #include "RouteCompat.h"
00070
00071 #ifndef RTMIDI
00072 #ifndef MMSYSTEM_H
00073 #define MMSYSTEM_H
00074
00075 #include <mmsystem.h>
00076 #endif
00077 #endif
00078
00079
00080 #include "Device.h"
00081 #include "MidiKern.h"
00082
00083
00084 #include "Icon/DevUnknown.xpm"
00085 #include "Icon/DevMidiPort.xpm"
00086 #include "Icon/DevMidiFile.xpm"
00087 #include "Icon/DevGMN.xpm"
00088 #include "Icon/NewPlop.xpm"
00089 #include "Icon/PlayPlop.xpm"
00090 #include "Icon/PausePlop.xpm"
00091 #include "Icon/ErrorPlop.xpm"
00092 #include "Icon/AddStop.xpm"
00093 #include "Icon/AddPlay.xpm"
00094 #include "Icon/AddPause.xpm"
00095 #include "Icon/AddStopDis.xpm"
00096
00097
00098 #ifdef RTMIDI
00099 #include "RtMidi.h"
00100
00101 extern RtMidiOut *rtmidiout;
00102
00103 extern RtMidiIn *rtmidiin;
00104
00105 #endif
00106
00107 #define xd 32 // Devicelogo
00108 #define yd 32
00109
00110 #define xb 24 // Box
00111 #define yb 24
00112
00113 #define ydt 4 // Text
00114 #define yt 16
00115
00116 #define yh 12 // Headline
00117
00118 #define yr (yd+ydt+yt+yz) // Route
00119
00120 #define BACKGROUND *wxLIGHT_GREY // Background color
00121
00122 #define RT_INDEVICE 0
00123 #define RT_INFILTER 1
00124 #define RT_BOX 2
00125 #define RT_OUTFILTER 3
00126 #define RT_OUTDEVICE 4
00127 #define RT_PLAYBUTTON 5
00128 #define RT_STOPBUTTON 6
00129
00130 #define FILENAMELENGTH 200
00131 #define POINT_IN(p, x1, y1, xl, yl) \
00132 (x1 <= p.x && p.x < x1+xl && y1 < p.y && p.y < y1+yl)
00133
00134 DevType IsDT;
00135
00136 extern int curBox;
00137
00138
00139
00140
00141
00142
00143 #define max(a, b) ((a) < (b) ? (b) : (a))
00144
00145 int GetTextWidth(wxDC& dc, const wxString &s)
00146 {
00147 wxCoord w, h;
00148 dc.GetTextExtent(s, &w, &h);
00149 return w;
00150 }
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 void TextPin(wxDC &dc, int xm, int y, int xl, const wxString &s, char withBox)
00161 {
00162 if ( withBox )
00163 dc.DrawRectangle(xm-xl/2, y, xl, yt);
00164
00165 wxString s1 = s;
00166
00167 int w = GetTextWidth(dc, s1);
00168
00169 while ( s1.Length() > 3 ) {
00170 if ( (w = GetTextWidth(dc, s1)) < xl )
00171 break;
00172
00173 s1 = s1.Mid(4).Prepend(_("..."));
00174 }
00175
00176 dc.SetBackgroundMode(wxTRANSPARENT);
00177 dc.DrawText(s1, xm - w/2, y + 2);
00178 dc.SetBackgroundMode(wxSOLID);
00179 }
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189 wxString sRange(int from, int to)
00190 {
00191 if ( from == to )
00192 return wxString::Format(_T("%d"), from);
00193 else if ( from < to )
00194 return wxString::Format(_("%d -- %d"), from, to);
00195
00196 return _("--");
00197 }
00198
00199
00200
00201
00202 void PrintBox(wxDC &dc, int xm, int ym, int nr, char active, int x3)
00203 {
00204 if ( nr == -2 )
00205 return;
00206
00207 wxString s(_T("x"));
00208 if ( nr >= 0 )
00209 s.Printf(_T("%d"), nr);
00210 wxBrush Brush = wxBrush(BoxColor(nr));
00211 dc.SetBrush(Brush);
00212
00213 if ( !active ) {
00214 int xv = (x3+xb+2*xz) / 4, yv = (yb+yr) / 4;
00215 dc.SetPen(wxPen(BACKGROUND, 1));
00216 dc.DrawLine(xm, ym, xm-xv, ym);
00217 dc.SetPen(*wxBLACK_PEN);
00218 dc.DrawLine(xm-xv, ym, xm-xv, ym+yv);
00219 dc.DrawLine(xm-xv, ym+yv, xm+xv, ym+yv);
00220 dc.DrawLine(xm+xv, ym+yv, xm+xv, ym);
00221 } else
00222 dc.SetPen(wxPen(*wxBLACK, 2));
00223
00224 dc.DrawRectangle(xm-xb/2, ym-yb/2, xb, yb);
00225 dc.SetPen(wxNullPen);
00226 dc.SetBrush(wxNullBrush);
00227 wxCoord w, h;
00228 dc.GetTextExtent(s, &w, &h);
00229 dc.SetBackgroundMode(wxTRANSPARENT);
00230 dc.DrawText(s, xm - w/2, ym-h/2);
00231 dc.SetBackgroundMode(wxSOLID);
00232 }
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435 BEGIN_EVENT_TABLE(MutRouteWnd, wxScrolledWindow)
00436
00437
00438
00439 END_EVENT_TABLE()
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454 wxFont RouteFont(10, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
00455
00456 void testdialog();
00457
00458
00459 MutRouteWnd::MurFileDataType MutRouteWnd::MurFileData;
00460
00461 MutRouteWnd::MutRouteWnd(wxWindow *parent, const wxPoint& pos, const wxSize& size)
00462 : wxScrolledWindow(parent, wxID_ANY, pos, size,
00463 wxVSCROLL|wxHSCROLL|wxTAB_TRAVERSAL, wxT("Route"))
00464 {
00465
00466
00467
00468
00469 DevIcon[DTUnknown] = new ICON(devunknown);
00470 DevIcon[DTMidiPort] = new ICON(devmidiport);
00471 DevIcon[DTMidiFile] = new ICON(devmidifile);
00472 DevIcon[DTGis] = new ICON(devgmn);
00473 ConIcon[0] = new wxBitmap(AddStop_xpm);
00474 ConIcon[1] = new wxBitmap(AddPlay_xpm);
00475 ConIcon[2] = new wxBitmap(AddPause_xpm);
00476 ConIcon[3] = new wxBitmap(AddStopDis_xpm);
00477 PlopIcon[0] = new ICON(newplop);
00478 PlopIcon[1] = new ICON(playplop);
00479 PlopIcon[2] = new ICON(pauseplop);
00480 PlopIcon[3] = new ICON(errorplop);
00481 spacey = 8;
00482 spacex = 20;
00483 x1 = 80;
00484 x2 = 80;
00485 x3 = 30;
00486 x4 = 80;
00487 x5 = 80;
00488 SetBackgroundColour(BACKGROUND);
00489
00490
00491
00492 DEBUGLOG (other, _T("this is window %p"),this);
00493 SetSizer(new wxFlexGridSizer(3,0,50));
00494 SetScrollRate(1, 1);
00495
00496 initMutIconShapes();
00497 InitShapes();
00498 }
00499
00500 void MutRouteWnd::InitShapes()
00501 {
00502 wxASSERT(GetSizer());
00503 wxSizerFlags flags;
00504 flags.Align(wxALIGN_CENTER_VERTICAL | wxALIGN_CENTER_HORIZONTAL);
00505 flags.Proportion(1);
00506 flags.TripleBorder();
00507
00508 wxASSERT(InputDevices.empty());
00509 MutInputDeviceShape * newin = new MutNewInputDeviceShape(this,wxID_ANY);
00510 GetSizer()->Add(newin, flags);
00511 InputDevices.Append(newin);
00512
00513 wxASSERT(Boxes.empty());
00514 MutBoxShape * boxShape = new NewMutBoxShape(this,wxID_ANY);
00515 GetSizer()->Add(boxShape, flags);
00516 Boxes.Append(boxShape);
00517
00518 wxASSERT(OutputDevices.empty());
00519 MutOutputDeviceShape * newout = new MutNewOutputDeviceShape(this,wxID_ANY);
00520 GetSizer()->Add(newout, flags);
00521 OutputDevices.Append(newout);
00522
00523 createInputDevices(flags);
00524 createBoxes(flags);
00525 createOutputDevices(flags);
00526 FitInside();
00527
00528 PRINTSIZER(GetSizer());
00529 DebugCheckRoutes();
00530 }
00531
00532 void MutRouteWnd::InitDevices()
00533 {
00534 createInputDevices(MutInputDeviceShape::GetSizerFlags());
00535 createBoxes(MutBoxShape::GetSizerFlags());
00536 createOutputDevices(MutOutputDeviceShape::GetSizerFlags());
00537 FitInside();
00538
00539 PRINTSIZER(GetSizer());
00540 DebugCheckRoutes();
00541 }
00542
00543 void MutRouteWnd::ClearDevices()
00544 {
00545 ClearInputDevices();
00546 ClearBoxes();
00547 ClearOutputDevices();
00548 }
00549
00550 void MutRouteWnd::createInputDevices(wxSizerFlags flags)
00551
00552 {
00553 MutInputDeviceShape::SetSizerFlags(flags);
00554 InputSizer = new wxGridSizer(1);
00555
00556 GetSizer()->Add(InputSizer, 0, wxEXPAND);
00557
00558 for (InDevice *In = InDevice::GetDeviceList(); In; In = In->GetNext()) {
00559 wxASSERT (In != In -> GetNext());
00560 DEBUGLOG (other, _T("In the loop %p -> %p"), In, In->GetNext());
00561 MutInputDeviceShape * newin = MutInputDeviceShape::CreateShape(this,wxID_ANY, In);
00562 wxASSERT(newin);
00563 InputSizer->Add(newin, flags);
00564 InputDevices.Append(newin);
00565 }
00566 }
00567
00568 void MutRouteWnd::ClearInputDevices()
00569 {
00570 InputDevices.Clear();
00571 InputSizer->Clear(true);
00572 }
00573
00574 void MutRouteWnd::createBoxes(wxSizerFlags flags)
00575 {
00576 MutBoxShape::SetSizerFlags(flags);
00577 BoxSizer = new wxGridSizer (1);
00578 MutBoxShape * boxShape;
00579
00580
00581 for (int i = 0; i< MAX_BOX; i++) {
00582 BoxPTRs[i] = NULL;
00583 }
00584
00585 GetSizer()->Add(BoxSizer, 0, wxEXPAND);
00586
00587 for (MutDeviceShapeList::iterator iter = InputDevices.begin();
00588 iter != InputDevices.end(); ++iter) {
00589
00590 MutInputDeviceShape * device = dynamic_cast<MutInputDeviceShape*>(*iter);
00591 wxASSERT(device);
00592 if (!device) continue;
00593
00594 Route * Route = device->getRoutes();
00595 while (Route) {
00596 wxASSERT(0<= Route->Box && Route->Box < MAX_BOX);
00597 if (!BoxPTRs[Route->Box]) {
00598 DEBUGLOG (other, _T("Creating box"));
00599 BoxPTRs[Route->Box] = boxShape =
00600 new MutBoxShape(this,wxID_ANY, Route->Box);
00601 DEBUGLOG (other, _T("Box shape: %p"),boxShape);
00602 wxASSERT(boxShape);
00603 if (!boxShape) continue;
00604 AddBox(boxShape, flags);
00605 } else {
00606 boxShape = BoxPTRs[Route->Box];
00607 wxASSERT(wxDynamicCast(boxShape,MutBoxShape));
00608 }
00609
00610 DEBUGLOG (other, _T("Adding Route to Box %p on window %p"),boxShape,this);
00611 MutBoxChannelShape * channel =
00612 boxShape->AddChannel(Route);
00613 channel->SetInput(device);
00614
00615 Route = Route->GetNext();
00616 }
00617 }
00618
00619
00620 Route * route = Route::GetRouteList();
00621 while (route) {
00622 wxASSERT(0<= route->Box && route->Box < MAX_BOX);
00623
00624 bool found = false;
00625
00626 wxSizerItemList & list = BoxSizer->GetChildren();
00627 for (wxSizerItemList::const_iterator i = list.begin(); i != list.end(); i++) {
00628 MutBoxShape * box = static_cast<MutBoxShape * > ((*i)->GetWindow());
00629 wxASSERT(dynamic_cast<MutBoxShape *> ((*i)->GetWindow()));
00630 if (box && box->HasChannel(route)) {
00631 found = true;
00632 break;
00633 }
00634 }
00635 if (found) {
00636 route = route -> GetGlobalNext();
00637 continue;
00638 }
00639
00640 if (!BoxPTRs[route->Box]) {
00641 DEBUGLOG (other, _T("Creating box"));
00642 BoxPTRs[route->Box] = boxShape =
00643 new MutBoxShape(this,wxID_ANY, route->Box);
00644 DEBUGLOG (other, _T("Box shape: %p"),boxShape);
00645 wxASSERT(boxShape);
00646 if (!boxShape) continue;
00647 AddBox(boxShape, flags);
00648 } else {
00649 boxShape = BoxPTRs[route->Box];
00650 wxASSERT(wxDynamicCast(boxShape,MutBoxShape));
00651 }
00652
00653 DEBUGLOG (other, _T("Adding Route to Box %p on window %p"),boxShape,this);
00654 boxShape->AddChannel(route);
00655
00656 route = route->GetGlobalNext();
00657 }
00658
00659 }
00660 void MutRouteWnd::ClearBoxes()
00661 {
00662 Boxes.Clear();
00663 BoxSizer->Clear(true);
00664 }
00665
00666
00667 void MutRouteWnd::createOutputDevices(wxSizerFlags flags)
00668
00669 {
00670 MutOutputDeviceShape::SetSizerFlags(flags);
00671 OutputSizer = new wxGridSizer (1);
00672
00673 GetSizer()->Add(OutputSizer, 0, wxEXPAND | wxALL,0);
00674
00675 for (OutDevice *Out = OutDevice::GetDeviceList(); Out; Out = Out->GetNext()) {
00676 MutOutputDeviceShape * newout = MutOutputDeviceShape::CreateShape(this,wxID_ANY,Out);
00677
00678 OutputSizer->Add(newout, flags);
00679 OutputDevices.Append(newout);
00680
00681 for (MutBoxShapeList::iterator i = Boxes.begin(); i != Boxes.end(); i++) {
00682 MutBoxShape * box = *i;
00683
00684 box->AddPossibleOutput(newout);
00685 }
00686
00687 }
00688 }
00689 void MutRouteWnd::ClearOutputDevices()
00690 {
00691 OutputDevices.Clear();
00692 OutputSizer->Clear(true);
00693 }
00694
00695
00696
00697
00698 void MutRouteWnd::CmRouteLoad(wxCommandEvent& event)
00699 {
00700
00701 event.Skip(false);
00702
00703 wxString filename = FileNameDialog(wxGetApp().GetTopWindow(),
00704 event.GetId());
00705
00706 if (!filename) return;
00707
00708 MurFileData.name.Assign(filename);
00709
00710 wxFFile file(filename);
00711 if (!file.IsOpened()) {
00712 wxLogError(_("File '%s' couldn't be loaded"),filename.c_str());
00713 return;
00714 }
00715 wxString text;
00716 if (! file.ReadAll(&text, MurFileData.autoConverter)) {
00717 wxLogError(_("File '%s' could be opened, but not loaded."),
00718 filename.c_str());
00719 return;
00720 }
00721
00722
00723 wxGetApp().CmRoutes(event);
00724 MutFrame * frame =
00725 dynamic_cast<MutFrame*>(wxWindow::FindWindowById(WK_ROUTE));
00726 wxWindowList & list = frame->GetChildren();
00727 MutRouteWnd * routewnd=NULL;
00728 for (wxWindowList::iterator i = list.begin();i!= list.end();i++) {
00729 routewnd = dynamic_cast<MutRouteWnd *> (*i);
00730 if (routewnd) break;
00731 }
00732 wxASSERT(routewnd);
00733 if (routewnd) {
00734 routewnd->ClearDevices();
00735 }
00736
00737 compat30::LoadRoutes(text);
00738
00739 if (routewnd) {
00740 routewnd->InitDevices();
00741 }
00742
00743 wxCommandEvent ev(wxEVT_COMMAND_MENU_SELECTED,CM_ROUTES);
00744 wxGetApp().ProcessEvent(ev);
00745 }
00746
00747 void MutRouteWnd::CmRouteSave(wxCommandEvent& event)
00748 {
00749 DEBUGLOGTYPE(other,MutFrame,_T(""));
00750 event.Skip(false);
00751
00752 if (!MurFileData.name.IsOk() ) {
00753 CmRouteSaveAs(event);
00754 return;
00755 }
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765 wxFFile file(MurFileData.name.GetFullPath(), _T("w"));
00766
00767 if (!file.IsOpened()) {
00768 wxLogError(_("Cannot open routes file '%s' for writing."),
00769 MurFileData.name.GetFullPath().c_str());
00770 return;
00771 }
00772
00773 wxString RouteConfig;
00774
00775 compat30::SaveRoutes(RouteConfig);
00776
00777 if (file.Write(_T("# Mutabor 3.x routes configuration\n"),
00778 MurFileData.autoConverter))
00779 if (file.Write(RouteConfig, MurFileData.autoConverter)) {
00780 file.Close();
00781 return;
00782 }
00783
00784 wxLogError(_("Error writing file '%s'."),
00785
00786 MurFileData.name.GetFullPath().c_str());
00787 file.Close();
00788 }
00789
00790 void MutRouteWnd::CmRouteSaveAs(wxCommandEvent& event)
00791 {
00792 DEBUGLOGTYPE(other,MutFrame,_T(""));
00793
00794
00795 event.Skip(false);
00796
00797 wxString filename = FileNameDialog(wxGetApp().GetTopWindow(),
00798 event.GetId(),
00799 MurFileData.name.GetFullPath());
00800
00801 if (!filename) return;
00802
00803 MurFileData.name.Assign(filename);
00804
00805 if (!MurFileData.name.IsOk()) {
00806 wxLogError(_("The string '%s' is not a valid file name."),
00807 filename.c_str());
00808 return;
00809 }
00810
00811 CmRouteSave(event);
00812 }
00813
00814
00815
00816
00817
00818
00819
00820
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852 void MutRouteWnd::OnDraw(wxDC& dc)
00853 {
00854 wxScrolledWindow::OnDraw(dc);
00855 PRINTSIZER(GetSizer());
00856 dc.SetDeviceOrigin(0,0);
00857 wxASSERT(BoxSizer);
00858 wxSizerItemList & list = BoxSizer->GetChildren();
00859 for (wxSizerItemList::const_iterator i = list.begin(); i != list.end(); i++) {
00860 MutBoxShape * box = static_cast<MutBoxShape * > ((*i)->GetWindow());
00861 wxASSERT(dynamic_cast<MutBoxShape *> ((*i)->GetWindow()));
00862 if (box)
00863 box->DrawLines(dc);
00864 }
00865
00866 return;
00867
00868 #if 0
00869
00870 wxSize R = GetClientSize();
00871 int t1 = 50;
00872 int t5 = 50;
00873
00874 for (EDevice *In = InEDevices; In; In = In->Next) {
00875 t1 = max(t1, GetTextWidth(dc, In->Name));
00876
00877 for (ERoute *R = In->Routes; R; R = R->Next)
00878 if ( R->Out )
00879 t5 = max(t5, GetTextWidth(dc, R->Out->Name));
00880 }
00881
00882 x1 = max((int)(R.GetWidth() - 10*xz - 30 - 80 - 80) / 2, 50);
00883
00884 x5 = x1;
00885
00886 if ( x1 < t1 || x5 < t5 ) {
00887 int s = x5+x1;
00888 x1 = s*t1/(t1+t5);
00889 x5 = s*t5/(t1+t5);
00890 }
00891
00892
00893 int y = yh + yz+yd/2;
00894
00895 int z1 = xz+x1/2;
00896
00897 int z2 = 3*xz+x1+x2/2;
00898
00899 int z3 = 5*xz+x1+x2+x3/2;
00900
00901 int z4 = 7*xz+x1+x2+x3+x4/2;
00902
00903 int z5 = 9*xz+x1+x2+x3+x4+x5/2;
00904
00905 int z1t = z1;
00906
00907 if ( z1-xd/2-20 < 2 )
00908 z1 = xd/2+22;
00909
00910 wxString s;
00911
00912 dc.SetFont(RouteFont);
00913 dc.SetBackgroundMode(wxSOLID);
00914 wxPen GrayPen(wxColour(0xee, 0xee, 0xee), 1);
00915
00916 for (REUSE(EDevice*) In = InEDevices; In; In = In->Next) {
00917
00918
00919 dc.SetPen(*wxBLACK_PEN);
00920 dc.SetBrush(*wxWHITE_BRUSH);
00921 dc.DrawLine(z1, y, 2*xz+x1, y);
00922
00923
00924 dc.DrawIcon(*DevIcon[In->DT], z1-xd/2, y-yd/2);
00925
00926
00927 TextPin(dc, z1t, y+yd/2+ydt, x1, In->Name, 0);
00928
00929
00930
00931 if ( LogicOn ) {
00932 if ( In->Mode == -1 )
00933 dc.DrawIcon(*PlopIcon[0], z1, y-20);
00934 else if ( In->Mode == 3 )
00935 dc.DrawIcon(*PlopIcon[3], z1, y-20);
00936 else if ( In->DT >= DTMidiFile ) {
00937
00938
00939
00940
00941
00942
00943 dc.DrawBitmap(*ConIcon[(In->Mode == 1) ? 2 : 1],
00944 z1-xd/2-20, y-16, false);
00945 dc.DrawBitmap(*ConIcon[(In->Mode) ? 0 : 3],
00946 z1-xd/2-20, y+2, false);
00947
00948 if ( In->Mode > 0 )
00949 dc.DrawIcon(*PlopIcon[In->Mode], z1, y-20);
00950 }
00951 }
00952
00953
00954 int n = In->nRoutes(), yl = 0;
00955
00956 if ( n > 1 )
00957 yl = (n-1)*yr;
00958
00959 dc.DrawLine(2*xz+x1, y, 2*xz+x1, y+yl);
00960
00961 for (ERoute *R = In->Routes; R; R = R->Next) {
00962
00963 dc.DrawLine(2*xz+x1, y, z5, y);
00964
00965
00966
00967 switch ( R->Type ) {
00968
00969 case RTall:
00970 s = _("all");
00971
00972 break;
00973
00974 case RTelse:
00975 s = _("else");
00976
00977 break;
00978
00979 case RTchannel:
00980 if ( In->DT == DTGis )
00981 s = wxString::Format(_("box: %s"), sRange(R->IFrom, R->ITo).c_str());
00982 else
00983 s = wxString::Format(_("channel: %s"),
00984 sRange(R->IFrom, R->ITo).c_str());
00985
00986 break;
00987
00988 case RTstaff:
00989 if ( In->DT == DTGis)
00990 s = wxString::Format(_("staff: %s"), sRange(R->IFrom, R->ITo).c_str());
00991 else if ( In->DT == DTMidiPort )
00992 s = wxString::Format(_("keys: %s"), sRange(R->IFrom, R->ITo).c_str());
00993 else
00994 s = wxString::Format(_("track: %s"), sRange(R->IFrom, R->ITo).c_str());
00995
00996 break;
00997 }
00998
00999 TextPin(dc, z2, y-yt/2, x2, s, 1);
01000
01001
01002 PrintBox(dc, z3, y, R->Box, R->Active, x3);
01003 dc.SetPen(*wxBLACK_PEN);
01004
01005
01006
01007 if ( R->OFrom != -1 && R->Out && R->Out->DT != DTGis ) {
01008 s = wxString::Format(_("channel: %s"),
01009 sRange(R->OFrom, R->OTo).c_str());
01010 dc.SetPen(*wxBLACK_PEN);
01011 dc.SetBrush(*wxWHITE_BRUSH);
01012 TextPin(dc, z4, y-yt/2, x4, s, 1);
01013 }
01014
01015
01016 if ( R->Out ) {
01017 dc.DrawIcon(*DevIcon[R->Out->DT], z5-xd/2, y-yd/2);
01018 TextPin(dc, z5, y+yd/2+ydt, x5, R->Out->Name, 0);
01019 }
01020
01021 y+=yr;
01022 }
01023
01024
01025 dc.SetPen(GrayPen);
01026
01027 dc.SetBrush(*wxTRANSPARENT_BRUSH);
01028
01029 dc.DrawRectangle(z2-x2/2, y-yt/2-26, x2, yt-26);
01030
01031
01032 if ( !n )
01033 y += yr;
01034
01035 y += yz;
01036 }
01037
01038 dc.SetPen(GrayPen);
01039
01040 dc.SetBrush(*wxTRANSPARENT_BRUSH);
01041 dc.DrawRectangle(z1-xd/2, y-yd/2, xd, yd);
01042 SetVirtualSize(CalcXl(), CalcYl());
01043 #endif
01044 }
01045
01046
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088
01089
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114
01115
01116
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146 #if 0
01147 int MutRouteWnd::CalcYl()
01148 {
01149 int yl = yh+yz;
01150
01151 for (EDevice *In = InEDevices; In; In = In->Next) {
01152 yl += yr+yz;
01153 int n = In->nRoutes();
01154
01155 if ( n > 1 )
01156 yl += (n-1)*yr;
01157 }
01158
01159 return yl+yr;
01160 }
01161
01162 bool MutRouteWnd::CheckPoint(wxPoint point, EDevice **in, ERoute **r, int &token, bool &needNew)
01163 {
01164 int y = yh + yz, ya, n;
01165 int z1 = xz+x1/2;
01166 int z2 = 3*xz+x1+x2/2;
01167 int z3 = 5*xz+x1+x2+x3/2;
01168 int z4 = 7*xz+x1+x2+x3+x4/2;
01169 int z5 = 9*xz+x1+x2+x3+x4+x5/2;
01170
01171 if ( z1-xd/2-20 < 2 )
01172 z1 = xd/2+22;
01173
01174
01175 if ( point.y < y && z1-x1/2 <= point.x && point.x <= z1+x1/2 ) {
01176 *in = InEDevices;
01177 token = RT_INDEVICE;
01178 needNew = TRUE;
01179 return 1;
01180 }
01181
01182 if ( point.y < y )
01183 return 0;
01184
01185 for (*in = InEDevices; *in; *in = (*in)->Next) {
01186 ya = yr+yz;
01187 n = (*in)->nRoutes();
01188
01189 if ( n > 1 )
01190 ya += (n-1)*yr;
01191
01192 if ( point.y < y+ya )
01193 break;
01194
01195 y += ya;
01196 }
01197
01198 if ( !*in && z1-x1/2 <= point.x && point.x <= z1+x1/2 ) {
01199 token = RT_INDEVICE;
01200 needNew = TRUE;
01201 return 1;
01202 }
01203
01204 if ( !*in )
01205 return 0;
01206
01207
01208 y += yd/2;
01209
01210 n = (point.y-y+yr-yb/2-1)/yr;
01211
01212 ya = y+n*yr;
01213
01214 *r = (*in)->GetRoute(n);
01215
01216
01217 token = RT_INDEVICE;
01218
01219 needNew = FALSE;
01220
01221
01222
01223 if ( LogicOn && POINT_IN(point, z1-xd/2-20, y-16, 14, 14) ) {
01224 token = RT_PLAYBUTTON;
01225 return 1;
01226 }
01227
01228 if ( LogicOn && POINT_IN(point, z1-xd/2-20, y+2, 14, 14) ) {
01229 token = RT_STOPBUTTON;
01230 return 1;
01231 }
01232
01233 if ( POINT_IN(point, z1-x1/2, y-yd/2, x1, yd+ydt+yt) )
01234 return 1;
01235
01236 if ( z1-x1/2 <= point.x && point.x <= z1+x1/2 ) {
01237 *in = (*in)->Next;
01238 needNew = TRUE;
01239 return 1;
01240 }
01241
01242
01243 token = RT_INFILTER;
01244
01245 if ( POINT_IN(point, z2-x2/2, ya-yt/2, x2, yt) )
01246 return 1;
01247
01248 if ( z2-x2/2 <= point.x && point.x <= z2+x2/2 ) {
01249 needNew = TRUE;
01250 return 1;
01251 }
01252
01253
01254 token = RT_BOX;
01255
01256 if ( POINT_IN(point, z3-xb/2, ya-yb/2, xb, yb) )
01257 return 1;
01258
01259
01260 token = RT_OUTFILTER;
01261
01262 if ( POINT_IN(point, z4-x4/2, ya-yt/2, x4, yt) )
01263 return 1;
01264
01265
01266 token = RT_OUTDEVICE;
01267
01268 if ( POINT_IN(point, z5-xd/2, ya-yd/2, xd, yd) ||
01269 POINT_IN(point, z5-x5/2, ya+yd/2+ydt, x5, yt) )
01270 return 1;
01271
01272 return 0;
01273 }
01274 #endif
01275 #if 0
01276 void MutRouteWnd::OnLeftDown(wxMouseEvent &event)
01277 {
01278 EDevice *In=0;
01279 ERoute *R=0;
01280 bool NeedNew;
01281 int Token;
01282
01283 wxPoint rp;
01284 CalcUnscrolledPosition(event.GetX(), event.GetY(), &rp.x, &rp.y);
01285
01286
01287 if ( !CheckPoint(rp, &In, &R, Token, NeedNew) )
01288 return;
01289
01290 if ( !R || NeedNew )
01291 return;
01292
01293 if ( R->Box >= 0 ) {
01294 wxCommandEvent event1(wxEVT_COMMAND_MENU_SELECTED, CM_BOX);
01295 event1.SetId(R->Box);
01296 GetParent()->ProcessEvent(event1);
01297 }
01298
01299 if ( In->DT < DTMidiPort )
01300 return;
01301
01302 if ( Token == RT_PLAYBUTTON ) {
01303 if ( In->Mode == MutaborDevicePlay )
01304 In->Mode = MutaborDevicePause;
01305 else
01306 In->Mode = MutaborDevicePlay;
01307
01308 InDeviceAction(In->Nr, In->Mode);
01309
01310
01311 Refresh();
01312 }
01313
01314 if ( Token == RT_STOPBUTTON ) {
01315 if ( In->Mode != MutaborDeviceStop ) {
01316 In->Mode = MutaborDeviceStop;
01317 InDeviceAction(In->Nr, In->Mode);
01318
01319 Refresh();
01320 }
01321 }
01322 }
01323 #endif
01324
01325 #if 0
01326 void MutRouteWnd::OnLeftDClick(wxMouseEvent &event)
01327 {
01328 EDevice *In=NULL;
01329 ERoute *R=NULL, **R1 = NULL;
01330 bool NeedNew;
01331 int Token, Res = wxID_CANCEL;
01332 wxPoint rp;
01333
01334 CalcUnscrolledPosition(event.GetX(), event.GetY(), &rp.x, &rp.y);
01335
01336 if ( !CheckPoint(rp, &In, &R, Token, NeedNew) )
01337 return;
01338
01339 if ( !R && Token > RT_INFILTER )
01340 return;
01341
01342 int nMidi;
01343
01344
01345
01346
01347
01348
01349
01350 switch ( Token ) {
01351
01352 case RT_INDEVICE: {
01353
01354 if ( NeedNew ) {
01355 In = NewDevice(&InEDevices, DTUnknown, wxEmptyString, 0, 0, In);
01356 Refresh();
01357 }
01358
01359 InputDevDlg in(this);
01360
01361
01362 #ifdef RTMIDI
01363 nMidi = rtmidiin->getPortCount();
01364
01365 if ( nMidi ) {
01366 #ifdef __WXMSW__
01367 wxString portName;
01368 #else
01369 std::string portName;
01370 #endif
01371
01372 for (int i = 0; i < nMidi; i++) {
01373 try {
01374 portName = rtmidiin->getPortName(i);
01375 #ifdef __WXMSW__
01376 in.AppendPortChoice(portName);
01377 #else
01378 in.AppendPortChoice(muT(portName.c_str()));
01379 #endif
01380 } catch (RtError &error) {
01381 error.printMessage();
01382 break;
01383 }
01384 }
01385 } else
01386 in.AppendPortChoice(_("no device"));
01387
01388 #else
01389
01390
01391
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401 #endif
01402 in.SetType(DTUnknown);
01403
01404 in.SetMidiDevice(0);
01405
01406 in.SetMidiFile(wxEmptyString);
01407
01408 in.SetGUIDOFile(wxEmptyString);
01409
01410
01411 DevType type = DTUnknown;
01412
01413 in.SetType( In->DT );
01414
01415 switch ( In->DT ) {
01416
01417 case DTGis:
01418 in.SetGUIDOFile(In->Name);
01419
01420 break;
01421
01422 case DTMidiPort:
01423 in.SetMidiDevice(In->DevId);
01424
01425 break;
01426
01427 case DTMidiFile:
01428 in.SetMidiFile(In->Name);
01429
01430 break;
01431
01432 case DTNotSet:
01433 wxLogWarning(_("Unexpected value: DTNotSet"));
01434
01435 break;
01436
01437 case DTUnknown:
01438 break;
01439
01440 default:
01441 wxLogError(_("Unexpected device type: %d"), In->DT);
01442 }
01443
01444 Res = in.ShowModal();
01445
01446 if ( Res == wxID_OK ) {
01447 DEBUGLOG (other, _T("Got value %d"),in.GetType());
01448 type = in.GetType();
01449
01450 switch (type) {
01451
01452 case DTMidiPort:
01453 NewDevice(&InEDevices,
01454 DTMidiPort,
01455 in.GetPortString(in.GetMidiDevice()),
01456 in.GetMidiDevice(), In, In);
01457
01458 break;
01459
01460 case DTMidiFile:
01461 NewDevice(&InEDevices, DTMidiFile, in.GetMidiFile(), 0, In, In);
01462
01463 break;
01464
01465 case DTGis:
01466 NewDevice(&InEDevices, DTGis, in.GetGUIDOFile(), 0, In, In);
01467
01468 break;
01469
01470 case DTNotSet:
01471
01472 case DTUnknown:
01473 break;
01474
01475 default:
01476 wxLogWarning(_("Unexpected value: %d"),type);
01477 }
01478 } else if ( Res == wxID_REMOVE || (NeedNew && Res == wxCANCEL) )
01479 NewDevice(&InEDevices, DTNotSet, wxEmptyString, 0, In, 0);
01480
01481 break;
01482 }
01483
01484 case RT_INFILTER: {
01485
01486
01487 if ( !R )
01488 NeedNew = TRUE;
01489
01490 if ( NeedNew ) {
01491
01492
01493 for (R1 = &In->Routes; *R1; R1 = &((*R1)->Next))
01494 if ( *R1 == R )
01495 break;
01496
01497 R = new ERoute(RTall, 0, 0, -2, 0, 0, 0, 15);
01498
01499 R->Next = *R1;
01500
01501 *R1 = R;
01502
01503 Refresh();
01504 }
01505
01506
01507 IsDT = In->DT;
01508
01509 InputFilterDlg dlg(this, In->DT);
01510
01511 dlg.SetType(R->Type);
01512
01513 dlg.SetFrom(R->IFrom);
01514
01515 dlg.SetTo(R->ITo);
01516
01517 dlg.UpdateLayout(R->Type);
01518
01519 Res = dlg.ShowModal();
01520
01521 if ( Res == wxID_OK ) {
01522 R->Type = (RouteType)dlg.GetType();
01523 R->IFrom = dlg.GetFrom();
01524 R->ITo = dlg.GetTo();
01525 } else if ( Res == wxID_REMOVE || (NeedNew && Res == wxID_CANCEL) )
01526 for (R1 = &(In->Routes); *R1; R1 = &((*R1)->Next))
01527 if ( *R1 == R ) {
01528 *R1 = R->Next;
01529 R->Next = 0;
01530 break;
01531 }
01532
01533 break;
01534 }
01535
01536 case RT_BOX: {
01537 BoxDlg dlg(this);
01538
01539 dlg.SetBoxNr(0);
01540 int Type = 0;
01541
01542 if ( R->Box == NoBox )
01543 Type = 2;
01544 else if ( R->Box == GmnBox )
01545 Type = 1;
01546 else {
01547 Type = 0;
01548 dlg.SetBoxNr(R->Box);
01549 }
01550
01551 dlg.SetBoxType(Type);
01552
01553 dlg.ctrlBox1->SetValue(Type == 0);
01554 dlg.ctrlBox2->SetValue(Type == 1);
01555 dlg.ctrlBox3->SetValue(Type == 2);
01556 dlg.SetMode(!R->Active);
01557 dlg.UpdateLayout(Type);
01558 Res = dlg.ShowModal();
01559
01560 if ( Res == wxID_OK ) {
01561 switch ( dlg.GetBoxType() ) {
01562
01563 case 0:
01564 R->Box = dlg.GetBoxNr();
01565
01566 break;
01567
01568 case 1:
01569 R->Box = GmnBox;
01570
01571 break;
01572
01573 case 2:
01574 R->Box = NoBox;
01575
01576 break;
01577 }
01578
01579 R->Active = !dlg.GetMode();
01580 }
01581
01582 break;
01583 }
01584
01585 case RT_OUTFILTER: {
01586 OutputFilterDlg dlg(this);
01587 dlg.SetFrom(R->OFrom);
01588 dlg.SetTo(R->OTo);
01589 dlg.SetAvoidDrumChannel(R->ONoDrum);
01590 Res = dlg.ShowModal();
01591
01592 if ( Res == wxID_OK ) {
01593 R->OFrom = dlg.GetFrom();
01594 R->OTo = dlg.GetTo();
01595 R->ONoDrum = dlg.GetAvoidDrumChannel();
01596 }
01597
01598 break;
01599 }
01600
01601 case RT_OUTDEVICE:
01602 EDevice *Out = R->Out;
01603
01604
01605 if ( !Out ) {
01606 Out = NewDevice(&OutEDevices, DTUnknown, wxEmptyString, 0, 0, 0);
01607 R->Out = Out;
01608 Refresh();
01609 NeedNew = TRUE;
01610 }
01611
01612
01613 OutputDevDlg out(this);
01614
01615 #ifdef RTMIDI
01616 nMidi = rtmidiout->getPortCount();
01617
01618 if ( nMidi ) {
01619 #ifdef __WXMSW__
01620 wxString portName;
01621 #else
01622 std::string portName;
01623 #endif
01624
01625 for (int i = 0; i < nMidi; i++) {
01626 try {
01627 portName = rtmidiout->getPortName(i);
01628 #ifdef __WXMSW__
01629 out.ctrlMidiDevice->Append(portName);
01630 #else
01631 out.ctrlMidiDevice->Append(muT(portName.c_str()));
01632 #endif
01633 } catch (RtError &error) {
01634 error.printMessage();
01635 break;
01636 }
01637 }
01638 } else
01639 out.ctrlMidiDevice->Append(_("no device"));
01640
01641 #else
01642 nMidi = midiOutGetNumDevs();
01643
01644 if ( nMidi ) {
01645 for (int i = 0; i < nMidi; i++) {
01646 MIDIOUTCAPS miout;
01647 midiOutGetDevCaps(i, &miout, sizeof(MIDIOUTCAPS));
01648 DataR0.Device.AddString(miout.szPname);
01649 }
01650 } else
01651 DataR0.Device.AddString("no device");
01652
01653 #endif
01654 out.SetType(0);
01655
01656 out.SetMidiDevice(0);
01657
01658 out.SetMidiDeviceBending(2);
01659
01660 out.SetMidiFile(wxEmptyString);
01661
01662 out.SetMidiFileBending(2);
01663
01664 out.SetGUIDOFile(wxEmptyString);
01665
01666
01667 int type = 0;
01668
01669 switch ( Out->DT ) {
01670
01671 case DTGis:
01672 out.SetType(type = 2);
01673
01674 out.SetGUIDOFile(Out->Name);
01675
01676 break;
01677
01678 case DTMidiPort:
01679 out.SetMidiDevice(Out->DevId);
01680
01681 out.SetMidiDeviceBending(Out->BendingRange);
01682
01683 break;
01684
01685 case DTMidiFile:
01686 out.SetType(type = 1);
01687
01688 out.SetMidiFile(Out->Name);
01689
01690 out.SetMidiFileBending(Out->BendingRange);
01691
01692 break;
01693
01694 case DTNotSet:
01695 wxLogWarning(_("Unexpected value: DTNotSet"));
01696
01697 break;
01698
01699 case DTUnknown:
01700 break;
01701
01702 default:
01703 wxLogError(_("Unexpected device type: %d"), Out->DT);
01704 }
01705
01706 out.UpdateLayout(type);
01707
01708 Res = out.ShowModal();
01709
01710 if ( Res == wxID_OK ) {
01711 int type = out.GetType();
01712
01713 if ( type == 0 ) {
01714 Out = NewDevice(&OutEDevices,
01715 DTMidiPort,
01716 out.ctrlMidiDevice->GetString(out.GetMidiDevice()),
01717 out.GetMidiDevice(), Out, Out);
01718 Out->BendingRange = out.GetMidiDeviceBending();
01719 } else if ( type == 1 ) {
01720 Out = NewDevice(&OutEDevices,
01721 DTMidiFile,
01722 out.GetMidiFile(),
01723 0, Out, Out);
01724 Out->BendingRange = out.GetMidiFileBending();
01725 } else
01726 Out = NewDevice(&OutEDevices, DTGis, out.GetGUIDOFile(), 0, Out, Out);
01727 } else if ( Res == wxID_REMOVE || (NeedNew && Res == wxCANCEL) )
01728 Out = 0;
01729
01730 R->Out = Out;
01731
01732 break;
01733 }
01734
01735
01736 if ( Res == wxID_OK || Res == wxID_REMOVE || NeedNew )
01737 Refresh();
01738 }
01739 #endif
01740
01741
01742
01743
01744
01745
01746
01747
01748
01749