Audacity  3.0.3
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 
13 
14 #include "PlayableTrackControls.h"
15 #include "../../../commands/CommandManager.h"
16 #include "Project.h"
17 #include "../../../ProjectSettings.h"
18 #include "../../../RefreshCode.h"
19 #include "../../../Track.h"
20 #include "../../../TrackPanelAx.h"
21 #include "../../../TrackInfo.h"
22 #include "../../../TrackPanelMouseEvent.h"
23 #include "../../../TrackUtilities.h"
24 
26 ( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
27  : ButtonHandle{ pTrack, rect }
28 {}
29 
31 {
32 }
33 
35  (const wxMouseEvent &event, AudacityProject *pProject, wxWindow *)
36 {
37  auto pTrack = mpTrack.lock();
38  if ( dynamic_cast< PlayableTrack* >( pTrack.get() ) )
39  TrackUtilities::DoTrackMute(*pProject, pTrack.get(), event.ShiftDown());
40 
42 }
43 
45  const wxMouseState &, AudacityProject &project) const
46 {
47  auto name = XO("Mute");
48  auto focused =
49  TrackFocus::Get( project ).Get() == GetTrack().get();
50  if (!focused)
51  return name;
52 
53  auto &commandManager = CommandManager::Get( project );
54  ComponentInterfaceSymbol command{ wxT("TrackMute"), name };
55  return commandManager.DescribeCommandsAndShortcuts(&command, 1u);
56 }
57 
59 (std::weak_ptr<MuteButtonHandle> &holder,
60  const wxMouseState &state, const wxRect &rect,
61  const AudacityProject *pProject, const std::shared_ptr<Track> &pTrack)
62 {
63  wxRect buttonRect;
64  if ( pTrack )
65  PlayableTrackControls::GetMuteSoloRect(rect, buttonRect, false,
66  !ProjectSettings::Get( *pProject ).IsSoloNone(), pTrack.get());
67  if ( TrackInfo::HideTopItem( rect, buttonRect ) )
68  return {};
69 
70  if ( pTrack && buttonRect.Contains(state.m_x, state.m_y) ) {
71  auto result = std::make_shared<MuteButtonHandle>(pTrack, buttonRect);
72  result = AssignUIHandlePtr(holder, result);
73  return result;
74  }
75  else
76  return {};
77 }
78 
80 
82 ( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
83  : ButtonHandle{ pTrack, rect }
84 {}
85 
87 {
88 }
89 
91 (const wxMouseEvent &event, AudacityProject *pProject, wxWindow *WXUNUSED(pParent))
92 {
93  auto pTrack = mpTrack.lock();
94  if ( dynamic_cast< PlayableTrack* >( pTrack.get() ) )
95  TrackUtilities::DoTrackSolo(*pProject, pTrack.get(), event.ShiftDown());
96 
98 }
99 
101  const wxMouseState &, AudacityProject &project) const
102 {
103  auto name = XO("Solo");
104  auto focused =
105  TrackFocus::Get( project ).Get() == GetTrack().get();
106  if (!focused)
107  return name;
108 
109  auto &commandManager = CommandManager::Get( project );
110  ComponentInterfaceSymbol command{ wxT("TrackSolo"), name };
111  return commandManager.DescribeCommandsAndShortcuts( &command, 1u );
112 }
113 
115 (std::weak_ptr<SoloButtonHandle> &holder,
116  const wxMouseState &state, const wxRect &rect,
117  const AudacityProject *pProject, const std::shared_ptr<Track> &pTrack)
118 {
119  wxRect buttonRect;
120  if ( pTrack )
121  PlayableTrackControls::GetMuteSoloRect(rect, buttonRect, true,
122  !ProjectSettings::Get( *pProject ).IsSoloNone(), pTrack.get());
123 
124  if ( TrackInfo::HideTopItem( rect, buttonRect ) )
125  return {};
126 
127  if ( pTrack && buttonRect.Contains(state.m_x, state.m_y) ) {
128  auto result = std::make_shared<SoloButtonHandle>( pTrack, buttonRect );
129  result = AssignUIHandlePtr(holder, result);
130  return result;
131  }
132  else
133  return {};
134 }
PlayableTrackControls.h
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
MuteButtonHandle::HitTest
static UIHandlePtr HitTest(std::weak_ptr< MuteButtonHandle > &holder, const wxMouseState &state, const wxRect &rect, const AudacityProject *pProject, const std::shared_ptr< Track > &pTrack)
Definition: PlayableTrackButtonHandles.cpp:59
RefreshCode::RefreshNone
@ RefreshNone
Definition: RefreshCode.h:21
Project.h
ClientData::Site::Get
Subclass & Get(const RegisteredFactory &key)
Get reference to an attachment, creating on demand if not present, down-cast it to Subclass.
Definition: ClientData.h:309
ButtonHandle::mpTrack
std::weak_ptr< Track > mpTrack
Definition: ButtonHandle.h:72
XO
#define XO(s)
Definition: Internat.h:31
ProjectSettings::Get
static ProjectSettings & Get(AudacityProject &project)
Definition: ProjectSettings.cpp:44
MuteButtonHandle::~MuteButtonHandle
virtual ~MuteButtonHandle()
Definition: PlayableTrackButtonHandles.cpp:30
ButtonHandle::GetTrack
std::shared_ptr< Track > GetTrack() const
Definition: ButtonHandle.h:30
MuteButtonHandle::Tip
TranslatableString Tip(const wxMouseState &state, AudacityProject &) const override
Definition: PlayableTrackButtonHandles.cpp:44
TrackUtilities::DoTrackSolo
void DoTrackSolo(AudacityProject &project, Track *t, bool exclusive)
Definition: TrackUtilities.cpp:112
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
PlayableTrackButtonHandles.h
PlayableTrackControls::GetMuteSoloRect
static void GetMuteSoloRect(const wxRect &rect, wxRect &dest, bool solo, bool bHasSoloButton, const Track *pTrack)
Definition: PlayableTrackControls.cpp:164
SoloButtonHandle::SoloButtonHandle
SoloButtonHandle(const SoloButtonHandle &)=delete
ButtonHandle
A UIHandle for a TrackPanel button, such as the Mute and Solo buttons.
Definition: ButtonHandle.h:26
UIHandle::Result
unsigned Result
Definition: UIHandle.h:38
name
const TranslatableString name
Definition: Distortion.cpp:98
SoloButtonHandle::CommitChanges
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
Definition: PlayableTrackButtonHandles.cpp:91
UIHandlePtr
std::shared_ptr< UIHandle > UIHandlePtr
Definition: CellularPanel.h:28
TrackFocus::Get
Track * Get()
Definition: TrackPanelAx.cpp:755
SoloButtonHandle::~SoloButtonHandle
virtual ~SoloButtonHandle()
Definition: PlayableTrackButtonHandles.cpp:86
PlayableTrack
AudioTrack subclass that can also be audibly replayed by the program.
Definition: Track.h:854
MuteButtonHandle::CommitChanges
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
Definition: PlayableTrackButtonHandles.cpp:35
SoloButtonHandle::HitTest
static UIHandlePtr HitTest(std::weak_ptr< SoloButtonHandle > &holder, const wxMouseState &state, const wxRect &rect, const AudacityProject *pProject, const std::shared_ptr< Track > &pTrack)
Definition: PlayableTrackButtonHandles.cpp:115
TrackInfo::HideTopItem
AUDACITY_DLL_API bool HideTopItem(const wxRect &rect, const wxRect &subRect, int allowance=0)
Definition: TrackInfo.cpp:207
TrackUtilities::DoTrackMute
void DoTrackMute(AudacityProject &project, Track *t, bool exclusive)
Definition: TrackUtilities.cpp:64
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
ProjectSettings::IsSoloNone
bool IsSoloNone() const
Definition: ProjectSettings.h:128
AssignUIHandlePtr
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:151
CommandManager::Get
static CommandManager & Get(AudacityProject &project)
Definition: CommandManager.cpp:207
SoloButtonHandle::Tip
TranslatableString Tip(const wxMouseState &state, AudacityProject &) const override
Definition: PlayableTrackButtonHandles.cpp:100
MuteButtonHandle::MuteButtonHandle
MuteButtonHandle(const MuteButtonHandle &)=delete