Audacity 3.2.0
PlayableTrackButtonHandles.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5PlayableTrackButtonHandles.cpp
6
7Paul Licameli split from TrackPanel.cpp
8
9**********************************************************************/
10
11
13
15#include "../../../commands/CommandManager.h"
16#include "Project.h"
17#include "../../../ProjectSettings.h"
18#include "../../../RefreshCode.h"
19#include "../../../RealtimeEffectPanel.h"
20#include "Track.h"
21#include "../../../TrackPanelAx.h"
22#include "../../../TrackInfo.h"
23#include "../../../TrackPanelMouseEvent.h"
24#include "../../../TrackUtilities.h"
25
26#include <wx/window.h>
27
29( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
30 : ButtonHandle{ pTrack, rect }
31{}
32
34{
35}
36
38 (const wxMouseEvent &event, AudacityProject *pProject, wxWindow *)
39{
40 auto pTrack = mpTrack.lock();
41 if ( dynamic_cast< PlayableTrack* >( pTrack.get() ) )
42 TrackUtilities::DoTrackMute(*pProject, pTrack.get(), event.ShiftDown());
43
45}
46
48 const wxMouseState &, AudacityProject &project) const
49{
50 auto name = XO("Mute");
51 auto focused =
52 TrackFocus::Get( project ).Get() == GetTrack().get();
53 if (!focused)
54 return name;
55
56 auto &commandManager = CommandManager::Get( project );
57 ComponentInterfaceSymbol command{ wxT("TrackMute"), name };
58 return commandManager.DescribeCommandsAndShortcuts(&command, 1u);
59}
60
62(std::weak_ptr<MuteButtonHandle> &holder,
63 const wxMouseState &state, const wxRect &rect,
64 const AudacityProject *pProject, const std::shared_ptr<Track> &pTrack)
65{
66 wxRect buttonRect;
67 if ( pTrack )
68 PlayableTrackControls::GetMuteSoloRect(rect, buttonRect, false,
69 !ProjectSettings::Get( *pProject ).IsSoloNone(), pTrack.get());
70 if ( TrackInfo::HideTopItem( rect, buttonRect ) )
71 return {};
72
73 if ( pTrack && buttonRect.Contains(state.m_x, state.m_y) ) {
74 auto result = std::make_shared<MuteButtonHandle>(pTrack, buttonRect);
75 result = AssignUIHandlePtr(holder, result);
76 return result;
77 }
78 else
79 return {};
80}
81
83
85( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
86 : ButtonHandle{ pTrack, rect }
87{}
88
90{
91}
92
94(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *WXUNUSED(pParent))
95{
96 auto pTrack = mpTrack.lock();
97 if ( dynamic_cast< PlayableTrack* >( pTrack.get() ) )
98 TrackUtilities::DoTrackSolo(*pProject, pTrack.get(), event.ShiftDown());
99
101}
102
104 const wxMouseState &, AudacityProject &project) const
105{
106 auto name = XO("Solo");
107 auto focused =
108 TrackFocus::Get( project ).Get() == GetTrack().get();
109 if (!focused)
110 return name;
111
112 auto &commandManager = CommandManager::Get( project );
113 ComponentInterfaceSymbol command{ wxT("TrackSolo"), name };
114 return commandManager.DescribeCommandsAndShortcuts( &command, 1u );
115}
116
118(std::weak_ptr<SoloButtonHandle> &holder,
119 const wxMouseState &state, const wxRect &rect,
120 const AudacityProject *pProject, const std::shared_ptr<Track> &pTrack)
121{
122 wxRect buttonRect;
123 if ( pTrack )
124 PlayableTrackControls::GetMuteSoloRect(rect, buttonRect, true,
125 !ProjectSettings::Get( *pProject ).IsSoloNone(), pTrack.get());
126
127 if ( TrackInfo::HideTopItem( rect, buttonRect ) )
128 return {};
129
130 if ( pTrack && buttonRect.Contains(state.m_x, state.m_y) ) {
131 auto result = std::make_shared<SoloButtonHandle>( pTrack, buttonRect );
132 result = AssignUIHandlePtr(holder, result);
133 return result;
134 }
135 else
136 return {};
137}
138
140
142( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
143 : ButtonHandle{ pTrack, rect }
144{}
145
147{
148}
149
151(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent)
152{
153 RealtimeEffectPanel::Get(*pProject).ShowPanel(mpTrack.lock().get(), true);
155}
156
158 const wxMouseState &, AudacityProject &project) const
159{
160 auto name = XO("Effects");
161 auto focused =
162 TrackFocus::Get( project ).Get() == GetTrack().get();
163 if (!focused)
164 return name;
165 else {
166 return name;
167 // Instead supply shortcut when "TrackEffects" is defined
168 /*
169 auto &commandManager = CommandManager::Get( project );
170 ComponentInterfaceSymbol command{ wxT("TrackEffects"), name };
171 return commandManager.DescribeCommandsAndShortcuts( &command, 1u );
172 */
173 }
174}
175
177(std::weak_ptr<EffectsButtonHandle> &holder,
178 const wxMouseState &state, const wxRect &rect,
179 const AudacityProject *pProject, const std::shared_ptr<Track> &pTrack)
180{
181 wxRect buttonRect;
182 if ( pTrack )
184 pTrack.get());
185
186 if ( TrackInfo::HideTopItem( rect, buttonRect ) )
187 return {};
188
189 if ( pTrack && buttonRect.Contains(state.m_x, state.m_y) ) {
190 auto result = std::make_shared<EffectsButtonHandle>( pTrack, buttonRect );
191 result = AssignUIHandlePtr(holder, result);
192 return result;
193 }
194 else
195 return {};
196}
wxT("CloseDown"))
std::shared_ptr< UIHandle > UIHandlePtr
Definition: CellularPanel.h:28
const TranslatableString name
Definition: Distortion.cpp:82
#define XO(s)
Definition: Internat.h:31
declares abstract base class Track, TrackList, and iterators over TrackList
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:151
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
A UIHandle for a TrackPanel button, such as the Mute and Solo buttons.
Definition: ButtonHandle.h:26
std::weak_ptr< Track > mpTrack
Definition: ButtonHandle.h:72
std::shared_ptr< Track > GetTrack() const
Definition: ButtonHandle.h:30
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
static CommandManager & Get(AudacityProject &project)
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
TranslatableString Tip(const wxMouseState &state, AudacityProject &) const override
static UIHandlePtr HitTest(std::weak_ptr< EffectsButtonHandle > &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
EffectsButtonHandle(const EffectsButtonHandle &)=delete
static UIHandlePtr HitTest(std::weak_ptr< MuteButtonHandle > &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
TranslatableString Tip(const wxMouseState &state, AudacityProject &) const override
MuteButtonHandle(const MuteButtonHandle &)=delete
static void GetEffectsRect(const wxRect &rect, wxRect &dest, const Track *pTrack)
static void GetMuteSoloRect(const wxRect &rect, wxRect &dest, bool solo, bool bHasSoloButton, const Track *pTrack)
AudioTrack subclass that can also be audibly replayed by the program.
Definition: Track.h:916
static ProjectSettings & Get(AudacityProject &project)
bool IsSoloNone() const
void ShowPanel(Track *track, bool focus)
static RealtimeEffectPanel & Get(AudacityProject &project)
Result CommitChanges(const wxMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
static UIHandlePtr HitTest(std::weak_ptr< SoloButtonHandle > &holder, const wxMouseState &state, const wxRect &rect, const AudacityProject *pProject, const std::shared_ptr< Track > &pTrack)
SoloButtonHandle(const SoloButtonHandle &)=delete
TranslatableString Tip(const wxMouseState &state, AudacityProject &) const override
Track * Get()
Holds a msgid for the translation catalog; may also bind format arguments.
unsigned Result
Definition: UIHandle.h:38
AUDACITY_DLL_API bool HideTopItem(const wxRect &rect, const wxRect &subRect, int allowance=0)
Definition: TrackInfo.cpp:208
void DoTrackMute(AudacityProject &project, Track *t, bool exclusive)
void DoTrackSolo(AudacityProject &project, Track *t, bool exclusive)