Audacity  3.0.3
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 
12 
13 #ifdef USE_MIDI
14 #include "NoteTrackButtonHandle.h"
15 
16 #include "../../../../HitTestResult.h"
17 #include "NoteTrackControls.h"
18 #include "../../../../TrackPanelMouseEvent.h"
19 #include "../../../../NoteTrack.h"
20 #include "../../../../ProjectHistory.h"
21 #include "../../../../RefreshCode.h"
22 #include "../../../../TrackInfo.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;
58  if ( TrackInfo::HideTopItem( rect, midiRect ) )
59  return {};
60  if (midiRect.Contains(state.m_x, state.m_y)) {
61  auto channel = pTrack->FindChannel(midiRect, state.m_x, state.m_y);
62  auto result = std::make_shared<NoteTrackButtonHandle>(
63  pTrack, channel, midiRect );
64  result = AssignUIHandlePtr(holder, result);
65  return result;
66  }
67  else
68  return {};
69 }
70 
73 {
75 }
76 
79 {
81 }
82 
85 {
86  // auto pTrack = pProject->GetTracks()->Lock(mpTrack);
87  auto pTrack = mpTrack.lock();
88  if ( !pTrack )
89  return {};
90  // No special message or cursor
91  return {};
92 }
93 
95 (const TrackPanelMouseEvent &evt, AudacityProject *pProject, wxWindow *)
96 {
97  using namespace RefreshCode;
98 
99  auto pTrack = TrackList::Get( *pProject ).Lock(mpTrack);
100  if (!pTrack)
101  return Cancelled;
102 
103  const wxMouseEvent &event = evt.event;
104  if (pTrack->LabelClick(mRect, event.m_x, event.m_y,
105  event.Button(wxMOUSE_BTN_RIGHT))) {
106  // No undo items needed??
107  ProjectHistory::Get( *pProject ).ModifyState(false);
108  return RefreshAll;
109  }
110  return RefreshNone;
111 }
112 
114 {
116 }
117 
118 #endif
ProjectHistory::ModifyState
void ModifyState(bool bWantsAutoSave)
Definition: ProjectHistory.cpp:124
NoteTrackButtonHandle::NoteTrackButtonHandle
NoteTrackButtonHandle()
RefreshCode::RefreshAll
@ RefreshAll
Definition: RefreshCode.h:26
RefreshCode::RefreshNone
@ RefreshNone
Definition: RefreshCode.h:21
TrackList::Lock
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:1542
RefreshCode::Cancelled
@ Cancelled
Definition: RefreshCode.h:23
NoteTrackButtonHandle::Drag
Result Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
Definition: NoteTrackButtonHandle.cpp:78
NoteTrackButtonHandle::Preview
HitTestPreview Preview(const TrackPanelMouseState &state, AudacityProject *pProject) override
Definition: NoteTrackButtonHandle.cpp:84
UIHandle::mChangeHighlight
Result mChangeHighlight
Definition: UIHandle.h:139
NoteTrackButtonHandle::mpTrack
std::weak_ptr< NoteTrack > mpTrack
Definition: NoteTrackButtonHandle.h:67
NoteTrackButtonHandle::Click
Result Click(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
Definition: NoteTrackButtonHandle.cpp:72
UIHandle::Result
unsigned Result
Definition: UIHandle.h:38
NoteTrackButtonHandle::Release
Result Release(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
Definition: NoteTrackButtonHandle.cpp:95
UIHandlePtr
std::shared_ptr< UIHandle > UIHandlePtr
Definition: CellularPanel.h:28
NoteTrackButtonHandle::~NoteTrackButtonHandle
virtual ~NoteTrackButtonHandle()
Definition: NoteTrackButtonHandle.cpp:38
HitTestPreview
Definition: HitTestResult.h:20
NoteTrackButtonHandle::Cancel
Result Cancel(AudacityProject *pProject) override
Definition: NoteTrackButtonHandle.cpp:113
NoteTrackButtonHandle::Enter
void Enter(bool forward, AudacityProject *) override
Definition: NoteTrackButtonHandle.cpp:33
RefreshCode::RefreshCell
@ RefreshCell
Definition: RefreshCode.h:24
NoteTrackButtonHandle::mRect
wxRect mRect
Definition: NoteTrackButtonHandle.h:69
TrackList::Get
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:506
TrackInfo::HideTopItem
AUDACITY_DLL_API bool HideTopItem(const wxRect &rect, const wxRect &subRect, int allowance=0)
Definition: TrackInfo.cpp:207
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
TrackPanelMouseEvent
Definition: TrackPanelMouseEvent.h:46
TrackPanelMouseState
Definition: TrackPanelMouseEvent.h:28
NoteTrackButtonHandle::NeedChangeHighlight
static UIHandle::Result NeedChangeHighlight(const NoteTrackButtonHandle &oldState, const NoteTrackButtonHandle &newState)
Definition: NoteTrackButtonHandle.cpp:43
NoteTrackButtonHandle::GetChannel
int GetChannel() const
Definition: NoteTrackButtonHandle.h:42
NoteTrackButtonHandle.h
NoteTrackControls::GetMidiControlsRect
static void GetMidiControlsRect(const wxRect &rect, wxRect &dest)
Definition: NoteTrackControls.cpp:242
AssignUIHandlePtr
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:151
NoteTrack::FindChannel
int FindChannel(const wxRect &rect, int mx, int my)
Definition: NoteTrack.cpp:356
RefreshCode
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
NoteTrackButtonHandle
Definition: NoteTrackButtonHandle.h:22
NoteTrackButtonHandle::HitTest
static UIHandlePtr HitTest(std::weak_ptr< NoteTrackButtonHandle > &holder, const wxMouseState &state, const wxRect &rect, const std::shared_ptr< NoteTrack > &pTrack)
Definition: NoteTrackButtonHandle.cpp:52
TrackPanelMouseEvent::event
wxMouseEvent & event
Definition: TrackPanelMouseEvent.h:58
NoteTrackControls.h
ProjectHistory::Get
static ProjectHistory & Get(AudacityProject &project)
Definition: ProjectHistory.cpp:26