1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-07-31 16:09:28 +02:00

EffectUIHost uses ShuttleGui

This commit is contained in:
Paul Licameli 2020-01-23 19:10:38 -05:00
commit 5ecd090266
16 changed files with 215 additions and 212 deletions

View File

@ -49,6 +49,8 @@
#include "audacity/ConfigInterface.h"
#include "audacity/EffectAutomationParameters.h" // for command automation
class ShuttleGui;
typedef enum EffectType : int
{
EffectTypeNone,
@ -231,7 +233,7 @@ public:
virtual void SetHostUI(EffectUIHostInterface *host) = 0;
virtual bool IsGraphicalUI() = 0;
virtual bool PopulateUI(wxWindow *parent) = 0;
virtual bool PopulateUI(ShuttleGui &S) = 0;
virtual bool ValidateUI() = 0;
virtual bool HideUI() = 0;
virtual bool CloseUI() = 0;

View File

@ -374,7 +374,7 @@ wxBitmapButton * ShuttleGuiBase::AddBitmapButton(
return wxDynamicCast(wxWindow::FindWindowById( miId, mpDlg), wxBitmapButton);
wxBitmapButton * pBtn;
mpWind = pBtn = safenew wxBitmapButton(GetParent(), miId, Bitmap,
wxDefaultPosition, wxDefaultSize, GetStyle( wxNO_BORDER ) );
wxDefaultPosition, wxDefaultSize, GetStyle( wxBU_AUTODRAW ) );
pBtn->SetBackgroundColour(
wxColour( 246,246,243));
// wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
@ -2077,8 +2077,13 @@ void ShuttleGuiBase::UpdateSizersCore(bool bPrepend, int Flags, bool prompt)
if ( !mItem.mToolTip.empty() )
mpWind->SetToolTip( mItem.mToolTip.Translation() );
if ( !mItem.mName.empty() )
if ( !mItem.mName.empty() ) {
mpWind->SetName( mItem.mName.Stripped().Translation() );
#ifndef __WXMAC__
if (auto pButton = dynamic_cast< wxBitmapButton* >( mpWind ))
pButton->SetLabel( mItem.mName.Translation() );
#endif
}
if ( !mItem.mNameSuffix.empty() )
mpWind->SetName(

View File

@ -615,14 +615,14 @@ void Effect::SetHostUI(EffectUIHostInterface *WXUNUSED(host))
{
}
bool Effect::PopulateUI(wxWindow *parent)
bool Effect::PopulateUI(ShuttleGui &S)
{
auto parent = S.GetParent();
mUIParent = parent;
mUIParent->PushEventHandler(this);
// LoadUserPreset(GetCurrentSettingsGroup());
ShuttleGui S(mUIParent, eIsCreating);
PopulateOrExchange(S);
mUIParent->SetMinSize(mUIParent->GetSizer()->GetMinSize());

View File

@ -158,7 +158,7 @@ class AUDACITY_DLL_API Effect /* not final */ : public wxEvtHandler,
// EffectUIClientInterface implementation
void SetHostUI(EffectUIHostInterface *host) override;
bool PopulateUI(wxWindow *parent) override;
bool PopulateUI(ShuttleGui &S) final;
bool IsGraphicalUI() override;
bool ValidateUI() override;
bool HideUI() override;

View File

@ -856,224 +856,224 @@ int EffectUIHost::ShowModal()
// EffectUIHost implementation
// ============================================================================
bool EffectUIHost::Initialize()
wxPanel *EffectUIHost::BuildButtonBar(wxWindow *parent)
{
EffectPanel *w = safenew EffectPanel(this);
RTL_WORKAROUND(w);
{
auto vs = std::make_unique<wxBoxSizer>(wxVERTICAL);
{
auto hs = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
// Try to give the window a sensible default/minimum size
w->SetMinSize(wxSize(wxMax(600, mParent->GetSize().GetWidth() * 2 / 3),
mParent->GetSize().GetHeight() / 2));
auto gAudioIO = AudioIO::Get();
mDisableTransport = !gAudioIO->IsAvailable(mProject);
mPlaying = gAudioIO->IsStreamActive(); // not exactly right, but will suffice
mCapturing = gAudioIO->IsStreamActive() && gAudioIO->GetNumCaptureChannels() > 0;
if (!mClient->PopulateUI(w))
{
return false;
}
hs->Add(w, 1, wxEXPAND);
vs->Add(hs.release(), 1, wxEXPAND);
}
wxPanel *buttonPanel = safenew wxPanelWrapper(this, wxID_ANY);
wxPanel *const bar = safenew wxPanelWrapper(buttonPanel, wxID_ANY);
// This fools NVDA into not saying "Panel" when the dialog gets focus
bar->SetName(wxT("\a"));
bar->SetLabel(wxT("\a"));
{
auto bs = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
mSupportsRealtime = mEffect && mEffect->SupportsRealtime();
mIsGUI = mClient->IsGraphicalUI();
mIsBatch = (mEffect && mEffect->IsBatchProcessing()) ||
(mCommand && mCommand->IsBatchProcessing());
wxBitmapButton *bb;
int margin = 0;
mSupportsRealtime = mEffect && mEffect->SupportsRealtime();
mIsGUI = mClient->IsGraphicalUI();
mIsBatch = (mEffect && mEffect->IsBatchProcessing()) ||
(mCommand && mCommand->IsBatchProcessing());
int margin = 0;
#if defined(__WXMAC__)
margin = 3; // I'm sure it's needed because of the order things are created...
margin = 3; // I'm sure it's needed because of the order things are created...
#endif
const auto bar = safenew wxPanelWrapper(parent, wxID_ANY);
// This fools NVDA into not saying "Panel" when the dialog gets focus
bar->SetName(TranslatableString::Inaudible);
bar->SetLabel(TranslatableString::Inaudible);
ShuttleGui S{ bar, eIsCreating,
false /* horizontal */,
{ -1, -1 } /* minimum size */
};
{
S.SetBorder( margin );
if (!mIsGUI)
{
mMenuBtn = S.Id( kMenuID )
.ToolTip(XO("Manage presets and options"))
.AddButton( XO("&Manage"), wxALIGN_CENTER | wxTOP | wxBOTTOM );
}
else
{
mMenuBtn = S.Id( kMenuID )
.ToolTip(XO("Manage presets and options"))
.Name(XO("&Manage"))
.AddBitmapButton( CreateBitmap(effect_menu_xpm, true, true) );
mMenuBtn->SetBitmapPressed(CreateBitmap(effect_menu_xpm, false, true));
}
S.AddSpace( 5, 5 );
if (!mIsBatch)
{
if (!mIsGUI)
{
wxASSERT(bar); // To justify safenew
mMenuBtn = safenew wxButton(bar, kMenuID, _("&Manage"));
bs->Add(mMenuBtn, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, margin);
if (mSupportsRealtime)
{
mPlayToggleBtn = S.Id( kPlayID )
.ToolTip(XO("Start and stop playback"))
.AddButton( XO("Start &Playback"),
wxALIGN_CENTER | wxTOP | wxBOTTOM );
}
else if (mEffect &&
(mEffect->GetType() != EffectTypeAnalyze) &&
(mEffect->GetType() != EffectTypeTool) )
{
mPlayToggleBtn = S.Id( kPlayID )
.ToolTip(XO("Preview effect"))
.AddButton( XO("&Preview"),
wxALIGN_CENTER | wxTOP | wxBOTTOM );
}
}
else
{
wxASSERT(bar); // To justify safenew
mMenuBtn = safenew wxBitmapButton(bar, kMenuID, CreateBitmap(effect_menu_xpm, true, true));
mMenuBtn->SetBitmapPressed(CreateBitmap(effect_menu_xpm, false, true));
mPlayBM = CreateBitmap(effect_play_xpm, true, false);
mPlayDisabledBM = CreateBitmap(effect_play_disabled_xpm, true, true);
mStopBM = CreateBitmap(effect_stop_xpm, true, false);
mStopDisabledBM = CreateBitmap(effect_stop_disabled_xpm, true, false);
mPlayBtn = S.Id( kPlayID ).AddBitmapButton( mPlayBM );
mPlayBtn->SetBitmapDisabled(mPlayDisabledBM);
mPlayBtn->SetBitmapPressed(CreateBitmap(effect_play_xpm, false, true));
if (!mSupportsRealtime)
{
mPlayBtn->SetToolTip(_("Preview effect"));
#if defined(__WXMAC__)
mMenuBtn->SetName(_("&Manage"));
mPlayBtn->SetName(_("Preview effect"));
#else
mMenuBtn->SetLabel(_("&Manage"));
mPlayBtn->SetLabel(_("&Preview effect"));
#endif
bs->Add(mMenuBtn);
}
}
mMenuBtn->SetToolTip(_("Manage presets and options"));
bs->Add(5, 5);
if (!mIsBatch)
if (mSupportsRealtime)
{
if (!mIsGUI)
{
if (mSupportsRealtime)
{
wxASSERT(bar); // To justify safenew
mPlayToggleBtn = safenew wxButton(bar, kPlayID, _("Start &Playback"));
mPlayToggleBtn->SetToolTip(_("Start and stop playback"));
bs->Add(mPlayToggleBtn, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, margin);
}
else if (mEffect &&
(mEffect->GetType() != EffectTypeAnalyze) &&
(mEffect->GetType() != EffectTypeTool)
)
{
wxASSERT(bar); // To justify safenew
mPlayToggleBtn = safenew wxButton(bar, kPlayID, _("&Preview"));
mPlayToggleBtn->SetToolTip(_("Preview effect"));
bs->Add(mPlayToggleBtn, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, margin);
}
mRewindBtn = S.Id( kRewindID )
.ToolTip(XO("Skip backward"))
.AddButton( XO("Skip &Backward"),
wxALIGN_CENTER | wxTOP | wxBOTTOM );
}
else
{
mPlayBM = CreateBitmap(effect_play_xpm, true, false);
mPlayDisabledBM = CreateBitmap(effect_play_disabled_xpm, true, true);
mStopBM = CreateBitmap(effect_stop_xpm, true, false);
mStopDisabledBM = CreateBitmap(effect_stop_disabled_xpm, true, false);
wxASSERT(bar); // To justify safenew
bb = safenew wxBitmapButton(bar, kPlayID, mPlayBM);
bb->SetBitmapDisabled(mPlayDisabledBM);
bb->SetBitmapPressed(CreateBitmap(effect_play_xpm, false, true));
mPlayBtn = bb;
bs->Add(mPlayBtn);
if (!mSupportsRealtime)
{
mPlayBtn->SetToolTip(_("Preview effect"));
#if defined(__WXMAC__)
mPlayBtn->SetName(_("Preview effect"));
#else
mPlayBtn->SetLabel(_("&Preview effect"));
#endif
}
mRewindBtn = S.Id( kRewindID )
.ToolTip(XO("Skip backward"))
.Name(XO("Skip &Backward"))
.AddBitmapButton( CreateBitmap(
effect_rewind_xpm, true, true) );
mRewindBtn->SetBitmapDisabled(
CreateBitmap(effect_rewind_disabled_xpm, true, false));
mRewindBtn->SetBitmapPressed(CreateBitmap(effect_rewind_xpm, false, true));
}
if (mSupportsRealtime)
if (!mIsGUI)
{
if (!mIsGUI)
{
wxASSERT(bar); // To justify safenew
mRewindBtn = safenew wxButton(bar, kRewindID, _("Skip &Backward"));
bs->Add(mRewindBtn, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, margin);
}
else
{
wxASSERT(bar); // To justify safenew
bb = safenew wxBitmapButton(bar, kRewindID, CreateBitmap(effect_rewind_xpm, true, true));
bb->SetBitmapDisabled(CreateBitmap(effect_rewind_disabled_xpm, true, false));
bb->SetBitmapPressed(CreateBitmap(effect_rewind_xpm, false, true));
mRewindBtn = bb;
#if defined(__WXMAC__)
mRewindBtn->SetName(_("Skip &Backward"));
#else
mRewindBtn->SetLabel(_("Skip &Backward"));
#endif
bs->Add(mRewindBtn);
}
mRewindBtn->SetToolTip(_("Skip backward"));
if (!mIsGUI)
{
wxASSERT(bar); // To justify safenew
mFFwdBtn = safenew wxButton(bar, kFFwdID, _("Skip &Forward"));
bs->Add(mFFwdBtn, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, margin);
}
else
{
wxASSERT(bar); // To justify safenew
bb = safenew wxBitmapButton(bar, kFFwdID, CreateBitmap(effect_ffwd_xpm, true, true));
bb->SetBitmapDisabled(CreateBitmap(effect_ffwd_disabled_xpm, true, false));
bb->SetBitmapPressed(CreateBitmap(effect_ffwd_xpm, false, true));
mFFwdBtn = bb;
#if defined(__WXMAC__)
mFFwdBtn->SetName(_("Skip &Forward"));
#else
mFFwdBtn->SetLabel(_("Skip &Forward"));
#endif
bs->Add(mFFwdBtn);
}
mFFwdBtn->SetToolTip(_("Skip forward"));
bs->Add(5, 5);
mEnableCb = safenew wxCheckBox(bar, kEnableID, _("&Enable"));
mEnableCb->SetValue(mEnabled);
mEnableCb->SetName(_("Enable"));
bs->Add(mEnableCb, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, margin);
mFFwdBtn = S.Id( kFFwdID )
.ToolTip(XO("Skip forward"))
.AddButton( XO("Skip &Forward"),
wxALIGN_CENTER | wxTOP | wxBOTTOM );
}
else
{
mFFwdBtn = S.Id( kFFwdID )
.ToolTip(XO("Skip forward"))
.Name(XO("Skip &Forward"))
.AddBitmapButton( CreateBitmap(
effect_ffwd_xpm, true, true) );
mFFwdBtn->SetBitmapDisabled(
CreateBitmap(effect_ffwd_disabled_xpm, true, false));
mFFwdBtn->SetBitmapPressed(CreateBitmap(effect_ffwd_xpm, false, true));
}
S.AddSpace( 5, 5 );
mEnableCb = S.Id( kEnableID )
.Position(wxALIGN_CENTER | wxTOP | wxBOTTOM)
.Name(XO("Enable"))
.AddCheckBox( XO("&Enable"), mEnabled );
//
}
bar->SetSizerAndFit(bs.release());
}
long buttons;
if ( mEffect && mEffect->ManualPage().empty() && mEffect->HelpPage().empty()) {
buttons = eApplyButton + eCloseButton;
this->SetAcceleratorTable(wxNullAcceleratorTable);
}
else {
buttons = eApplyButton + eCloseButton + eHelpButton;
wxAcceleratorEntry entries[1];
#if defined(__WXMAC__)
// Is there a standard shortcut on Mac?
#else
entries[0].Set(wxACCEL_NORMAL, (int) WXK_F1, wxID_HELP);
#endif
wxAcceleratorTable accel(1, entries);
this->SetAcceleratorTable(accel);
}
if (mEffect && mEffect->mUIDebug) {
buttons += eDebugButton;
}
buttonPanel->SetSizer(CreateStdButtonSizer(buttonPanel, buttons, bar).release());
vs->Add(buttonPanel, 0, wxEXPAND);
SetSizer(vs.release());
}
bar->GetSizer()->SetSizeHints( bar );
return bar;
}
bool EffectUIHost::Initialize()
{
{
auto gAudioIO = AudioIO::Get();
mDisableTransport = !gAudioIO->IsAvailable(mProject);
mPlaying = gAudioIO->IsStreamActive(); // not exactly right, but will suffice
mCapturing = gAudioIO->IsStreamActive() && gAudioIO->GetNumCaptureChannels() > 0;
}
EffectPanel *w {};
ShuttleGui S{ this, eIsCreating };
{
S.StartHorizontalLay( wxEXPAND );
{
Destroy_ptr<EffectPanel> uw{ safenew EffectPanel( S.GetParent() ) };
RTL_WORKAROUND(uw.get());
// Try to give the window a sensible default/minimum size
uw->SetMinSize(wxSize(wxMax(600, mParent->GetSize().GetWidth() * 2 / 3),
mParent->GetSize().GetHeight() / 2));
ShuttleGui S1{ uw.get(), eIsCreating };
if (!mClient->PopulateUI(S1))
{
return false;
}
S.Prop( 1 )
.Position(wxEXPAND)
.AddWindow((w = uw.release()));
}
S.EndHorizontalLay();
S.StartPanel();
{
const auto bar = BuildButtonBar( S.GetParent() );
long buttons;
if ( mEffect && mEffect->ManualPage().empty() && mEffect->HelpPage().empty()) {
buttons = eApplyButton | eCloseButton;
this->SetAcceleratorTable(wxNullAcceleratorTable);
}
else {
buttons = eApplyButton | eCloseButton | eHelpButton;
wxAcceleratorEntry entries[1];
#if defined(__WXMAC__)
// Is there a standard shortcut on Mac?
#else
entries[0].Set(wxACCEL_NORMAL, (int) WXK_F1, wxID_HELP);
#endif
wxAcceleratorTable accel(1, entries);
this->SetAcceleratorTable(accel);
}
if (mEffect && mEffect->mUIDebug) {
buttons |= eDebugButton;
}
S.AddStandardButtons(buttons, bar);
}
S.EndPanel();
}
Layout();
Fit();
Center();
mApplyBtn = (wxButton *) FindWindow(wxID_APPLY);
mCloseBtn = (wxButton *) FindWindow(wxID_CANCEL);
UpdateControls();
w->SetAccept(!mIsGUI);
(!mIsGUI ? w : FindWindow(wxID_APPLY))->SetFocus();
LoadUserPresets();
InitializeRealtime();
SetMinSize(GetSize());
return true;
}

View File

@ -137,6 +137,8 @@ public:
bool Initialize();
private:
wxPanel *BuildButtonBar( wxWindow *parent );
void OnInitDialog(wxInitDialogEvent & evt);
void OnErase(wxEraseEvent & evt);
void OnPaint(wxPaintEvent & evt);

View File

@ -723,19 +723,6 @@ bool EffectEqualization::Process()
return bGoodResult;
}
bool EffectEqualization::PopulateUI(wxWindow *parent)
{
mUIParent = parent;
mUIParent->PushEventHandler(this);
LoadUserPreset(GetCurrentSettingsGroup());
ShuttleGui S(mUIParent, eIsCreating);
PopulateOrExchange(S);
return true;
}
bool EffectEqualization::CloseUI()
{
mCurve = NULL;
@ -746,6 +733,9 @@ bool EffectEqualization::CloseUI()
void EffectEqualization::PopulateOrExchange(ShuttleGui & S)
{
if ( S.GetMode() == eIsCreating )
LoadUserPreset(GetCurrentSettingsGroup());
//LoadCurves();
auto trackList = inputTracks();

View File

@ -131,7 +131,6 @@ public:
bool Init() override;
bool Process() override;
bool PopulateUI(wxWindow *parent) override;
bool CloseUI() override;
void PopulateOrExchange(ShuttleGui & S) override;
bool TransferDataToWindow() override;

View File

@ -1761,8 +1761,9 @@ void VSTEffect::SetHostUI(EffectUIHostInterface *host)
mUIHost = host;
}
bool VSTEffect::PopulateUI(wxWindow *parent)
bool VSTEffect::PopulateUI(ShuttleGui &S)
{
auto parent = S.GetParent();
mDialog = static_cast<wxDialog *>(wxGetTopLevelParent(parent));
mParent = parent;

View File

@ -167,7 +167,7 @@ class VSTEffect final : public wxEvtHandler,
// EffectUIClientInterface implementation
void SetHostUI(EffectUIHostInterface *host) override;
bool PopulateUI(wxWindow *parent) override;
bool PopulateUI(ShuttleGui &S) override;
bool IsGraphicalUI() override;
bool ValidateUI() override;
bool HideUI() override;

View File

@ -1717,10 +1717,11 @@ void AudioUnitEffect::SetHostUI(EffectUIHostInterface *host)
mUIHost = host;
}
bool AudioUnitEffect::PopulateUI(wxWindow *parent)
bool AudioUnitEffect::PopulateUI(ShuttleGui &S)
{
// OSStatus result;
auto parent = S.GetParent();
mDialog = static_cast<wxDialog *>(wxGetTopLevelParent(parent));
mParent = parent;

View File

@ -117,7 +117,7 @@ public:
// EffectUIClientInterface implementation
void SetHostUI(EffectUIHostInterface *host) override;
bool PopulateUI(wxWindow *parent) override;
bool PopulateUI(ShuttleGui &S) override;
bool IsGraphicalUI() override;
bool ValidateUI() override;
bool HideUI() override;

View File

@ -1195,8 +1195,10 @@ void LadspaEffect::SetHostUI(EffectUIHostInterface *host)
mUIHost = host;
}
bool LadspaEffect::PopulateUI(wxWindow *parent)
bool LadspaEffect::PopulateUI(ShuttleGui &S)
{
auto parent = S.GetParent();
mParent = parent;
mParent->PushEventHandler(this);

View File

@ -115,7 +115,7 @@ public:
// EffectUIClientInterface implementation
void SetHostUI(EffectUIHostInterface *host) override;
bool PopulateUI(wxWindow *parent) override;
bool PopulateUI(ShuttleGui &S) override;
bool IsGraphicalUI() override;
bool ValidateUI() override;
bool HideUI() override;

View File

@ -1548,8 +1548,9 @@ void LV2Effect::SetHostUI(EffectUIHostInterface *host)
mUIHost = host;
}
bool LV2Effect::PopulateUI(wxWindow *parent)
bool LV2Effect::PopulateUI(ShuttleGui &S)
{
auto parent = S.GetParent();
mParent = parent;
mParent->PushEventHandler(this);

View File

@ -314,7 +314,7 @@ public:
// EffectUIClientInterface implementation
void SetHostUI(EffectUIHostInterface *host) override;
bool PopulateUI(wxWindow *parent) override;
bool PopulateUI(ShuttleGui &S) override;
bool IsGraphicalUI() override;
bool ValidateUI() override;
bool HideUI() override;