Audacity  3.0.3
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 
12 #include "WaveTrackSliderHandles.h"
13 
14 #include "WaveTrackControls.h"
15 #include "../../../../ProjectHistory.h"
16 #include "../../../../RefreshCode.h"
17 #include "../../../../TrackInfo.h"
18 #include "../../../../TrackPanel.h"
19 #include "../../../../TrackPanelAx.h"
20 #include "../../../../UndoManager.h"
21 #include "../../../../WaveTrack.h"
22 
24 ( SliderFn sliderFn, const wxRect &rect, const std::shared_ptr<Track> &pTrack )
25  : SliderHandle{ sliderFn, rect, pTrack }
26 {}
27 
29 {
30 }
31 
32 std::shared_ptr<WaveTrack> GainSliderHandle::GetWaveTrack() const
33 {
34  return std::static_pointer_cast<WaveTrack>(mpTrack.lock());
35 }
36 
38 {
39  if (GetWaveTrack())
40  return GetWaveTrack()->GetGain();
41  else
42  return 0;
43 }
44 
46 (AudacityProject *pProject, float newValue)
47 {
48  (void)pProject;//Compiler food
49  auto pTrack = GetWaveTrack();
50 
51  if (pTrack) {
52  for (auto channel :
53  TrackList::Channels(pTrack.get()))
54  channel->SetGain(newValue);
55  }
56 
58 }
59 
61 (const wxMouseEvent &, AudacityProject *pProject)
62 {
63  ProjectHistory::Get( *pProject )
64  .PushState(XO("Moved gain slider"), XO("Gain"), UndoPush::CONSOLIDATE);
66 }
67 
69  const wxMouseState &, AudacityProject &project) const
70 {
72  float value = 0;
73 
74  auto pTrack = GetWaveTrack();
75  if (pTrack)
76  value = pTrack->GetGain();
77 
78  // LLL: Can't access the slider since Tip() is a const method and getting the slider
79  // is not, so duplicate what LWSlider does.
80 
81  /* i18n-hint dB abbreviates decibels */
82  val = XO("%+.1f dB").Format(LINEAR_TO_DB(value));
83 
84  /* i18n-hint: An item name followed by a value, with appropriate separating punctuation */
85  return XO("%s: %s").Format(XO("Gain"), val);
86 }
87 
89 (std::weak_ptr<GainSliderHandle> &holder,
90  const wxMouseState &state, const wxRect &rect,
91  const std::shared_ptr<Track> &pTrack)
92 {
93  if (!state.ButtonIsDown(wxMOUSE_BTN_LEFT))
94  return {};
95 
96  wxRect sliderRect;
97  WaveTrackControls::GetGainRect(rect.GetTopLeft(), sliderRect);
98  if ( TrackInfo::HideTopItem( rect, sliderRect))
99  return {};
100  if (sliderRect.Contains(state.m_x, state.m_y)) {
101  wxRect sliderRect2;
102  WaveTrackControls::GetGainRect(rect.GetTopLeft(), sliderRect2);
103  auto sliderFn =
104  []( AudacityProject *pProject, const wxRect &sliderRect, Track *pTrack ) {
106  (sliderRect, static_cast<WaveTrack*>( pTrack ), true,
107  &TrackPanel::Get( *pProject ));
108  };
109  auto result =
110  std::make_shared<GainSliderHandle>( sliderFn, sliderRect2, pTrack );
111  result = AssignUIHandlePtr(holder, result);
112 
113  return result;
114  }
115  else
116  return {};
117 }
118 
120 
122 ( SliderFn sliderFn, const wxRect &rect, const std::shared_ptr<Track> &pTrack )
123  : SliderHandle{ sliderFn, rect, pTrack }
124 {}
125 
127 {
128 }
129 
130 std::shared_ptr<WaveTrack> PanSliderHandle::GetWaveTrack() const
131 {
132  return std::static_pointer_cast<WaveTrack>(mpTrack.lock());
133 }
134 
136 {
137  if (GetWaveTrack())
138  return GetWaveTrack()->GetPan();
139  else
140  return 0;
141 }
142 
144 {
145  (void)pProject;//Compiler food
146  using namespace RefreshCode;
147  Result result = RefreshNone;
148  auto pTrack = GetWaveTrack();
149 
150  if (pTrack) {
151  for (auto channel :
152  TrackList::Channels(pTrack.get()))
153  channel->SetPan(newValue);
154  }
155 
156  return result;
157 }
158 
160 (const wxMouseEvent &, AudacityProject *pProject)
161 {
162  ProjectHistory::Get( *pProject )
163  .PushState(XO("Moved pan slider"), XO("Pan"), UndoPush::CONSOLIDATE);
165 }
166 
168  const wxMouseState &, AudacityProject &project) const
169 {
170  TranslatableString val;
171  float value = 0.0;
172 
173  auto pTrack = GetWaveTrack();
174  if (pTrack)
175  value = pTrack->GetPan();
176 
177  // LLL: Can't access the slider since Tip() is a const method and getting the slider
178  // is not, so duplicate what LWSlider does.
179 
180  if (value == 0.0)
181  {
182  val = XO("Center");
183  }
184  else
185  {
186  const auto v = 100.0f * fabsf(value);
187  if (value < 0.0)
188  /* i18n-hint: Stereo pan setting */
189  val = XO("%.0f%% Left").Format(v);
190  else
191  /* i18n-hint: Stereo pan setting */
192  val = XO("%.0f%% Right").Format(v);
193  }
194 
195  /* i18n-hint: An item name followed by a value, with appropriate separating punctuation */
196  return XO("%s: %s").Format(XO("Pan"), val);
197 }
198 
200 (std::weak_ptr<PanSliderHandle> &holder,
201  const wxMouseState &state, const wxRect &rect,
202  const std::shared_ptr<Track> &pTrack)
203 {
204  if (!state.ButtonIsDown(wxMOUSE_BTN_LEFT))
205  return {};
206 
207  wxRect sliderRect;
208  WaveTrackControls::GetPanRect(rect.GetTopLeft(), sliderRect);
209  if ( TrackInfo::HideTopItem( rect, sliderRect))
210  return {};
211  if (sliderRect.Contains(state.m_x, state.m_y)) {
212  auto sliderFn =
213  []( AudacityProject *pProject, const wxRect &sliderRect, Track *pTrack ) {
215  (sliderRect, static_cast<WaveTrack*>( pTrack ), true,
216  &TrackPanel::Get( *pProject ));
217  };
218  auto result = std::make_shared<PanSliderHandle>(
219  sliderFn, sliderRect, pTrack );
220  result = AssignUIHandlePtr(holder, result);
221 
222  return result;
223  }
224  else
225  return {};
226 }
GainSliderHandle::HitTest
static UIHandlePtr HitTest(std::weak_ptr< GainSliderHandle > &holder, const wxMouseState &state, const wxRect &rect, const std::shared_ptr< Track > &pTrack)
Definition: WaveTrackSliderHandles.cpp:89
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:69
PanSliderHandle::CommitChanges
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject) override
Definition: WaveTrackSliderHandles.cpp:160
RefreshCode::RefreshNone
@ RefreshNone
Definition: RefreshCode.h:21
TrackList::Channels
static auto Channels(TrackType *pTrack) -> TrackIterRange< TrackType >
Definition: Track.h:1484
PanSliderHandle::SetValue
Result SetValue(AudacityProject *pProject, float newValue) override
Definition: WaveTrackSliderHandles.cpp:143
TrackPanel::Get
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:227
XO
#define XO(s)
Definition: Internat.h:31
GainSliderHandle::Tip
TranslatableString Tip(const wxMouseState &state, AudacityProject &) const override
Definition: WaveTrackSliderHandles.cpp:68
SliderHandle
Definition: SliderHandle.h:23
WaveTrackControls::GetGainRect
static void GetGainRect(const wxPoint &topLeft, wxRect &dest)
Definition: WaveTrackControls.cpp:1096
GainSliderHandle::~GainSliderHandle
virtual ~GainSliderHandle()
Definition: WaveTrackSliderHandles.cpp:28
PanSliderHandle::PanSliderHandle
PanSliderHandle(const PanSliderHandle &)=delete
PanSliderHandle::~PanSliderHandle
virtual ~PanSliderHandle()
Definition: WaveTrackSliderHandles.cpp:126
WaveTrackControls::GetPanRect
static void GetPanRect(const wxPoint &topLeft, wxRect &dest)
Definition: WaveTrackControls.cpp:1104
UIHandle::Result
unsigned Result
Definition: UIHandle.h:38
PanSliderHandle::HitTest
static UIHandlePtr HitTest(std::weak_ptr< PanSliderHandle > &holder, const wxMouseState &state, const wxRect &rect, const std::shared_ptr< Track > &pTrack)
Definition: WaveTrackSliderHandles.cpp:200
UIHandlePtr
std::shared_ptr< UIHandle > UIHandlePtr
Definition: CellularPanel.h:28
SliderHandle::mpTrack
std::weak_ptr< Track > mpTrack
Definition: SliderHandle.h:75
GainSliderHandle::CommitChanges
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject) override
Definition: WaveTrackSliderHandles.cpp:61
WaveTrackControls::GainSlider
static LWSlider * GainSlider(CellularPanel &panel, const WaveTrack &wt)
Definition: WaveTrackControls.cpp:1130
RefreshCode::RefreshCell
@ RefreshCell
Definition: RefreshCode.h:24
GainSliderHandle::GainSliderHandle
GainSliderHandle(const GainSliderHandle &)=delete
ProjectHistory::PushState
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
Definition: ProjectHistory.cpp:90
TrackInfo::HideTopItem
AUDACITY_DLL_API bool HideTopItem(const wxRect &rect, const wxRect &subRect, int allowance=0)
Definition: TrackInfo.cpp:207
Track
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:239
SliderHandle::SliderFn
LWSlider *(*)(AudacityProject *, const wxRect &, Track *) SliderFn
Definition: SliderHandle.h:27
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
GainSliderHandle::GetValue
float GetValue() override
Definition: WaveTrackSliderHandles.cpp:37
WaveTrackControls::PanSlider
static LWSlider * PanSlider(CellularPanel &panel, const WaveTrack &wt)
Definition: WaveTrackControls.cpp:1186
PanSliderHandle::GetValue
float GetValue() override
Definition: WaveTrackSliderHandles.cpp:135
UndoPush::CONSOLIDATE
@ CONSOLIDATE
GainSliderHandle::GetWaveTrack
std::shared_ptr< WaveTrack > GetWaveTrack() const
Definition: WaveTrackSliderHandles.cpp:32
LINEAR_TO_DB
#define LINEAR_TO_DB(x)
Definition: MemoryX.h:631
WaveTrackControls.h
AssignUIHandlePtr
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:151
RefreshCode
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
PanSliderHandle::GetWaveTrack
std::shared_ptr< WaveTrack > GetWaveTrack() const
Definition: WaveTrackSliderHandles.cpp:130
GainSliderHandle::SetValue
Result SetValue(AudacityProject *pProject, float newValue) override
Definition: WaveTrackSliderHandles.cpp:46
PanSliderHandle::Tip
TranslatableString Tip(const wxMouseState &state, AudacityProject &) const override
Definition: WaveTrackSliderHandles.cpp:167
ProjectHistory::Get
static ProjectHistory & Get(AudacityProject &project)
Definition: ProjectHistory.cpp:26
WaveTrackSliderHandles.h