Audacity 3.2.0
WaveTrackSliderHandles.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5WaveTrackSliderHandles.cpp
6
7Paul Licameli split from TrackPanel.cpp
8
9**********************************************************************/
10
11
13
14#include "WaveTrackControls.h"
15#include "ProjectHistory.h"
16#include "../../../../RefreshCode.h"
17#include "../../../ui/CommonTrackInfo.h"
18#include "../../../../TrackPanel.h"
19#include "TrackFocus.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
32std::shared_ptr<WaveTrack> VolumeSliderHandle::GetWaveTrack() const
33{
34 return std::static_pointer_cast<WaveTrack>(mpTrack.lock());
35}
36
38{
39 if (GetWaveTrack())
40 return GetWaveTrack()->GetVolume();
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 pTrack->SetVolume(newValue);
53
55}
56
58(const wxMouseEvent &, AudacityProject *pProject)
59{
60 ProjectHistory::Get( *pProject )
61 .PushState(XO("Moved volume slider"), XO("Volume"), UndoPush::CONSOLIDATE);
63}
64
66 const wxMouseState &, AudacityProject &project) const
67{
69 float value = 0;
70
71 auto pTrack = GetWaveTrack();
72 if (pTrack)
73 value = pTrack->GetVolume();
74
75 // LLL: Can't access the slider since Tip() is a const method and getting the slider
76 // is not, so duplicate what LWSlider does.
77
78 /* i18n-hint dB abbreviates decibels */
79 val = XO("%+.1f dB").Format(LINEAR_TO_DB(value));
80
81 /* i18n-hint: An item name followed by a value, with appropriate separating punctuation */
82 return XO("%s: %s").Format(XO("Volume"), val);
83}
84
86(std::weak_ptr<VolumeSliderHandle> &holder,
87 const wxMouseState &state, const wxRect &rect,
88 const std::shared_ptr<Track> &pTrack)
89{
90 if (!state.ButtonIsDown(wxMOUSE_BTN_LEFT))
91 return {};
92
93 wxRect sliderRect;
94 WaveTrackControls::GetVolumeRect(rect, sliderRect);
95 if ( CommonTrackInfo::HideTopItem( rect, sliderRect))
96 return {};
97 if (sliderRect.Contains(state.m_x, state.m_y)) {
98 wxRect sliderRect2;
99 WaveTrackControls::GetVolumeRect(rect, sliderRect2);
100 auto sliderFn =
101 []( AudacityProject *pProject, const wxRect &sliderRect, Track *pTrack ) {
103 (sliderRect, static_cast<WaveTrack*>( pTrack ), true,
104 &TrackPanel::Get( *pProject ));
105 };
106 auto result =
107 std::make_shared<VolumeSliderHandle>( sliderFn, sliderRect2, pTrack );
108 result = AssignUIHandlePtr(holder, result);
109
110 return result;
111 }
112 else
113 return {};
114}
115
117
119( SliderFn sliderFn, const wxRect &rect, const std::shared_ptr<Track> &pTrack )
120 : SliderHandle{ sliderFn, rect, pTrack }
121{}
122
124{
125}
126
127std::shared_ptr<WaveTrack> PanSliderHandle::GetWaveTrack() const
128{
129 return std::static_pointer_cast<WaveTrack>(mpTrack.lock());
130}
131
133{
134 if (GetWaveTrack())
135 return GetWaveTrack()->GetPan();
136 else
137 return 0;
138}
139
141{
142 (void)pProject;//Compiler food
143 using namespace RefreshCode;
144 Result result = RefreshNone;
145 auto pTrack = GetWaveTrack();
146
147 if (pTrack)
148 pTrack->SetPan(newValue);
149
150 return result;
151}
152
154(const wxMouseEvent &, AudacityProject *pProject)
155{
156 ProjectHistory::Get( *pProject )
157 .PushState(XO("Moved pan slider"), XO("Pan"), UndoPush::CONSOLIDATE);
159}
160
162 const wxMouseState &, AudacityProject &project) const
163{
165 float value = 0.0;
166
167 auto pTrack = GetWaveTrack();
168 if (pTrack)
169 value = pTrack->GetPan();
170
171 // LLL: Can't access the slider since Tip() is a const method and getting the slider
172 // is not, so duplicate what LWSlider does.
173
174 if (value == 0.0)
175 {
176 val = XO("Center");
177 }
178 else
179 {
180 const auto v = 100.0f * fabsf(value);
181 if (value < 0.0)
182 /* i18n-hint: Stereo pan setting */
183 val = XO("%.0f%% Left").Format(v);
184 else
185 /* i18n-hint: Stereo pan setting */
186 val = XO("%.0f%% Right").Format(v);
187 }
188
189 /* i18n-hint: An item name followed by a value, with appropriate separating punctuation */
190 return XO("%s: %s").Format(XO("Pan"), val);
191}
192
194(std::weak_ptr<PanSliderHandle> &holder,
195 const wxMouseState &state, const wxRect &rect,
196 const std::shared_ptr<Track> &pTrack)
197{
198 if (!state.ButtonIsDown(wxMOUSE_BTN_LEFT))
199 return {};
200
201 wxRect sliderRect;
202 WaveTrackControls::GetPanRect(rect, sliderRect);
203 if ( CommonTrackInfo::HideTopItem( rect, sliderRect))
204 return {};
205 if (sliderRect.Contains(state.m_x, state.m_y)) {
206 auto sliderFn =
207 []( AudacityProject *pProject, const wxRect &sliderRect, Track *pTrack ) {
209 (sliderRect, static_cast<WaveTrack*>( pTrack ), true,
210 &TrackPanel::Get( *pProject ));
211 };
212 auto result = std::make_shared<PanSliderHandle>(
213 sliderFn, sliderRect, pTrack );
214 result = AssignUIHandlePtr(holder, result);
215
216 return result;
217 }
218 else
219 return {};
220}
std::shared_ptr< UIHandle > UIHandlePtr
Definition: CellularPanel.h:28
XO("Cut/Copy/Paste")
#define LINEAR_TO_DB(x)
Definition: MemoryX.h:339
const auto project
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:164
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
std::shared_ptr< WaveTrack > GetWaveTrack() const
PanSliderHandle(const PanSliderHandle &)=delete
float GetValue() override
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject) override
TranslatableString Tip(const wxMouseState &state, AudacityProject &) const override
Result SetValue(AudacityProject *pProject, float newValue) override
static UIHandlePtr HitTest(std::weak_ptr< PanSliderHandle > &holder, const wxMouseState &state, const wxRect &rect, const std::shared_ptr< Track > &pTrack)
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
LWSlider *(*)(AudacityProject *, const wxRect &, Track *) SliderFn
Definition: SliderHandle.h:27
std::weak_ptr< Track > mpTrack
Definition: SliderHandle.h:76
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:234
Holds a msgid for the translation catalog; may also bind format arguments.
unsigned Result
Definition: UIHandle.h:40
Result SetValue(AudacityProject *pProject, float newValue) override
VolumeSliderHandle(const VolumeSliderHandle &)=delete
std::shared_ptr< WaveTrack > GetWaveTrack() const
static UIHandlePtr HitTest(std::weak_ptr< VolumeSliderHandle > &holder, const wxMouseState &state, const wxRect &rect, const std::shared_ptr< Track > &pTrack)
TranslatableString Tip(const wxMouseState &state, AudacityProject &) const override
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject) override
static void GetVolumeRect(const wxRect &rect, wxRect &dest)
static void GetPanRect(const wxRect &rect, wxRect &dest)
static LWSlider * VolumeSlider(CellularPanel &panel, const WaveTrack &wt)
static LWSlider * PanSlider(CellularPanel &panel, const WaveTrack &wt)
A Track that contains audio waveform data.
Definition: WaveTrack.h:203
AUDACITY_DLL_API bool HideTopItem(const wxRect &rect, const wxRect &subRect, int allowance=0)
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16