-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMixerBoard.cpp
1756 lines (1504 loc) · 57.3 KB
/
MixerBoard.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**********************************************************************
Audacity: A Digital Audio Editor
MixerBoard.cpp
Vaughan Johnson, January 2007
Dominic Mazzoni
**********************************************************************/
#include "Audacity.h"
#include "Experimental.h"
#include <math.h>
#include <wx/dcmemory.h>
#include <wx/arrimpl.cpp>
#include <wx/settings.h> // for wxSystemSettings::GetColour and wxSystemSettings::GetMetric
#include "AColor.h"
#include "MixerBoard.h"
#ifdef EXPERIMENTAL_MIDI_OUT
#include "NoteTrack.h"
#endif
#include "Project.h"
#include "Track.h"
#include "../images/MusicalInstruments.h"
#ifdef __WXMSW__
#include "../images/AudacityLogo.xpm"
#else
#include "../images/AudacityLogo48x48.xpm"
#endif
// class MixerTrackSlider
BEGIN_EVENT_TABLE(MixerTrackSlider, ASlider)
EVT_MOUSE_EVENTS(MixerTrackSlider::OnMouseEvent)
EVT_SET_FOCUS(MixerTrackSlider::OnFocus)
EVT_KILL_FOCUS(MixerTrackSlider::OnFocus)
EVT_COMMAND(wxID_ANY, EVT_CAPTURE_KEY, MixerTrackSlider::OnCaptureKey)
END_EVENT_TABLE()
MixerTrackSlider::MixerTrackSlider(wxWindow * parent,
wxWindowID id,
wxString name,
const wxPoint & pos,
const wxSize & size,
int style /*= FRAC_SLIDER*/,
bool popup /*= true*/,
bool canUseShift /*= true*/,
float stepValue /*= STEP_CONTINUOUS*/,
int orientation /*= wxHORIZONTAL*/)
: ASlider(parent, id, name, pos, size,
style, popup, canUseShift, stepValue, orientation)
{
}
void MixerTrackSlider::OnMouseEvent(wxMouseEvent &event)
{
ASlider::OnMouseEvent(event);
if (event.ButtonUp())
{
MixerTrackCluster* pMixerTrackCluster = (MixerTrackCluster*)(this->GetParent());
switch (mStyle)
{
case DB_SLIDER: pMixerTrackCluster->HandleSliderGain(true); break;
case PAN_SLIDER: pMixerTrackCluster->HandleSliderPan(true); break;
default: break; // no-op
}
}
}
void MixerTrackSlider::OnFocus(wxFocusEvent &event)
{
wxCommandEvent e(EVT_CAPTURE_KEYBOARD);
if (event.GetEventType() == wxEVT_KILL_FOCUS) {
e.SetEventType(EVT_RELEASE_KEYBOARD);
}
e.SetEventObject(this);
GetParent()->GetEventHandler()->ProcessEvent(e);
Refresh(false);
event.Skip();
}
void MixerTrackSlider::OnCaptureKey(wxCommandEvent &event)
{
wxKeyEvent *kevent = (wxKeyEvent *)event.GetEventObject();
int keyCode = kevent->GetKeyCode();
// Pass LEFT/RIGHT/UP/DOWN/PAGEUP/PAGEDOWN through for input/output sliders
if (keyCode == WXK_LEFT || keyCode == WXK_RIGHT ||
keyCode == WXK_UP || keyCode == WXK_DOWN ||
keyCode == WXK_PAGEUP || keyCode == WXK_PAGEDOWN) {
return;
}
event.Skip();
return;
}
// class MixerTrackCluster
#define kInset 4
#define kDoubleInset (2 * kInset)
#define kTripleInset (3 * kInset)
#define kQuadrupleInset (4 * kInset)
#define TRACK_NAME_HEIGHT 18
#define MUSICAL_INSTRUMENT_HEIGHT_AND_WIDTH 48
#define MUTE_SOLO_HEIGHT 16
#define PAN_HEIGHT 24
#define kLeftSideStackWidth MUSICAL_INSTRUMENT_HEIGHT_AND_WIDTH - kDoubleInset //vvv Change when numbers shown on slider scale.
#define kRightSideStackWidth MUSICAL_INSTRUMENT_HEIGHT_AND_WIDTH + kDoubleInset
#define kMixerTrackClusterWidth kLeftSideStackWidth + kRightSideStackWidth + kQuadrupleInset // kDoubleInset margin on both sides
enum {
ID_BITMAPBUTTON_MUSICAL_INSTRUMENT = 13000,
ID_SLIDER_PAN,
ID_SLIDER_GAIN,
ID_TOGGLEBUTTON_MUTE,
ID_TOGGLEBUTTON_SOLO,
};
BEGIN_EVENT_TABLE(MixerTrackCluster, wxPanel)
EVT_CHAR(MixerTrackCluster::OnKeyEvent)
EVT_MOUSE_EVENTS(MixerTrackCluster::OnMouseEvent)
EVT_PAINT(MixerTrackCluster::OnPaint)
EVT_BUTTON(ID_BITMAPBUTTON_MUSICAL_INSTRUMENT, MixerTrackCluster::OnButton_MusicalInstrument)
EVT_SLIDER(ID_SLIDER_PAN, MixerTrackCluster::OnSlider_Pan)
EVT_SLIDER(ID_SLIDER_GAIN, MixerTrackCluster::OnSlider_Gain)
//v EVT_COMMAND_SCROLL(ID_SLIDER_GAIN, MixerTrackCluster::OnSliderScroll_Gain)
EVT_COMMAND(ID_TOGGLEBUTTON_MUTE, wxEVT_COMMAND_BUTTON_CLICKED, MixerTrackCluster::OnButton_Mute)
EVT_COMMAND(ID_TOGGLEBUTTON_SOLO, wxEVT_COMMAND_BUTTON_CLICKED, MixerTrackCluster::OnButton_Solo)
END_EVENT_TABLE()
MixerTrackCluster::MixerTrackCluster(wxWindow* parent,
MixerBoard* grandParent, AudacityProject* project,
WaveTrack* pLeftTrack, WaveTrack* pRightTrack /*= NULL*/,
const wxPoint& pos /*= wxDefaultPosition*/,
const wxSize& size /*= wxDefaultSize*/)
: wxPanel(parent, -1, pos, size)
{
mMixerBoard = grandParent;
mProject = project;
#ifdef EXPERIMENTAL_MIDI_OUT
if (pLeftTrack->GetKind() == Track::Note) {
mLeftTrack = NULL;
mNoteTrack = (NoteTrack*) pLeftTrack;
mTrack = pLeftTrack;
} else {
wxASSERT(pLeftTrack->GetKind() == Track::Wave);
mTrack = mLeftTrack = pLeftTrack;
mNoteTrack = NULL;
}
#else
wxASSERT(pLeftTrack->GetKind() == Track::Wave);
mLeftTrack = pLeftTrack;
#endif
mRightTrack = pRightTrack;
SetName(mLeftTrack->GetName());
this->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
// Not sure why, but sizers weren't getting offset vertically,
// probably because not using wxDefaultPosition,
// so positions are calculated explicitly below, and sizers code was removed.
// (Still available in Audacity_UmixIt branch off 1.2.6.)
// track name
wxPoint ctrlPos(kDoubleInset, kDoubleInset);
wxSize ctrlSize(size.GetWidth() - kQuadrupleInset, TRACK_NAME_HEIGHT);
mStaticText_TrackName =
#ifdef EXPERIMENTAL_MIDI_OUT
new wxStaticText(this, -1, mTrack->GetName(), ctrlPos, ctrlSize,
wxALIGN_CENTRE | wxST_NO_AUTORESIZE | wxSUNKEN_BORDER);
#else
new wxStaticText(this, -1, mLeftTrack->GetName(), ctrlPos, ctrlSize,
wxALIGN_CENTRE | 0x0001 | wxBORDER_SUNKEN);
#endif
//v Useful when different tracks are different colors, but not now.
// mStaticText_TrackName->SetBackgroundColour(this->GetTrackColor());
// gain slider at left
ctrlPos.x = kDoubleInset;
ctrlPos.y += TRACK_NAME_HEIGHT + kDoubleInset;
const int nGainSliderHeight =
size.GetHeight() - ctrlPos.y - kQuadrupleInset;
ctrlSize.Set(kLeftSideStackWidth - kQuadrupleInset, nGainSliderHeight);
#ifdef EXPERIMENTAL_MIDI_OUT
if (mNoteTrack) {
mSlider_Gain =
new MixerTrackSlider(
this, ID_SLIDER_GAIN,
/* i18n-hint: title of the MIDI Velocity slider */
_("Velocity"),
ctrlPos, ctrlSize, VEL_SLIDER, true,
true, 0.0, wxVERTICAL);
} else
#endif
mSlider_Gain =
new MixerTrackSlider(
this, ID_SLIDER_GAIN,
/* i18n-hint: title of the Gain slider, used to adjust the volume */
_("Gain"),
ctrlPos, ctrlSize, DB_SLIDER, true,
true, 0.0, wxVERTICAL);
mSlider_Gain->SetName(_("Gain"));
this->UpdateGain();
// other controls and meter at right
// musical instrument image
ctrlPos.x += kLeftSideStackWidth + kInset; // + kInset to center it in right side stack
ctrlSize.Set(MUSICAL_INSTRUMENT_HEIGHT_AND_WIDTH, MUSICAL_INSTRUMENT_HEIGHT_AND_WIDTH);
#ifdef EXPERIMENTAL_MIDI_OUT
wxBitmap* bitmap = mMixerBoard->GetMusicalInstrumentBitmap(mTrack->GetName());
#else
wxBitmap* bitmap = mMixerBoard->GetMusicalInstrumentBitmap(mLeftTrack);
#endif
wxASSERT(bitmap);
mBitmapButton_MusicalInstrument =
new wxBitmapButton(this, ID_BITMAPBUTTON_MUSICAL_INSTRUMENT, *bitmap,
ctrlPos, ctrlSize,
wxBU_AUTODRAW, wxDefaultValidator,
_("Musical Instrument"));
mBitmapButton_MusicalInstrument->SetName(_("Musical Instrument"));
// pan slider
ctrlPos.x -= kInset; // Remove inset for instrument, so Pan is at leftmost of left side stack.
ctrlPos.y += MUSICAL_INSTRUMENT_HEIGHT_AND_WIDTH + kDoubleInset;
ctrlSize.Set(kRightSideStackWidth, PAN_HEIGHT);
// The width of the pan slider must be odd (don't ask).
if (!(ctrlSize.x & 1))
ctrlSize.x--;
mSlider_Pan =
new MixerTrackSlider(
this, ID_SLIDER_PAN,
/* i18n-hint: Title of the Pan slider, used to move the sound left or right */
_("Pan"),
ctrlPos, ctrlSize, PAN_SLIDER, true);
mSlider_Pan->SetName(_("Pan"));
this->UpdatePan();
// mute/solo buttons stacked below Pan slider
ctrlPos.y += PAN_HEIGHT + kDoubleInset;
ctrlSize.Set(mMixerBoard->mMuteSoloWidth, MUTE_SOLO_HEIGHT);
mToggleButton_Mute =
new AButton(this, ID_TOGGLEBUTTON_MUTE,
ctrlPos, ctrlSize,
*(mMixerBoard->mImageMuteUp), *(mMixerBoard->mImageMuteOver),
*(mMixerBoard->mImageMuteDown), *(mMixerBoard->mImageMuteDisabled),
true); // toggle button
mToggleButton_Mute->SetName(_("Mute"));
mToggleButton_Mute->SetAlternateImages(
*(mMixerBoard->mImageMuteUp), *(mMixerBoard->mImageMuteOver),
*(mMixerBoard->mImageMuteDown), *(mMixerBoard->mImageMuteDisabled));
this->UpdateMute();
ctrlPos.y += MUTE_SOLO_HEIGHT;
mToggleButton_Solo =
new AButton(this, ID_TOGGLEBUTTON_SOLO,
ctrlPos, ctrlSize,
*(mMixerBoard->mImageSoloUp), *(mMixerBoard->mImageSoloOver),
*(mMixerBoard->mImageSoloDown), *(mMixerBoard->mImageSoloDisabled),
true); // toggle button
mToggleButton_Solo->SetName(_("Solo"));
this->UpdateSolo();
bool bSoloNone = mProject->IsSoloNone();
mToggleButton_Solo->Show(!bSoloNone);
// meter
ctrlPos.y += (bSoloNone ? 0 : MUTE_SOLO_HEIGHT) + kDoubleInset;
const int nMeterHeight =
nGainSliderHeight -
(MUSICAL_INSTRUMENT_HEIGHT_AND_WIDTH + kDoubleInset) -
(PAN_HEIGHT + kDoubleInset) -
(MUTE_SOLO_HEIGHT + (bSoloNone ? 0 : MUTE_SOLO_HEIGHT) + kDoubleInset);
ctrlSize.Set(kRightSideStackWidth, nMeterHeight);
#ifdef EXPERIMENTAL_MIDI_OUT
if (mLeftTrack) {
#endif
mMeter =
new Meter(this, -1, // wxWindow* parent, wxWindowID id,
false, // bool isInput
ctrlPos, ctrlSize, // const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
Meter::MixerTrackCluster); // Style style = HorizontalStereo,
mMeter->SetName(_("Signal Level Meter"));
#ifdef EXPERIMENTAL_MIDI_OUT
} else {
mMeter = NULL;
}
#endif
#if wxUSE_TOOLTIPS
#ifdef EXPERIMENTAL_MIDI_OUT
mStaticText_TrackName->SetToolTip(mTrack->GetName());
#else
mStaticText_TrackName->SetToolTip(mLeftTrack->GetName());
#endif
mToggleButton_Mute->SetToolTip(_("Mute"));
mToggleButton_Solo->SetToolTip(_("Solo"));
#ifdef EXPERIMENTAL_MIDI_OUT
if (mLeftTrack)
#endif
mMeter->SetToolTip(_("Signal Level Meter"));
#endif // wxUSE_TOOLTIPS
#ifdef __WXMAC__
wxSizeEvent dummyEvent;
this->OnSize(dummyEvent);
UpdateGain();
#endif
}
void MixerTrackCluster::HandleResize() // For wxSizeEvents, update gain slider and meter.
{
wxSize scrolledWindowClientSize = this->GetParent()->GetClientSize();
const int newClusterHeight =
scrolledWindowClientSize.GetHeight() - kDoubleInset - // nClusterHeight from MixerBoard::UpdateTrackClusters
wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y) + // wxScrolledWindow::GetClientSize doesn't account for its scrollbar size.
kDoubleInset;
this->SetSize(-1, newClusterHeight);
// Change only the heights of mSlider_Gain and mMeter.
// But update shown status of mToggleButton_Solo, which affects top of mMeter.
const int nGainSliderHeight =
newClusterHeight -
(kInset + // margin above mStaticText_TrackName
TRACK_NAME_HEIGHT + kDoubleInset) - // mStaticText_TrackName + margin
kQuadrupleInset; // margin below gain slider
mSlider_Gain->SetSize(-1, nGainSliderHeight);
bool bSoloNone = mProject->IsSoloNone();
mToggleButton_Solo->Show(!bSoloNone);
const int nRequiredHeightAboveMeter =
MUSICAL_INSTRUMENT_HEIGHT_AND_WIDTH + kDoubleInset +
PAN_HEIGHT + kDoubleInset +
MUTE_SOLO_HEIGHT + (bSoloNone ? 0 : MUTE_SOLO_HEIGHT) + kDoubleInset;
const int nMeterY =
kDoubleInset + // margin at top
TRACK_NAME_HEIGHT + kDoubleInset +
nRequiredHeightAboveMeter;
const int nMeterHeight = nGainSliderHeight - nRequiredHeightAboveMeter;
#ifdef EXPERIMENTAL_MIDI_OUT
if (mMeter)
#endif
mMeter->SetSize(-1, nMeterY, -1, nMeterHeight);
}
void MixerTrackCluster::HandleSliderGain(const bool bWantPushState /*= false*/)
{
float fValue = mSlider_Gain->Get();
if (mLeftTrack)
mLeftTrack->SetGain(fValue);
#ifdef EXPERIMENTAL_MIDI_OUT
else
mNoteTrack->SetGain(fValue);
#endif
if (mRightTrack)
mRightTrack->SetGain(fValue);
// Update the TrackPanel correspondingly.
#ifdef EXPERIMENTAL_MIDI_OUT
mProject->RefreshTPTrack(mTrack);
#else
mProject->RefreshTPTrack(mLeftTrack);
#endif
if (bWantPushState)
mProject->TP_PushState(_("Moved gain slider"), _("Gain"), PUSH_CONSOLIDATE );
}
void MixerTrackCluster::HandleSliderPan(const bool bWantPushState /*= false*/)
{
float fValue = mSlider_Pan->Get();
if (mLeftTrack) // test in case track is a NoteTrack
mLeftTrack->SetPan(fValue);
if (mRightTrack)
mRightTrack->SetPan(fValue);
// Update the TrackPanel correspondingly.
#ifdef EXPERIMENTAL_MIDI_OUT
mProject->RefreshTPTrack(mTrack);
#else
mProject->RefreshTPTrack(mLeftTrack);
#endif
if (bWantPushState)
mProject->TP_PushState(_("Moved pan slider"), _("Pan"), PUSH_CONSOLIDATE );
}
void MixerTrackCluster::ResetMeter(const bool bResetClipping)
{
#ifdef EXPERIMENTAL_MIDI_OUT
if (mMeter)
#endif
mMeter->Reset(mLeftTrack->GetRate(), bResetClipping);
}
// These are used by TrackPanel for synchronizing control states, etc.
// Update the controls that can be affected by state change.
void MixerTrackCluster::UpdateForStateChange()
{
this->UpdateName();
this->UpdatePan();
this->UpdateGain();
}
void MixerTrackCluster::UpdateName()
{
#ifdef EXPERIMENTAL_MIDI_OUT
const wxString newName = mTrack->GetName();
#else
const wxString newName = mLeftTrack->GetName();
#endif
SetName(newName);
mStaticText_TrackName->SetLabel(newName);
#if wxUSE_TOOLTIPS
mStaticText_TrackName->SetToolTip(newName);
#endif
mBitmapButton_MusicalInstrument->SetBitmapLabel(
#ifdef EXPERIMENTAL_MIDI_OUT
*(mMixerBoard->GetMusicalInstrumentBitmap(newName)));
#else
*(mMixerBoard->GetMusicalInstrumentBitmap(mLeftTrack)));
#endif
}
void MixerTrackCluster::UpdateMute()
{
#ifdef EXPERIMENTAL_MIDI_OUT
mToggleButton_Mute->SetAlternate(mTrack->GetSolo());
if (mTrack->GetMute())
#else
mToggleButton_Mute->SetAlternate(mLeftTrack->GetSolo());
if (mLeftTrack->GetMute())
#endif
mToggleButton_Mute->PushDown();
else
mToggleButton_Mute->PopUp();
}
void MixerTrackCluster::UpdateSolo()
{
#ifdef EXPERIMENTAL_MIDI_OUT
bool bIsSolo = mTrack->GetSolo();
#else
bool bIsSolo = mLeftTrack->GetSolo();
#endif
if (bIsSolo)
mToggleButton_Solo->PushDown();
else
mToggleButton_Solo->PopUp();
mToggleButton_Mute->SetAlternate(bIsSolo);
}
void MixerTrackCluster::UpdatePan()
{
#ifdef EXPERIMENTAL_MIDI_OUT
if (mNoteTrack) {
mSlider_Pan->Hide();
return;
}
#endif
mSlider_Pan->Set(mLeftTrack->GetPan());
}
void MixerTrackCluster::UpdateGain()
{
#ifdef EXPERIMENTAL_MIDI_OUT
if (mNoteTrack) {
mSlider_Gain->SetStyle(VEL_SLIDER);
mSlider_Gain->Set(mNoteTrack->GetGain());
return;
}
mSlider_Gain->SetStyle(DB_SLIDER);
#endif
mSlider_Gain->Set(mLeftTrack->GetGain());
}
void MixerTrackCluster::UpdateMeter(const double t0, const double t1)
{
#ifdef EXPERIMENTAL_MIDI_OUT
// NoteTracks do not (currently) register on meters. It would probably be
// a good idea to display 16 channel "active" lights rather than a meter
if (!mLeftTrack)
return;
#else
wxASSERT(mLeftTrack && (mLeftTrack->GetKind() == Track::Wave));
#endif
//vvv Vaughan, 2010-11-27:
// NOTE TO ROGER DANNENBERG:
// I undid the mTrack hack in this conditional, as the rest of the method still assumed it's a wavetrack
// so dereferencing mLeftTrack would have gotten a NULL pointer fault.
// I really think MixerTrackCluster should be factored for NoteTracks.
// REPLY: I think bSuccess prevents dereferencing mLeftTrack, but I will
// check. We should talk about whether it's better to factor
// MixerTrackCluster or more fully hide track types from MixerTrackCluster.
// For now, out change plan produced the following:
// Vaughan, 2011=10-15: There's no bSuccess here, so I don't know what you mean.
// But this change is consistent with the others for EXPERIMENTAL_MIDI_OUT, so I accept it.
if ((t0 < 0.0) || (t1 < 0.0) || (t0 >= t1) || // bad time value or nothing to show
#ifdef EXPERIMENTAL_MIDI_OUT
((mMixerBoard->HasSolo() || mTrack->GetMute()) && !mTrack->GetSolo()))
#else
((mMixerBoard->HasSolo() || mLeftTrack->GetMute()) && !mLeftTrack->GetSolo()))
#endif
{
//v Vaughan, 2011-02-25: Moved the update back to TrackPanel::OnTimer() as it helps with
// playback issues reported by Bill and noted on Bug 258, so no assert.
// Vaughan, 2011-02-04: Now that we're updating all meters from audacityAudioCallback,
// this causes an assert if you click Mute while playing, because ResetMeter() resets
// the timer, and wxTimerbase says that can only be done from main thread --
// but it seems to work fine.
this->ResetMeter(false);
return;
}
// Vaughan, 2010-11-27:
// This commented out code is flawed. Mistaken understanding of "frame" vs "window".
// Caused me to override Meter::UpdateDisplay().
// But I think it's got a good idea, of calling WaveTracks' GetMinMax and GetRMS
// instead of passing in all the data and asking the meter to derive peak and rms.
// May be worth revisiting as I think it should perform better, because it uses the min/max/rms
// stored in blockfiles, rather than calculating them, but for now, changing it to use the
// original Meter::UpdateDisplay(). New code is below the previous (now commented out).
//
//const int kFramesPerBuffer = 4;
//float min; // dummy, since it's not shown in meters
//float* maxLeft = new float[kFramesPerBuffer];
//float* rmsLeft = new float[kFramesPerBuffer];
//float* maxRight = new float[kFramesPerBuffer];
//float* rmsRight = new float[kFramesPerBuffer];
//
//#ifdef EXPERIMENTAL_MIDI_OUT
// bool bSuccess = (mLeftTrack != NULL);
//#else
// bool bSuccess = true;
//#endif
//const double dFrameInterval = (t1 - t0) / (double)kFramesPerBuffer;
//double dFrameT0 = t0;
//double dFrameT1 = t0 + dFrameInterval;
//int i = 0;
//while (bSuccess && (i < kFramesPerBuffer))
//{
// bSuccess &=
// mLeftTrack->GetMinMax(&min, &(maxLeft[i]), dFrameT0, dFrameT1) &&
// mLeftTrack->GetRMS(&(rmsLeft[i]), dFrameT0, dFrameT1);
// if (bSuccess && mRightTrack)
// bSuccess &=
// mRightTrack->GetMinMax(&min, &(maxRight[i]), dFrameT0, dFrameT1) &&
// mRightTrack->GetRMS(&(rmsRight[i]), dFrameT0, dFrameT1);
// else
// {
// // Mono: Start with raw values same as left.
// // To be modified by bWantPostFadeValues and channel pan/gain.
// maxRight[i] = maxLeft[i];
// rmsRight[i] = rmsLeft[i];
// }
// dFrameT0 += dFrameInterval;
// dFrameT1 += dFrameInterval;
// i++;
//}
//
//const bool bWantPostFadeValues = true; //v Turn this into a checkbox on MixerBoard? For now, always true.
//if (bSuccess && bWantPostFadeValues)
//if (bSuccess)
//{
// for (i = 0; i < kFramesPerBuffer; i++)
// {
// float gain = mLeftTrack->GetChannelGain(0);
// maxLeft[i] *= gain;
// rmsLeft[i] *= gain;
// if (mRightTrack)
// gain = mRightTrack->GetChannelGain(1);
// maxRight[i] *= gain;
// rmsRight[i] *= gain;
// }
// mMeter->UpdateDisplay(
// 2, // If mono, show left track values in both meters, as in MeterToolBar, rather than kNumChannels.
// kFramesPerBuffer,
// maxLeft, rmsLeft,
// maxRight, rmsRight,
// mLeftTrack->TimeToLongSamples(t1 - t0));
//}
//
//delete[] maxLeft;
//delete[] rmsLeft;
//delete[] maxRight;
//delete[] rmsRight;
sampleCount startSample = (sampleCount)((mLeftTrack->GetRate() * t0) + 0.5);
sampleCount nFrames = (sampleCount)((mLeftTrack->GetRate() * (t1 - t0)) + 0.5);
float* meterFloatsArray = NULL;
float* tempFloatsArray = new float[nFrames];
bool bSuccess = mLeftTrack->Get((samplePtr)tempFloatsArray, floatSample, startSample, nFrames);
if (bSuccess)
{
// We always pass a stereo sample array to the meter, as it shows 2 channels.
// Mono shows same in both meters.
// Since we're not mixing, need to duplicate same signal for "right" channel in mono case.
meterFloatsArray = new float[2 * nFrames];
// Interleave for stereo. Left/mono first.
for (int index = 0; index < nFrames; index++)
meterFloatsArray[2 * index] = tempFloatsArray[index];
if (mRightTrack)
bSuccess = mRightTrack->Get((samplePtr)tempFloatsArray, floatSample, startSample, nFrames);
if (bSuccess)
// Interleave right channel, or duplicate same signal for "right" channel in mono case.
for (int index = 0; index < nFrames; index++)
meterFloatsArray[(2 * index) + 1] = tempFloatsArray[index];
}
//const bool bWantPostFadeValues = true; //v Turn this into a checkbox on MixerBoard? For now, always true.
//if (bSuccess && bWantPostFadeValues)
if (bSuccess)
{
//vvv Need to apply envelope, too? See Mixer::MixSameRate.
float gain = mLeftTrack->GetChannelGain(0);
if (gain < 1.0)
for (int index = 0; index < nFrames; index++)
meterFloatsArray[2 * index] *= gain;
if (mRightTrack)
gain = mRightTrack->GetChannelGain(1);
else
gain = mLeftTrack->GetChannelGain(1);
if (gain < 1.0)
for (int index = 0; index < nFrames; index++)
meterFloatsArray[(2 * index) + 1] *= gain;
// Clip to [-1.0, 1.0] range.
for (int index = 0; index < 2 * nFrames; index++)
if (meterFloatsArray[index] < -1.0)
meterFloatsArray[index] = -1.0;
else if (meterFloatsArray[index] > 1.0)
meterFloatsArray[index] = 1.0;
mMeter->UpdateDisplay(2, nFrames, meterFloatsArray);
}
else
this->ResetMeter(false);
delete[] meterFloatsArray;
delete[] tempFloatsArray;
}
// private
wxColour MixerTrackCluster::GetTrackColor()
{
//#if (AUDACITY_BRANDING == BRAND_UMIXIT)
// return AColor::GetTrackColor((void*)mLeftTrack);
//#else
return wxColour(102, 255, 102); // same as Meter playback color
//#endif
}
// event handlers
void MixerTrackCluster::HandleSelect(const bool bShiftDown)
{
if (bShiftDown)
{
// ShiftDown => Just toggle selection on this track.
#ifdef EXPERIMENTAL_MIDI_OUT
bool bSelect = !mTrack->GetSelected();
mTrack->SetSelected(bSelect);
#else
bool bSelect = !mLeftTrack->GetSelected();
mLeftTrack->SetSelected(bSelect);
#endif
if (mRightTrack)
mRightTrack->SetSelected(bSelect);
// Refresh only this MixerTrackCluster and WaveTrack in TrackPanel.
this->Refresh(true);
#ifdef EXPERIMENTAL_MIDI_OUT
mProject->RefreshTPTrack(mTrack);
#else
mProject->RefreshTPTrack(mLeftTrack);
#endif
}
else
{
// exclusive select
mProject->SelectNone();
#ifdef EXPERIMENTAL_MIDI_OUT
mTrack->SetSelected(true);
#else
mLeftTrack->SetSelected(true);
#endif
if (mRightTrack)
mRightTrack->SetSelected(true);
if (mProject->GetSel0() >= mProject->GetSel1())
{
// No range previously selected, so use the range of this track.
#ifdef EXPERIMENTAL_MIDI_OUT
mProject->mViewInfo.sel0 = mTrack->GetOffset();
mProject->mViewInfo.sel1 = mTrack->GetEndTime();
#else
mProject->mViewInfo.sel0 = mLeftTrack->GetOffset();
mProject->mViewInfo.sel1 = mLeftTrack->GetEndTime();
#endif
}
// Exclusive select, so refresh all MixerTrackClusters.
// This could just be a call to wxWindow::Refresh, but this is
// more efficient and when ProjectLogo is shown as background,
// it's necessary to prevent blinking.
mMixerBoard->RefreshTrackClusters(false);
}
}
void MixerTrackCluster::OnKeyEvent(wxKeyEvent & event)
{
mProject->HandleKeyDown(event);
}
void MixerTrackCluster::OnMouseEvent(wxMouseEvent& event)
{
if (event.ButtonUp())
this->HandleSelect(event.ShiftDown());
else
event.Skip();
}
void MixerTrackCluster::OnPaint(wxPaintEvent & WXUNUSED(event))
{
wxPaintDC dc(this);
#ifdef __WXMAC__
// Fill with correct color, not scroller background. Done automatically on Windows.
AColor::Medium(&dc, false);
dc.DrawRectangle(this->GetClientRect());
#endif
wxSize clusterSize = this->GetSize();
wxRect bev(0, 0, clusterSize.GetWidth() - 1, clusterSize.GetHeight() - 1);
#ifdef EXPERIMENTAL_MIDI_OUT
if (mTrack->GetSelected())
#else
if (mLeftTrack->GetSelected())
#endif
{
for (unsigned int i = 0; i < 4; i++) // 4 gives a big bevel, but there were complaints about visibility otherwise.
{
bev.Inflate(-1, -1);
AColor::Bevel(dc, false, bev);
}
}
else
AColor::Bevel(dc, true, bev);
}
void MixerTrackCluster::OnButton_MusicalInstrument(wxCommandEvent& WXUNUSED(event))
{
bool bShiftDown = ::wxGetMouseState().ShiftDown();
this->HandleSelect(bShiftDown);
}
void MixerTrackCluster::OnSlider_Gain(wxCommandEvent& WXUNUSED(event))
{
this->HandleSliderGain();
}
//v void MixerTrackCluster::OnSliderScroll_Gain(wxScrollEvent& WXUNUSED(event))
//{
//int sliderValue = (int)(mSlider_Gain->Get()); //v mSlider_Gain->GetValue();
//#ifdef __WXMSW__
// // Negate because wxSlider on Windows has min at top, max at bottom.
// // mSlider_Gain->GetValue() is in [-6,36]. wxSlider has min at top, so this is [-36dB,6dB].
// sliderValue = -sliderValue;
//#endif
//wxString str = _("Gain: ");
//if (sliderValue > 0)
// str += "+";
//str += wxString::Format("%d dB", sliderValue);
//mSlider_Gain->SetToolTip(str);
//}
void MixerTrackCluster::OnSlider_Pan(wxCommandEvent& WXUNUSED(event))
{
this->HandleSliderPan();
}
void MixerTrackCluster::OnButton_Mute(wxCommandEvent& WXUNUSED(event))
{
#ifdef EXPERIMENTAL_MIDI_OUT
mProject->HandleTrackMute(mTrack, mToggleButton_Mute->WasShiftDown());
mToggleButton_Mute->SetAlternate(mTrack->GetSolo());
#else
mProject->HandleTrackMute(mLeftTrack, mToggleButton_Mute->WasShiftDown());
mToggleButton_Mute->SetAlternate(mLeftTrack->GetSolo());
#endif
// Update the TrackPanel correspondingly.
if (mProject->IsSoloSimple())
{
// Have to refresh all tracks.
mMixerBoard->UpdateSolo();
mProject->RedrawProject();
}
else
// Update only the changed track.
#ifdef EXPERIMENTAL_MIDI_OUT
mProject->RefreshTPTrack(mTrack);
#else
mProject->RefreshTPTrack(mLeftTrack);
#endif
}
void MixerTrackCluster::OnButton_Solo(wxCommandEvent& WXUNUSED(event))
{
#ifdef EXPERIMENTAL_MIDI_OUT
mProject->HandleTrackSolo(mTrack, mToggleButton_Solo->WasShiftDown());
bool bIsSolo = mTrack->GetSolo();
#else
mProject->HandleTrackSolo(mLeftTrack, mToggleButton_Solo->WasShiftDown());
bool bIsSolo = mLeftTrack->GetSolo();
#endif
mToggleButton_Mute->SetAlternate(bIsSolo);
// Update the TrackPanel correspondingly.
if (mProject->IsSoloSimple())
{
// Have to refresh all tracks.
mMixerBoard->UpdateMute();
mMixerBoard->UpdateSolo();
mProject->RedrawProject();
}
else
// Update only the changed track.
#ifdef EXPERIMENTAL_MIDI_OUT
mProject->RefreshTPTrack(mTrack);
#else
mProject->RefreshTPTrack(mLeftTrack);
#endif
}
// class MusicalInstrument
MusicalInstrument::MusicalInstrument(wxBitmap* pBitmap, const wxString strXPMfilename)
{
mBitmap = pBitmap;
int nUnderscoreIndex;
wxString strFilename = strXPMfilename;
strFilename.MakeLower(); // Make sure, so we don't have to do case insensitive comparison.
wxString strKeyword;
while ((nUnderscoreIndex = strFilename.Find(wxT('_'))) != -1)
{
strKeyword = strFilename.Left(nUnderscoreIndex);
mKeywords.Add(strKeyword);
strFilename = strFilename.Mid(nUnderscoreIndex + 1);
}
if (!strFilename.IsEmpty()) // Skip trailing underscores.
mKeywords.Add(strFilename); // Add the last one.
}
MusicalInstrument::~MusicalInstrument()
{
delete mBitmap;
mKeywords.Clear();
}
WX_DEFINE_OBJARRAY(MusicalInstrumentArray);
// class MixerBoardScrolledWindow
// wxScrolledWindow ignores mouse clicks in client area,
// but they don't get passed to Mixerboard.
// We need to catch them to deselect all track clusters.
BEGIN_EVENT_TABLE(MixerBoardScrolledWindow, wxScrolledWindow)
EVT_MOUSE_EVENTS(MixerBoardScrolledWindow::OnMouseEvent)
END_EVENT_TABLE()
MixerBoardScrolledWindow::MixerBoardScrolledWindow(AudacityProject* project,
MixerBoard* parent, wxWindowID id /*= -1*/,
const wxPoint& pos /*= wxDefaultPosition*/,
const wxSize& size /*= wxDefaultSize*/,
long style /*= wxHSCROLL | wxVSCROLL*/)
: wxScrolledWindow(parent, id, pos, size, style)
{
mMixerBoard = parent;
mProject = project;
}
MixerBoardScrolledWindow::~MixerBoardScrolledWindow()
{
}
void MixerBoardScrolledWindow::OnMouseEvent(wxMouseEvent& event)
{
if (event.ButtonUp())
{
//v Even when I implement MixerBoard::OnMouseEvent and call event.Skip()
// here, MixerBoard::OnMouseEvent never gets called.
// So, added mProject to MixerBoardScrolledWindow and just directly do what's needed here.
mProject->SelectNone();
}
else
event.Skip();
}
// class MixerBoard
#define MIXER_BOARD_MIN_HEIGHT 460
// Min width is one cluster wide, plus margins.
#define MIXER_BOARD_MIN_WIDTH kTripleInset + kMixerTrackClusterWidth + kTripleInset
BEGIN_EVENT_TABLE(MixerBoard, wxWindow)
EVT_SIZE(MixerBoard::OnSize)
END_EVENT_TABLE()
MixerBoard::MixerBoard(AudacityProject* pProject,
wxFrame* parent,
const wxPoint& pos /*= wxDefaultPosition*/,
const wxSize& size /*= wxDefaultSize*/)
: wxWindow(parent, -1, pos, size)
{
// public data members
// mute & solo button images
// Create once and store on MixerBoard for use in all MixerTrackClusters.
mImageMuteUp = NULL;
mImageMuteOver = NULL;
mImageMuteDown = NULL;
mImageMuteDownWhileSolo = NULL;
mImageMuteDisabled = NULL;
mImageSoloUp = NULL;
mImageSoloOver = NULL;
mImageSoloDown = NULL;
mImageSoloDisabled = NULL;
mMuteSoloWidth = kRightSideStackWidth - kInset; // correct for max width, but really set in MixerBoard::CreateMuteSoloImages
// private data members
this->LoadMusicalInstruments(); // Set up mMusicalInstruments.
mProject = pProject;
mScrolledWindow =
new MixerBoardScrolledWindow(
pProject, // AudacityProject* project,
this, -1, // wxWindow* parent, wxWindowID id = -1,
this->GetClientAreaOrigin(), // const wxPoint& pos = wxDefaultPosition,
size, // const wxSize& size = wxDefaultSize,
wxHSCROLL); // long style = wxHSCROLL | wxVSCROLL, const wxString& name = "scrolledWindow")
// Set background color to same as TrackPanel background.
#ifdef EXPERIMENTAL_THEMING
mScrolledWindow->SetBackgroundColour(this->GetParent()->GetBackgroundColour());
#else
mScrolledWindow->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW));
#endif
mScrolledWindow->SetScrollRate(10, 0); // no vertical scroll
mScrolledWindow->SetVirtualSize(size);