Audacity  2.2.2
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  **********************************************************************/
10 
11 #include "../../../../Audacity.h"
12 #include "NoteTrackSliderHandles.h"
13 
14 #ifdef EXPERIMENTAL_MIDI_OUT
15 
16 #include "../../../../HitTestResult.h"
17 #include "../../../../MixerBoard.h"
18 #include "../../../../Project.h"
19 #include "../../../../RefreshCode.h"
20 #include "../../../../TrackPanel.h" // for TrackInfo
21 #include "../../../../UndoManager.h"
22 #include "../../../../NoteTrack.h"
23 
24 VelocitySliderHandle::VelocitySliderHandle
25 ( SliderFn sliderFn, const wxRect &rect,
26  const std::shared_ptr<Track> &pTrack )
27  : SliderHandle{ sliderFn, rect, pTrack }
28 {}
29 
30 VelocitySliderHandle::~VelocitySliderHandle()
31 {
32 }
33 
34 std::shared_ptr<NoteTrack> VelocitySliderHandle::GetNoteTrack()
35 {
36  return std::static_pointer_cast<NoteTrack>(mpTrack.lock());
37 }
38 
39 float VelocitySliderHandle::GetValue()
40 {
41  if (GetNoteTrack())
42  return GetNoteTrack()->GetVelocity();
43  else
44  return 0;
45 }
46 
47 UIHandle::Result VelocitySliderHandle::SetValue
48 (AudacityProject *pProject, float newValue)
49 {
50  auto pTrack = GetNoteTrack();
51 
52  if (pTrack) {
53  pTrack->SetVelocity(newValue);
54 
55  MixerBoard *const pMixerBoard = pProject->GetMixerBoard();
56  if (pMixerBoard)
57  pMixerBoard->UpdateVelocity(pTrack.get());
58  }
59 
61 }
62 
63 UIHandle::Result VelocitySliderHandle::CommitChanges
64 (const wxMouseEvent &, AudacityProject *pProject)
65 {
66  pProject->PushState(_("Moved velocity slider"), _("Velocity"), UndoPush::CONSOLIDATE);
68 }
69 
70 
71 
72 UIHandlePtr VelocitySliderHandle::HitTest
73 (std::weak_ptr<VelocitySliderHandle> &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::GetVelocityRect(rect.GetTopLeft(), sliderRect);
82  if ( TrackInfo::HideTopItem( rect, sliderRect, kTrackInfoSliderAllowance ) )
83  return {};
84  if (sliderRect.Contains(state.m_x, state.m_y)) {
85  auto sliderFn =
86  []( AudacityProject *pProject, const wxRect &sliderRect, Track *pTrack ) {
87  return TrackInfo::VelocitySlider
88  (sliderRect, static_cast<NoteTrack*>( pTrack ), true,
89  const_cast<TrackPanel*>(pProject->GetTrackPanel()));
90  };
91  auto result = std::make_shared<VelocitySliderHandle>(
92  sliderFn, sliderRect, pTrack );
93  result = AssignUIHandlePtr(holder, result);
94 
95  return result;
96  }
97  else
98  return {};
99 }
100 
101 #endif
MixerBoard * GetMixerBoard()
Definition: Project.h:516
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
unsigned Result
Definition: UIHandle.h:37
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:101
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")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void PushState(const wxString &desc, const wxString &shortDesc)
Definition: Project.cpp:4695
TrackPanel * GetTrackPanel()
Definition: Project.h:307
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:162
A Track that is used for Midi notes. (Somewhat old code).