forked from audacity/audacity
/
TrackPanel.cpp
9530 lines (8242 loc) · 302 KB
/
TrackPanel.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
TrackPanel.cpp
Dominic Mazzoni
and lots of other contributors
Implements TrackPanel and TrackInfo.
********************************************************************//*!
\todo
Refactoring of the TrackPanel, possibly as described
in \ref TrackPanelRefactor
*//*****************************************************************//*!
\file TrackPanel.cpp
\brief
Implements TrackPanel and TrackInfo.
TrackPanel.cpp is currently some of the worst code in Audacity.
It's not really unreadable, there's just way too much stuff in this
one file. Rather than apply a quick fix, the long-term plan
is to create a GUITrack class that knows how to draw itself
and handle events. Then this class just helps coordinate
between tracks.
Plans under discussion are described in \ref TrackPanelRefactor
*//********************************************************************/
// Documentation: Rather than have a lengthy \todo section, having
// a \todo a \file and a \page in EXACTLY that order gets Doxygen to
// put the following lengthy description of refactoring on a NEW page
// and link to it from the docs.
/*****************************************************************//**
\class TrackPanel
\brief
The TrackPanel class coordinates updates and operations on the
main part of the screen which contains multiple tracks.
It uses many other classes, but in particular it uses the
TrackInfo class to draw the controls area on the left of a track,
and the TrackArtist class to draw the actual waveforms.
Note that in some of the older code here, e.g., GetLabelWidth(),
"Label" means the TrackInfo plus the vertical ruler.
Confusing relative to LabelTrack labels.
The TrackPanel manages multiple tracks and their TrackInfos.
Note that with stereo tracks there will be one TrackInfo
being used by two wavetracks.
*//*****************************************************************//**
\class TrackInfo
\brief
The TrackInfo is shown to the side of a track
It has the menus, pan and gain controls displayed in it.
So "Info" is somewhat a misnomer. Should possibly be "TrackControls".
TrackPanel and not TrackInfo takes care of the functionality for
each of the buttons in that panel.
In its current implementation TrackInfo is not derived from a
wxWindow. Following the original coding style, it has
been coded as a 'flyweight' class, which is passed
state as needed, except for the array of gains and pans.
If we'd instead coded it as a wxWindow, we would have an instance
of this class for each instance displayed.
*//**************************************************************//**
\class TrackPanelListener
\brief A now badly named class which is used to give access to a
subset of the TrackPanel methods from all over the place.
*//**************************************************************//**
\class TrackList
\brief A list of TrackListNode items.
*//**************************************************************//**
\class TrackListIterator
\brief An iterator for a TrackList.
*//**************************************************************//**
\class TrackListNode
\brief Used by TrackList, points to a Track.
*//**************************************************************//**
\class TrackPanel::AudacityTimer
\brief Timer class dedicated to infomring the TrackPanel that it
is time to refresh some aspect of the screen.
*//*****************************************************************//**
\page TrackPanelRefactor Track Panel Refactor
\brief Planned refactoring of TrackPanel.cpp
- Move menus from current TrackPanel into TrackInfo.
- Convert TrackInfo from 'flyweight' to heavyweight.
- Split GuiStereoTrack and GuiWaveTrack out from TrackPanel.
JKC: Incremental refactoring started April/2003
Possibly aiming for Gui classes something like this - it's under
discussion:
<pre>
+----------------------------------------------------+
| AdornedRulerPanel |
+----------------------------------------------------+
+----------------------------------------------------+
|+------------+ +-----------------------------------+|
|| | | (L) GuiWaveTrack ||
|| TrackInfo | +-----------------------------------+|
|| | +-----------------------------------+|
|| | | (R) GuiWaveTrack ||
|+------------+ +-----------------------------------+|
+-------- GuiStereoTrack ----------------------------+
+----------------------------------------------------+
|+------------+ +-----------------------------------+|
|| | | (L) GuiWaveTrack ||
|| TrackInfo | +-----------------------------------+|
|| | +-----------------------------------+|
|| | | (R) GuiWaveTrack ||
|+------------+ +-----------------------------------+|
+-------- GuiStereoTrack ----------------------------+
</pre>
With the whole lot sitting in a TrackPanel which forwards
events to the sub objects.
The GuiStereoTrack class will do the special logic for
Stereo channel grouping.
The precise names of the classes are subject to revision.
Have deliberately not created NEW files for the NEW classes
such as AdornedRulerPanel and TrackInfo - yet.
*//*****************************************************************/
#include "Audacity.h"
#include "Experimental.h"
#include "TrackPanel.h"
#include "TrackPanelCell.h"
#include "TrackPanelCellIterator.h"
//#define DEBUG_DRAW_TIMING 1
// #define SPECTRAL_EDITING_ESC_KEY
#include <wx/fontenum.h>
#include <wx/numdlg.h>
#include <wx/spinctrl.h>
#include "FreqWindow.h" // for SpectrumAnalyst
#include "AColor.h"
#include "AllThemeResources.h"
#include "AudioIO.h"
#include "Envelope.h"
#include "float_cast.h"
#include "LabelTrack.h"
#include "MixerBoard.h"
#include "NoteTrack.h"
#include "NumberScale.h"
#include "Prefs.h"
#include "Snap.h"
#include "ShuttleGui.h"
#include "TimeTrack.h"
#include "TrackArtist.h"
#include "TrackPanelAx.h"
#include "UndoManager.h"
#include "WaveTrack.h"
#include "commands/Keyboard.h"
#include "ondemand/ODManager.h"
#include "prefs/PrefsDialog.h"
#include "prefs/SpectrumPrefs.h"
#include "prefs/WaveformPrefs.h"
#include "toolbars/ControlToolBar.h"
#include "toolbars/ToolsToolBar.h"
// To do: eliminate this!
#include "tracks/ui/Scrubbing.h"
#define ZOOMLIMIT 0.001f
//This loads the appropriate set of cursors, depending on platform.
#include "../images/Cursors.h"
DEFINE_EVENT_TYPE(EVT_TRACK_PANEL_TIMER)
/*
This is a diagram of TrackPanel's division of one (non-stereo) track rectangle.
Total height equals Track::GetHeight()'s value. Total width is the wxWindow's width.
Each charater that is not . represents one pixel.
Inset space of this track, and top inset of the next track, are used to draw the focus highlight.
Top inset of the right channel of a stereo track, and bottom shadow line of the
left channel, are used for the channel separator.
TrackInfo::GetTrackInfoWidth() == GetVRulerOffset()
counts columns from the left edge up to and including controls, and is a constant.
GetVRulerWidth() is variable -- all tracks have the same ruler width at any time,
but that width may be adjusted when tracks change their vertical scales.
GetLabelWidth() counts columns up to and including the VRuler.
GetLeftOffset() is yet one more -- it counts the "one pixel" column.
FindTrack() for label returns a rectangle up to and including the One Pixel column,
but OMITS left and top insets
FindTrack() for !label returns a rectangle with x == GetLeftOffset(), and INCLUDES
right and top insets
+--------------- ... ------ ... --------------------- ... ... -------------+
| Top Inset |
| |
| +------------ ... ------ ... --------------------- ... ... ----------+ |
| L|+-Border---- ... ------ ... --------------------- ... ... -Border-+ |R |
| e||+---------- ... -++--- ... -+++----------------- ... ... -------+| |i |
| f|B| || ||| |BS|g |
| t|o| Controls || V |O| The good stuff |oh|h |
| |r| || R |n| |ra|t |
| I|d| || u |e| |dd| |
| n|e| || l | | |eo|I |
| s|r| || e |P| |rw|n |
| e||| || r |i| ||||s |
| t||| || |x| ||||e |
| ||| || |e| ||||t |
| ||| || |l| |||| |
| ||| || ||| |||| |
. ... .. ... .... .
. ... .. ... .... .
. ... .. ... .... .
| ||| || ||| |||| |
| ||+---------- -++-- ... -+++----------------- ... ... -------+||| |
| |+-Border---- ... ----- ... --------------------- ... ... -Border-+|| |
| | Shadow---- ... ----- ... --------------------- ... ... --Shadow-+| |
*/
// Is the distance between A and B less than D?
template < class A, class B, class DIST > bool within(A a, B b, DIST d)
{
return (a > b - d) && (a < b + d);
}
template < class CLIPPEE, class CLIPVAL >
void clip_top(CLIPPEE & clippee, CLIPVAL val)
{
if (clippee > val)
clippee = val;
}
template < class CLIPPEE, class CLIPVAL >
void clip_bottom(CLIPPEE & clippee, CLIPVAL val)
{
if (clippee < val)
clippee = val;
}
enum {
TrackPanelFirstID = 2000,
OnSetNameID,
OnSetFontID,
OnMoveUpID,
OnMoveDownID,
OnMoveTopID,
OnMoveBottomID,
OnUpOctaveID,
OnDownOctaveID,
OnChannelLeftID,
OnChannelRightID,
OnChannelMonoID,
OnRate8ID, // <---
OnRate11ID, // |
OnRate16ID, // |
OnRate22ID, // |
OnRate44ID, // |
OnRate48ID, // | Leave these in order
OnRate88ID, // |
OnRate96ID, // |
OnRate176ID, // | see OnTrackMenu()
OnRate192ID, // |
OnRate352ID, // |
OnRate384ID, // |
OnRateOtherID, // |
// |
On16BitID, // |
On24BitID, // |
OnFloatID, // <---
OnWaveformID,
OnWaveformDBID,
OnSpectrumID,
OnSpectrogramSettingsID,
OnSplitStereoID,
OnSplitStereoMonoID,
OnMergeStereoID,
OnSwapChannelsID,
OnSetTimeTrackRangeID,
OnTimeTrackLinID,
OnTimeTrackLogID,
OnTimeTrackLogIntID,
// Reserve an ample block of ids for waveform scale types
OnFirstWaveformScaleID,
OnLastWaveformScaleID = OnFirstWaveformScaleID + 9,
// Reserve an ample block of ids for spectrum scale types
OnFirstSpectrumScaleID,
OnLastSpectrumScaleID = OnFirstSpectrumScaleID + 19,
OnZoomInVerticalID,
OnZoomOutVerticalID,
OnZoomFitVerticalID,
};
BEGIN_EVENT_TABLE(TrackPanel, OverlayPanel)
EVT_MOUSE_EVENTS(TrackPanel::OnMouseEvent)
EVT_MOUSE_CAPTURE_LOST(TrackPanel::OnCaptureLost)
EVT_COMMAND(wxID_ANY, EVT_CAPTURE_KEY, TrackPanel::OnCaptureKey)
EVT_KEY_DOWN(TrackPanel::OnKeyDown)
EVT_KEY_UP(TrackPanel::OnKeyUp)
EVT_CHAR(TrackPanel::OnChar)
EVT_PAINT(TrackPanel::OnPaint)
EVT_SET_FOCUS(TrackPanel::OnSetFocus)
EVT_KILL_FOCUS(TrackPanel::OnKillFocus)
EVT_CONTEXT_MENU(TrackPanel::OnContextMenu)
EVT_MENU(OnSetNameID, TrackPanel::OnSetName)
EVT_MENU(OnSetFontID, TrackPanel::OnSetFont)
EVT_MENU(OnSetTimeTrackRangeID, TrackPanel::OnSetTimeTrackRange)
EVT_MENU_RANGE(OnMoveUpID, OnMoveDownID, TrackPanel::OnMoveTrack)
EVT_MENU_RANGE(OnMoveTopID, OnMoveBottomID, TrackPanel::OnMoveTrack)
EVT_MENU_RANGE(OnUpOctaveID, OnDownOctaveID, TrackPanel::OnChangeOctave)
EVT_MENU_RANGE(OnChannelLeftID, OnChannelMonoID,
TrackPanel::OnChannelChange)
EVT_MENU_RANGE(OnWaveformID, OnSpectrumID, TrackPanel::OnSetDisplay)
EVT_MENU(OnSpectrogramSettingsID, TrackPanel::OnSpectrogramSettings)
EVT_MENU_RANGE(OnRate8ID, OnRate384ID, TrackPanel::OnRateChange)
EVT_MENU_RANGE(On16BitID, OnFloatID, TrackPanel::OnFormatChange)
EVT_MENU(OnRateOtherID, TrackPanel::OnRateOther)
EVT_MENU(OnSwapChannelsID, TrackPanel::OnSwapChannels)
EVT_MENU(OnSplitStereoID, TrackPanel::OnSplitStereo)
EVT_MENU(OnSplitStereoMonoID, TrackPanel::OnSplitStereoMono)
EVT_MENU(OnMergeStereoID, TrackPanel::OnMergeStereo)
EVT_MENU(OnTimeTrackLinID, TrackPanel::OnTimeTrackLin)
EVT_MENU(OnTimeTrackLogID, TrackPanel::OnTimeTrackLog)
EVT_MENU(OnTimeTrackLogIntID, TrackPanel::OnTimeTrackLogInt)
EVT_MENU_RANGE(OnFirstWaveformScaleID, OnLastWaveformScaleID, TrackPanel::OnWaveformScaleType)
EVT_MENU_RANGE(OnFirstSpectrumScaleID, OnLastSpectrumScaleID, TrackPanel::OnSpectrumScaleType)
EVT_MENU(OnZoomInVerticalID, TrackPanel::OnZoomInVertical)
EVT_MENU(OnZoomOutVerticalID, TrackPanel::OnZoomOutVertical)
EVT_MENU(OnZoomFitVerticalID, TrackPanel::OnZoomFitVertical)
EVT_TIMER(wxID_ANY, TrackPanel::OnTimer)
END_EVENT_TABLE()
/// Makes a cursor from an XPM, uses CursorId as a fallback.
/// TODO: Move this function to some other source file for reuse elsewhere.
std::unique_ptr<wxCursor> MakeCursor( int WXUNUSED(CursorId), const char * pXpm[36], int HotX, int HotY )
{
#ifdef CURSORS_SIZE32
const int HotAdjust =0;
#else
const int HotAdjust =8;
#endif
wxImage Image = wxImage(wxBitmap(pXpm).ConvertToImage());
Image.SetMaskColour(255,0,0);
Image.SetMask();// Enable mask.
Image.SetOption( wxIMAGE_OPTION_CUR_HOTSPOT_X, HotX-HotAdjust );
Image.SetOption( wxIMAGE_OPTION_CUR_HOTSPOT_Y, HotY-HotAdjust );
return std::make_unique<wxCursor>( Image );
}
// Don't warn us about using 'this' in the base member initializer list.
#ifndef __WXGTK__ //Get rid if this pragma for gtk
#pragma warning( disable: 4355 )
#endif
TrackPanel::TrackPanel(wxWindow * parent, wxWindowID id,
const wxPoint & pos,
const wxSize & size,
const std::shared_ptr<TrackList> &tracks,
ViewInfo * viewInfo,
TrackPanelListener * listener,
AdornedRulerPanel * ruler)
: OverlayPanel(parent, id, pos, size, wxWANTS_CHARS | wxNO_BORDER),
mTrackInfo(this),
mListener(listener),
mTracks(tracks),
mViewInfo(viewInfo),
mRuler(ruler),
mTrackArtist(nullptr),
mRefreshBacking(false),
mConverter(NumericConverter::TIME),
mAutoScrolling(false),
mVertScrollRemainder(0),
vrulerSize(36,0)
#ifndef __WXGTK__ //Get rid if this pragma for gtk
#pragma warning( default: 4355 )
#endif
{
SetLabel(_("Track Panel"));
SetName(_("Track Panel"));
SetBackgroundStyle(wxBG_STYLE_PAINT);
{
auto pAx = std::make_unique <TrackPanelAx>( this );
#if wxUSE_ACCESSIBILITY
// wxWidgets owns the accessible object
SetAccessible(mAx = pAx.release());
#else
// wxWidgets doesn not own the object, but we need to retain it
mAx = std::move(pAx);
#endif
}
mMouseCapture = IsUncaptured;
mSlideUpDownOnly = false;
mLabelTrackStartXPos=-1;
mCircularTrackNavigation = false;
mRedrawAfterStop = false;
mPencilCursor = MakeCursor( wxCURSOR_PENCIL, DrawCursorXpm, 12, 22);
mSelectCursor = MakeCursor( wxCURSOR_IBEAM, IBeamCursorXpm, 17, 16);
mEnvelopeCursor= MakeCursor( wxCURSOR_ARROW, EnvCursorXpm, 16, 16);
mDisabledCursor= MakeCursor( wxCURSOR_NO_ENTRY, DisabledCursorXpm,16, 16);
mSlideCursor = MakeCursor( wxCURSOR_SIZEWE, TimeCursorXpm, 16, 16);
mZoomInCursor = MakeCursor( wxCURSOR_MAGNIFIER, ZoomInCursorXpm, 19, 15);
mZoomOutCursor = MakeCursor( wxCURSOR_MAGNIFIER, ZoomOutCursorXpm, 19, 15);
mLabelCursorLeft = MakeCursor( wxCURSOR_ARROW, LabelCursorLeftXpm, 19, 15);
mLabelCursorRight = MakeCursor( wxCURSOR_ARROW, LabelCursorRightXpm, 16, 16);
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
mBottomFrequencyCursor =
MakeCursor( wxCURSOR_ARROW, BottomFrequencyCursorXpm, 16, 16);
mTopFrequencyCursor =
MakeCursor( wxCURSOR_ARROW, TopFrequencyCursorXpm, 16, 16);
mBandWidthCursor = MakeCursor( wxCURSOR_ARROW, BandWidthCursorXpm, 16, 16);
#endif
#if USE_MIDI
mStretchMode = stretchCenter;
mStretching = false;
mStretched = false;
mStretchStart = 0;
mStretchCursor = MakeCursor( wxCURSOR_BULLSEYE, StretchCursorXpm, 16, 16);
mStretchLeftCursor = MakeCursor( wxCURSOR_BULLSEYE,
StretchLeftCursorXpm, 16, 16);
mStretchRightCursor = MakeCursor( wxCURSOR_BULLSEYE,
StretchRightCursorXpm, 16, 16);
#endif
mArrowCursor = std::make_unique<wxCursor>(wxCURSOR_ARROW);
mSmoothCursor = std::make_unique<wxCursor>(wxCURSOR_SPRAYCAN);
mResizeCursor = std::make_unique<wxCursor>(wxCURSOR_SIZENS);
mRearrangeCursor = std::make_unique<wxCursor>(wxCURSOR_HAND);
mAdjustLeftSelectionCursor = std::make_unique<wxCursor>(wxCURSOR_POINT_LEFT);
mAdjustRightSelectionCursor = std::make_unique<wxCursor>(wxCURSOR_POINT_RIGHT);
// Menu pointers are set to NULL here. Delay building of menus until after
// the command managter is finished, so that we can look up shortcut
// key strings that need to appear in some of the popup menus.
mWaveTrackMenu = NULL;
mChannelItemsInsertionPoint = 0;
mNoteTrackMenu = NULL;
mLabelTrackMenu = NULL;
mTimeTrackMenu = NULL;
BuildMenus();
mTrackArtist = std::make_unique<TrackArtist>();
mTrackArtist->SetInset(1, kTopMargin, kRightMargin, kBottomMargin);
mCapturedTrack = NULL;
mPopupMenuTarget = NULL;
mTimeCount = 0;
mTimer.parent = this;
mTimer.Start(kTimerInterval, FALSE);
//Initialize a member variable pointing to the current
//drawing track.
mDrawingTrack =NULL;
//More initializations, some of these for no other reason than
//to prevent runtime memory check warnings
mZoomStart = -1;
mZoomEnd = -1;
mPrevWidth = -1;
mPrevHeight = -1;
// This is used to snap the cursor to the nearest track that
// lines up with it.
mSnapManager = NULL;
mSnapLeft = -1;
mSnapRight = -1;
// Register for tracklist updates
mTracks->Connect(EVT_TRACKLIST_RESIZED,
wxCommandEventHandler(TrackPanel::OnTrackListResized),
NULL,
this);
mTracks->Connect(EVT_TRACKLIST_UPDATED,
wxCommandEventHandler(TrackPanel::OnTrackListUpdated),
NULL,
this);
#ifdef EXPERIMENTAL_SPECTRAL_EDITING
mFreqSelMode = FREQ_SEL_INVALID;
mFrequencySnapper = std::make_unique<SpectrumAnalyst>();
mLastF0 = mLastF1 = SelectedRegion::UndefinedFrequency;
#endif
mSelStartValid = false;
mSelStart = 0;
}
TrackPanel::~TrackPanel()
{
mTimer.Stop();
// Unregister for tracklist updates
mTracks->Disconnect(EVT_TRACKLIST_UPDATED,
wxCommandEventHandler(TrackPanel::OnTrackListUpdated),
NULL,
this);
mTracks->Disconnect(EVT_TRACKLIST_RESIZED,
wxCommandEventHandler(TrackPanel::OnTrackListResized),
NULL,
this);
// This can happen if a label is being edited and the user presses
// ALT+F4 or Command+Q
if (HasCapture())
ReleaseMouse();
DeleteMenus();
}
void TrackPanel::BuildMenusIfNeeded(void)
{
if (!mRateMenu)
BuildMenus();
}
void TrackPanel::BuildMenus(void)
{
// Get rid of existing menus
DeleteMenus();
// Use AppendCheckItem so we can have ticks beside the items.
// We would use AppendRadioItem but it only currently works on windows and GTK.
auto rateMenu = std::make_unique<wxMenu>();
rateMenu->AppendRadioItem(OnRate8ID, wxT("8000 Hz"));
rateMenu->AppendRadioItem(OnRate11ID, wxT("11025 Hz"));
rateMenu->AppendRadioItem(OnRate16ID, wxT("16000 Hz"));
rateMenu->AppendRadioItem(OnRate22ID, wxT("22050 Hz"));
rateMenu->AppendRadioItem(OnRate44ID, wxT("44100 Hz"));
rateMenu->AppendRadioItem(OnRate48ID, wxT("48000 Hz"));
rateMenu->AppendRadioItem(OnRate88ID, wxT("88200 Hz"));
rateMenu->AppendRadioItem(OnRate96ID, wxT("96000 Hz"));
rateMenu->AppendRadioItem(OnRate176ID, wxT("176400 Hz"));
rateMenu->AppendRadioItem(OnRate192ID, wxT("192000 Hz"));
rateMenu->AppendRadioItem(OnRate352ID, wxT("352800 Hz"));
rateMenu->AppendRadioItem(OnRate384ID, wxT("384000 Hz"));
rateMenu->AppendRadioItem(OnRateOtherID, _("&Other..."));
auto formatMenu = std::make_unique<wxMenu>();
formatMenu->AppendRadioItem(On16BitID, GetSampleFormatStr(int16Sample));
formatMenu->AppendRadioItem(On24BitID, GetSampleFormatStr(int24Sample));
formatMenu->AppendRadioItem(OnFloatID, GetSampleFormatStr(floatSample));
/* build the pop-down menu used on wave (sampled audio) tracks */
mWaveTrackMenu = std::make_unique<wxMenu>();
BuildCommonDropMenuItems(mWaveTrackMenu.get()); // does name, up/down etc
mWaveTrackMenu->AppendRadioItem(OnWaveformID, _("Wa&veform"));
mWaveTrackMenu->AppendRadioItem(OnWaveformDBID, _("&Waveform (dB)"));
mWaveTrackMenu->AppendRadioItem(OnSpectrumID, _("&Spectrogram"));
mWaveTrackMenu->Append(OnSpectrogramSettingsID, _("S&pectrogram Settings..."));
mWaveTrackMenu->AppendSeparator();
// include both mono and stereo items as a work around for bug 1250
mWaveTrackMenu->AppendRadioItem(OnChannelMonoID, _("&Mono"));
mWaveTrackMenu->AppendRadioItem(OnChannelLeftID, _("&Left Channel"));
mWaveTrackMenu->AppendRadioItem(OnChannelRightID, _("&Right Channel"));
mWaveTrackMenu->Append(OnMergeStereoID, _("Ma&ke Stereo Track"));
mWaveTrackMenu->Append(OnSwapChannelsID, _("Swap Stereo &Channels"));
mWaveTrackMenu->Append(OnSplitStereoID, _("Spl&it Stereo Track"));
mWaveTrackMenu->Append(OnSplitStereoMonoID, _("Split Stereo to Mo&no"));
mWaveTrackMenu->AppendSeparator();
mWaveTrackMenu->Append(0, _("&Format"), (mFormatMenu = formatMenu.release()));
mWaveTrackMenu->AppendSeparator();
mWaveTrackMenu->Append(0, _("Rat&e"), (mRateMenu = rateMenu.release()));
/* build the pop-down menu used on note (MIDI) tracks */
mNoteTrackMenu = std::make_unique<wxMenu>();
BuildCommonDropMenuItems(mNoteTrackMenu.get()); // does name, up/down etc
mNoteTrackMenu->Append(OnUpOctaveID, _("Up &Octave"));
mNoteTrackMenu->Append(OnDownOctaveID, _("Down Octa&ve"));
/* build the pop-down menu used on label tracks */
mLabelTrackMenu = std::make_unique<wxMenu>();
BuildCommonDropMenuItems(mLabelTrackMenu.get()); // does name, up/down etc
mLabelTrackMenu->Append(OnSetFontID, _("&Font..."));
/* build the pop-down menu used on time warping tracks */
mTimeTrackMenu = std::make_unique<wxMenu>();
BuildCommonDropMenuItems(mTimeTrackMenu.get()); // does name, up/down etc
mTimeTrackMenu->AppendRadioItem(OnTimeTrackLinID, wxT("&Linear scale"));
mTimeTrackMenu->AppendRadioItem(OnTimeTrackLogID, _("L&ogarithmic scale"));
mTimeTrackMenu->AppendSeparator();
mTimeTrackMenu->Append(OnSetTimeTrackRangeID, _("&Range..."));
mTimeTrackMenu->AppendCheckItem(OnTimeTrackLogIntID, _("Logarithmic &Interpolation"));
/*
mRulerWaveformMenu = std::make_unique<wxMenu>();
BuildVRulerMenuItems
(mRulerWaveformMenu.get(), OnFirstWaveformScaleID,
WaveformSettings::GetScaleNames());
mRulerSpectrumMenu = std::make_unique<wxMenu>();
BuildVRulerMenuItems
(mRulerSpectrumMenu.get(), OnFirstSpectrumScaleID,
SpectrogramSettings::GetScaleNames());
*/
}
void TrackPanel::BuildCommonDropMenuItems(wxMenu * menu)
{
menu->Append(OnSetNameID, _("&Name..."));
menu->AppendSeparator();
// It is not correct to use KeyStringDisplay here -- wxWidgets will apply
// its equivalent to the key names passed to menu functions.
menu->Append(OnMoveUpID, _("Move Track &Up") + wxT("\t") +
(GetProject()->GetCommandManager()->GetKeyFromName(wxT("TrackMoveUp"))));
menu->Append(OnMoveDownID, _("Move Track &Down") + wxT("\t") +
(GetProject()->GetCommandManager()->GetKeyFromName(wxT("TrackMoveDown"))));
menu->Append(OnMoveTopID, _("Move Track to &Top") + wxT("\t") +
(GetProject()->GetCommandManager()->GetKeyFromName(wxT("TrackMoveTop"))));
menu->Append(OnMoveBottomID, _("Move Track to &Bottom") + wxT("\t") +
(GetProject()->GetCommandManager()->GetKeyFromName(wxT("TrackMoveBottom"))));
menu->AppendSeparator();
}
/*
// left over from PRL's vertical ruler context menu experiment in 2.1.2
// static
void TrackPanel::BuildVRulerMenuItems
(wxMenu * menu, int firstId, const wxArrayString &names)
{
int id = firstId;
for (int ii = 0, nn = names.size(); ii < nn; ++ii)
menu->AppendRadioItem(id++, names[ii]);
menu->AppendSeparator();
menu->Append(OnZoomInVerticalID, _("Zoom In\tLeft-Click/Left-Drag"));
menu->Append(OnZoomOutVerticalID, _("Zoom Out\tShift-Left-Click"));
menu->Append(OnZoomFitVerticalID, _("Zoom to Fit\tShift-Right-Click"));
}
*/
void TrackPanel::DeleteMenus(void)
{
// Note that the submenus (mRateMenu, ...)
// are deleted by their parent
mRateMenu = mFormatMenu = nullptr;
mWaveTrackMenu.reset();
mNoteTrackMenu.reset();
mLabelTrackMenu.reset();
mTimeTrackMenu.reset();
mRulerWaveformMenu.reset();
mRulerSpectrumMenu.reset();
}
#ifdef EXPERIMENTAL_OUTPUT_DISPLAY
void TrackPanel::UpdateVirtualStereoOrder()
{
TrackListOfKindIterator iter(TrackKind::Wave, mTracks);
Track *t;
int temp;
for (t = iter.First(); t; t = iter.Next()) {
const auto wt = static_cast<WaveTrack*>(t);
if(t->GetChannel() == Track::MonoChannel){
if(WaveTrack::mMonoAsVirtualStereo && wt->GetPan() != 0){
temp = wt->GetHeight();
wt->SetHeight(temp*wt->GetVirtualTrackPercentage());
wt->SetHeight(temp - wt->GetHeight(),true);
}else if(!WaveTrack::mMonoAsVirtualStereo && wt->GetPan() != 0){
wt->SetHeight(wt->GetHeight() + wt->GetHeight(true));
}
}
}
t = iter.First();
if(t){
t->ReorderList(false);
}
}
#endif
void TrackPanel::UpdatePrefs()
{
gPrefs->Read(wxT("/GUI/AutoScroll"), &mViewInfo->bUpdateTrackIndicator,
true);
gPrefs->Read(wxT("/GUI/AdjustSelectionEdges"), &mAdjustSelectionEdges,
true);
gPrefs->Read(wxT("/GUI/CircularTrackNavigation"), &mCircularTrackNavigation,
false);
gPrefs->Read(wxT("/GUI/Solo"), &mSoloPref, wxT("Simple"));
#ifdef EXPERIMENTAL_OUTPUT_DISPLAY
bool temp = WaveTrack::mMonoAsVirtualStereo;
gPrefs->Read(wxT("/GUI/MonoAsVirtualStereo"), &WaveTrack::mMonoAsVirtualStereo,
false);
if(WaveTrack::mMonoAsVirtualStereo != temp)
UpdateVirtualStereoOrder();
#endif
mViewInfo->UpdatePrefs();
if (mTrackArtist) {
mTrackArtist->UpdatePrefs();
}
// All vertical rulers must be recalculated since the minimum and maximum
// frequences may have been changed.
UpdateVRulers();
mTrackInfo.UpdatePrefs();
Refresh();
}
/// Remembers the track we clicked on and why we captured it.
/// We also use this method to clear the record
/// of the captured track, passing NULL as the track.
void TrackPanel::SetCapturedTrack( Track * t, enum MouseCaptureEnum MouseCapture )
{
#if defined(__WXDEBUG__)
if (t == NULL) {
wxASSERT(MouseCapture == IsUncaptured);
}
else {
wxASSERT(MouseCapture != IsUncaptured);
}
#endif
mCapturedTrack = t;
mMouseCapture = MouseCapture;
}
void TrackPanel::SelectNone()
{
TrackListIterator iter(GetTracks());
Track *t = iter.First();
while (t) {
SelectTrack(t, false, false);
t = iter.Next();
}
}
/// Select all tracks marked by the label track lt
void TrackPanel::SelectTracksByLabel( LabelTrack *lt )
{
TrackListIterator iter(GetTracks());
Track *t = iter.First();
//do nothing if at least one other track is selected
while (t) {
if( t->GetSelected() && t != lt )
return;
t = iter.Next();
}
//otherwise, select all tracks
t = iter.First();
while( t )
{
SelectTrack(t, true);
t = iter.Next();
}
}
// Set selection length to the length of a track -- but if sync-lock is turned
// on, use the largest possible selection in the sync-lock group.
// If it's a stereo track, do the same for the stereo channels.
void TrackPanel::SelectTrackLength(Track *t)
{
AudacityProject *p = GetActiveProject();
SyncLockedTracksIterator it(GetTracks());
Track *t1 = it.StartWith(t);
double minOffset = t->GetOffset();
double maxEnd = t->GetEndTime();
// If we have a sync-lock group and sync-lock linking is on,
// check the sync-lock group tracks.
if (p->IsSyncLocked() && t1 != NULL)
{
for ( ; t1; t1 = it.Next())
{
if (t1->GetOffset() < minOffset)
minOffset = t1->GetOffset();
if (t1->GetEndTime() > maxEnd)
maxEnd = t1->GetEndTime();
}
}
else
{
// Otherwise, check for a stereo pair
t1 = t->GetLink();
if (t1)
{
if (t1->GetOffset() < minOffset)
minOffset = t1->GetOffset();
if (t1->GetEndTime() > maxEnd)
maxEnd = t1->GetEndTime();
}
}
// PRL: double click or click on track control.
// should this select all frequencies too? I think not.
mViewInfo->selectedRegion.setTimes(minOffset, maxEnd);
}
void TrackPanel::GetTracksUsableArea(int *width, int *height) const
{
GetSize(width, height);
if (width) {
*width -= GetLeftOffset();
*width -= kRightMargin;
*width = std::max(0, *width);
}
}
/// Gets the pointer to the AudacityProject that
/// goes with this track panel.
AudacityProject * TrackPanel::GetProject() const
{
//JKC casting away constness here.
//Do it in two stages in case 'this' is not a wxWindow.
//when the compiler will flag the error.
wxWindow const * const pConstWind = this;
wxWindow * pWind=(wxWindow*)pConstWind;
#ifdef EXPERIMENTAL_NOTEBOOK
pWind = pWind->GetParent(); //Page
wxASSERT( pWind );
pWind = pWind->GetParent(); //Notebook
wxASSERT( pWind );
#endif
pWind = pWind->GetParent(); //MainPanel
wxASSERT( pWind );
pWind = pWind->GetParent(); //Project
wxASSERT( pWind );
return (AudacityProject*)pWind;
}
/// AS: This gets called on our wx timer events.
void TrackPanel::OnTimer(wxTimerEvent& )
{
#ifdef __WXMAC__
// Unfortunate part of fix for bug 1431
// Without this, the toolbars hide only every other time that you press
// the yellow title bar button. For some reason, not every press sends
// us a deactivate event for the application.
{
auto project = GetProject();
if (project->IsIconized())
project->MacShowUndockedToolbars(false);
}
#endif
mTimeCount++;
// AS: If the user is dragging the mouse and there is a track that
// has captured the mouse, then scroll the screen, as necessary.
if ((mMouseCapture==IsSelecting) && mCapturedTrack) {
ScrollDuringDrag();
}
AudacityProject *const p = GetProject();
// Check whether we were playing or recording, but the stream has stopped.
if (p->GetAudioIOToken()>0 && !IsAudioActive())
{
//the stream may have been started up after this one finished (by some other project)
//in that case reset the buttons don't stop the stream
p->GetControlToolBar()->StopPlaying(!gAudioIO->IsStreamActive());
}
// Next, check to see if we were playing or recording
// audio, but now Audio I/O is completely finished.
if (p->GetAudioIOToken()>0 &&
!gAudioIO->IsAudioTokenActive(p->GetAudioIOToken()))
{
p->FixScrollbars();
p->SetAudioIOToken(0);
p->RedrawProject();
mRedrawAfterStop = false;
//ANSWER-ME: Was DisplaySelection added to solve a repaint problem?
DisplaySelection();
}
if (mLastDrawnSelectedRegion != mViewInfo->selectedRegion) {
UpdateSelectionDisplay();
}
// Notify listeners for timer ticks
{
wxCommandEvent e(EVT_TRACK_PANEL_TIMER);
p->GetEventHandler()->ProcessEvent(e);
}
DrawOverlays(false);
mRuler->DrawOverlays(false);
if(IsAudioActive() && gAudioIO->GetNumCaptureChannels()) {
// Periodically update the display while recording
if (!mRedrawAfterStop) {
mRedrawAfterStop = true;
MakeParentRedrawScrollbars();
mListener->TP_ScrollUpDown( 99999999 );
Refresh( false );
}
else {
if ((mTimeCount % 5) == 0) {
// Must tell OnPaint() to recreate the backing bitmap
// since we've not done a full refresh.
mRefreshBacking = true;
Refresh( false );
}
}
}
if(mTimeCount > 1000)
mTimeCount = 0;
}
/// We check on each timer tick to see if we need to scroll.
/// Scrolling is handled by mListener, which is an interface
/// to the window TrackPanel is embedded in.
void TrackPanel::ScrollDuringDrag()
{
// DM: If we're "autoscrolling" (which means that we're scrolling
// because the user dragged from inside to outside the window,
// not because the user clicked in the scroll bar), then
// the selection code needs to be handled slightly differently.
// We set this flag ("mAutoScrolling") to tell the selecting