mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-16 08:09:32 +02:00
Move DoEffect out of PluginMenus
This commit is contained in:
parent
691eee681c
commit
ff2cf496cd
@ -26,7 +26,6 @@
|
|||||||
#include "AudioIOBase.h"
|
#include "AudioIOBase.h"
|
||||||
#include "CommonCommandFlags.h"
|
#include "CommonCommandFlags.h"
|
||||||
#include "LabelTrack.h"
|
#include "LabelTrack.h"
|
||||||
#include "Menus.h"
|
|
||||||
#include "ModuleManager.h"
|
#include "ModuleManager.h"
|
||||||
#include "Prefs.h"
|
#include "Prefs.h"
|
||||||
#include "Project.h"
|
#include "Project.h"
|
||||||
@ -1405,7 +1404,7 @@ void NyqBench::OnGo(wxCommandEvent & e)
|
|||||||
mRunning = true;
|
mRunning = true;
|
||||||
UpdateWindowUI();
|
UpdateWindowUI();
|
||||||
|
|
||||||
PluginActions::DoEffect(ID, CommandContext(*p), 0);
|
EffectManager::DoEffect(ID, CommandContext(*p), 0);
|
||||||
|
|
||||||
mRunning = false;
|
mRunning = false;
|
||||||
UpdateWindowUI();
|
UpdateWindowUI();
|
||||||
|
@ -785,7 +785,7 @@ bool MacroCommands::ApplyEffectCommand(
|
|||||||
EffectManager::kDontRepeatLast);
|
EffectManager::kDontRepeatLast);
|
||||||
else
|
else
|
||||||
// and apply the effect...
|
// and apply the effect...
|
||||||
res = PluginActions::DoEffect(ID,
|
res = EffectManager::DoEffect(ID,
|
||||||
Context,
|
Context,
|
||||||
EffectManager::kConfigured |
|
EffectManager::kConfigured |
|
||||||
EffectManager::kSkipState |
|
EffectManager::kSkipState |
|
||||||
@ -820,7 +820,7 @@ bool MacroCommands::HandleTextualCommand( CommandManager &commandManager,
|
|||||||
{
|
{
|
||||||
if (em.GetCommandIdentifier(plug->GetID()) == Str)
|
if (em.GetCommandIdentifier(plug->GetID()) == Str)
|
||||||
{
|
{
|
||||||
return PluginActions::DoEffect(
|
return EffectManager::DoEffect(
|
||||||
plug->GetID(), context,
|
plug->GetID(), context,
|
||||||
EffectManager::kConfigured);
|
EffectManager::kConfigured);
|
||||||
}
|
}
|
||||||
|
@ -138,12 +138,6 @@ void DoTogglePinnedHead( AudacityProject & );
|
|||||||
void DoRecord( AudacityProject & );
|
void DoRecord( AudacityProject & );
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Namespace for helper functions to do with plug ins
|
|
||||||
namespace PluginActions {
|
|
||||||
bool DoEffect(
|
|
||||||
const PluginID & ID, const CommandContext & context, unsigned flags );
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Namespace for functions for Help menu
|
/// Namespace for functions for Help menu
|
||||||
namespace HelpActions {
|
namespace HelpActions {
|
||||||
void DoHelpWelcome( AudacityProject & );
|
void DoHelpWelcome( AudacityProject & );
|
||||||
|
@ -1712,7 +1712,7 @@ bool ProjectFileManager::Import(
|
|||||||
SelectUtilities::SelectNone( project );
|
SelectUtilities::SelectNone( project );
|
||||||
SelectUtilities::SelectAllIfNone( project );
|
SelectUtilities::SelectAllIfNone( project );
|
||||||
const CommandContext context( project );
|
const CommandContext context( project );
|
||||||
PluginActions::DoEffect(
|
EffectManager::DoEffect(
|
||||||
EffectManager::Get().GetEffectByIdentifier(wxT("Normalize")),
|
EffectManager::Get().GetEffectByIdentifier(wxT("Normalize")),
|
||||||
context,
|
context,
|
||||||
EffectManager::kConfigured);
|
EffectManager::kConfigured);
|
||||||
|
@ -777,7 +777,7 @@ bool Effect::Apply()
|
|||||||
// This is absolute hackage...but easy and I can't think of another way just now.
|
// This is absolute hackage...but easy and I can't think of another way just now.
|
||||||
//
|
//
|
||||||
// It should callback to the EffectManager to kick off the processing
|
// It should callback to the EffectManager to kick off the processing
|
||||||
return PluginActions::DoEffect(GetID(), context,
|
return EffectManager::DoEffect(GetID(), context,
|
||||||
EffectManager::kConfigured);
|
EffectManager::kConfigured);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,8 +37,18 @@ effects.
|
|||||||
|
|
||||||
#include "../ShuttleGetDefinition.h"
|
#include "../ShuttleGetDefinition.h"
|
||||||
#include "../commands/CommandContext.h"
|
#include "../commands/CommandContext.h"
|
||||||
|
#include "../commands/CommandManager.h"
|
||||||
#include "../commands/Command.h"
|
#include "../commands/Command.h"
|
||||||
|
#include "../Menus.h"
|
||||||
|
#include "../MissingAliasFileDialog.h"
|
||||||
#include "../PluginManager.h"
|
#include "../PluginManager.h"
|
||||||
|
#include "../ProjectHistory.h"
|
||||||
|
#include "../ProjectSettings.h"
|
||||||
|
#include "../ProjectWindow.h"
|
||||||
|
#include "../SelectUtilities.h"
|
||||||
|
#include "../TrackPanel.h"
|
||||||
|
#include "../ViewInfo.h"
|
||||||
|
#include "../WaveTrack.h"
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -88,6 +98,134 @@ void EffectManager::UnregisterEffect(const PluginID & ID)
|
|||||||
mEffects.erase(id);
|
mEffects.erase(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// DoEffect() takes a PluginID and has the EffectManager execute the associated
|
||||||
|
/// effect.
|
||||||
|
///
|
||||||
|
/// At the moment flags are used only to indicate whether to prompt for
|
||||||
|
// parameters, whether to save the state to history and whether to allow
|
||||||
|
/// 'Repeat Last Effect'.
|
||||||
|
|
||||||
|
/* static */ bool EffectManager::DoEffect(
|
||||||
|
const PluginID & ID, const CommandContext &context, unsigned flags )
|
||||||
|
{
|
||||||
|
AudacityProject &project = context.project;
|
||||||
|
const auto &settings = ProjectSettings::Get( project );
|
||||||
|
auto &tracks = TrackList::Get( project );
|
||||||
|
auto &trackPanel = TrackPanel::Get( project );
|
||||||
|
auto &trackFactory = TrackFactory::Get( project );
|
||||||
|
auto rate = settings.GetRate();
|
||||||
|
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
|
||||||
|
auto &commandManager = CommandManager::Get( project );
|
||||||
|
auto &window = ProjectWindow::Get( project );
|
||||||
|
|
||||||
|
const PluginDescriptor *plug = PluginManager::Get().GetPlugin(ID);
|
||||||
|
if (!plug)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
EffectType type = plug->GetEffectType();
|
||||||
|
|
||||||
|
// Make sure there's no activity since the effect is about to be applied
|
||||||
|
// to the project's tracks. Mainly for Apply during RTP, but also used
|
||||||
|
// for batch commands
|
||||||
|
if (flags & EffectManager::kConfigured)
|
||||||
|
{
|
||||||
|
TransportActions::DoStop(project);
|
||||||
|
SelectUtilities::SelectAllIfNone( project );
|
||||||
|
}
|
||||||
|
|
||||||
|
MissingAliasFilesDialog::SetShouldShow(true);
|
||||||
|
|
||||||
|
auto nTracksOriginally = tracks.size();
|
||||||
|
wxWindow *focus = wxWindow::FindFocus();
|
||||||
|
wxWindow *parent = nullptr;
|
||||||
|
if (focus != nullptr) {
|
||||||
|
parent = focus->GetParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool success = false;
|
||||||
|
auto cleanup = finally( [&] {
|
||||||
|
|
||||||
|
if (!success) {
|
||||||
|
// For now, we're limiting realtime preview to a single effect, so
|
||||||
|
// make sure the menus reflect that fact that one may have just been
|
||||||
|
// opened.
|
||||||
|
MenuManager::Get(project).UpdateMenus( false );
|
||||||
|
}
|
||||||
|
|
||||||
|
} );
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
bool clean = true;
|
||||||
|
for (auto t : tracks.Selected< const WaveTrack >()) {
|
||||||
|
if (t->GetEndTime() != 0.0)
|
||||||
|
clean = false;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
EffectManager & em = EffectManager::Get();
|
||||||
|
|
||||||
|
success = em.DoEffect(ID, &window, rate,
|
||||||
|
&tracks, &trackFactory, &selectedRegion,
|
||||||
|
(flags & EffectManager::kConfigured) == 0);
|
||||||
|
|
||||||
|
if (!success)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (em.GetSkipStateFlag())
|
||||||
|
flags = flags | EffectManager::kSkipState;
|
||||||
|
|
||||||
|
if (!(flags & EffectManager::kSkipState))
|
||||||
|
{
|
||||||
|
wxString shortDesc = em.GetCommandName(ID);
|
||||||
|
wxString longDesc = em.GetCommandDescription(ID);
|
||||||
|
ProjectHistory::Get( project ).PushState(longDesc, shortDesc);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(flags & EffectManager::kDontRepeatLast))
|
||||||
|
{
|
||||||
|
// Only remember a successful effect, don't remember insert,
|
||||||
|
// or analyze effects.
|
||||||
|
if (type == EffectTypeProcess) {
|
||||||
|
wxString shortDesc = em.GetCommandName(ID);
|
||||||
|
MenuManager::Get(project).mLastEffect = ID;
|
||||||
|
wxString lastEffectDesc;
|
||||||
|
/* i18n-hint: %s will be the name of the effect which will be
|
||||||
|
* repeated if this menu item is chosen */
|
||||||
|
lastEffectDesc.Printf(_("Repeat %s"), shortDesc);
|
||||||
|
commandManager.Modify(wxT("RepeatLastEffect"), lastEffectDesc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//STM:
|
||||||
|
//The following automatically re-zooms after sound was generated.
|
||||||
|
// IMO, it was disorienting, removing to try out without re-fitting
|
||||||
|
//mchinen:12/14/08 reapplying for generate effects
|
||||||
|
if (type == EffectTypeGenerate)
|
||||||
|
{
|
||||||
|
if (count == 0 || (clean && selectedRegion.t0() == 0.0))
|
||||||
|
ViewActions::DoZoomFit(project);
|
||||||
|
// trackPanel->Refresh(false);
|
||||||
|
}
|
||||||
|
window.RedrawProject();
|
||||||
|
if (focus != nullptr && focus->GetParent()==parent) {
|
||||||
|
focus->SetFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
// A fix for Bug 63
|
||||||
|
// New tracks added? Scroll them into view so that user sees them.
|
||||||
|
// Don't care what track type. An analyser might just have added a
|
||||||
|
// Label track and we want to see it.
|
||||||
|
if( tracks.size() > nTracksOriginally ){
|
||||||
|
// 0.0 is min scroll position, 1.0 is max scroll position.
|
||||||
|
trackPanel.VerticalScroll( 1.0 );
|
||||||
|
} else {
|
||||||
|
trackPanel.EnsureVisible(trackPanel.GetFirstSelectedTrack());
|
||||||
|
trackPanel.Refresh(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool EffectManager::DoEffect(const PluginID & ID,
|
bool EffectManager::DoEffect(const PluginID & ID,
|
||||||
wxWindow *parent,
|
wxWindow *parent,
|
||||||
double projectRate,
|
double projectRate,
|
||||||
|
@ -67,6 +67,9 @@ public:
|
|||||||
// them by index number, usually when the user selects one from a menu.
|
// them by index number, usually when the user selects one from a menu.
|
||||||
//
|
//
|
||||||
public:
|
public:
|
||||||
|
static bool DoEffect(
|
||||||
|
const PluginID & ID, const CommandContext &context, unsigned flags );
|
||||||
|
|
||||||
EffectManager();
|
EffectManager();
|
||||||
virtual ~EffectManager();
|
virtual ~EffectManager();
|
||||||
|
|
||||||
|
@ -309,7 +309,7 @@ void EffectRack::OnApply(wxCommandEvent & WXUNUSED(evt))
|
|||||||
{
|
{
|
||||||
if (mPowerState[i])
|
if (mPowerState[i])
|
||||||
{
|
{
|
||||||
if (!PluginActions::DoEffect(mEffects[i]->GetID(),
|
if (!EffectManager::DoEffect(mEffects[i]->GetID(),
|
||||||
*project,
|
*project,
|
||||||
EffectManager::kConfigured))
|
EffectManager::kConfigured))
|
||||||
// If any effect fails (or throws), then stop.
|
// If any effect fails (or throws), then stop.
|
||||||
|
@ -7,18 +7,11 @@
|
|||||||
#include "../CommonCommandFlags.h"
|
#include "../CommonCommandFlags.h"
|
||||||
#include "../FreqWindow.h"
|
#include "../FreqWindow.h"
|
||||||
#include "../Menus.h"
|
#include "../Menus.h"
|
||||||
#include "../MissingAliasFileDialog.h"
|
|
||||||
#include "../PluginManager.h"
|
#include "../PluginManager.h"
|
||||||
#include "../Prefs.h"
|
#include "../Prefs.h"
|
||||||
#include "../Project.h"
|
#include "../Project.h"
|
||||||
#include "../ProjectHistory.h"
|
|
||||||
#include "../ProjectSettings.h"
|
|
||||||
#include "../ProjectWindow.h"
|
#include "../ProjectWindow.h"
|
||||||
#include "../Screenshot.h"
|
#include "../Screenshot.h"
|
||||||
#include "../SelectUtilities.h"
|
|
||||||
#include "../TrackPanel.h"
|
|
||||||
#include "../ViewInfo.h"
|
|
||||||
#include "../WaveTrack.h"
|
|
||||||
#include "../commands/CommandContext.h"
|
#include "../commands/CommandContext.h"
|
||||||
#include "../commands/CommandManager.h"
|
#include "../commands/CommandManager.h"
|
||||||
#include "../commands/ScreenshotCommand.h"
|
#include "../commands/ScreenshotCommand.h"
|
||||||
@ -417,135 +410,6 @@ MenuTable::BaseItemPtrs PopulateMacrosMenu( CommandFlag flags );
|
|||||||
|
|
||||||
namespace PluginActions {
|
namespace PluginActions {
|
||||||
|
|
||||||
// exported helper functions
|
|
||||||
|
|
||||||
/// DoEffect() takes a PluginID and has the EffectManager execute the associated
|
|
||||||
/// effect.
|
|
||||||
///
|
|
||||||
/// At the moment flags are used only to indicate whether to prompt for
|
|
||||||
// parameters, whether to save the state to history and whether to allow
|
|
||||||
/// 'Repeat Last Effect'.
|
|
||||||
bool DoEffect(
|
|
||||||
const PluginID & ID, const CommandContext &context, unsigned flags )
|
|
||||||
{
|
|
||||||
AudacityProject &project = context.project;
|
|
||||||
const auto &settings = ProjectSettings::Get( project );
|
|
||||||
auto &tracks = TrackList::Get( project );
|
|
||||||
auto &trackPanel = TrackPanel::Get( project );
|
|
||||||
auto &trackFactory = TrackFactory::Get( project );
|
|
||||||
auto rate = settings.GetRate();
|
|
||||||
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
|
|
||||||
auto &commandManager = CommandManager::Get( project );
|
|
||||||
auto &window = ProjectWindow::Get( project );
|
|
||||||
|
|
||||||
const PluginDescriptor *plug = PluginManager::Get().GetPlugin(ID);
|
|
||||||
if (!plug)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
EffectType type = plug->GetEffectType();
|
|
||||||
|
|
||||||
// Make sure there's no activity since the effect is about to be applied
|
|
||||||
// to the project's tracks. Mainly for Apply during RTP, but also used
|
|
||||||
// for batch commands
|
|
||||||
if (flags & EffectManager::kConfigured)
|
|
||||||
{
|
|
||||||
TransportActions::DoStop(project);
|
|
||||||
SelectUtilities::SelectAllIfNone( project );
|
|
||||||
}
|
|
||||||
|
|
||||||
MissingAliasFilesDialog::SetShouldShow(true);
|
|
||||||
|
|
||||||
auto nTracksOriginally = tracks.size();
|
|
||||||
wxWindow *focus = wxWindow::FindFocus();
|
|
||||||
wxWindow *parent = nullptr;
|
|
||||||
if (focus != nullptr) {
|
|
||||||
parent = focus->GetParent();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool success = false;
|
|
||||||
auto cleanup = finally( [&] {
|
|
||||||
|
|
||||||
if (!success) {
|
|
||||||
// For now, we're limiting realtime preview to a single effect, so
|
|
||||||
// make sure the menus reflect that fact that one may have just been
|
|
||||||
// opened.
|
|
||||||
MenuManager::Get(project).UpdateMenus( false );
|
|
||||||
}
|
|
||||||
|
|
||||||
} );
|
|
||||||
|
|
||||||
int count = 0;
|
|
||||||
bool clean = true;
|
|
||||||
for (auto t : tracks.Selected< const WaveTrack >()) {
|
|
||||||
if (t->GetEndTime() != 0.0)
|
|
||||||
clean = false;
|
|
||||||
count++;
|
|
||||||
}
|
|
||||||
|
|
||||||
EffectManager & em = EffectManager::Get();
|
|
||||||
|
|
||||||
success = em.DoEffect(ID, &window, rate,
|
|
||||||
&tracks, &trackFactory, &selectedRegion,
|
|
||||||
(flags & EffectManager::kConfigured) == 0);
|
|
||||||
|
|
||||||
if (!success)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (em.GetSkipStateFlag())
|
|
||||||
flags = flags | EffectManager::kSkipState;
|
|
||||||
|
|
||||||
if (!(flags & EffectManager::kSkipState))
|
|
||||||
{
|
|
||||||
wxString shortDesc = em.GetCommandName(ID);
|
|
||||||
wxString longDesc = em.GetCommandDescription(ID);
|
|
||||||
ProjectHistory::Get( project ).PushState(longDesc, shortDesc);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(flags & EffectManager::kDontRepeatLast))
|
|
||||||
{
|
|
||||||
// Only remember a successful effect, don't remember insert,
|
|
||||||
// or analyze effects.
|
|
||||||
if (type == EffectTypeProcess) {
|
|
||||||
wxString shortDesc = em.GetCommandName(ID);
|
|
||||||
MenuManager::Get(project).mLastEffect = ID;
|
|
||||||
wxString lastEffectDesc;
|
|
||||||
/* i18n-hint: %s will be the name of the effect which will be
|
|
||||||
* repeated if this menu item is chosen */
|
|
||||||
lastEffectDesc.Printf(_("Repeat %s"), shortDesc);
|
|
||||||
commandManager.Modify(wxT("RepeatLastEffect"), lastEffectDesc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//STM:
|
|
||||||
//The following automatically re-zooms after sound was generated.
|
|
||||||
// IMO, it was disorienting, removing to try out without re-fitting
|
|
||||||
//mchinen:12/14/08 reapplying for generate effects
|
|
||||||
if (type == EffectTypeGenerate)
|
|
||||||
{
|
|
||||||
if (count == 0 || (clean && selectedRegion.t0() == 0.0))
|
|
||||||
ViewActions::DoZoomFit(project);
|
|
||||||
// trackPanel->Refresh(false);
|
|
||||||
}
|
|
||||||
window.RedrawProject();
|
|
||||||
if (focus != nullptr && focus->GetParent()==parent) {
|
|
||||||
focus->SetFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
// A fix for Bug 63
|
|
||||||
// New tracks added? Scroll them into view so that user sees them.
|
|
||||||
// Don't care what track type. An analyser might just have added a
|
|
||||||
// Label track and we want to see it.
|
|
||||||
if( tracks.size() > nTracksOriginally ){
|
|
||||||
// 0.0 is min scroll position, 1.0 is max scroll position.
|
|
||||||
trackPanel.VerticalScroll( 1.0 );
|
|
||||||
} else {
|
|
||||||
trackPanel.EnsureVisible(trackPanel.GetFirstSelectedTrack());
|
|
||||||
trackPanel.Refresh(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Menu handler functions
|
// Menu handler functions
|
||||||
|
|
||||||
struct Handler : CommandHandlerObject {
|
struct Handler : CommandHandlerObject {
|
||||||
@ -559,7 +423,7 @@ void OnManageGenerators(const CommandContext &context)
|
|||||||
void OnEffect(const CommandContext &context)
|
void OnEffect(const CommandContext &context)
|
||||||
{
|
{
|
||||||
// using GET to interpret parameter as a PluginID
|
// using GET to interpret parameter as a PluginID
|
||||||
DoEffect(context.parameter.GET(), context, 0);
|
EffectManager::DoEffect(context.parameter.GET(), context, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnManageEffects(const CommandContext &context)
|
void OnManageEffects(const CommandContext &context)
|
||||||
@ -573,7 +437,8 @@ void OnRepeatLastEffect(const CommandContext &context)
|
|||||||
auto lastEffect = MenuManager::Get(context.project).mLastEffect;
|
auto lastEffect = MenuManager::Get(context.project).mLastEffect;
|
||||||
if (!lastEffect.empty())
|
if (!lastEffect.empty())
|
||||||
{
|
{
|
||||||
DoEffect( lastEffect, context, EffectManager::kConfigured );
|
EffectManager::DoEffect(
|
||||||
|
lastEffect, context, EffectManager::kConfigured );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -674,7 +674,7 @@ void OnNewTimeTrack(const CommandContext &context)
|
|||||||
|
|
||||||
void OnStereoToMono(const CommandContext &context)
|
void OnStereoToMono(const CommandContext &context)
|
||||||
{
|
{
|
||||||
PluginActions::DoEffect(
|
EffectManager::DoEffect(
|
||||||
EffectManager::Get().GetEffectByIdentifier(wxT("StereoToMono")),
|
EffectManager::Get().GetEffectByIdentifier(wxT("StereoToMono")),
|
||||||
context,
|
context,
|
||||||
EffectManager::kConfigured);
|
EffectManager::kConfigured);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user