00001
00032
00033
00034
00035
00036 #include "Defs.h"
00037
00038 #include "wx/wxprec.h"
00039
00040 #ifdef __BORLANDC__
00041 #pragma hdrstop
00042 #endif
00043
00044 #ifndef WX_PRECOMP
00045 #include "wx/wx.h"
00046
00047 #endif
00048
00049 #include "Global.h"
00050
00051 #include "Runtime.h"
00052 #include "MidiKern.h"
00053
00054
00055 #include "MutLogicWnd.h"
00056 #include "MutChild.h"
00057 #include "MutFrame.h"
00058 #include "MutRouteWnd.h"
00059
00060
00061
00062 #include "Icon/Logic.xpm"
00063 #include "Icon/LogicOpen.xpm"
00064 #include "Icon/Tonesyst.xpm"
00065 #include "Icon/TonesystOpen.xpm"
00066
00067
00068 int pubTaste;
00069
00070 extern bool UseColorBars;
00071
00072
00073
00074
00075
00076
00077 #define MUTTAGX 90
00078 #define MUTTAGY 70
00079
00080
00081 wxSize MutTagSize(MUTTAGX, MUTTAGY);
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092 class MutTag : public wxWindow
00093 {
00094
00095 public:
00096
00097 MutTag(wxWindow *parent, const wxPoint& pos,
00098 int isLogic, int isOpen, int key, const wxString& text);
00099
00100 private:
00101 bool IsLogic;
00102 int Key;
00103 wxIcon Icon;
00104 wxString Text;
00105 int TPos;
00106
00107 public:
00108 int GetKey()
00109 {
00110 return Key;
00111 }
00112
00113 bool GetIsLogic()
00114
00115 {
00116 return IsLogic;
00117 }
00118
00119 void InitText(wxDC& dc);
00120
00121
00122
00123 void OnPaint(wxPaintEvent& WXUNUSED(event));
00124 void OnChar(wxKeyEvent& event);
00125 void OnLeftDown(wxMouseEvent& event);
00126 void OnFocus(wxFocusEvent& event);
00127
00128 private:
00129 void PaintCenteredText(wxDC &dc, wxString s, int y)
00130 {
00131 wxCoord w, h;
00132 dc.GetTextExtent(s, &w, &h);
00133 dc.DrawText(s, (MUTTAGX-w)/2, y);
00134 }
00135
00136 public:
00137 DECLARE_EVENT_TABLE()
00138 };
00139
00140 BEGIN_EVENT_TABLE(MutTag, wxWindow)
00141 EVT_PAINT(MutTag::OnPaint)
00142 EVT_CHAR(MutTag::OnChar)
00143 EVT_LEFT_DOWN(MutTag::OnLeftDown)
00144 EVT_SET_FOCUS(MutTag::OnFocus)
00145 EVT_KILL_FOCUS(MutTag::OnFocus)
00146 END_EVENT_TABLE()
00147
00148
00149
00150
00151
00152
00153
00154 MutTag::MutTag(wxWindow *parent, const wxPoint& pos,
00155 int isLogic, int isOpen, int key, const wxString& text)
00156 : wxWindow(parent, CM_MUTTAG, pos, MutTagSize)
00157 {
00158
00159
00160
00161
00162
00163
00164 const char ** TagIcon[4] = {
00165 tonesyst_xpm, logic_xpm, tonesystopen_xpm, logicopen_xpm
00166 };
00167
00168 Icon = wxIcon(TagIcon[isLogic + 2*isOpen]);
00169 Text = text;
00170 TPos = -1;
00171 IsLogic = isLogic;
00172 Key = key;
00173
00174
00175 }
00176
00177 void MutTag::InitText(wxDC& dc)
00178
00179 {
00180 int i = Text.Length();
00181 wxCoord w, h;
00182 dc.GetTextExtent(Text, &w, &h);
00183
00184 if ( w <= MUTTAGX-4 ) TPos = 0;
00185
00186 while ( i >= 0 ) {
00187 if ( Text[i] == '_' ) {
00188 Text[i] = '-';
00189 if ( TPos == -1 ) {
00190 dc.GetTextExtent(Text.Left(i+1), &w, &h);
00191 if ( w <= MUTTAGX-4 ) TPos = i+1;
00192 }
00193 }
00194
00195 i--;
00196 }
00197
00198 if ( TPos == -1 ) TPos = 0;
00199
00200 dc.GetTextExtent(Text.Mid(TPos), &w, &h);
00201
00202 if ( w > MUTTAGX-4 )
00203 Text.Last() = '.';
00204
00205 dc.GetTextExtent(Text.Mid(TPos), &w, &h);
00206
00207 int l = Text.Length();
00208
00209 while ( w > MUTTAGX-4 ) {
00210 l--;
00211 Text.Truncate(l);
00212 Text.Last() = '.';
00213 dc.GetTextExtent(Text.Mid(TPos), &w, &h);
00214 }
00215 }
00216
00217 void MutTag::OnPaint(wxPaintEvent& WXUNUSED(event))
00218 {
00219 wxPaintDC dc(this);
00220
00221 dc.SetMapMode(wxMM_TEXT);
00222
00223
00224 if ( TPos == -1 ) InitText(dc);
00225
00226
00227 wxPen SelPen(*wxBLACK, 1, wxDOT);
00228
00229 if ( wxWindow::FindFocus() == this )
00230 dc.SetPen(SelPen);
00231 else
00232 dc.SetPen(*wxWHITE_PEN);
00233
00234 if ( TPos )
00235 dc.DrawRectangle(1, 3, MUTTAGX-6, MUTTAGY-3);
00236 else
00237 dc.DrawRectangle(1, 3, MUTTAGX-6, MUTTAGY-6);
00238
00239 dc.SetPen(wxNullPen);
00240
00241
00242 dc.DrawIcon(Icon, MUTTAGX/2-16, 10);
00243
00244
00245 dc.SetBackgroundMode(wxTRANSPARENT);
00246
00247 PaintCenteredText(dc, wxString::Format(_T("%c"), Key), 20);
00248
00249 dc.SetBackgroundMode(wxSOLID);
00250
00251
00252 if ( TPos ) {
00253 PaintCenteredText(dc, Text.Mid(0, TPos), 44);
00254 PaintCenteredText(dc, Text.Mid(TPos), 56);
00255 } else
00256 PaintCenteredText(dc, Text, 50);
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 void MutTag::OnChar(wxKeyEvent& event)
00311 {
00312
00313
00314 if ( ('A' < event.GetKeyCode() && event.GetKeyCode() <= 'z') || event.GetKeyCode() == WXK_TAB || event.GetKeyCode() == WXK_RETURN || event.GetKeyCode() == WXK_SPACE )
00315 wxPostEvent(GetParent(),event);
00316 }
00317
00318 void MutTag::OnLeftDown(wxMouseEvent& event)
00319 {
00320 wxCommandEvent event1(wxEVT_COMMAND_MENU_SELECTED, CM_MUTTAG);
00321 event1.SetEventObject(this);
00322
00323 wxPostEvent(GetParent(),event1);
00324 event.Skip();
00325 }
00326
00327 void MutTag::OnFocus(wxFocusEvent& event)
00328 {
00329 Refresh();
00330 ((MutLogicWnd*)GetParent())->CorrectScroller();
00331 event.Skip();
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 BEGIN_EVENT_TABLE(MutLogicWnd, wxScrolledWindow)
00363 EVT_CHAR(MutLogicWnd::OnChar)
00364 EVT_SIZE(MutLogicWnd::OnSize)
00365 EVT_MENU(CM_MUTTAG, MutLogicWnd::CmMutTag)
00366 EVT_CLOSE(MutLogicWnd::OnClose)
00367 END_EVENT_TABLE()
00368
00369 MutLogicWnd::MutLogicWnd(wxWindow *parent,
00370 int box,
00371
00372 const wxPoint& pos,
00373 const wxSize& size)
00374 : wxScrolledWindow(parent, -1, pos, size, wxHSCROLL | wxVSCROLL | wxTAB_TRAVERSAL)
00375 {
00376 #ifdef DEBUG
00377 std::cout << "MutLogicWnd::MutLogicWnd: Box " << box << std::endl;
00378 #endif
00379
00380
00381
00382 boxnumber = box;
00383 ColorBar1 = 0;
00384 ColorBar2 = 0;
00385
00386 SetScrollRate( 10, 10 );
00387 SetBackgroundColour(*wxWHITE);
00388 Ok = false;
00389 CmBox();
00390
00391 winAttr = GetWinAttr(WK_LOGIC,box);
00392 wxASSERT(!winAttr->Win);
00393 winAttr->Win = this;
00394 }
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404 void MutLogicWnd::doClose(wxEvent& event)
00405 {
00406 DEBUGLOG (other, _T(""));
00407 wxWindow * parent;
00408 bool stop;
00409 wxCommandEvent event1(wxEVT_COMMAND_MENU_SELECTED, CM_STOP);
00410
00411 if ( (stop = (NumberOfOpen(WK_LOGIC) <= 1) ) ) {
00412 parent = GetParent();
00413
00414 while (!(dynamic_cast<MutFrame *>(parent))) {
00415 DEBUGLOG (other, _T("Searching for MutFrame: %p..."),parent);
00416 parent = parent->GetParent();
00417 }
00418
00419
00420 }
00421
00422
00423 event.Skip(false);
00424
00425 Destroy();
00426
00427 DEBUGLOGBASE(other,"MutLogicWnd",_T("Destroyed Window"));
00428
00429 if (stop) wxPostEvent(parent,event1);
00430
00431 DEBUGLOGBASE(other,"MutLogicWnd",_T("Destroyed Window"));
00432 }
00433
00434
00435
00436
00437 void MutLogicWnd::OnChar(wxKeyEvent& event)
00438 {
00439 pubTaste = event.GetKeyCode();
00440 CmTaste();
00441 event.Skip();
00442 }
00443
00444 void MutLogicWnd::CmTaste()
00445
00446 {
00447 int key = pubTaste;
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470 if ( key == WXK_SPACE ) {
00471
00472
00473
00474
00475 wxWindow *w = wxWindow::FindFocus();
00476
00477 if ( w && w->GetId() == CM_MUTTAG )
00478 UpDate(((MutTag*)w)->GetKey(), ((MutTag*)w)->GetIsLogic());
00479 } else {
00480
00481
00482
00483 if ( 'a' <= key && key <= 'z' ) key += 'A' - 'a';
00484
00485
00486 char isLogic = IsLogicKey((char)key);
00487
00488 if ( isLogic == 2 ) return;
00489
00490
00491 UpDate(key, isLogic);
00492 }
00493 }
00494
00495 void MutLogicWnd::OnSize(wxSizeEvent& event)
00496 {
00497
00498 event.Skip();
00499 DoLayout();
00500 }
00501
00502 #define max(a, b) ((a) < (b) ? (b) : (a))
00503
00504 void MutLogicWnd::DoLayout()
00505 {
00506 wxSize R = GetClientSize();
00507 int nx = (R.GetWidth()-4) / MUTTAGX, ny = (R.GetHeight()-4)/ MUTTAGY;
00508 bool quer = R.GetWidth() > R.GetHeight();
00509
00510 if ( nx * ny < nTags )
00511 {
00512
00513 if ( ny < 1) ny = 1;
00514
00515 if ( quer ) nx = (nTags + ny -1) / ny;
00516 }
00517 std::cout << nTags << nx << std::endl;
00518
00519 if ( nx < 1 ) nx = 1;
00520
00521 ny = (nTags + nx -1) / nx;
00522
00523 int x = 4, y = 4, xi = 0;
00524
00525 std::cout << nx << MUTTAGX << ny << MUTTAGY << std::endl;
00526
00527 SetVirtualSize(nx*MUTTAGX+8, ny*MUTTAGY+8);
00528
00529 int xv, yv;
00530
00531 GetViewStart(&xv, &yv);
00532
00533 for (wxWindowList::iterator i = GetChildren().begin(); i!=GetChildren().end(); i++) {
00534 wxWindow * Win= *i;
00535 if ( Win->GetId() == CM_MUTTAG ) {
00536
00537 Win->Move(x-xv*10, y-yv*10);
00538 x += MUTTAGX;
00539 xi++;
00540
00541 if ( xi == nx ) {
00542 x = 4;
00543 xi = 0;
00544 y += MUTTAGY;
00545 }
00546 }
00547 }
00548
00549 if ( xi )
00550 y += MUTTAGY;
00551
00552
00553 if ( ColorBar1 )
00554 ColorBar1->SetSize(-xv*10, -yv*10, max(nx*MUTTAGX+8, R.GetWidth()), 2);
00555
00556 if ( ColorBar2 )
00557 ColorBar2->SetSize(-xv*10, -yv*10, 2, max(ny*MUTTAGY+8, R.GetHeight()));
00558
00559 CorrectScroller();
00560 };
00561
00562
00563
00564 void MutLogicWnd::CmMutTag(wxCommandEvent& event)
00565 {
00566 MutTag *Tag = (MutTag*)event.GetEventObject();
00567 UpDate(Tag->GetKey(), Tag->GetIsLogic());
00568 }
00569
00570 void MutLogicWnd::CorrectScroller()
00571 {
00572 wxWindow *Win = wxWindow::FindFocus();
00573
00574 if ( !Win || Win->GetId() != CM_MUTTAG )
00575 return;
00576
00577 int xView, yView;
00578
00579 GetViewStart(&xView, &yView);
00580
00581 xView *=10;
00582
00583 yView *=10;
00584
00585 int xw, yw;
00586
00587 Win->GetPosition(&xw, &yw);
00588
00589 xw += xView;
00590
00591 yw += yView;
00592
00593 int w, h;
00594
00595 GetClientSize(&w, &h);
00596
00597 int dx = xView, dy = yView;
00598
00599
00600 if ( xw + MUTTAGX > xView+w ) dx = xw + MUTTAGX - w;
00601
00602 if ( yw + MUTTAGY > yView+h ) dy = yw + MUTTAGY - h;
00603
00604
00605 if ( xw < xView ) dx = xw;
00606
00607 if ( yw < yView ) dy = yw;
00608
00609 Scroll(dx / 10, dy / 10);
00610 }
00611
00612
00613 void MutLogicWnd::UpDate(int thekey, bool isLogicKey)
00614 {
00615
00616 KeyboardAnalyse(boxnumber, thekey, isLogicKey);
00617 curTaste[boxnumber][isLogicKey] = thekey;
00618 wxWindow *ToFocus = NULL;
00619
00620 if ( isLogicKey )
00621 curTaste[boxnumber][0] = 0;
00622
00623
00624 DestroyChildren();
00625
00626
00627 char isLogic, s[200], s1[200], key, isOpen;
00628
00629 wxString sText, sEinst;
00630
00631 wxWindow *aWin;
00632
00633 nTags = 0;
00634
00635 if ( GetMutTag(isLogic, s, s1, key, boxnumber) )
00636 do {
00637 nTags++;
00638 sText = muT(s);
00639 sEinst = muT(s1);
00640
00641 if ( (isOpen = (key == curTaste[boxnumber][(size_t)isLogic])) != 0 ) {
00642 if ( isLogic ) {
00643 curLogic[boxnumber] = sText;
00644
00645 if ( !sEinst.IsEmpty() )
00646 curTS[boxnumber] = sEinst;
00647 else if ( !curTS[boxnumber] )
00648 curTS[boxnumber] = _("(INITIAL)");
00649 else if ( curTS[boxnumber][0] != '[' )
00650 curTS[boxnumber] = wxString::Format(_T("[%s]"), curTS[boxnumber].c_str());
00651 } else
00652 curTS[boxnumber] = sText;
00653 }
00654
00655 aWin = new MutTag(this, wxDefaultPosition, isLogic, isOpen, key, sText);
00656
00657 if ( isOpen ) ToFocus = aWin;
00658 } while ( GetMutTag(isLogic, s, s1, key) );
00659
00660
00661 if ( UseColorBars ) {
00662 wxColour BarColor = BoxColor(boxnumber);
00663 ColorBar1 = new wxWindow(this, -1, wxPoint(0, 0), wxSize(2,2));
00664 ColorBar1->SetBackgroundColour(BarColor);
00665 ColorBar1->Disable();
00666 ColorBar2 = new wxWindow(this, -1, wxPoint(0, 0), wxSize(2,2));
00667 ColorBar2->SetBackgroundColour(BarColor);
00668 ColorBar2->Disable();
00669 } else {
00670 ColorBar1 = 0;
00671 ColorBar2 = 0;
00672 }
00673
00674
00675
00676
00677 #if 0
00678 if ( !ToFocus )
00679 ToFocus = GetChildren().GetFirst()->GetData();
00680 #endif
00681
00682 if ( ToFocus && FindFocus() != ToFocus)
00683 ToFocus->SetFocus();
00684
00685
00686 DoLayout();
00687
00688 wxCommandEvent event1(wxEVT_COMMAND_MENU_SELECTED,
00689 CM_UPDATEUI);
00690 GetParent()->GetEventHandler()->ProcessEvent(event1);
00691 Ok = true;
00692 }
00693
00694
00695 void MutLogicWnd::CmBox()
00696 {
00697 DEBUGLOG (other, _T("%s at box %d"),CompiledFile.c_str(),boxnumber );
00698
00699 GetParent()->SetName(wxString::Format(_("Logic: %s - Box %d"),
00700 CompiledFile.c_str(), boxnumber));
00701
00702 UpDate(0, true);
00703 }
00704
00705
00706
00707
00708
00709
00710
00711