Audacity 3.2.0
NoteTrackSliderHandles.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 NoteTrackSliderHandles.cpp
6
7 Paul Licameli split from TrackPanel.cpp
8
9 **********************************************************************/
11
12#include "NoteTrackControls.h"
13#include "ProjectHistory.h"
14#include "../../../../RefreshCode.h"
15#include "../../../ui/CommonTrackInfo.h"
16#include "../../../../TrackPanel.h"
17#include "UndoManager.h"
18#include "NoteTrack.h"
19#include "ViewInfo.h"
20
22( SliderFn sliderFn, const wxRect &rect,
23 const std::shared_ptr<Track> &pTrack )
24 : SliderHandle{ sliderFn, rect, pTrack }
25{}
26
28{
29}
30
31std::shared_ptr<NoteTrack> VelocitySliderHandle::GetNoteTrack() const
32{
33 return std::static_pointer_cast<NoteTrack>(mpTrack.lock());
34}
35
37{
38 if (GetNoteTrack())
39 return GetNoteTrack()->GetVelocity();
40 else
41 return 0;
42}
43
45(AudacityProject *pProject, float newValue)
46{
47 (void)pProject;//Compiler food
48 auto pTrack = GetNoteTrack();
49
50 if (pTrack) {
51 pTrack->SetVelocity(newValue);
52 }
53
55}
56
58(const wxMouseEvent &, AudacityProject *pProject)
59{
60 ProjectHistory::Get( *pProject )
61 .PushState(XO("Moved velocity slider"), XO("Velocity"),
64}
65
67 const wxMouseState &, AudacityProject &project) const
68{
70 float value = 0;
71
72 auto pTrack = GetNoteTrack();
73 if (pTrack)
74 value = pTrack->GetVelocity();
75
76 // LLL: Can't access the slider since Tip() is a const method and getting the slider
77 // is not, so duplicate what LWSlider does.
78
79 if (value > 0.0f)
80 // Signed
81 val = Verbatim("%+d").Format((int)value);
82 else
83 // Zero, or signed negative
84 val = Verbatim("%d").Format((int)value);
85
86 /* i18n-hint: An item name followed by a value, with appropriate separating punctuation */
87 return XO("%s: %s").Format(XO("Velocity"), val);
88}
89
91(std::weak_ptr<VelocitySliderHandle> &holder,
92 const wxMouseState &state, const wxRect &rect,
93 const std::shared_ptr<Track> &pTrack)
94{
95 if (!state.ButtonIsDown(wxMOUSE_BTN_LEFT))
96 return {};
97
98 wxRect sliderRect;
99 NoteTrackControls::GetVelocityRect(rect, sliderRect);
101 return {};
102 if (sliderRect.Contains(state.m_x, state.m_y)) {
103 auto sliderFn =
104 []( AudacityProject *pProject, const wxRect &sliderRect, Track *pTrack ) {
106 (sliderRect, static_cast<NoteTrack*>( pTrack ), true,
107 &TrackPanel::Get( *pProject ));
108 };
109 auto result = std::make_shared<VelocitySliderHandle>(
110 sliderFn, sliderRect, pTrack );
111 result = AssignUIHandlePtr(holder, result);
112
113 return result;
114 }
115 else
116 return {};
117}
std::shared_ptr< UIHandle > UIHandlePtr
Definition: CellularPanel.h:28
XO("Cut/Copy/Paste")
const auto project
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:164
@ kTrackInfoSliderAllowance
Definition: ViewInfo.h:101
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static LWSlider * VelocitySlider(const wxRect &sliderRect, const NoteTrack *t, bool captured, wxWindow *pParent)
static void GetVelocityRect(const wxRect &rect, wxRect &dest)
A Track that is used for Midi notes. (Somewhat old code).
Definition: NoteTrack.h:78
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.
TranslatableString & Format(Args &&...args) &
Capture variadic format arguments (by copy) when there is no plural.
unsigned Result
Definition: UIHandle.h:40
std::shared_ptr< NoteTrack > GetNoteTrack() const
TranslatableString Tip(const wxMouseState &state, AudacityProject &) const override
Result SetValue(AudacityProject *pProject, float newValue) override
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject) override
VelocitySliderHandle(const VelocitySliderHandle &)=delete
static UIHandlePtr HitTest(std::weak_ptr< VelocitySliderHandle > &holder, const wxMouseState &state, const wxRect &rect, const std::shared_ptr< Track > &pTrack)
AUDACITY_DLL_API bool HideTopItem(const wxRect &rect, const wxRect &subRect, int allowance=0)