Audacity  2.2.2
NoteTrackButtonHandle.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 NoteTrackButtonHandle.cpp
6 
7 Paul Licameli split from TrackPanel.cpp
8 
9 **********************************************************************/
10 
11 #include "../../../../Audacity.h"
12 
13 #ifdef USE_MIDI
14 
15 #include "NoteTrackButtonHandle.h"
16 
17 #include "../../../../HitTestResult.h"
18 #include "../../../../TrackPanelMouseEvent.h"
19 #include "../../../../NoteTrack.h"
20 #include "../../../../Project.h"
21 #include "../../../../RefreshCode.h"
22 #include "../../../../TrackPanel.h"
23 
25 ( const std::shared_ptr<NoteTrack> &pTrack,
26  int channel, const wxRect &rect )
27  : mpTrack{ pTrack }
28  , mChannel{ channel }
29  , mRect{ rect }
30 {
31 }
32 
34 {
36 }
37 
39 {
40 }
41 
43 (const NoteTrackButtonHandle &oldState, const NoteTrackButtonHandle &newState)
44 {
45  if (oldState.GetChannel() != newState.GetChannel())
46  // Repaint whenever the highlighted button is different
48  return 0;
49 }
50 
52  (std::weak_ptr<NoteTrackButtonHandle> &holder,
53  const wxMouseState &state, const wxRect &rect,
54  const std::shared_ptr<NoteTrack> &pTrack)
55 {
56  wxRect midiRect;
57  TrackInfo::GetMidiControlsRect(rect, midiRect);
58  if ( TrackInfo::HideTopItem( rect, midiRect ) )
59  return {};
60  if (pTrack->GetKind() == Track::Note &&
61  midiRect.Contains(state.m_x, state.m_y)) {
62  auto channel = pTrack->FindChannel(midiRect, state.m_x, state.m_y);
63  auto result = std::make_shared<NoteTrackButtonHandle>(
64  pTrack, channel, midiRect );
65  result = AssignUIHandlePtr(holder, result);
66  return result;
67  }
68  else
69  return {};
70 }
71 
74 {
76 }
77 
80 {
82 }
83 
85 (const TrackPanelMouseState &, const AudacityProject *)
86 {
87  // auto pTrack = pProject->GetTracks()->Lock(mpTrack);
88  auto pTrack = mpTrack.lock();
89  if ( !pTrack )
90  return {};
91  // No special message or cursor
92  return {};
93 }
94 
96 (const TrackPanelMouseEvent &evt, AudacityProject *pProject, wxWindow *)
97 {
98  using namespace RefreshCode;
99 
100  auto pTrack = pProject->GetTracks()->Lock(mpTrack);
101  if (!pTrack)
102  return Cancelled;
103 
104  const wxMouseEvent &event = evt.event;
105  if (pTrack->LabelClick(mRect, event.m_x, event.m_y,
106  event.Button(wxMOUSE_BTN_RIGHT))) {
107  // No undo items needed??
108  pProject->ModifyState(false);
109  return RefreshAll;
110  }
111  return RefreshNone;
112 }
113 
115 {
117 }
118 
119 #endif
std::weak_ptr< NoteTrack > mpTrack
Result Release(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
Result Cancel(AudacityProject *pProject) override
static UIHandlePtr HitTest(std::weak_ptr< NoteTrackButtonHandle > &holder, const wxMouseState &state, const wxRect &rect, const std::shared_ptr< NoteTrack > &pTrack)
static UIHandle::Result NeedChangeHighlight(const NoteTrackButtonHandle &oldState, const NoteTrackButtonHandle &newState)
Result mChangeHighlight
Definition: UIHandle.h:150
Result Click(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
unsigned Result
Definition: UIHandle.h:37
void Enter(bool forward) override
virtual ~NoteTrackButtonHandle()
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:733
void ModifyState(bool bWantsAutoSave)
Definition: Project.cpp:4740
std::shared_ptr< UIHandle > UIHandlePtr
Definition: TrackPanel.h:59
static bool HideTopItem(const wxRect &rect, const wxRect &subRect, int allowance=0)
HitTestPreview Preview(const TrackPanelMouseState &state, const AudacityProject *pProject) override
Result Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
TrackList * GetTracks()
Definition: Project.h:192
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:162