Remove GetActiveProject from EffectRack...

... and make one EffectRack window per project
This commit is contained in:
Paul Licameli 2020-01-04 16:12:00 -05:00
parent dd4870b83f
commit 129c9deb99
5 changed files with 38 additions and 47 deletions

View File

@ -67,17 +67,10 @@ EffectManager & EffectManager::Get()
EffectManager::EffectManager()
{
mSkipStateFlag = false;
#if defined(EXPERIMENTAL_EFFECTS_RACK)
mRack = NULL;
#endif
}
EffectManager::~EffectManager()
{
#if defined(EXPERIMENTAL_EFFECTS_RACK)
// wxWidgets has already destroyed the rack since it was derived from wxFrame. So
// no need to DELETE it here.
#endif
}
// Here solely for the purpose of Nyquist Workbench until
@ -166,7 +159,7 @@ void EffectManager::UnregisterEffect(const PluginID & ID)
EffectManager & em = EffectManager::Get();
success = em.DoEffect(ID, &window, rate,
success = em.DoEffect(ID, &window, context.project, rate,
&tracks, &trackFactory, selectedRegion,
(flags & EffectManager::kConfigured) == 0);
@ -238,6 +231,7 @@ void EffectManager::UnregisterEffect(const PluginID & ID)
bool EffectManager::DoEffect(const PluginID & ID,
wxWindow *parent,
AudacityProject &project,
double projectRate,
TrackList *list,
TrackFactory *factory,
@ -256,8 +250,10 @@ bool EffectManager::DoEffect(const PluginID & ID,
#if defined(EXPERIMENTAL_EFFECTS_RACK)
if (effect->SupportsRealtime())
{
GetRack()->Add(effect);
EffectRack::Get( project ).Add(effect);
}
#else
(void)project;
#endif
bool res = effect->DoEffect(parent,
@ -636,27 +632,6 @@ void EffectManager::SetBatchProcessing(const PluginID & ID, bool start)
}
#if defined(EXPERIMENTAL_EFFECTS_RACK)
EffectRack *EffectManager::GetRack()
{
if (!mRack)
{
// EffectRack is constructed with the current project as owner, so safenew is OK
mRack = safenew EffectRack();
// Make sure what I just commented remains true:
wxASSERT(mRack->GetParent());
mRack->CenterOnParent();
}
return mRack;
}
void EffectManager::ShowRack()
{
GetRack()->Show(!GetRack()->IsShown());
}
#endif
Effect *EffectManager::GetEffect(const PluginID & ID)
{
// Must have a "valid" ID

View File

@ -21,6 +21,7 @@
#include "audacity/Types.h"
class AudacityCommand;
class AudacityProject;
class CommandContext;
class CommandMessageTarget;
class ComponentInterfaceSymbol;
@ -87,6 +88,7 @@ public:
// Audacity's standard UI.
bool DoEffect(const PluginID & ID,
wxWindow *parent,
AudacityProject &project,
double projectRate,
TrackList *list,
TrackFactory *factory,
@ -143,10 +145,6 @@ public:
void SetSkipStateFlag(bool flag);
bool GetSkipStateFlag();
#if defined(EXPERIMENTAL_EFFECTS_RACK)
void ShowRack();
#endif
const PluginID & GetEffectByIdentifier(const CommandID & strTarget);
private:
@ -154,10 +152,6 @@ private:
Effect *GetEffect(const PluginID & ID);
AudacityCommand *GetAudacityCommand(const PluginID & ID);
#if defined(EXPERIMENTAL_EFFECTS_RACK)
EffectRack *GetRack();
#endif
private:
EffectMap mEffects;
AudacityCommandMap mCommands;
@ -170,8 +164,6 @@ private:
bool mSkipStateFlag;
#if defined(EXPERIMENTAL_EFFECTS_RACK)
EffectRack *mRack;
friend class EffectRack;
#endif

View File

@ -80,8 +80,8 @@ BEGIN_EVENT_TABLE(EffectRack, wxFrame)
EVT_COMMAND_RANGE(ID_FAV, ID_FAV + 99, wxEVT_COMMAND_BUTTON_CLICKED, EffectRack::OnFav)
END_EVENT_TABLE()
EffectRack::EffectRack()
: wxFrame( FindProjectFrame( GetActiveProject() ),
EffectRack::EffectRack( AudacityProject &project )
: wxFrame( &GetProjectFrame( project ),
wxID_ANY,
_("Effects Rack"),
wxDefaultPosition,
@ -91,6 +91,7 @@ EffectRack::EffectRack()
wxCAPTION |
wxFRAME_NO_TASKBAR |
wxFRAME_FLOAT_ON_PARENT)
, mProject{ project }
{
mBypassing = false;
mNumEffects = 0;
@ -296,7 +297,7 @@ void EffectRack::OnTimer(wxTimerEvent & WXUNUSED(evt))
void EffectRack::OnApply(wxCommandEvent & WXUNUSED(evt))
{
AudacityProject *project = GetActiveProject();
AudacityProject *project = &mProject;
bool success = false;
auto state = UndoManager::Get( *project ).GetCurrentState();
@ -568,4 +569,20 @@ void EffectRack::UpdateActive()
);
}
namespace
{
AudacityProject::AttachedWindows::RegisteredFactory sKey{
[]( AudacityProject &parent ) -> wxWeakRef< wxWindow > {
auto result = safenew EffectRack( parent );
result->CenterOnParent();
return result;
}
};
}
EffectRack &EffectRack::Get( AudacityProject &project )
{
return project.AttachedWindows::Get< EffectRack >( sKey );
}
#endif

View File

@ -28,17 +28,21 @@ class wxFlexGridSizer;
class wxPanel;
class wxStaticText;
class AudacityProject;
class Effect;
using EffectArray = std::vector<Effect*>;
class EffectRack final : public wxFrame
{
public:
EffectRack();
EffectRack( AudacityProject &project );
virtual ~EffectRack();
void Add(Effect *effect, bool active = false, bool favorite = false);
static EffectRack &Get( AudacityProject &project );
private:
wxBitmap CreateBitmap(const char *const xpm[], bool up, bool pusher);
@ -59,6 +63,8 @@ private:
void OnRemove(wxCommandEvent & evt);
private:
AudacityProject &mProject;
wxStaticText *mLatency;
int mLastLatency;

View File

@ -23,7 +23,7 @@
#include "../tracks/ui/TrackView.h"
#ifdef EXPERIMENTAL_EFFECTS_RACK
#include "../effects/EffectManager.h"
#include "../effects/EffectRack.h"
#endif
#include <wx/scrolbar.h>
@ -383,9 +383,10 @@ void OnShowClipping(const CommandContext &context)
}
#if defined(EXPERIMENTAL_EFFECTS_RACK)
void OnShowEffectsRack(const CommandContext &WXUNUSED(context) )
void OnShowEffectsRack(const CommandContext &context )
{
EffectManager::Get().ShowRack();
auto &rack = EffectRack::Get( context.project );
rack.Show( !rack.IsShown() );
}
#endif