Audacity  2.3.1
MixerBoard.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  MixerBoard.h
6 
7  Vaughan Johnson, January 2007
8 
9 **********************************************************************/
10 
11 #include "Experimental.h"
12 
13 #ifndef __AUDACITY_MIXER_BOARD__
14 #define __AUDACITY_MIXER_BOARD__
15 
16 #include <wx/frame.h>
17 #include <wx/bmpbuttn.h>
18 #include <wx/hashmap.h>
19 #include <wx/image.h>
20 #include <wx/scrolwin.h>
21 #include <wx/statbmp.h>
22 #include <wx/stattext.h>
23 
24 #include "widgets/AButton.h"
25 #include "widgets/ASlider.h"
26 #include "widgets/wxPanelWrapper.h"
27 
28 struct TrackListEvent;
29 
30 // containment hierarchy:
31 // MixerBoardFrame -> MixerBoard -> MixerBoardScrolledWindow -> MixerTrackCluster(s)
32 
33 
34 // MixerTrackSlider is a subclass just to override OnMouseEvent,
35 // so we can know when adjustment ends, so we can PushState only then.
36 class MixerTrackSlider final : public ASlider
37 {
38 public:
39  MixerTrackSlider(wxWindow * parent,
40  wxWindowID id,
41  const wxString &name,
42  const wxPoint & pos,
43  const wxSize & size,
44  const ASlider::Options &options = ASlider::Options{});
45  virtual ~MixerTrackSlider() {}
46 
47  void OnMouseEvent(wxMouseEvent & event);
48 
49  void OnFocus(wxFocusEvent &event);
50  void OnCaptureKey(wxCommandEvent& event);
51 
52 protected:
53  bool mIsPan;
54 
55 public:
56  DECLARE_EVENT_TABLE()
57 };
58 
59 
60 class AudacityProject;
61 class MeterPanel;
62 class MixerBoard;
63 
64 class Track;
65 #ifdef USE_MIDI
66 class NoteTrack;
67 #endif
68 class PlayableTrack;
69 
70 class WaveTrack;
71 class auStaticText;
72 
73 class MixerTrackCluster final : public wxPanelWrapper
74 {
75 public:
76  MixerTrackCluster(wxWindow* parent,
77  MixerBoard* grandParent, AudacityProject* project,
78  const std::shared_ptr<PlayableTrack> &pTrack,
79  const wxPoint& pos = wxDefaultPosition,
80  const wxSize& size = wxDefaultSize);
81  virtual ~MixerTrackCluster() {}
82 
83  WaveTrack *GetWave() const;
84  WaveTrack *GetRight() const;
85 #ifdef EXPERIMENTAL_MIDI_OUT
86  NoteTrack *GetNote() const;
87 #endif
88 
89  //void UpdatePrefs();
90 
91  void HandleResize(); // For wxSizeEvents, update gain slider and meter.
92 
93  void HandleSliderGain(const bool bWantPushState = false);
94 #ifdef EXPERIMENTAL_MIDI_OUT
95  void HandleSliderVelocity(const bool bWantPushState = false);
96 #endif
97  void HandleSliderPan(const bool bWantPushState = false);
98 
99  void ResetMeter(const bool bResetClipping);
100 
101  void UpdateForStateChange();
102  void UpdateMeter(const double t0, const double t1);
103 
104 private:
105  wxColour GetTrackColor();
106 
107  // event handlers
108  void HandleSelect(bool bShiftDown, bool bControlDown);
109 
110  void OnKeyEvent(wxKeyEvent& event);
111  void OnMouseEvent(wxMouseEvent& event);
112  void OnPaint(wxPaintEvent& evt);
113 
114  void OnButton_MusicalInstrument(wxCommandEvent& event);
115  void OnSlider_Gain(wxCommandEvent& event);
116 #ifdef EXPERIMENTAL_MIDI_OUT
117  void OnSlider_Velocity(wxCommandEvent& event);
118 #endif
119  void OnSlider_Pan(wxCommandEvent& event);
120  void OnButton_Mute(wxCommandEvent& event);
121  void OnButton_Solo(wxCommandEvent& event);
122  //v void OnSliderScroll_Gain(wxScrollEvent& event);
123 
124 
125 public:
126  std::shared_ptr<PlayableTrack> mTrack;
127 
128 private:
131 
132  // controls
139 #ifdef EXPERIMENTAL_MIDI_OUT
141 #endif
142  wxWeakRef<MeterPanel> mMeter;
143 
144 public:
145  DECLARE_EVENT_TABLE()
146 };
147 
148 
150 {
151 public:
152  MusicalInstrument(std::unique_ptr<wxBitmap> &&pBitmap, const wxString & strXPMfilename);
153  virtual ~MusicalInstrument();
154 
155  std::unique_ptr<wxBitmap> mBitmap;
156  wxArrayString mKeywords;
157 };
158 
159 using MusicalInstrumentArray = std::vector<std::unique_ptr<MusicalInstrument>>;
160 
161 
162 
163 // wxScrolledWindow ignores mouse clicks in client area,
164 // but they don't get passed to Mixerboard.
165 // We need to catch them to deselect all track clusters.
166 class MixerBoardScrolledWindow final : public wxScrolledWindow
167 {
168 public:
170  MixerBoard* parent, wxWindowID id = -1,
171  const wxPoint& pos = wxDefaultPosition,
172  const wxSize& size = wxDefaultSize,
173  long style = wxHSCROLL | wxVSCROLL);
174  virtual ~MixerBoardScrolledWindow();
175 
176 private:
177  void OnMouseEvent(wxMouseEvent& event);
178 
179 private:
182 
183 public:
184  DECLARE_EVENT_TABLE()
185 };
186 
187 
188 class MixerBoardFrame;
189 class TrackList;
190 
191 class MixerBoard final : public wxWindow
192 {
193  friend class MixerBoardFrame;
194 
195 public:
196  MixerBoard(AudacityProject* pProject,
197  wxFrame* parent,
198  const wxPoint& pos = wxDefaultPosition,
199  const wxSize& size = wxDefaultSize);
200 
201  void UpdatePrefs();
202 
203  // Add clusters for any tracks we're not yet showing.
204  // Update pointers for tracks we're aleady showing.
205  void UpdateTrackClusters();
206 
207  int GetTrackClustersWidth();
208 
209 
210  wxBitmap* GetMusicalInstrumentBitmap(const Track *pTrack);
211 
212  bool HasSolo();
213 
214  void RefreshTrackClusters(bool bEraseBackground = true);
215  void ResizeTrackClusters();
216 
217  void UpdateMeters(const double t1, const bool bLoopedPlay);
218 
219  void UpdateWidth();
220 
221 private:
222  void ResetMeters(const bool bResetClipping);
223  void RemoveTrackCluster(size_t nIndex);
224  void MakeButtonBitmap( wxMemoryDC & dc, wxBitmap & bitmap,
225  wxRect & bev, const wxString & str, bool up );
226  void CreateMuteSoloImages();
227  int FindMixerTrackCluster(const PlayableTrack* pTrack,
228  MixerTrackCluster** hMixerTrackCluster) const;
229  void LoadMusicalInstruments();
230 
231  // event handlers
232  void OnPaint(wxPaintEvent& evt);
233  void OnSize(wxSizeEvent &evt);
234  void OnTimer(wxCommandEvent &event);
235  void OnTrackSetChanged(wxEvent &event);
236  void OnTrackChanged(TrackListEvent &event);
237  void OnStartStop(wxCommandEvent &event);
238 
239 public:
240  // mute & solo button images: Create once and store on MixerBoard for use in all MixerTrackClusters.
241  std::unique_ptr<wxImage> mImageMuteUp, mImageMuteOver, mImageMuteDown,
242  mImageMuteDownWhileSolo, // the one actually alternate image
244 
246 
247 private:
248  // Track clusters are maintained in the same order as the WaveTracks.
249  std::vector<MixerTrackCluster*> mMixerTrackClusters;
250 
253  MixerBoardScrolledWindow* mScrolledWindow; // Holds the MixerTrackClusters and handles scrolling.
254  double mPrevT1;
256  bool mUpToDate{ false };
257 
258 public:
259  DECLARE_EVENT_TABLE()
260 };
261 
262 
263 class MixerBoardFrame final : public wxFrame
264 {
265 public:
267  virtual ~MixerBoardFrame();
268 
269  void Recreate(AudacityProject *pProject);
270 
271 private:
272  // event handlers
273  void OnCloseWindow(wxCloseEvent &WXUNUSED(event));
274  void OnMaximize(wxMaximizeEvent &event);
275  void OnSize(wxSizeEvent &evt);
276  void OnKeyEvent(wxKeyEvent &evt);
277 
278 public:
280 
281 public:
282  DECLARE_EVENT_TABLE()
283 };
284 
285 #endif // __AUDACITY_MIXER_BOARD__
286 
287 
void RefreshTrackClusters(bool bEraseBackground=true)
void OnKeyEvent(wxKeyEvent &evt)
void HandleSelect(bool bShiftDown, bool bControlDown)
Definition: MixerBoard.cpp:667
void OnPaint(wxPaintEvent &evt)
Definition: MixerBoard.cpp:681
void OnButton_Solo(wxCommandEvent &event)
Definition: MixerBoard.cpp:762
std::unique_ptr< wxImage > mImageMuteDisabled
Definition: MixerBoard.h:241
MixerTrackSlider * mSlider_Pan
Definition: MixerBoard.h:137
void OnPaint(wxPaintEvent &evt)
void OnMouseEvent(wxMouseEvent &event)
Definition: MixerBoard.cpp:826
MixerBoard(AudacityProject *pProject, wxFrame *parent, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
Definition: MixerBoard.cpp:853
void OnSlider_Gain(wxCommandEvent &event)
Definition: MixerBoard.cpp:714
auStaticText * mStaticText_TrackName
Definition: MixerBoard.h:133
std::unique_ptr< wxImage > mImageSoloDisabled
Definition: MixerBoard.h:241
void ResizeTrackClusters()
AudacityProject * mProject
Definition: MixerBoard.h:252
void OnMouseEvent(wxMouseEvent &event)
Definition: MixerBoard.cpp:673
std::unique_ptr< wxImage > mImageMuteDown
Definition: MixerBoard.h:241
void OnKeyEvent(wxKeyEvent &event)
is like wxStaticText, except it can be themed. wxStaticText can't be.
Definition: Theme.h:177
void OnMaximize(wxMaximizeEvent &event)
wxWeakRef< MeterPanel > mMeter
Definition: MixerBoard.h:142
void OnFocus(wxFocusEvent &event)
Definition: MixerBoard.cpp:90
MixerTrackSlider(wxWindow *parent, wxWindowID id, const wxString &name, const wxPoint &pos, const wxSize &size, const ASlider::Options &options=ASlider::Options{})
Definition: MixerBoard.cpp:64
std::unique_ptr< wxImage > mImageSoloOver
Definition: MixerBoard.h:241
MixerBoard * mMixerBoard
Definition: MixerBoard.h:180
void UpdateForStateChange()
Definition: MixerBoard.cpp:456
MeterPanel is a panel that paints the meter used for monitoring or playback.
Definition: Meter.h:102
std::vector< MixerTrackCluster * > mMixerTrackClusters
Definition: MixerBoard.h:249
int mMuteSoloWidth
Definition: MixerBoard.h:245
void LoadMusicalInstruments()
virtual ~MixerBoardScrolledWindow()
Definition: MixerBoard.cpp:822
void OnTrackSetChanged(wxEvent &event)
wxColour GetTrackColor()
Definition: MixerBoard.cpp:659
void OnTrackChanged(TrackListEvent &event)
std::unique_ptr< wxBitmap > mBitmap
Definition: MixerBoard.h:155
void UpdateMeter(const double t0, const double t1)
Definition: MixerBoard.cpp:501
void OnButton_MusicalInstrument(wxCommandEvent &event)
Definition: MixerBoard.cpp:708
void HandleSliderPan(const bool bWantPushState=false)
Definition: MixerBoard.cpp:433
void CreateMuteSoloImages()
TrackList is a flat linked list of tracks supporting Add, Remove, Clear, and Contains, plus serialization of the list of tracks.
Definition: Track.h:1121
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:174
std::unique_ptr< wxImage > mImageMuteDownWhileSolo
Definition: MixerBoard.h:241
void ResetMeter(const bool bResetClipping)
Definition: MixerBoard.cpp:448
wxBitmapButton * mBitmapButton_MusicalInstrument
Definition: MixerBoard.h:134
virtual ~MixerTrackCluster()
Definition: MixerBoard.h:81
virtual ~MusicalInstrument()
Definition: MixerBoard.cpp:795
wxBitmap * GetMusicalInstrumentBitmap(const Track *pTrack)
MixerBoardScrolledWindow * mScrolledWindow
Definition: MixerBoard.h:253
void OnMouseEvent(wxMouseEvent &event)
Definition: MixerBoard.cpp:74
std::unique_ptr< wxImage > mImageSoloUp
Definition: MixerBoard.h:241
std::shared_ptr< PlayableTrack > mTrack
Definition: MixerBoard.h:126
std::unique_ptr< wxImage > mImageMuteOver
Definition: MixerBoard.h:241
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
void HandleSliderVelocity(const bool bWantPushState=false)
Definition: MixerBoard.cpp:420
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:191
void UpdateWidth()
AudacityProject * mProject
Definition: MixerBoard.h:181
MixerTrackCluster(wxWindow *parent, MixerBoard *grandParent, AudacityProject *project, const std::shared_ptr< PlayableTrack > &pTrack, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
Definition: MixerBoard.cpp:165
virtual ~MixerBoardFrame()
NoteTrack * GetNote() const
Definition: MixerBoard.cpp:346
void Recreate(AudacityProject *pProject)
void OnCaptureKey(wxCommandEvent &event)
Definition: MixerBoard.cpp:104
An AudioTrack that can be played and stopped.
Definition: Track.h:769
AButton * mToggleButton_Solo
Definition: MixerBoard.h:136
void OnSlider_Pan(wxCommandEvent &event)
Definition: MixerBoard.cpp:741
void UpdateMeters(const double t1, const bool bLoopedPlay)
int FindMixerTrackCluster(const PlayableTrack *pTrack, MixerTrackCluster **hMixerTrackCluster) const
virtual ~MixerTrackSlider()
Definition: MixerBoard.h:45
std::unique_ptr< wxImage > mImageMuteUp
Definition: MixerBoard.h:241
bool mUpToDate
Definition: MixerBoard.h:256
void OnTimer(wxCommandEvent &event)
ASlider is a custom slider, allowing for a slicker look and feel.
Definition: ASlider.h:243
const wxChar * name
Definition: Distortion.cpp:94
void RemoveTrackCluster(size_t nIndex)
AButton * mToggleButton_Mute
Definition: MixerBoard.h:135
void OnSize(wxSizeEvent &evt)
MixerBoardFrame(AudacityProject *parent)
void MakeButtonBitmap(wxMemoryDC &dc, wxBitmap &bitmap, wxRect &bev, const wxString &str, bool up)
void OnSize(wxSizeEvent &evt)
WaveTrack * GetRight() const
Definition: MixerBoard.cpp:335
MusicalInstrumentArray mMusicalInstruments
Definition: MixerBoard.h:251
void OnButton_Mute(wxCommandEvent &event)
Definition: MixerBoard.cpp:746
MixerTrackSlider * mSlider_Gain
Definition: MixerBoard.h:138
void OnSlider_Velocity(wxCommandEvent &event)
Definition: MixerBoard.cpp:720
void OnCloseWindow(wxCloseEvent &WXUNUSED(event))
wxArrayString mKeywords
Definition: MixerBoard.h:156
WaveTrack * GetWave() const
Definition: MixerBoard.cpp:330
MixerBoardScrolledWindow(AudacityProject *project, MixerBoard *parent, wxWindowID id=-1, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxHSCROLL|wxVSCROLL)
Definition: MixerBoard.cpp:811
std::unique_ptr< wxImage > mImageSoloDown
Definition: MixerBoard.h:241
int GetTrackClustersWidth()
MixerBoard * mMixerBoard
Definition: MixerBoard.h:129
MusicalInstrument(std::unique_ptr< wxBitmap > &&pBitmap, const wxString &strXPMfilename)
Definition: MixerBoard.cpp:777
void UpdatePrefs()
Definition: MixerBoard.cpp:946
AudacityProject * mProject
Definition: MixerBoard.h:130
double mPrevT1
Definition: MixerBoard.h:254
void ResetMeters(const bool bResetClipping)
TrackList * mTracks
Definition: MixerBoard.h:255
MixerBoard * mMixerBoard
Definition: MixerBoard.h:279
void HandleSliderGain(const bool bWantPushState=false)
Definition: MixerBoard.cpp:405
std::vector< std::unique_ptr< MusicalInstrument >> MusicalInstrumentArray
Definition: MixerBoard.h:159
bool HasSolo()
A wxButton with mouse-over behaviour.
Definition: AButton.h:28
void OnStartStop(wxCommandEvent &event)
A Track that is used for Midi notes. (Somewhat old code).
Definition: NoteTrack.h:66
void UpdateTrackClusters()
Definition: MixerBoard.cpp:980
MixerTrackSlider * mSlider_Velocity
Definition: MixerBoard.h:140