Audacity  2.2.2
PlayableTrackButtonHandles.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 PlayableTrackButtonHandles.cpp
6 
7 Paul Licameli split from TrackPanel.cpp
8 
9 **********************************************************************/
10 
11 #include "../../../Audacity.h"
13 
14 #include "../../../commands/CommandManager.h"
15 #include "../../../HitTestResult.h"
16 #include "../../../Project.h"
17 #include "../../../RefreshCode.h"
18 #include "../../../Track.h"
19 #include "../../../TrackPanel.h"
20 #include "../../../TrackPanelMouseEvent.h"
21 
23 ( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
24  : ButtonHandle{ pTrack, rect }
25 {}
26 
28 {
29 }
30 
32  (const wxMouseEvent &event, AudacityProject *pProject, wxWindow *)
33 {
34  auto pTrack = mpTrack.lock();
35  if ( dynamic_cast< PlayableTrack* >( pTrack.get() ) )
36  pProject->DoTrackMute(pTrack.get(), event.ShiftDown());
37 
39 }
40 
41 wxString MuteButtonHandle::Tip(const wxMouseState &) const
42 {
43  auto name = _("Mute");
44  auto project = ::GetActiveProject();
45  auto focused =
46  project->GetTrackPanel()->GetFocusedTrack() == GetTrack().get();
47  if (!focused)
48  return name;
49 
50  auto commandManager = project->GetCommandManager();
51  TranslatedInternalString command{ wxT("TrackMute"), name };
52  return commandManager->DescribeCommandsAndShortcuts(&command, 1u);
53 }
54 
56 (std::weak_ptr<MuteButtonHandle> &holder,
57  const wxMouseState &state, const wxRect &rect,
58  const AudacityProject *pProject, const std::shared_ptr<Track> &pTrack)
59 {
60  wxRect buttonRect;
61  if ( pTrack )
62  TrackInfo::GetMuteSoloRect(rect, buttonRect, false,
63  !pProject->IsSoloNone(), pTrack.get());
64  if ( TrackInfo::HideTopItem( rect, buttonRect ) )
65  return {};
66 
67  if ( pTrack && buttonRect.Contains(state.m_x, state.m_y) ) {
68  auto result = std::make_shared<MuteButtonHandle>(pTrack, buttonRect);
69  result = AssignUIHandlePtr(holder, result);
70  return result;
71  }
72  else
73  return {};
74 }
75 
77 
79 ( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
80  : ButtonHandle{ pTrack, rect }
81 {}
82 
84 {
85 }
86 
88 (const wxMouseEvent &event, AudacityProject *pProject, wxWindow *WXUNUSED(pParent))
89 {
90  auto pTrack = mpTrack.lock();
91  if ( dynamic_cast< PlayableTrack* >( pTrack.get() ) )
92  pProject->DoTrackSolo(pTrack.get(), event.ShiftDown());
93 
95 }
96 
97 wxString SoloButtonHandle::Tip(const wxMouseState &) const
98 {
99  auto name = _("Solo");
100  auto project = ::GetActiveProject();
101  auto focused =
102  project->GetTrackPanel()->GetFocusedTrack() == GetTrack().get();
103  if (!focused)
104  return name;
105 
106  auto commandManager = project->GetCommandManager();
107  TranslatedInternalString command{ wxT("TrackSolo"), name };
108  return commandManager->DescribeCommandsAndShortcuts( &command, 1u );
109 }
110 
112 (std::weak_ptr<SoloButtonHandle> &holder,
113  const wxMouseState &state, const wxRect &rect,
114  const AudacityProject *pProject, const std::shared_ptr<Track> &pTrack)
115 {
116  wxRect buttonRect;
117  if ( pTrack )
118  TrackInfo::GetMuteSoloRect(rect, buttonRect, true,
119  !pProject->IsSoloNone(), pTrack.get());
120 
121  if ( TrackInfo::HideTopItem( rect, buttonRect ) )
122  return {};
123 
124  if ( pTrack && buttonRect.Contains(state.m_x, state.m_y) ) {
125  auto result = std::make_shared<SoloButtonHandle>( pTrack, buttonRect );
126  result = AssignUIHandlePtr(holder, result);
127  return result;
128  }
129  else
130  return {};
131 }
wxString Tip(const wxMouseState &state) const override
static UIHandlePtr HitTest(std::weak_ptr< SoloButtonHandle > &holder, const wxMouseState &state, const wxRect &rect, const AudacityProject *pProject, const std::shared_ptr< Track > &pTrack)
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
std::shared_ptr< Track > GetTrack() const
Definition: ButtonHandle.h:28
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
unsigned Result
Definition: UIHandle.h:37
void DoTrackSolo(Track *pTrack, bool exclusive)
Definition: Project.cpp:5685
void DoTrackMute(Track *pTrack, bool exclusive)
Definition: Project.cpp:5669
std::shared_ptr< UIHandle > UIHandlePtr
Definition: TrackPanel.h:59
static bool HideTopItem(const wxRect &rect, const wxRect &subRect, int allowance=0)
bool IsSoloNone() const
Definition: Project.h:607
static void GetMuteSoloRect(const wxRect &rect, wxRect &dest, bool solo, bool bHasSoloButton, const Track *pTrack)
_("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
const wxChar * name
Definition: Distortion.cpp:94
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
wxString Tip(const wxMouseState &state) const override
MuteButtonHandle(const MuteButtonHandle &)=delete
SoloButtonHandle(const SoloButtonHandle &)=delete
static UIHandlePtr HitTest(std::weak_ptr< MuteButtonHandle > &holder, const wxMouseState &state, const wxRect &rect, const AudacityProject *pProject, const std::shared_ptr< Track > &pTrack)
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:162