Audacity  2.2.2
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 // containment hierarchy:
29 // MixerBoardFrame -> MixerBoard -> MixerBoardScrolledWindow -> MixerTrackCluster(s)
30 
31 
32 // MixerTrackSlider is a subclass just to override OnMouseEvent,
33 // so we can know when adjustment ends, so we can PushState only then.
34 class MixerTrackSlider final : public ASlider
35 {
36 public:
37  MixerTrackSlider(wxWindow * parent,
38  wxWindowID id,
39  const wxString &name,
40  const wxPoint & pos,
41  const wxSize & size,
42  const ASlider::Options &options = ASlider::Options{});
43  virtual ~MixerTrackSlider() {}
44 
45  void OnMouseEvent(wxMouseEvent & event);
46 
47  void OnFocus(wxFocusEvent &event);
48  void OnCaptureKey(wxCommandEvent& event);
49 
50 protected:
51  bool mIsPan;
52 
53 public:
54  DECLARE_EVENT_TABLE()
55 };
56 
57 
58 class AudacityProject;
59 class MeterPanel;
60 class MixerBoard;
61 
62 class Track;
63 #ifdef USE_MIDI
64 class NoteTrack;
65 #endif
66 class PlayableTrack;
67 
68 class WaveTrack;
69 class auStaticText;
70 
71 class MixerTrackCluster final : public wxPanelWrapper
72 {
73 public:
74  MixerTrackCluster(wxWindow* parent,
75  MixerBoard* grandParent, AudacityProject* project,
76  const std::shared_ptr<PlayableTrack> &pTrack,
77  const wxPoint& pos = wxDefaultPosition,
78  const wxSize& size = wxDefaultSize);
79  virtual ~MixerTrackCluster() {}
80 
81  WaveTrack *GetWave() const;
82  WaveTrack *GetRight() const;
83 #ifdef EXPERIMENTAL_MIDI_OUT
84  NoteTrack *GetNote() const;
85 #endif
86 
87  void UpdatePrefs();
88 
89  void HandleResize(); // For wxSizeEvents, update gain slider and meter.
90 
91  void HandleSliderGain(const bool bWantPushState = false);
92 #ifdef EXPERIMENTAL_MIDI_OUT
93  void HandleSliderVelocity(const bool bWantPushState = false);
94 #endif
95  void HandleSliderPan(const bool bWantPushState = false);
96 
97  void ResetMeter(const bool bResetClipping);
98 
99  // These are used by TrackPanel for synchronizing control states.
100  void UpdateForStateChange(); // Update the controls that can be affected by state change.
101  void UpdateName();
102  void UpdateMute();
103  void UpdateSolo();
104  void UpdatePan();
105  void UpdateGain();
106 #ifdef EXPERIMENTAL_MIDI_OUT
107  void UpdateVelocity();
108 #endif
109  void UpdateMeter(const double t0, const double t1);
110 
111 private:
112  wxColour GetTrackColor();
113 
114  // event handlers
115  void HandleSelect(bool bShiftDown, bool bControlDown);
116 
117  void OnKeyEvent(wxKeyEvent& event);
118  void OnMouseEvent(wxMouseEvent& event);
119  void OnPaint(wxPaintEvent& evt);
120 
121  void OnButton_MusicalInstrument(wxCommandEvent& event);
122  void OnSlider_Gain(wxCommandEvent& event);
123 #ifdef EXPERIMENTAL_MIDI_OUT
124  void OnSlider_Velocity(wxCommandEvent& event);
125 #endif
126  void OnSlider_Pan(wxCommandEvent& event);
127  void OnButton_Mute(wxCommandEvent& event);
128  void OnButton_Solo(wxCommandEvent& event);
129  //v void OnSliderScroll_Gain(wxScrollEvent& event);
130 
131 
132 public:
133  std::shared_ptr<PlayableTrack> mTrack;
134 
135 private:
138 
139  // controls
146 #ifdef EXPERIMENTAL_MIDI_OUT
147  MixerTrackSlider* mSlider_Velocity;
148 #endif
150 
151 public:
152  DECLARE_EVENT_TABLE()
153 };
154 
155 
157 {
158 public:
159  MusicalInstrument(std::unique_ptr<wxBitmap> &&pBitmap, const wxString & strXPMfilename);
160  virtual ~MusicalInstrument();
161 
162  std::unique_ptr<wxBitmap> mBitmap;
163  wxArrayString mKeywords;
164 };
165 
166 using MusicalInstrumentArray = std::vector<std::unique_ptr<MusicalInstrument>>;
167 
168 
169 
170 // wxScrolledWindow ignores mouse clicks in client area,
171 // but they don't get passed to Mixerboard.
172 // We need to catch them to deselect all track clusters.
173 class MixerBoardScrolledWindow final : public wxScrolledWindow
174 {
175 public:
177  MixerBoard* parent, wxWindowID id = -1,
178  const wxPoint& pos = wxDefaultPosition,
179  const wxSize& size = wxDefaultSize,
180  long style = wxHSCROLL | wxVSCROLL);
181  virtual ~MixerBoardScrolledWindow();
182 
183 private:
184  void OnMouseEvent(wxMouseEvent& event);
185 
186 private:
189 
190 public:
191  DECLARE_EVENT_TABLE()
192 };
193 
194 
195 class MixerBoardFrame;
196 class TrackList;
197 
198 class MixerBoard final : public wxWindow
199 {
200  friend class MixerBoardFrame;
201 
202 public:
203  MixerBoard(AudacityProject* pProject,
204  wxFrame* parent,
205  const wxPoint& pos = wxDefaultPosition,
206  const wxSize& size = wxDefaultSize);
207 
208  void UpdatePrefs();
209 
210  // Add clusters for any tracks we're not yet showing.
211  // Update pointers for tracks we're aleady showing.
212  void UpdateTrackClusters();
213 
214  int GetTrackClustersWidth();
215  void MoveTrackCluster(const PlayableTrack* pTrack, bool bUp); // Up in TrackPanel is left in MixerBoard.
216  void RemoveTrackCluster(const PlayableTrack* pTrack);
217  void RemoveTrackCluster(size_t nIndex);
218 
219 
220  wxBitmap* GetMusicalInstrumentBitmap(const Track *pTrack);
221 
222  bool HasSolo();
223 
224  void RefreshTrackCluster(const PlayableTrack* pTrack, bool bEraseBackground = true);
225  void RefreshTrackClusters(bool bEraseBackground = true);
226  void ResizeTrackClusters();
227 
228  void ResetMeters(const bool bResetClipping);
229 
230  void UpdateName(const PlayableTrack* pTrack);
231  void UpdateMute(const PlayableTrack* pTrack = NULL); // NULL means update for all tracks.
232  void UpdateSolo(const PlayableTrack* pTrack = NULL); // NULL means update for all tracks.
233  void UpdatePan(const PlayableTrack* pTrack = NULL); // NULL means update for all tracks.
234  void UpdateGain(const PlayableTrack* pTrack);
235 #ifdef EXPERIMENTAL_MIDI_OUT
236  void UpdateVelocity(const PlayableTrack* pTrack);
237 #endif
238 
239  void UpdateMeters(const double t1, const bool bLoopedPlay);
240 
241  void UpdateWidth();
242 
243 private:
244  void MakeButtonBitmap( wxMemoryDC & dc, wxBitmap & bitmap,
245  wxRect & bev, const wxString & str, bool up );
246  void CreateMuteSoloImages();
247  int FindMixerTrackCluster(const PlayableTrack* pTrack,
248  MixerTrackCluster** hMixerTrackCluster) const;
249  void LoadMusicalInstruments();
250 
251  // event handlers
252  void OnSize(wxSizeEvent &evt);
253  void OnTimer(wxCommandEvent &event);
254 
255 
256 public:
257  // mute & solo button images: Create once and store on MixerBoard for use in all MixerTrackClusters.
258  std::unique_ptr<wxImage> mImageMuteUp, mImageMuteOver, mImageMuteDown,
259  mImageMuteDownWhileSolo, // the one actually alternate image
261 
263 
264 private:
265  // Track clusters are maintained in the same order as the WaveTracks.
266  std::vector<MixerTrackCluster*> mMixerTrackClusters;
267 
270  MixerBoardScrolledWindow* mScrolledWindow; // Holds the MixerTrackClusters and handles scrolling.
271  double mPrevT1;
273 
274 public:
275  DECLARE_EVENT_TABLE()
276 };
277 
278 
279 class MixerBoardFrame final : public wxFrame
280 {
281 public:
283  virtual ~MixerBoardFrame();
284 
285 private:
286  // event handlers
287  void OnCloseWindow(wxCloseEvent &WXUNUSED(event));
288  void OnMaximize(wxMaximizeEvent &event);
289  void OnSize(wxSizeEvent &evt);
290  void OnKeyEvent(wxKeyEvent &evt);
291 
292 public:
294 
295 public:
296  DECLARE_EVENT_TABLE()
297 };
298 
299 #endif // __AUDACITY_MIXER_BOARD__
300 
301 
void RefreshTrackClusters(bool bEraseBackground=true)
void OnKeyEvent(wxKeyEvent &evt)
A list of TrackListNode items.
Definition: Track.h:619
void HandleSelect(bool bShiftDown, bool bControlDown)
Definition: MixerBoard.cpp:685
void OnPaint(wxPaintEvent &evt)
Definition: MixerBoard.cpp:699
void OnButton_Solo(wxCommandEvent &event)
Definition: MixerBoard.cpp:778
std::unique_ptr< wxImage > mImageMuteDisabled
Definition: MixerBoard.h:258
MixerTrackSlider * mSlider_Pan
Definition: MixerBoard.h:144
void OnMouseEvent(wxMouseEvent &event)
Definition: MixerBoard.cpp:847
MixerBoard(AudacityProject *pProject, wxFrame *parent, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
Definition: MixerBoard.cpp:873
void OnSlider_Gain(wxCommandEvent &event)
Definition: MixerBoard.cpp:729
auStaticText * mStaticText_TrackName
Definition: MixerBoard.h:140
std::unique_ptr< wxImage > mImageSoloDisabled
Definition: MixerBoard.h:258
void ResizeTrackClusters()
AudacityProject * mProject
Definition: MixerBoard.h:269
void OnMouseEvent(wxMouseEvent &event)
Definition: MixerBoard.cpp:691
std::unique_ptr< wxImage > mImageMuteDown
Definition: MixerBoard.h:258
void OnKeyEvent(wxKeyEvent &event)
is like wxStaticText, except it can be themed. wxStaticText can't be.
Definition: Theme.h:177
void OnMaximize(wxMaximizeEvent &event)
void OnFocus(wxFocusEvent &event)
Definition: MixerBoard.cpp:85
MixerTrackSlider(wxWindow *parent, wxWindowID id, const wxString &name, const wxPoint &pos, const wxSize &size, const ASlider::Options &options=ASlider::Options{})
Definition: MixerBoard.cpp:59
void RefreshTrackCluster(const PlayableTrack *pTrack, bool bEraseBackground=true)
void RemoveTrackCluster(const PlayableTrack *pTrack)
std::unique_ptr< wxImage > mImageSoloOver
Definition: MixerBoard.h:258
MixerBoard * mMixerBoard
Definition: MixerBoard.h:187
void UpdateForStateChange()
Definition: MixerBoard.cpp:451
MeterPanel is a panel that paints the meter used for monitoring or playback.
Definition: Meter.h:97
std::vector< MixerTrackCluster * > mMixerTrackClusters
Definition: MixerBoard.h:266
int mMuteSoloWidth
Definition: MixerBoard.h:262
void LoadMusicalInstruments()
virtual ~MixerBoardScrolledWindow()
Definition: MixerBoard.cpp:843
void UpdatePan(const PlayableTrack *pTrack=NULL)
wxColour GetTrackColor()
Definition: MixerBoard.cpp:677
std::unique_ptr< wxBitmap > mBitmap
Definition: MixerBoard.h:162
void UpdateMeter(const double t0, const double t1)
Definition: MixerBoard.cpp:520
void OnButton_MusicalInstrument(wxCommandEvent &event)
Definition: MixerBoard.cpp:723
void HandleSliderPan(const bool bWantPushState=false)
Definition: MixerBoard.cpp:426
void CreateMuteSoloImages()
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
std::unique_ptr< wxImage > mImageMuteDownWhileSolo
Definition: MixerBoard.h:258
void ResetMeter(const bool bResetClipping)
Definition: MixerBoard.cpp:441
wxBitmapButton * mBitmapButton_MusicalInstrument
Definition: MixerBoard.h:141
virtual ~MixerTrackCluster()
Definition: MixerBoard.h:79
virtual ~MusicalInstrument()
Definition: MixerBoard.cpp:816
wxBitmap * GetMusicalInstrumentBitmap(const Track *pTrack)
void UpdateSolo(const PlayableTrack *pTrack=NULL)
MixerBoardScrolledWindow * mScrolledWindow
Definition: MixerBoard.h:270
void OnMouseEvent(wxMouseEvent &event)
Definition: MixerBoard.cpp:69
std::unique_ptr< wxImage > mImageSoloUp
Definition: MixerBoard.h:258
std::shared_ptr< PlayableTrack > mTrack
Definition: MixerBoard.h:133
std::unique_ptr< wxImage > mImageMuteOver
Definition: MixerBoard.h:258
A Track that contains audio waveform data.
Definition: WaveTrack.h:60
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:102
void UpdateWidth()
AudacityProject * mProject
Definition: MixerBoard.h:188
MixerTrackCluster(wxWindow *parent, MixerBoard *grandParent, AudacityProject *project, const std::shared_ptr< PlayableTrack > &pTrack, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize)
Definition: MixerBoard.cpp:160
virtual ~MixerBoardFrame()
void UpdateGain(const PlayableTrack *pTrack)
void MoveTrackCluster(const PlayableTrack *pTrack, bool bUp)
void OnCaptureKey(wxCommandEvent &event)
Definition: MixerBoard.cpp:99
An AudioTrack that can be played and stopped.
Definition: Track.h:376
AButton * mToggleButton_Solo
Definition: MixerBoard.h:143
void OnSlider_Pan(wxCommandEvent &event)
Definition: MixerBoard.cpp:756
void UpdateMeters(const double t1, const bool bLoopedPlay)
int FindMixerTrackCluster(const PlayableTrack *pTrack, MixerTrackCluster **hMixerTrackCluster) const
void UpdateName(const PlayableTrack *pTrack)
virtual ~MixerTrackSlider()
Definition: MixerBoard.h:43
std::unique_ptr< wxImage > mImageMuteUp
Definition: MixerBoard.h:258
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
AButton * mToggleButton_Mute
Definition: MixerBoard.h:142
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:334
MusicalInstrumentArray mMusicalInstruments
Definition: MixerBoard.h:268
void OnButton_Mute(wxCommandEvent &event)
Definition: MixerBoard.cpp:761
MixerTrackSlider * mSlider_Gain
Definition: MixerBoard.h:145
void OnCloseWindow(wxCloseEvent &WXUNUSED(event))
wxArrayString mKeywords
Definition: MixerBoard.h:163
WaveTrack * GetWave() const
Definition: MixerBoard.cpp:329
MixerBoardScrolledWindow(AudacityProject *project, MixerBoard *parent, wxWindowID id=-1, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxHSCROLL|wxVSCROLL)
Definition: MixerBoard.cpp:832
std::unique_ptr< wxImage > mImageSoloDown
Definition: MixerBoard.h:258
MeterPanel * mMeter
Definition: MixerBoard.h:149
int GetTrackClustersWidth()
MixerBoard * mMixerBoard
Definition: MixerBoard.h:136
MusicalInstrument(std::unique_ptr< wxBitmap > &&pBitmap, const wxString &strXPMfilename)
Definition: MixerBoard.cpp:798
void UpdatePrefs()
Definition: MixerBoard.cpp:940
AudacityProject * mProject
Definition: MixerBoard.h:137
double mPrevT1
Definition: MixerBoard.h:271
void ResetMeters(const bool bResetClipping)
TrackList * mTracks
Definition: MixerBoard.h:272
MixerBoard * mMixerBoard
Definition: MixerBoard.h:293
void HandleSliderGain(const bool bWantPushState=false)
Definition: MixerBoard.cpp:398
std::vector< std::unique_ptr< MusicalInstrument >> MusicalInstrumentArray
Definition: MixerBoard.h:166
bool HasSolo()
void UpdateMute(const PlayableTrack *pTrack=NULL)
A wxButton with mouse-over behaviour.
Definition: AButton.h:28
A Track that is used for Midi notes. (Somewhat old code).
void UpdateTrackClusters()
Definition: MixerBoard.cpp:973