1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-09-15 07:50:22 +02:00

EffectUIClientInterface::PopulateUI takes ShuttleGui &

This commit is contained in:
Paul Licameli 2017-10-26 08:51:41 -04:00
parent eff5b2ef92
commit 1c84932dfa
12 changed files with 62 additions and 52 deletions

View File

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

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 = parent;
mUIParent->PushEventHandler(this); mUIParent->PushEventHandler(this);
// LoadUserPreset(GetCurrentSettingsGroup()); // LoadUserPreset(GetCurrentSettingsGroup());
ShuttleGui S(mUIParent, eIsCreating);
PopulateOrExchange(S); PopulateOrExchange(S);
mUIParent->SetMinSize(mUIParent->GetSizer()->GetMinSize()); mUIParent->SetMinSize(mUIParent->GetSizer()->GetMinSize());

View File

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

View File

@ -858,54 +858,57 @@ int EffectUIHost::ShowModal()
bool EffectUIHost::Initialize() bool EffectUIHost::Initialize()
{ {
EffectPanel *w = safenew EffectPanel(this); EffectPanel *w {};
RTL_WORKAROUND(w);
{ {
auto vs = std::make_unique<wxBoxSizer>(wxVERTICAL); auto vs = std::make_unique<wxBoxSizer>(wxVERTICAL);
{ {
auto hs = std::make_unique<wxBoxSizer>(wxHORIZONTAL); auto hs = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
Destroy_ptr<EffectPanel> uw{ safenew EffectPanel(this) };
RTL_WORKAROUND(uw.get());
// Try to give the window a sensible default/minimum size // Try to give the window a sensible default/minimum size
w->SetMinSize(wxSize(wxMax(600, mParent->GetSize().GetWidth() * 2 / 3), uw->SetMinSize(wxSize(wxMax(600, mParent->GetSize().GetWidth() * 2 / 3),
mParent->GetSize().GetHeight() / 2)); mParent->GetSize().GetHeight() / 2));
auto gAudioIO = AudioIO::Get(); auto gAudioIO = AudioIO::Get();
mDisableTransport = !gAudioIO->IsAvailable(mProject); mDisableTransport = !gAudioIO->IsAvailable(mProject);
mPlaying = gAudioIO->IsStreamActive(); // not exactly right, but will suffice mPlaying = gAudioIO->IsStreamActive(); // not exactly right, but will suffice
mCapturing = gAudioIO->IsStreamActive() && gAudioIO->GetNumCaptureChannels() > 0; mCapturing = gAudioIO->IsStreamActive() && gAudioIO->GetNumCaptureChannels() > 0;
if (!mClient->PopulateUI(w)) ShuttleGui S1{ uw.get(), eIsCreating };
if (!mClient->PopulateUI(S1))
{ {
return false; return false;
} }
hs->Add(w, 1, wxEXPAND); hs->Add((w = uw.release()), 1, wxEXPAND);
vs->Add(hs.release(), 1, wxEXPAND); vs->Add(hs.release(), 1, wxEXPAND);
} }
wxPanel *buttonPanel = safenew wxPanelWrapper(this, wxID_ANY); wxPanel *buttonPanel = safenew wxPanelWrapper(this, wxID_ANY);
wxPanel *const bar = safenew wxPanelWrapper(buttonPanel, wxID_ANY); wxPanel *const bar = safenew wxPanelWrapper(buttonPanel, wxID_ANY);
// This fools NVDA into not saying "Panel" when the dialog gets focus // This fools NVDA into not saying "Panel" when the dialog gets focus
bar->SetName(wxT("\a")); bar->SetName(wxT("\a"));
bar->SetLabel(wxT("\a")); bar->SetLabel(wxT("\a"));
{ {
auto bs = std::make_unique<wxBoxSizer>(wxHORIZONTAL); auto bs = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
mSupportsRealtime = mEffect && mEffect->SupportsRealtime(); mSupportsRealtime = mEffect && mEffect->SupportsRealtime();
mIsGUI = mClient->IsGraphicalUI(); mIsGUI = mClient->IsGraphicalUI();
mIsBatch = (mEffect && mEffect->IsBatchProcessing()) || mIsBatch = (mEffect && mEffect->IsBatchProcessing()) ||
(mCommand && mCommand->IsBatchProcessing()); (mCommand && mCommand->IsBatchProcessing());
wxBitmapButton *bb; wxBitmapButton *bb;
int margin = 0; int margin = 0;
#if defined(__WXMAC__) #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 #endif
if (!mIsGUI) if (!mIsGUI)
{ {
wxASSERT(bar); // To justify safenew wxASSERT(bar); // To justify safenew
@ -925,9 +928,9 @@ bool EffectUIHost::Initialize()
bs->Add(mMenuBtn); bs->Add(mMenuBtn);
} }
mMenuBtn->SetToolTip(_("Manage presets and options")); mMenuBtn->SetToolTip(_("Manage presets and options"));
bs->Add(5, 5); bs->Add(5, 5);
if (!mIsBatch) if (!mIsBatch)
{ {
if (!mIsGUI) if (!mIsGUI)
@ -940,9 +943,9 @@ bool EffectUIHost::Initialize()
bs->Add(mPlayToggleBtn, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, margin); bs->Add(mPlayToggleBtn, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, margin);
} }
else if (mEffect && else if (mEffect &&
(mEffect->GetType() != EffectTypeAnalyze) && (mEffect->GetType() != EffectTypeAnalyze) &&
(mEffect->GetType() != EffectTypeTool) (mEffect->GetType() != EffectTypeTool)
) )
{ {
wxASSERT(bar); // To justify safenew wxASSERT(bar); // To justify safenew
mPlayToggleBtn = safenew wxButton(bar, kPlayID, _("&Preview")); mPlayToggleBtn = safenew wxButton(bar, kPlayID, _("&Preview"));
@ -972,7 +975,7 @@ bool EffectUIHost::Initialize()
#endif #endif
} }
} }
if (mSupportsRealtime) if (mSupportsRealtime)
{ {
if (!mIsGUI) if (!mIsGUI)
@ -996,7 +999,7 @@ bool EffectUIHost::Initialize()
bs->Add(mRewindBtn); bs->Add(mRewindBtn);
} }
mRewindBtn->SetToolTip(_("Skip backward")); mRewindBtn->SetToolTip(_("Skip backward"));
if (!mIsGUI) if (!mIsGUI)
{ {
wxASSERT(bar); // To justify safenew wxASSERT(bar); // To justify safenew
@ -1018,19 +1021,19 @@ bool EffectUIHost::Initialize()
bs->Add(mFFwdBtn); bs->Add(mFFwdBtn);
} }
mFFwdBtn->SetToolTip(_("Skip forward")); mFFwdBtn->SetToolTip(_("Skip forward"));
bs->Add(5, 5); bs->Add(5, 5);
mEnableCb = safenew wxCheckBox(bar, kEnableID, _("&Enable")); mEnableCb = safenew wxCheckBox(bar, kEnableID, _("&Enable"));
mEnableCb->SetValue(mEnabled); mEnableCb->SetValue(mEnabled);
mEnableCb->SetName(_("Enable")); mEnableCb->SetName(_("Enable"));
bs->Add(mEnableCb, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, margin); bs->Add(mEnableCb, 0, wxALIGN_CENTER | wxTOP | wxBOTTOM, margin);
} }
} }
bar->SetSizerAndFit(bs.release()); bar->SetSizerAndFit(bs.release());
} }
long buttons; long buttons;
if ( mEffect && mEffect->ManualPage().empty() && mEffect->HelpPage().empty()) { if ( mEffect && mEffect->ManualPage().empty() && mEffect->HelpPage().empty()) {
buttons = eApplyButton + eCloseButton; buttons = eApplyButton + eCloseButton;
@ -1047,33 +1050,33 @@ bool EffectUIHost::Initialize()
wxAcceleratorTable accel(1, entries); wxAcceleratorTable accel(1, entries);
this->SetAcceleratorTable(accel); this->SetAcceleratorTable(accel);
} }
if (mEffect && mEffect->mUIDebug) { if (mEffect && mEffect->mUIDebug) {
buttons += eDebugButton; buttons += eDebugButton;
} }
buttonPanel->SetSizer(CreateStdButtonSizer(buttonPanel, buttons, bar).release()); buttonPanel->SetSizer(CreateStdButtonSizer(buttonPanel, buttons, bar).release());
vs->Add(buttonPanel, 0, wxEXPAND); vs->Add(buttonPanel, 0, wxEXPAND);
SetSizer(vs.release()); SetSizer(vs.release());
} }
Layout(); Layout();
Fit(); Fit();
Center(); Center();
mApplyBtn = (wxButton *) FindWindow(wxID_APPLY); mApplyBtn = (wxButton *) FindWindow(wxID_APPLY);
mCloseBtn = (wxButton *) FindWindow(wxID_CANCEL); mCloseBtn = (wxButton *) FindWindow(wxID_CANCEL);
UpdateControls(); UpdateControls();
w->SetAccept(!mIsGUI); w->SetAccept(!mIsGUI);
(!mIsGUI ? w : FindWindow(wxID_APPLY))->SetFocus(); (!mIsGUI ? w : FindWindow(wxID_APPLY))->SetFocus();
LoadUserPresets(); LoadUserPresets();
InitializeRealtime(); InitializeRealtime();
SetMinSize(GetSize()); SetMinSize(GetSize());
return true; return true;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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