1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*!********************************************************************
Audacity: A Digital Audio Editor
ShareAudioToolbar.cpp
Dmitry Vedenko
**********************************************************************/
#include "ShareAudioToolbar.h"
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <algorithm>
#if wxUSE_TOOLTIPS
#include <wx/tooltip.h>
#endif
#include "AColor.h"
#include "AllThemeResources.h"
#include "AudioIOBase.h"
#include "ExportUtils.h"
#include "PlayableTrack.h"
#include "Prefs.h"
#include "ProjectWindow.h"
#include "Theme.h"
#include "GetEffectsDialog.h"
#include "dialogs/ShareAudioDialog.h"
#include "toolbars/ToolManager.h"
#include "widgets/AButton.h"
#if !defined(__linux__)
#define ADD_MUSEHUB_BUTTON 1
#else
#define ADD_MUSEHUB_BUTTON 0
#endif
IMPLEMENT_CLASS(audacity::cloud::ShareAudioToolbar, ToolBar);
namespace audacity::cloud
{
Identifier ShareAudioToolbar::ID()
{
return wxT("Share Audio");
}
ShareAudioToolbar::ShareAudioToolbar(AudacityProject& project)
: ToolBar(project, XO("Share Audio"), ID())
{
}
ShareAudioToolbar::~ShareAudioToolbar()
{
}
ShareAudioToolbar& ShareAudioToolbar::Get(AudacityProject& project)
{
auto& toolManager = ToolManager::Get(project);
return *static_cast<ShareAudioToolbar*>(
toolManager.GetToolBar(ID()));
}
const ShareAudioToolbar& ShareAudioToolbar::Get(const AudacityProject& project)
{
return Get(const_cast<AudacityProject&>(project));
}
void ShareAudioToolbar::Create(wxWindow* parent)
{
ToolBar::Create(parent);
// Simulate a size event to set initial meter placement/size
wxSizeEvent event(GetSize(), GetId());
event.SetEventObject(this);
GetEventHandler()->ProcessEvent(event);
}
void ShareAudioToolbar::RegenerateTooltips()
{
#if wxUSE_TOOLTIPS
for (long iWinID = ID_SHARE_AUDIO_BUTTON; iWinID < BUTTON_COUNT; iWinID++)
{
auto pCtrl = static_cast<AButton*>(this->FindWindowById(iWinID));
if (!pCtrl) {
assert(true);
continue;
}
CommandID name;
switch (iWinID)
{
case ID_SHARE_AUDIO_BUTTON:
name = wxT("Share Audio");
break;
case ID_GET_EFFECTS_BUTTON:
name = wxT("Get Effects");
break;
}
std::vector<ComponentInterfaceSymbol> commands(
1u, { name, Verbatim(pCtrl->GetLabel()) });
ToolBar::SetButtonToolTip(
mProject, *pCtrl, commands.data(), commands.size());
}
#endif
}
void ShareAudioToolbar::Populate()
{
MakeButtonBackgroundsSmall();
SetBackgroundColour(theTheme.Colour(clrMedium));
MakeShareAudioButton();
#if ADD_MUSEHUB_BUTTON
MakeGetEffectsButton();
#endif
#if wxUSE_TOOLTIPS
RegenerateTooltips();
wxToolTip::Enable(true);
wxToolTip::SetDelay(1000);
#endif
// Set default order and mode
ArrangeButtons();
}
void ShareAudioToolbar::Repaint(wxDC* dc)
{
// this was used to add a bevel and can be removed
}
void ShareAudioToolbar::EnableDisableButtons()
{
auto gAudioIO = AudioIOBase::Get();
const bool audioStreamActive = gAudioIO &&
gAudioIO->IsStreamActive() && !gAudioIO->IsMonitoring();
bool hasAudio = false;
for (const auto& track : TrackList::Get(mProject).Any<PlayableTrack>())
{
if (track->GetStartTime() != track->GetEndTime())
{
hasAudio = true;
break;
}
}
mShareAudioButton->SetEnabled(hasAudio && !audioStreamActive);
}
void ShareAudioToolbar::ReCreateButtons()
{
ToolBar::ReCreateButtons();
EnableDisableButtons();
RegenerateTooltips();
}
AButton* ShareAudioToolbar::MakeButton(int id, const TranslatableString& label, const wxImage& icon)
{
#if ADD_MUSEHUB_BUTTON
const auto height = 25;
#else
const auto height = (toolbarSingle - toolbarMargin) * 2;
#endif
auto button = safenew AButton(this, id);
button->SetLabel(label);
button->SetButtonType(AButton::FrameTextHButton);
button->SetImages(
theTheme.Image(bmpRecoloredUpSmall),
theTheme.Image(bmpRecoloredUpHiliteSmall),
theTheme.Image(bmpRecoloredDownSmall),
theTheme.Image(bmpRecoloredHiliteSmall),
theTheme.Image(bmpRecoloredUpSmall));
button->SetIcon(icon);
button->SetForegroundColour(theTheme.Colour(clrTrackPanelText));
button->SetMinSize(wxSize{-1, height});
button->SetMaxSize(wxSize{-1, height});
button->SetFrameMid(3);
return button;
}
void ShareAudioToolbar::MakeShareAudioButton()
{
mShareAudioButton = MakeButton(ID_SHARE_AUDIO_BUTTON, XO("Share Audio"), theTheme.Image(bmpShareAudio));
#if !ADD_MUSEHUB_BUTTON
mShareAudioButton->SetButtonType(AButton::FrameTextVButton);
#endif
mShareAudioButton->Bind(wxEVT_BUTTON, [this](auto) {
audiocom::ShareAudioDialog dlg(
mProject, AudiocomTrace::ShareAudioButton,
&ProjectWindow::Get(mProject));
dlg.ShowModal();
mShareAudioButton->PopUp();
});
}
void ShareAudioToolbar::MakeGetEffectsButton()
{
mGetEffectsButton = MakeButton(ID_GET_EFFECTS_BUTTON, XO("Get Effects"), theTheme.Image(bmpPlug));
mGetEffectsButton->Bind(wxEVT_BUTTON, [this](auto) {
musehub::GetEffectsDialog dlg(&ProjectWindow::Get(mProject));
dlg.ShowModal();
mGetEffectsButton->PopUp();
});
}
void ShareAudioToolbar::ArrangeButtons()
{
#if ADD_MUSEHUB_BUTTON
wxGridSizer *sizer = new wxGridSizer(2, 1, toolbarSpacing, toolbarSpacing);
Add(sizer, 0, wxALIGN_CENTRE | wxALL, toolbarSpacing);
sizer->Add(mShareAudioButton, 0, wxEXPAND);
sizer->Add(mGetEffectsButton, 0, wxEXPAND);
sizer->Layout();
#else
Add(mShareAudioButton, 0, wxALIGN_CENTRE | wxALL, toolbarSpacing);
SetMinSize({ std::max(76, GetSizer()->GetMinSize().GetWidth()), -1 });
SetMaxSize({ -1, -1 });
#endif
// Layout the toolbar
Layout();
}
static RegisteredToolbarFactory factory {
[](AudacityProject& project)
{ return ToolBar::Holder { safenew ShareAudioToolbar { project } }; }
};
namespace
{
AttachedToolBarMenuItem sAttachment {
/* i18n-hint: Clicking this menu item shows the toolbar
that opens Share Audio dialog */
ShareAudioToolbar::ID(), wxT("ShareAudioTB"), XXO("&Share Audio Toolbar")
};
}
} // namespace audacity::cloud
|