Audacity  2.2.2
NoteTrackVRulerControls.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 NoteTrackVRulerControls.cpp
6 
7 Paul Licameli split from TrackPanel.cpp
8 
9 **********************************************************************/
10 
11 #include "../../../../Audacity.h"
12 
13 #ifdef USE_MIDI
14 
16 #include "NoteTrackVZoomHandle.h"
17 
18 #include "../../../../HitTestResult.h"
19 #include "../../../../NoteTrack.h"
20 #include "../../../../Project.h"
21 #include "../../../../RefreshCode.h"
22 #include "../../../../TrackPanelMouseEvent.h"
23 
24 
27 {
28 }
29 
30 std::vector<UIHandlePtr> NoteTrackVRulerControls::HitTest
31 (const TrackPanelMouseState &st,
32  const AudacityProject *pProject)
33 {
34  std::vector<UIHandlePtr> results;
35  UIHandlePtr result;
36 
37  if ( st.state.GetX() <= st.rect.GetRight() - kGuard ) {
38  auto track = std::static_pointer_cast<NoteTrack>(FindTrack());
40  mVZoomHandle, st.state, track, st.rect);
41  if (result)
42  results.push_back(result);
43  }
44 
45  auto more = TrackVRulerControls::HitTest(st, pProject);
46  std::copy(more.begin(), more.end(), std::back_inserter(results));
47 
48  return results;
49 }
50 
52 (const TrackPanelMouseEvent &evt, AudacityProject *pProject)
53 {
54  using namespace RefreshCode;
55  const wxMouseEvent &event = evt.event;
56 
57  if (!(event.ShiftDown() || event.CmdDown()))
58  return RefreshNone;
59 
60  // Always stop propagation even if the ruler didn't change. The ruler
61  // is a narrow enough target.
62  evt.event.Skip(false);
63 
64  const auto pTrack = FindTrack();
65  if (!pTrack)
66  return RefreshNone;
67  wxASSERT(pTrack->GetKind() == Track::Note);
68  auto steps = evt.steps;
69 
70  const auto nt = static_cast<NoteTrack*>(pTrack.get());
71  if (event.CmdDown() && !event.ShiftDown()) {
72  if (steps > 0)
73  nt->ZoomIn(evt.rect, evt.event.m_y);
74  else
75  nt->ZoomOut(evt.rect, evt.event.m_y);
76  } else if (!event.CmdDown() && event.ShiftDown()) {
77  // Scroll some fixed number of notes, independent of zoom level or track height:
78  static const int movement = 6; // 6 semitones is half an octave
79  nt->SetBottomNote(nt->GetBottomNote() + (int) (steps * movement));
80  } else {
81  return RefreshNone;
82  }
83 
84  pProject->ModifyState(true);
85 
86  return RefreshCell | UpdateVRuler;
87 }
88 
89 #endif
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override
const int kGuard
unsigned HandleWheelRotation(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
static UIHandlePtr HitTest(std::weak_ptr< NoteTrackVZoomHandle > &holder, const wxMouseState &state, const std::shared_ptr< NoteTrack > &pTrack, const wxRect &rect)
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override
void ModifyState(bool bWantsAutoSave)
Definition: Project.cpp:4740
std::shared_ptr< UIHandle > UIHandlePtr
Definition: TrackPanel.h:59
std::shared_ptr< Track > FindTrack() override
std::weak_ptr< NoteTrackVZoomHandle > mVZoomHandle
A Track that is used for Midi notes. (Somewhat old code).