mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-16 16:10:06 +02:00
MacroCommands remembers a reference to project...
... Eliminating several GetActiveProject calls, notably including those where we construct a CommandContext for executing commands.
This commit is contained in:
parent
f85f4db704
commit
c39718fa1f
@ -87,7 +87,8 @@ static const std::pair<TranslatableString, CommandID> SpecialCommands[] = {
|
|||||||
// end CLEANSPEECH remnant
|
// end CLEANSPEECH remnant
|
||||||
|
|
||||||
MacroCommands::MacroCommands( AudacityProject &project )
|
MacroCommands::MacroCommands( AudacityProject &project )
|
||||||
: mExporter{ project }
|
: mProject{ project }
|
||||||
|
, mExporter{ project }
|
||||||
{
|
{
|
||||||
ResetMacro();
|
ResetMacro();
|
||||||
|
|
||||||
@ -483,7 +484,7 @@ wxString MacroCommands::PromptForPresetFor(const CommandID & command, const wxSt
|
|||||||
|
|
||||||
double MacroCommands::GetEndTime()
|
double MacroCommands::GetEndTime()
|
||||||
{
|
{
|
||||||
AudacityProject *project = GetActiveProject();
|
AudacityProject *project = &mProject;
|
||||||
if( project == NULL )
|
if( project == NULL )
|
||||||
{
|
{
|
||||||
//AudacityMessageBox( XO("No project to process!") );
|
//AudacityMessageBox( XO("No project to process!") );
|
||||||
@ -495,9 +496,8 @@ double MacroCommands::GetEndTime()
|
|||||||
return endTime;
|
return endTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MacroCommands::IsMono()
|
bool MacroCommands::IsMono( AudacityProject *project )
|
||||||
{
|
{
|
||||||
AudacityProject *project = GetActiveProject();
|
|
||||||
if( project == NULL )
|
if( project == NULL )
|
||||||
{
|
{
|
||||||
//AudacityMessageBox( XO("No project and no Audio to process!") );
|
//AudacityMessageBox( XO("No project and no Audio to process!") );
|
||||||
@ -568,7 +568,7 @@ wxString MacroCommands::BuildCleanFileName(const FilePath &fileName,
|
|||||||
bool MacroCommands::WriteMp3File( const wxString & Name, int bitrate )
|
bool MacroCommands::WriteMp3File( const wxString & Name, int bitrate )
|
||||||
{ //check if current project is mono or stereo
|
{ //check if current project is mono or stereo
|
||||||
unsigned numChannels = 2;
|
unsigned numChannels = 2;
|
||||||
if (IsMono()) {
|
if (IsMono( &mProject )) {
|
||||||
numChannels = 1;
|
numChannels = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -622,10 +622,10 @@ bool MacroCommands::ApplySpecialCommand(
|
|||||||
if (ReportAndSkip(friendlyCommand, params))
|
if (ReportAndSkip(friendlyCommand, params))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
AudacityProject *project = GetActiveProject();
|
AudacityProject *project = &mProject;
|
||||||
|
|
||||||
unsigned numChannels = 1; //used to switch between mono and stereo export
|
unsigned numChannels = 1; //used to switch between mono and stereo export
|
||||||
if (IsMono()) {
|
if (IsMono( &mProject )) {
|
||||||
numChannels = 1; //export in mono
|
numChannels = 1; //export in mono
|
||||||
} else {
|
} else {
|
||||||
numChannels = 2; //export in stereo
|
numChannels = 2; //export in stereo
|
||||||
@ -771,7 +771,7 @@ bool MacroCommands::ApplyEffectCommand(
|
|||||||
if (!plug)
|
if (!plug)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
AudacityProject *project = GetActiveProject();
|
AudacityProject *project = &mProject;
|
||||||
|
|
||||||
// FIXME: for later versions may want to not select-all in batch mode.
|
// FIXME: for later versions may want to not select-all in batch mode.
|
||||||
// IF nothing selected, THEN select everything
|
// IF nothing selected, THEN select everything
|
||||||
@ -861,12 +861,12 @@ bool MacroCommands::ApplyCommand( const TranslatableString &friendlyCommand,
|
|||||||
if( pContext )
|
if( pContext )
|
||||||
return ApplyEffectCommand(
|
return ApplyEffectCommand(
|
||||||
ID, friendlyCommand, command, params, *pContext);
|
ID, friendlyCommand, command, params, *pContext);
|
||||||
const CommandContext context( *GetActiveProject() );
|
const CommandContext context( mProject );
|
||||||
return ApplyEffectCommand(
|
return ApplyEffectCommand(
|
||||||
ID, friendlyCommand, command, params, context);
|
ID, friendlyCommand, command, params, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
AudacityProject *project = GetActiveProject();
|
AudacityProject *project = &mProject;
|
||||||
auto &manager = CommandManager::Get( *project );
|
auto &manager = CommandManager::Get( *project );
|
||||||
if( pContext ){
|
if( pContext ){
|
||||||
if( HandleTextualCommand(
|
if( HandleTextualCommand(
|
||||||
@ -878,7 +878,7 @@ bool MacroCommands::ApplyCommand( const TranslatableString &friendlyCommand,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
const CommandContext context( *GetActiveProject() );
|
const CommandContext context( mProject );
|
||||||
if( HandleTextualCommand(
|
if( HandleTextualCommand(
|
||||||
manager, command, context, AlwaysEnabledFlag, true ) )
|
manager, command, context, AlwaysEnabledFlag, true ) )
|
||||||
return true;
|
return true;
|
||||||
@ -896,7 +896,7 @@ bool MacroCommands::ApplyCommandInBatchMode(
|
|||||||
const CommandID & command, const wxString ¶ms,
|
const CommandID & command, const wxString ¶ms,
|
||||||
CommandContext const * pContext)
|
CommandContext const * pContext)
|
||||||
{
|
{
|
||||||
AudacityProject *project = GetActiveProject();
|
AudacityProject *project = &mProject;
|
||||||
auto &settings = ProjectSettings::Get( *project );
|
auto &settings = ProjectSettings::Get( *project );
|
||||||
// Recalc flags and enable items that may have become enabled.
|
// Recalc flags and enable items that may have become enabled.
|
||||||
MenuManager::Get(*project).UpdateMenus(false);
|
MenuManager::Get(*project).UpdateMenus(false);
|
||||||
@ -931,7 +931,7 @@ bool MacroCommands::ApplyMacro(
|
|||||||
|
|
||||||
mFileName = filename;
|
mFileName = filename;
|
||||||
|
|
||||||
AudacityProject *proj = GetActiveProject();
|
AudacityProject *proj = &mProject;
|
||||||
bool res = false;
|
bool res = false;
|
||||||
auto cleanup2 = finally( [&] {
|
auto cleanup2 = finally( [&] {
|
||||||
if (!res) {
|
if (!res) {
|
||||||
|
@ -87,7 +87,7 @@ class MacroCommands final {
|
|||||||
const FileExtension &extension);
|
const FileExtension &extension);
|
||||||
bool WriteMp3File( const wxString & Name, int bitrate );
|
bool WriteMp3File( const wxString & Name, int bitrate );
|
||||||
double GetEndTime();
|
double GetEndTime();
|
||||||
static bool IsMono();
|
static bool IsMono( AudacityProject *project );
|
||||||
|
|
||||||
// These commands do not depend on the command list.
|
// These commands do not depend on the command list.
|
||||||
static void MigrateLegacyChains();
|
static void MigrateLegacyChains();
|
||||||
@ -123,6 +123,9 @@ class MacroCommands final {
|
|||||||
void Split(const wxString & str, wxString & command, wxString & param);
|
void Split(const wxString & str, wxString & command, wxString & param);
|
||||||
wxString Join(const wxString & command, const wxString & param);
|
wxString Join(const wxString & command, const wxString & param);
|
||||||
|
|
||||||
|
private:
|
||||||
|
AudacityProject &mProject;
|
||||||
|
|
||||||
CommandIDs mCommandMacro;
|
CommandIDs mCommandMacro;
|
||||||
wxArrayString mParamsMacro;
|
wxArrayString mParamsMacro;
|
||||||
bool mAbort;
|
bool mAbort;
|
||||||
|
@ -92,7 +92,7 @@ void DoExport( AudacityProject &project, const FileExtension & Format )
|
|||||||
FileHistory::Global().AddFileToHistory(filename);
|
FileHistory::Global().AddFileToHistory(filename);
|
||||||
// We're in batch mode, the file does not exist already.
|
// We're in batch mode, the file does not exist already.
|
||||||
// We really can proceed without prompting.
|
// We really can proceed without prompting.
|
||||||
int nChannels = MacroCommands::IsMono() ? 1 : 2;
|
int nChannels = MacroCommands::IsMono( &project ) ? 1 : 2;
|
||||||
e.Process(
|
e.Process(
|
||||||
nChannels, // numChannels,
|
nChannels, // numChannels,
|
||||||
Format, // type,
|
Format, // type,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user