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();
52  { name, wxT("TrackMute") } );
53  return commandManager->DescribeCommandsAndShortcuts(commands);
54 }
55 
57 (std::weak_ptr<MuteButtonHandle> &holder,
58  const wxMouseState &state, const wxRect &rect,
59  const AudacityProject *pProject, const std::shared_ptr<Track> &pTrack)
60 {
61  wxRect buttonRect;
62  if ( pTrack )
63  TrackInfo::GetMuteSoloRect(rect, buttonRect, false,
64  !pProject->IsSoloNone(), pTrack.get());
65  if ( TrackInfo::HideTopItem( rect, buttonRect ) )
66  return {};
67 
68  if ( pTrack && buttonRect.Contains(state.m_x, state.m_y) ) {
69  auto result = std::make_shared<MuteButtonHandle>(pTrack, buttonRect);
70  result = AssignUIHandlePtr(holder, result);
71  return result;
72  }
73  else
74  return {};
75 }
76 
78 
80 ( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
81  : ButtonHandle{ pTrack, rect }
82 {}
83 
85 {
86 }
87 
89 (const wxMouseEvent &event, AudacityProject *pProject, wxWindow *WXUNUSED(pParent))
90 {
91  auto pTrack = mpTrack.lock();
92  if ( dynamic_cast< PlayableTrack* >( pTrack.get() ) )
93  pProject->DoTrackSolo(pTrack.get(), event.ShiftDown());
94 
96 }
97 
98 wxString SoloButtonHandle::Tip(const wxMouseState &) const
99 {
100  auto name = _("Solo");
101  auto project = ::GetActiveProject();
102  auto focused =
103  project->GetTrackPanel()->GetFocusedTrack() == GetTrack().get();
104  if (!focused)
105  return name;
106 
107  auto commandManager = project->GetCommandManager();
109  { name, wxT("TrackSolo") } );
110  return commandManager->DescribeCommandsAndShortcuts(commands);
111 }
112 
114 (std::weak_ptr<SoloButtonHandle> &holder,
115  const wxMouseState &state, const wxRect &rect,
116  const AudacityProject *pProject, const std::shared_ptr<Track> &pTrack)
117 {
118  wxRect buttonRect;
119  if ( pTrack )
120  TrackInfo::GetMuteSoloRect(rect, buttonRect, true,
121  !pProject->IsSoloNone(), pTrack.get());
122 
123  if ( TrackInfo::HideTopItem( rect, buttonRect ) )
124  return {};
125 
126  if ( pTrack && buttonRect.Contains(state.m_x, state.m_y) ) {
127  auto result = std::make_shared<SoloButtonHandle>( pTrack, buttonRect );
128  result = AssignUIHandlePtr(holder, result);
129  return result;
130  }
131  else
132  return {};
133 }
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:158
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
unsigned Result
Definition: UIHandle.h:37
std::vector< LocalizedCommandName > LocalizedCommandNameVector
void DoTrackSolo(Track *pTrack, bool exclusive)
Definition: Project.cpp:5511
void DoTrackMute(Track *pTrack, bool exclusive)
Definition: Project.cpp:5495
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:592
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"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
const wxChar * name
Definition: Distortion.cpp:94
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300
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