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#ifdef EXPERIMENTAL_MIDI_OUT
13
14#include "NoteTrackControls.h"
15#include "ProjectHistory.h"
16#include "../../../../RefreshCode.h"
17#include "../../../ui/CommonTrackInfo.h"
18#include "../../../../TrackPanel.h"
19#include "UndoManager.h"
20#include "NoteTrack.h"
21#include "ViewInfo.h"
22
23VelocitySliderHandle::VelocitySliderHandle
24( SliderFn sliderFn, const wxRect &rect,
25 const std::shared_ptr<Track> &pTrack )
26 : SliderHandle{ sliderFn, rect, pTrack }
27{}
28
29VelocitySliderHandle::~VelocitySliderHandle()
30{
31}
32
33std::shared_ptr<NoteTrack> VelocitySliderHandle::GetNoteTrack() const
34{
35 return std::static_pointer_cast<NoteTrack>(mpTrack.lock());
36}
37
38float VelocitySliderHandle::GetValue()
39{
40 if (GetNoteTrack())
41 return GetNoteTrack()->GetVelocity();
42 else
43 return 0;
44}
45
46UIHandle::Result VelocitySliderHandle::SetValue
47(AudacityProject *pProject, float newValue)
48{
49 (void)pProject;//Compiler food
50 auto pTrack = GetNoteTrack();
51
52 if (pTrack) {
53 pTrack->SetVelocity(newValue);
54 }
55
57}
58
59UIHandle::Result VelocitySliderHandle::CommitChanges
60(const wxMouseEvent &, AudacityProject *pProject)
61{
62 ProjectHistory::Get( *pProject )
63 .PushState(XO("Moved velocity slider"), XO("Velocity"),
66}
67
68TranslatableString VelocitySliderHandle::Tip(
69 const wxMouseState &, AudacityProject &project) const
70{
72 float value = 0;
73
74 auto pTrack = GetNoteTrack();
75 if (pTrack)
76 value = pTrack->GetVelocity();
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 if (value > 0.0f)
82 // Signed
83 val = Verbatim("%+d").Format((int)value);
84 else
85 // Zero, or signed negative
86 val = Verbatim("%d").Format((int)value);
87
88 /* i18n-hint: An item name followed by a value, with appropriate separating punctuation */
89 return XO("%s: %s").Format(XO("Velocity"), val);
90}
91
92UIHandlePtr VelocitySliderHandle::HitTest
93(std::weak_ptr<VelocitySliderHandle> &holder,
94 const wxMouseState &state, const wxRect &rect,
95 const std::shared_ptr<Track> &pTrack)
96{
97 if (!state.ButtonIsDown(wxMOUSE_BTN_LEFT))
98 return {};
99
100 wxRect sliderRect;
101 NoteTrackControls::GetVelocityRect(rect.GetTopLeft(), sliderRect);
103 return {};
104 if (sliderRect.Contains(state.m_x, state.m_y)) {
105 auto sliderFn =
106 []( AudacityProject *pProject, const wxRect &sliderRect, Track *pTrack ) {
108 (sliderRect, static_cast<NoteTrack*>( pTrack ), true,
109 &TrackPanel::Get( *pProject ));
110 };
111 auto result = std::make_shared<VelocitySliderHandle>(
112 sliderFn, sliderRect, pTrack );
113 result = AssignUIHandlePtr(holder, result);
114
115 return result;
116 }
117 else
118 return {};
119}
120
121#endif
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:159
@ kTrackInfoSliderAllowance
Definition: ViewInfo.h:100
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 void GetVelocityRect(const wxPoint &topleft, wxRect &dest)
static LWSlider * VelocitySlider(const wxRect &sliderRect, const NoteTrack *t, bool captured, wxWindow *pParent)
A Track that is used for Midi notes. (Somewhat old code).
Definition: NoteTrack.h:86
void PushState(const TranslatableString &desc, const TranslatableString &shortDesc)
static ProjectHistory & Get(AudacityProject &project)
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:122
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:233
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:39
AUDACITY_DLL_API bool HideTopItem(const wxRect &rect, const wxRect &subRect, int allowance=0)