Audacity  2.2.2
WaveTrackSliderHandles.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 WaveTrackSliderHandles.cpp
6 
7 Paul Licameli split from TrackPanel.cpp
8 
9 **********************************************************************/
10 
11 #include "../../../../Audacity.h"
12 #include "WaveTrackSliderHandles.h"
13 
14 #include "../../../../HitTestResult.h"
15 #include "../../../../MixerBoard.h"
16 #include "../../../../Project.h"
17 #include "../../../../RefreshCode.h"
18 #include "../../../../TrackPanel.h"
19 #include "../../../../UndoManager.h"
20 #include "../../../../WaveTrack.h"
21 
23 ( SliderFn sliderFn, const wxRect &rect, const std::shared_ptr<Track> &pTrack )
24  : SliderHandle{ sliderFn, rect, pTrack }
25 {}
26 
28 {
29 }
30 
31 std::shared_ptr<WaveTrack> GainSliderHandle::GetWaveTrack()
32 {
33  return std::static_pointer_cast<WaveTrack>(mpTrack.lock());
34 }
35 
37 {
38  if (GetWaveTrack())
39  return GetWaveTrack()->GetGain();
40  else
41  return 0;
42 }
43 
45 (AudacityProject *pProject, float newValue)
46 {
47  auto pTrack = GetWaveTrack();
48 
49  if (pTrack) {
50  pTrack->SetGain(newValue);
51 
52  // Assume linked track is wave or null
53  const auto link = static_cast<WaveTrack*>(mpTrack.lock()->GetLink());
54  if (link)
55  link->SetGain(newValue);
56 
57  MixerBoard *const pMixerBoard = pProject->GetMixerBoard();
58  if (pMixerBoard)
59  pMixerBoard->UpdateGain(pTrack.get());
60  }
61 
63 }
64 
66 (const wxMouseEvent &, AudacityProject *pProject)
67 {
68  pProject->PushState(_("Moved gain slider"), _("Gain"), UndoPush::CONSOLIDATE);
70 }
71 
73 (std::weak_ptr<GainSliderHandle> &holder,
74  const wxMouseState &state, const wxRect &rect,
75  const std::shared_ptr<Track> &pTrack)
76 {
77  if (!state.ButtonIsDown(wxMOUSE_BTN_LEFT))
78  return {};
79 
80  wxRect sliderRect;
81  TrackInfo::GetGainRect(rect.GetTopLeft(), sliderRect);
82  if ( TrackInfo::HideTopItem( rect, sliderRect, kTrackInfoSliderAllowance ) )
83  return {};
84  if (sliderRect.Contains(state.m_x, state.m_y)) {
85  wxRect sliderRect;
86  TrackInfo::GetGainRect(rect.GetTopLeft(), sliderRect);
87  auto sliderFn =
88  []( AudacityProject *pProject, const wxRect &sliderRect, Track *pTrack ) {
90  (sliderRect, static_cast<WaveTrack*>( pTrack ), true,
91  const_cast<TrackPanel*>(pProject->GetTrackPanel()));
92  };
93  auto result =
94  std::make_shared<GainSliderHandle>( sliderFn, sliderRect, pTrack );
95  result = AssignUIHandlePtr(holder, result);
96 
97  return result;
98  }
99  else
100  return {};
101 }
102 
104 
106 ( SliderFn sliderFn, const wxRect &rect, const std::shared_ptr<Track> &pTrack )
107  : SliderHandle{ sliderFn, rect, pTrack }
108 {}
109 
111 {
112 }
113 
114 std::shared_ptr<WaveTrack> PanSliderHandle::GetWaveTrack()
115 {
116  return std::static_pointer_cast<WaveTrack>(mpTrack.lock());
117 }
118 
120 {
121  if (GetWaveTrack())
122  return GetWaveTrack()->GetPan();
123  else
124  return 0;
125 }
126 
128 {
129  using namespace RefreshCode;
130  Result result = RefreshNone;
131  auto pTrack = GetWaveTrack();
132 
133  if (pTrack) {
134  pTrack->SetPan(newValue);
135 
136  // Assume linked track is wave or null
137  const auto link = static_cast<WaveTrack*>(pTrack->GetLink());
138  if (link)
139  link->SetPan(newValue);
140 
141  MixerBoard *const pMixerBoard = pProject->GetMixerBoard();
142  if (pMixerBoard)
143  pMixerBoard->UpdatePan(pTrack.get());
144  }
145 
146  return result;
147 }
148 
150 (const wxMouseEvent &, AudacityProject *pProject)
151 {
152  pProject->PushState(_("Moved pan slider"), _("Pan"), UndoPush::CONSOLIDATE);
154 }
155 
157 (std::weak_ptr<PanSliderHandle> &holder,
158  const wxMouseState &state, const wxRect &rect,
159  const std::shared_ptr<Track> &pTrack)
160 {
161  if (!state.ButtonIsDown(wxMOUSE_BTN_LEFT))
162  return {};
163 
164  wxRect sliderRect;
165  TrackInfo::GetPanRect(rect.GetTopLeft(), sliderRect);
166  if ( TrackInfo::HideTopItem( rect, sliderRect, kTrackInfoSliderAllowance ) )
167  return {};
168  if (sliderRect.Contains(state.m_x, state.m_y)) {
169  auto sliderFn =
170  []( AudacityProject *pProject, const wxRect &sliderRect, Track *pTrack ) {
171  return TrackInfo::PanSlider
172  (sliderRect, static_cast<WaveTrack*>( pTrack ), true,
173  const_cast<TrackPanel*>(pProject->GetTrackPanel()));
174  };
175  auto result = std::make_shared<PanSliderHandle>(
176  sliderFn, sliderRect, pTrack );
177  result = AssignUIHandlePtr(holder, result);
178 
179  return result;
180  }
181  else
182  return {};
183 }
Result SetValue(AudacityProject *pProject, float newValue) override
std::weak_ptr< Track > mpTrack
Definition: SliderHandle.h:71
float GetValue() override
PanSliderHandle(const PanSliderHandle &)=delete
LWSlider *(*)(AudacityProject *, const wxRect &, Track *) SliderFn
Definition: SliderHandle.h:27
GainSliderHandle(const GainSliderHandle &)=delete
MixerBoard * GetMixerBoard()
Definition: Project.h:500
void UpdatePan(const PlayableTrack *pTrack=NULL)
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:158
std::shared_ptr< WaveTrack > GetWaveTrack()
static LWSlider * PanSlider(const wxRect &sliderRect, const WaveTrack *t, bool captured, wxWindow *pParent)
float GetValue() override
Result SetValue(AudacityProject *pProject, float newValue) override
unsigned Result
Definition: UIHandle.h:37
static void GetGainRect(const wxPoint &topLeft, wxRect &dest)
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:94
void UpdateGain(const PlayableTrack *pTrack)
void SetGain(float newGain)
Definition: WaveTrack.cpp:446
std::shared_ptr< UIHandle > UIHandlePtr
Definition: TrackPanel.h:59
static bool HideTopItem(const wxRect &rect, const wxRect &subRect, int allowance=0)
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
std::shared_ptr< WaveTrack > GetWaveTrack()
static UIHandlePtr HitTest(std::weak_ptr< GainSliderHandle > &holder, const wxMouseState &state, const wxRect &rect, const std::shared_ptr< Track > &pTrack)
void PushState(const wxString &desc, const wxString &shortDesc)
Definition: Project.cpp:4502
TrackPanel * GetTrackPanel()
Definition: Project.h:289
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject) override
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject) override
void SetPan(float newPan) override
Definition: WaveTrack.cpp:456
static void GetPanRect(const wxPoint &topLeft, wxRect &dest)
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:162
static UIHandlePtr HitTest(std::weak_ptr< PanSliderHandle > &holder, const wxMouseState &state, const wxRect &rect, const std::shared_ptr< Track > &pTrack)
static LWSlider * GainSlider(const wxRect &sliderRect, const WaveTrack *t, bool captured, wxWindow *pParent)