Audacity  2.2.2
NoteTrackControls.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 NoteTrackControls.cpp
6 
7 Paul Licameli split from TrackPanel.cpp
8 
9 **********************************************************************/
10 
11 #include "../../../../Audacity.h"
12 
13 #ifdef USE_MIDI
14 
15 #include "NoteTrackControls.h"
16 #include "NoteTrackButtonHandle.h"
17 
18 #include "../../ui/PlayableTrackButtonHandles.h"
19 #include "NoteTrackSliderHandles.h"
20 
21 #include "../../../../HitTestResult.h"
22 #include "../../../../TrackPanelMouseEvent.h"
23 #include "../../../../NoteTrack.h"
24 #include "../../../../widgets/PopupMenuTable.h"
25 #include "../../../../Project.h"
26 #include "../../../../RefreshCode.h"
27 
30 {
31 }
32 
33 std::vector<UIHandlePtr> NoteTrackControls::HitTest
34 (const TrackPanelMouseState & st,
35  const AudacityProject *pProject)
36 {
37  // Hits are mutually exclusive, results single
38  std::vector<UIHandlePtr> results;
39  const wxMouseState &state = st.state;
40  const wxRect &rect = st.rect;
41  if (state.ButtonIsDown(wxMOUSE_BTN_ANY)) {
42  auto track = std::static_pointer_cast<NoteTrack>(FindTrack());
43  auto result = [&]{
44  UIHandlePtr result;
45  if (NULL != (result = MuteButtonHandle::HitTest(
46  mMuteHandle, state, rect, pProject, track)))
47  return result;
48 
49  if (NULL != (result = SoloButtonHandle::HitTest(
50  mSoloHandle, state, rect, pProject, track)))
51  return result;
52 #ifdef EXPERIMENTAL_MIDI_OUT
53  if (NULL != (result = VelocitySliderHandle::HitTest(
54  mVelocityHandle, state, rect, track)))
55  return result;
56  if (NULL != (result = NoteTrackButtonHandle::HitTest(
57  mClickHandle, state, rect, track)))
58  return result;
59 #endif
60  return result;
61  }();
62  if (result) {
63  results.push_back(result);
64  return results;
65  }
66  }
67 
68  return TrackControls::HitTest(st, pProject);
69 }
70 
71 class NoteTrackMenuTable : public PopupMenuTable
72 {
73  NoteTrackMenuTable() : mpData(NULL) {}
74  DECLARE_POPUP_MENU(NoteTrackMenuTable);
75 
76 public:
77  static NoteTrackMenuTable &Instance();
78 
79 private:
80  void InitMenu(Menu*, void *pUserData) override
81  {
82  mpData = static_cast<TrackControls::InitMenuData*>(pUserData);
83  }
84 
85  void DestroyMenu() override
86  {
87  mpData = nullptr;
88  }
89 
91 
92  void OnChangeOctave(wxCommandEvent &);
93 };
94 
95 NoteTrackMenuTable &NoteTrackMenuTable::Instance()
96 {
97  static NoteTrackMenuTable instance;
98  return instance;
99 }
100 
101 enum {
102  OnUpOctaveID = 30000,
103  OnDownOctaveID,
104 };
105 
108 void NoteTrackMenuTable::OnChangeOctave(wxCommandEvent &event)
109 {
110  NoteTrack *const pTrack = static_cast<NoteTrack*>(mpData->pTrack);
111 
112  wxASSERT(event.GetId() == OnUpOctaveID
113  || event.GetId() == OnDownOctaveID);
114  wxASSERT(pTrack->GetKind() == Track::Note);
115 
116  const bool bDown = (OnDownOctaveID == event.GetId());
117  pTrack->SetBottomNote
118  (pTrack->GetBottomNote() + ((bDown) ? -12 : 12));
119 
120  AudacityProject *const project = ::GetActiveProject();
121  project->ModifyState(true);
122  mpData->result = RefreshCode::RefreshAll;
123 }
124 
125 BEGIN_POPUP_MENU(NoteTrackMenuTable)
127  POPUP_MENU_ITEM(OnUpOctaveID, _("Up &Octave"), OnChangeOctave)
128  POPUP_MENU_ITEM(OnDownOctaveID, _("Down Octa&ve"), OnChangeOctave)
130 
131 PopupMenuTable *NoteTrackControls::GetMenuExtension(Track *)
132 {
133 #if defined(USE_MIDI)
134  return &NoteTrackMenuTable::Instance();
135 #else
136  return NULL;
137 #endif
138 }
139 
140 #endif
std::weak_ptr< VelocitySliderHandle > mVelocityHandle
#define POPUP_MENU_SEPARATOR()
virtual void DestroyMenu()=0
static UIHandlePtr HitTest(std::weak_ptr< SoloButtonHandle > &holder, const wxMouseState &state, const wxRect &rect, const AudacityProject *pProject, const std::shared_ptr< Track > &pTrack)
virtual std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *) override=0
#define END_POPUP_MENU()
std::shared_ptr< Track > FindTrack() override
static UIHandlePtr HitTest(std::weak_ptr< NoteTrackButtonHandle > &holder, const wxMouseState &state, const wxRect &rect, const std::shared_ptr< NoteTrack > &pTrack)
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
std::weak_ptr< NoteTrackButtonHandle > mClickHandle
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:101
virtual void InitMenu(Menu *pMenu, void *pUserData)=0
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *pProject) override
#define DECLARE_POPUP_MENU(HandlerClass)
std::weak_ptr< MuteButtonHandle > mMuteHandle
void ModifyState(bool bWantsAutoSave)
Definition: Project.cpp:4740
std::shared_ptr< UIHandle > UIHandlePtr
Definition: TrackPanel.h:59
_("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
POPUP_MENU_ITEM(OnMoveUpID, _("Move Track &Up")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveUp")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveDownID
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
static UIHandlePtr HitTest(std::weak_ptr< MuteButtonHandle > &holder, const wxMouseState &state, const wxRect &rect, const AudacityProject *pProject, const std::shared_ptr< Track > &pTrack)
std::weak_ptr< SoloButtonHandle > mSoloHandle
BEGIN_POPUP_MENU(SpectrumVRulerMenuTable)
A Track that is used for Midi notes. (Somewhat old code).