mirror of
https://github.com/cookiengineer/audacity
synced 2025-04-30 15:49:41 +02:00
2582 enh repeat last process (#722)
* Enhancement: Add Repeat Last Process * add include UndoManager.h
This commit is contained in:
parent
8aaecdc596
commit
549dacf054
@ -238,11 +238,32 @@ const ReservedCommandFlag&
|
||||
}
|
||||
}; return flag; }
|
||||
const ReservedCommandFlag&
|
||||
HasLastEffectFlag() { static ReservedCommandFlag flag{
|
||||
HasLastGeneratorFlag() { static ReservedCommandFlag flag{
|
||||
[](const AudacityProject &project){
|
||||
return !MenuManager::Get( project ).mLastEffect.empty();
|
||||
return !MenuManager::Get( project ).mLastGenerator.empty();
|
||||
}
|
||||
}; return flag; }
|
||||
const ReservedCommandFlag&
|
||||
HasLastEffectFlag() { static ReservedCommandFlag flag{
|
||||
[](const AudacityProject &project) {
|
||||
return !MenuManager::Get(project).mLastEffect.empty();
|
||||
}
|
||||
}; return flag;
|
||||
}
|
||||
const ReservedCommandFlag&
|
||||
HasLastAnalyzerFlag() { static ReservedCommandFlag flag{
|
||||
[](const AudacityProject &project) {
|
||||
return !MenuManager::Get(project).mLastAnalyzer.empty();
|
||||
}
|
||||
}; return flag;
|
||||
}
|
||||
const ReservedCommandFlag&
|
||||
HasLastToolFlag() { static ReservedCommandFlag flag{
|
||||
[](const AudacityProject &project) {
|
||||
return !MenuManager::Get(project).mLastTool.empty();
|
||||
}
|
||||
}; return flag;
|
||||
}
|
||||
const ReservedCommandFlag&
|
||||
UndoAvailableFlag() { static ReservedCommandFlag flag{
|
||||
[](const AudacityProject &project){
|
||||
|
@ -38,7 +38,10 @@ extern AUDACITY_DLL_API const ReservedCommandFlag
|
||||
extern AUDACITY_DLL_API const ReservedCommandFlag
|
||||
&LabelTracksExistFlag(),
|
||||
&UnsavedChangesFlag(),
|
||||
&HasLastGeneratorFlag(),
|
||||
&HasLastEffectFlag(),
|
||||
&HasLastAnalyzerFlag(),
|
||||
&HasLastToolFlag(),
|
||||
&UndoAvailableFlag(),
|
||||
&RedoAvailableFlag(),
|
||||
&ZoomInAvailableFlag(),
|
||||
|
@ -30,6 +30,7 @@ class ViewInfo;
|
||||
enum EffectType : int;
|
||||
|
||||
typedef wxString PluginID;
|
||||
typedef wxString MacroID;
|
||||
typedef wxArrayString PluginIDs;
|
||||
|
||||
namespace Registry{ class Visitor; }
|
||||
@ -48,7 +49,11 @@ public:
|
||||
CommandFlag mLastFlags;
|
||||
|
||||
// Last effect applied to this project
|
||||
PluginID mLastGenerator{};
|
||||
PluginID mLastEffect{};
|
||||
PluginID mLastAnalyzer{};
|
||||
PluginID mLastTool{};
|
||||
bool mLastToolIsMacro;
|
||||
};
|
||||
|
||||
struct ToolbarMenuVisitor;
|
||||
|
@ -57,6 +57,8 @@ public:
|
||||
kSkipState = 0x02,
|
||||
// Flag used to disable "Repeat Last Effect"
|
||||
kDontRepeatLast = 0x04,
|
||||
// Flag used to disable "Select All during Repeat Generator Effect"
|
||||
kRepeatGen = 0x08,
|
||||
};
|
||||
|
||||
/** Get the singleton instance of the EffectManager. Probably not safe
|
||||
|
@ -1882,7 +1882,10 @@ wxDialog *EffectUI::DialogFactory( wxWindow &parent, EffectHostInterface *pHost,
|
||||
if (flags & EffectManager::kConfigured)
|
||||
{
|
||||
ProjectAudioManager::Get( project ).Stop();
|
||||
SelectUtilities::SelectAllIfNone( project );
|
||||
//Don't Select All if repeating Generator Effect
|
||||
if (!(flags & EffectManager::kConfigured)) {
|
||||
SelectUtilities::SelectAllIfNone(project);
|
||||
}
|
||||
}
|
||||
|
||||
auto nTracksOriginally = tracks.size();
|
||||
@ -1951,15 +1954,29 @@ wxDialog *EffectUI::DialogFactory( wxWindow &parent, EffectHostInterface *pHost,
|
||||
|
||||
if (!(flags & EffectManager::kDontRepeatLast))
|
||||
{
|
||||
// Only remember a successful effect, don't remember insert,
|
||||
// or analyze effects.
|
||||
if (type == EffectTypeProcess) {
|
||||
// Remember a successful generator, effect, analyzer, or tool Process
|
||||
auto shortDesc = em.GetCommandName(ID);
|
||||
MenuManager::Get(project).mLastEffect = ID;
|
||||
/* i18n-hint: %s will be the name of the effect which will be
|
||||
* repeated if this menu item is chosen */
|
||||
auto lastEffectDesc = XO("Repeat %s").Format( shortDesc );
|
||||
commandManager.Modify(wxT("RepeatLastEffect"), lastEffectDesc);
|
||||
auto lastEffectDesc = XO("Repeat %s").Format(shortDesc);
|
||||
switch ( type ) {
|
||||
case EffectTypeGenerate:
|
||||
commandManager.Modify(wxT("RepeatLastGenerator"), lastEffectDesc);
|
||||
MenuManager::Get(project).mLastGenerator = ID;
|
||||
break;
|
||||
case EffectTypeProcess:
|
||||
commandManager.Modify(wxT("RepeatLastEffect"), lastEffectDesc);
|
||||
MenuManager::Get(project).mLastEffect = ID;
|
||||
break;
|
||||
case EffectTypeAnalyze:
|
||||
commandManager.Modify(wxT("RepeatLastAnalyzer"), lastEffectDesc);
|
||||
MenuManager::Get(project).mLastAnalyzer = ID;
|
||||
break;
|
||||
case EffectTypeTool:
|
||||
commandManager.Modify(wxT("RepeatLastTool"), lastEffectDesc);
|
||||
MenuManager::Get(project).mLastTool = ID;
|
||||
MenuManager::Get(project).mLastToolIsMacro = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "../ProjectSelectionManager.h"
|
||||
#include "../toolbars/ToolManager.h"
|
||||
#include "../Screenshot.h"
|
||||
#include "../UndoManager.h"
|
||||
#include "../commands/CommandContext.h"
|
||||
#include "../commands/CommandManager.h"
|
||||
#include "../commands/ScreenshotCommand.h"
|
||||
@ -427,16 +428,50 @@ void OnManageEffects(const CommandContext &context)
|
||||
DoManagePluginsMenu(project, EffectTypeProcess);
|
||||
}
|
||||
|
||||
void OnRepeatLastGenerator(const CommandContext &context)
|
||||
{
|
||||
auto lastEffect = MenuManager::Get(context.project).mLastGenerator;
|
||||
if (!lastEffect.empty())
|
||||
{
|
||||
EffectUI::DoEffect(
|
||||
lastEffect, context, EffectManager::kConfigured | EffectManager::kRepeatGen);
|
||||
}
|
||||
}
|
||||
|
||||
void OnRepeatLastEffect(const CommandContext &context)
|
||||
{
|
||||
auto lastEffect = MenuManager::Get(context.project).mLastEffect;
|
||||
if (!lastEffect.empty())
|
||||
{
|
||||
EffectUI::DoEffect(
|
||||
lastEffect, context, EffectManager::kConfigured );
|
||||
lastEffect, context, EffectManager::kConfigured);
|
||||
}
|
||||
}
|
||||
|
||||
void OnRepeatLastAnalyzer(const CommandContext &context)
|
||||
{
|
||||
auto lastEffect = MenuManager::Get(context.project).mLastAnalyzer;
|
||||
if (!lastEffect.empty())
|
||||
{
|
||||
EffectUI::DoEffect(
|
||||
lastEffect, context, EffectManager::kConfigured);
|
||||
}
|
||||
}
|
||||
|
||||
void OnRepeatLastTool(const CommandContext &context)
|
||||
{
|
||||
auto lastEffect = MenuManager::Get(context.project).mLastTool;
|
||||
if (!lastEffect.empty())
|
||||
{
|
||||
if (!MenuManager::Get(context.project).mLastToolIsMacro)
|
||||
EffectUI::DoEffect(
|
||||
lastEffect, context, EffectManager::kConfigured);
|
||||
else
|
||||
OnApplyMacroDirectlyByName(context, lastEffect);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void OnManageAnalyzers(const CommandContext &context)
|
||||
{
|
||||
auto &project = context.project;
|
||||
@ -508,13 +543,17 @@ void OnDetectUpstreamDropouts(const CommandContext &context)
|
||||
}
|
||||
|
||||
void OnApplyMacroDirectly(const CommandContext &context )
|
||||
{
|
||||
const MacroID& Name = context.parameter.GET();
|
||||
OnApplyMacroDirectlyByName(context, Name);
|
||||
}
|
||||
void OnApplyMacroDirectlyByName(const CommandContext& context, const MacroID& Name)
|
||||
{
|
||||
auto &project = context.project;
|
||||
auto &window = ProjectWindow::Get( project );
|
||||
|
||||
//wxLogDebug( "Macro was: %s", context.parameter);
|
||||
ApplyMacroDialog dlg( &window, project );
|
||||
const auto &Name = context.parameter;
|
||||
//const auto &Name = context.parameter;
|
||||
|
||||
// We used numbers previously, but macros could get renumbered, making
|
||||
// macros containing macros unpredictable.
|
||||
@ -526,7 +565,24 @@ void OnApplyMacroDirectly(const CommandContext &context )
|
||||
#else
|
||||
dlg.ApplyMacroToProject( Name, false );
|
||||
#endif
|
||||
/* i18n-hint: %s will be the name of the macro which will be
|
||||
* repeated if this menu item is chosen */
|
||||
MenuManager::ModifyUndoMenuItems( project );
|
||||
|
||||
TranslatableString desc;
|
||||
EffectManager& em = EffectManager::Get();
|
||||
auto shortDesc = em.GetCommandName(Name);
|
||||
auto& undoManager = UndoManager::Get(project);
|
||||
auto& commandManager = CommandManager::Get(project);
|
||||
int cur = undoManager.GetCurrentState();
|
||||
if (undoManager.UndoAvailable()) {
|
||||
undoManager.GetShortDescription(cur, &desc);
|
||||
commandManager.Modify(wxT("RepeatLastTool"), XXO("&Repeat %s")
|
||||
.Format(desc));
|
||||
MenuManager::Get(project).mLastTool = Name;
|
||||
MenuManager::Get(project).mLastToolIsMacro = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void OnAudacityCommand(const CommandContext & ctx)
|
||||
@ -730,6 +786,26 @@ BaseItemSharedPtr GenerateMenu()
|
||||
),
|
||||
#endif
|
||||
|
||||
Section("RepeatLast",
|
||||
// Delayed evaluation:
|
||||
[](AudacityProject &project)
|
||||
{
|
||||
const auto &lastGenerator = MenuManager::Get(project).mLastGenerator;
|
||||
TranslatableString buildMenuLabel;
|
||||
if (!lastGenerator.empty())
|
||||
buildMenuLabel = XO("Repeat %s")
|
||||
.Format(EffectManager::Get().GetCommandName(lastGenerator));
|
||||
else
|
||||
buildMenuLabel = XO("Repeat Last Generator");
|
||||
|
||||
return Command(wxT("RepeatLastGenerator"), buildMenuLabel,
|
||||
FN(OnRepeatLastGenerator),
|
||||
AudioIONotBusyFlag() |
|
||||
HasLastGeneratorFlag(),
|
||||
wxT(" "), findCommandHandler);
|
||||
}
|
||||
),
|
||||
|
||||
Section( "Generators",
|
||||
// Delayed evaluation:
|
||||
[](AudacityProject &)
|
||||
@ -823,6 +899,26 @@ BaseItemSharedPtr AnalyzeMenu()
|
||||
),
|
||||
#endif
|
||||
|
||||
Section("RepeatLast",
|
||||
// Delayed evaluation:
|
||||
[](AudacityProject &project)
|
||||
{
|
||||
const auto &lastAnalyzer = MenuManager::Get(project).mLastAnalyzer;
|
||||
TranslatableString buildMenuLabel;
|
||||
if (!lastAnalyzer.empty())
|
||||
buildMenuLabel = XO("Repeat %s")
|
||||
.Format(EffectManager::Get().GetCommandName(lastAnalyzer));
|
||||
else
|
||||
buildMenuLabel = XO("Repeat Last Analyzer");
|
||||
|
||||
return Command(wxT("RepeatLastAnalyzer"), buildMenuLabel,
|
||||
FN(OnRepeatLastAnalyzer),
|
||||
AudioIONotBusyFlag() | TimeSelectedFlag() |
|
||||
WaveTracksSelectedFlag() | HasLastAnalyzerFlag(),
|
||||
wxT(" "), findCommandHandler);
|
||||
}
|
||||
),
|
||||
|
||||
Section( "Analyzers",
|
||||
Items( "Windows" ),
|
||||
|
||||
@ -859,7 +955,27 @@ BaseItemSharedPtr ToolsMenu()
|
||||
|
||||
#endif
|
||||
|
||||
Command( wxT("ManageMacros"), XXO("&Macros..."),
|
||||
Section( "RepeatLast",
|
||||
// Delayed evaluation:
|
||||
[](AudacityProject &project)
|
||||
{
|
||||
const auto &lastTool = MenuManager::Get(project).mLastTool;
|
||||
TranslatableString buildMenuLabel;
|
||||
if (!lastTool.empty())
|
||||
buildMenuLabel = XO("Repeat %s")
|
||||
.Format( EffectManager::Get().GetCommandName(lastTool) );
|
||||
else
|
||||
buildMenuLabel = XO("Repeat Last Tool");
|
||||
|
||||
return Command( wxT("RepeatLastTool"), buildMenuLabel,
|
||||
FN(OnRepeatLastTool),
|
||||
AudioIONotBusyFlag() |
|
||||
HasLastToolFlag(),
|
||||
wxT(" "), findCommandHandler );
|
||||
}
|
||||
),
|
||||
|
||||
Command( wxT("ManageMacros"), XXO("&Macros..."),
|
||||
FN(OnManageMacros), AudioIONotBusyFlag() ),
|
||||
|
||||
Menu( wxT("Macros"), XXO("&Apply Macro"),
|
||||
|
Loading…
x
Reference in New Issue
Block a user