1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 08:09:32 +02:00

Remove many calls to GetActiveProject

This commit is contained in:
Paul Licameli 2020-01-02 14:05:49 -05:00
commit ba5ce23668
37 changed files with 171 additions and 144 deletions

View File

@ -61,11 +61,12 @@ BEGIN_EVENT_TABLE(MacroCommandDialog, wxDialogWrapper)
EVT_LIST_ITEM_SELECTED(CommandsListID, MacroCommandDialog::OnItemSelected)
END_EVENT_TABLE();
MacroCommandDialog::MacroCommandDialog(wxWindow * parent, wxWindowID id):
MacroCommandDialog::MacroCommandDialog(
wxWindow * parent, wxWindowID id, AudacityProject &project):
wxDialogWrapper(parent, id, XO("Select Command"),
wxDefaultPosition, wxDefaultSize,
wxCAPTION | wxRESIZE_BORDER)
, mCatalog( GetActiveProject() )
, mCatalog{ &project }
{
SetLabel(XO("Select Command")); // Provide visual label
SetName(XO("Select Command")); // Provide audible label

View File

@ -21,12 +21,13 @@ class wxTextCtrl;
class wxListCtrl;
class wxListEvent;
class wxButton;
class AudacityProject;
class ShuttleGui;
class MacroCommandDialog final : public wxDialogWrapper {
public:
// constructors and destructors
MacroCommandDialog(wxWindow *parent, wxWindowID id);
MacroCommandDialog(wxWindow *parent, wxWindowID id, AudacityProject &project);
void SetCommandAndParams(const CommandID &Command, const wxString &Params);
public:
CommandID mSelectedCommand;

View File

@ -86,7 +86,9 @@ static const std::pair<TranslatableString, CommandID> SpecialCommands[] = {
};
// end CLEANSPEECH remnant
MacroCommands::MacroCommands()
MacroCommands::MacroCommands( AudacityProject &project )
: mProject{ project }
, mExporter{ project }
{
ResetMacro();
@ -482,7 +484,7 @@ wxString MacroCommands::PromptForPresetFor(const CommandID & command, const wxSt
double MacroCommands::GetEndTime()
{
AudacityProject *project = GetActiveProject();
AudacityProject *project = &mProject;
if( project == NULL )
{
//AudacityMessageBox( XO("No project to process!") );
@ -494,9 +496,8 @@ double MacroCommands::GetEndTime()
return endTime;
}
bool MacroCommands::IsMono()
bool MacroCommands::IsMono( AudacityProject *project )
{
AudacityProject *project = GetActiveProject();
if( project == NULL )
{
//AudacityMessageBox( XO("No project and no Audio to process!") );
@ -567,19 +568,18 @@ wxString MacroCommands::BuildCleanFileName(const FilePath &fileName,
bool MacroCommands::WriteMp3File( const wxString & Name, int bitrate )
{ //check if current project is mono or stereo
unsigned numChannels = 2;
if (IsMono()) {
if (IsMono( &mProject )) {
numChannels = 1;
}
double endTime = GetEndTime();
if( endTime <= 0.0f )
return false;
AudacityProject *project = GetActiveProject();
if( bitrate <=0 )
{
// 'No' bitrate given, use the current default.
// Use Mp3Stereo to control if export is to a stereo or mono file
return mExporter.Process(project, numChannels, wxT("MP3"), Name, false, 0.0, endTime);
return mExporter.Process(numChannels, wxT("MP3"), Name, false, 0.0, endTime);
}
@ -596,7 +596,7 @@ bool MacroCommands::WriteMp3File( const wxString & Name, int bitrate )
} );
// Use Mp3Stereo to control if export is to a stereo or mono file
rc = mExporter.Process(project, numChannels, wxT("MP3"), Name, false, 0.0, endTime);
rc = mExporter.Process(numChannels, wxT("MP3"), Name, false, 0.0, endTime);
return rc;
}
@ -622,10 +622,10 @@ bool MacroCommands::ApplySpecialCommand(
if (ReportAndSkip(friendlyCommand, params))
return true;
AudacityProject *project = GetActiveProject();
AudacityProject *project = &mProject;
unsigned numChannels = 1; //used to switch between mono and stereo export
if (IsMono()) {
if (IsMono( &mProject )) {
numChannels = 1; //export in mono
} else {
numChannels = 2; //export in stereo
@ -679,7 +679,7 @@ bool MacroCommands::ApplySpecialCommand(
if (endTime <= 0.0f) {
return false;
}
return mExporter.Process(project, numChannels, wxT("WAV"), filename, false, 0.0, endTime);
return mExporter.Process(numChannels, wxT("WAV"), filename, false, 0.0, endTime);
} else if (command == wxT("ExportOgg")) {
#ifdef USE_LIBVORBIS
filename.Replace(wxT(".mp3"), wxT(".ogg"), false);
@ -687,7 +687,7 @@ bool MacroCommands::ApplySpecialCommand(
if (endTime <= 0.0f) {
return false;
}
return mExporter.Process(project, numChannels, wxT("OGG"), filename, false, 0.0, endTime);
return mExporter.Process(numChannels, wxT("OGG"), filename, false, 0.0, endTime);
#else
AudacityMessageBox( XO(
"Ogg Vorbis support is not included in this build of Audacity"));
@ -700,7 +700,7 @@ bool MacroCommands::ApplySpecialCommand(
if (endTime <= 0.0f) {
return false;
}
return mExporter.Process(project, numChannels, wxT("FLAC"), filename, false, 0.0, endTime);
return mExporter.Process(numChannels, wxT("FLAC"), filename, false, 0.0, endTime);
#else
AudacityMessageBox(XO(
"FLAC support is not included in this build of Audacity"));
@ -771,7 +771,7 @@ bool MacroCommands::ApplyEffectCommand(
if (!plug)
return false;
AudacityProject *project = GetActiveProject();
AudacityProject *project = &mProject;
// FIXME: for later versions may want to not select-all in batch mode.
// IF nothing selected, THEN select everything
@ -861,12 +861,12 @@ bool MacroCommands::ApplyCommand( const TranslatableString &friendlyCommand,
if( pContext )
return ApplyEffectCommand(
ID, friendlyCommand, command, params, *pContext);
const CommandContext context( *GetActiveProject() );
const CommandContext context( mProject );
return ApplyEffectCommand(
ID, friendlyCommand, command, params, context);
}
AudacityProject *project = GetActiveProject();
AudacityProject *project = &mProject;
auto &manager = CommandManager::Get( *project );
if( pContext ){
if( HandleTextualCommand(
@ -878,7 +878,7 @@ bool MacroCommands::ApplyCommand( const TranslatableString &friendlyCommand,
}
else
{
const CommandContext context( *GetActiveProject() );
const CommandContext context( mProject );
if( HandleTextualCommand(
manager, command, context, AlwaysEnabledFlag, true ) )
return true;
@ -896,7 +896,7 @@ bool MacroCommands::ApplyCommandInBatchMode(
const CommandID & command, const wxString &params,
CommandContext const * pContext)
{
AudacityProject *project = GetActiveProject();
AudacityProject *project = &mProject;
auto &settings = ProjectSettings::Get( *project );
// Recalc flags and enable items that may have become enabled.
MenuManager::Get(*project).UpdateMenus(false);
@ -931,7 +931,7 @@ bool MacroCommands::ApplyMacro(
mFileName = filename;
AudacityProject *proj = GetActiveProject();
AudacityProject *proj = &mProject;
bool res = false;
auto cleanup2 = finally( [&] {
if (!res) {

View File

@ -59,7 +59,7 @@ class MacroCommands final {
const PluginID & ID, const CommandContext & context, unsigned flags );
// constructors and destructors
MacroCommands();
MacroCommands( AudacityProject &project );
public:
bool ApplyMacro( const MacroCommandsCatalog &catalog,
const wxString & filename = {});
@ -87,7 +87,7 @@ class MacroCommands final {
const FileExtension &extension);
bool WriteMp3File( const wxString & Name, int bitrate );
double GetEndTime();
static bool IsMono();
static bool IsMono( AudacityProject *project );
// These commands do not depend on the command list.
static void MigrateLegacyChains();
@ -123,6 +123,9 @@ class MacroCommands final {
void Split(const wxString & str, wxString & command, wxString & param);
wxString Join(const wxString & command, const wxString & param);
private:
AudacityProject &mProject;
CommandIDs mCommandMacro;
wxArrayString mParamsMacro;
bool mAbort;

View File

@ -80,13 +80,15 @@ BEGIN_EVENT_TABLE(ApplyMacroDialog, wxDialogWrapper)
EVT_BUTTON(wxID_HELP, ApplyMacroDialog::OnHelp)
END_EVENT_TABLE()
ApplyMacroDialog::ApplyMacroDialog(wxWindow * parent, bool bInherited):
ApplyMacroDialog::ApplyMacroDialog(
wxWindow * parent, AudacityProject &project, bool bInherited):
wxDialogWrapper(parent, wxID_ANY, XO("Macros Palette"),
wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
, mCatalog( GetActiveProject() )
, mMacroCommands{ project }
, mProject{ project }
, mCatalog( &project )
{
//AudacityProject * p = GetActiveProject();
mAbort = false;
mbExpanded = false;
if( bInherited )
@ -330,7 +332,7 @@ void ApplyMacroDialog::OnApplyToFiles(wxCommandEvent & WXUNUSED(event))
gPrefs->Write(wxT("/Batch/ActiveMacro"), name);
gPrefs->Flush();
AudacityProject *project = GetActiveProject();
AudacityProject *project = &mProject;
if (!TrackList::Get( *project ).empty()) {
AudacityMessageBox(
XO("Please save and close the current project first.") );
@ -518,8 +520,10 @@ enum {
};
/// Constructor
MacrosWindow::MacrosWindow(wxWindow * parent, bool bExpanded):
ApplyMacroDialog(parent, true)
MacrosWindow::MacrosWindow(
wxWindow * parent, AudacityProject &project, bool bExpanded):
ApplyMacroDialog(parent, project, true)
, mProject{ project }
{
mbExpanded = bExpanded;
auto Title = WindowTitle();
@ -726,7 +730,7 @@ void MacrosWindow::AddItem(const CommandID &Action, const wxString &Params)
void MacrosWindow::UpdateMenus()
{
// OK even on mac, as dialog is modal.
auto p = GetActiveProject();
auto p = &mProject;
MenuManager::Get(*p).RebuildMenuBar(*p);
}
@ -1060,7 +1064,7 @@ void MacrosWindow::InsertCommandAt(int item)
return;
}
MacroCommandDialog d(this, wxID_ANY);
MacroCommandDialog d(this, wxID_ANY, mProject);
if (!d.ShowModal()) {
Raise();

View File

@ -22,12 +22,14 @@ class wxListCtrl;
class wxListEvent;
class wxButton;
class wxTextCtrl;
class AudacityProject;
class ShuttleGui;
class ApplyMacroDialog : public wxDialogWrapper {
public:
// constructors and destructors
ApplyMacroDialog(wxWindow * parent, bool bInherited=false);
ApplyMacroDialog(
wxWindow * parent, AudacityProject &project, bool bInherited=false);
virtual ~ApplyMacroDialog();
public:
// Populate methods NOT virtual.
@ -61,6 +63,7 @@ class ApplyMacroDialog : public wxDialogWrapper {
wxString mMacroBeingRenamed;
protected:
AudacityProject &mProject;
const MacroCommandsCatalog mCatalog;
DECLARE_EVENT_TABLE()
@ -69,7 +72,8 @@ protected:
class MacrosWindow final : public ApplyMacroDialog
{
public:
MacrosWindow(wxWindow * parent, bool bExpanded=true);
MacrosWindow(
wxWindow * parent, AudacityProject &project, bool bExpanded=true);
~MacrosWindow();
void UpdateDisplay( bool bExpanded );
@ -118,6 +122,8 @@ private:
void InsertCommandAt(int item);
bool SaveChanges();
AudacityProject &mProject;
wxButton *mRemove;
wxButton *mRename;
wxButton *mRestore;

View File

@ -697,7 +697,7 @@ bool ProjectFileManager::SaveCopyWaveTracks(const FilePath & strProjectPathName,
// Export all WaveTracks to OGG.
bool bSuccess = true;
Exporter theExporter;
Exporter theExporter{ project };
wxFileName uniqueTrackFileName;
for (auto pTrack : (trackRange + &Track::IsLeader))
{
@ -711,7 +711,7 @@ bool ProjectFileManager::SaveCopyWaveTracks(const FilePath & strProjectPathName,
const auto startTime = channels.min( &Track::GetStartTime );
const auto endTime = channels.max( &Track::GetEndTime );
bSuccess =
theExporter.Process(&project, channels.size(),
theExporter.Process(channels.size(),
fileFormat, uniqueTrackFileName.GetFullPath(), true,
startTime, endTime);
@ -1620,7 +1620,7 @@ bool ProjectFileManager::Import(
auto newTags = oldTags->Duplicate();
Tags::Set( project, newTags );
bool success = Importer::Get().Import(fileName,
bool success = Importer::Get().Import(project, fileName,
&TrackFactory::Get( project ),
newTracks,
newTags.get(),

View File

@ -165,9 +165,11 @@ BEGIN_EVENT_TABLE(TimerRecordDialog, wxDialogWrapper)
END_EVENT_TABLE()
TimerRecordDialog::TimerRecordDialog(wxWindow* parent, bool bAlreadySaved)
TimerRecordDialog::TimerRecordDialog(
wxWindow* parent, AudacityProject &project, bool bAlreadySaved)
: wxDialogWrapper(parent, -1, XO("Audacity Timer Record"), wxDefaultPosition,
wxDefaultSize, wxCAPTION)
, mProject{ project }
{
SetName();
@ -329,7 +331,7 @@ void TimerRecordDialog::OnAutoSavePathButton_Click(wxCommandEvent& WXUNUSED(even
if (fName.empty())
return;
AudacityProject* pProject = GetActiveProject();
AudacityProject* pProject = &mProject;
// If project already exists then abort - we do not allow users to overwrite an existing project
// unless it is the current project.
@ -355,11 +357,10 @@ would overwrite another project.\nPlease try again and select an original name."
void TimerRecordDialog::OnAutoExportPathButton_Click(wxCommandEvent& WXUNUSED(event))
{
AudacityProject* pProject = GetActiveProject();
Exporter eExporter;
Exporter eExporter{ mProject };
// Call the Exporter to set the options required
if (eExporter.SetAutoExportOptions(pProject)) {
if (eExporter.SetAutoExportOptions()) {
// Populate the options so that we can destroy this instance of the Exporter
m_fnAutoExportFile = eExporter.GetAutoExportFileName();
m_iAutoExportFormat = eExporter.GetAutoExportFormat();
@ -424,7 +425,7 @@ void TimerRecordDialog::OnOK(wxCommandEvent& WXUNUSED(event))
// We don't stop the user from starting the recording
// as its possible that they plan to free up some
// space before the recording begins
AudacityProject* pProject = GetActiveProject();
AudacityProject* pProject = &mProject;
auto &projectManager = ProjectManager::Get( *pProject );
// How many minutes do we have left on the disc?
@ -539,7 +540,7 @@ bool TimerRecordDialog::RemoveAllAutoSaveFiles()
/// or if the post recording actions fail.
int TimerRecordDialog::RunWaitDialog()
{
AudacityProject* pProject = GetActiveProject();
AudacityProject* pProject = &mProject;
auto updateResult = ProgressResult::Success;
@ -620,7 +621,7 @@ int TimerRecordDialog::ExecutePostRecordActions(bool bWasStopped) {
// Finally, if there is no post-record action selected then we output
// a dialog detailing what has been carried out instead.
AudacityProject* pProject = GetActiveProject();
AudacityProject* pProject = &mProject;
bool bSaveOK = false;
bool bExportOK = false;
@ -642,10 +643,10 @@ int TimerRecordDialog::ExecutePostRecordActions(bool bWasStopped) {
// Do Automatic Export?
if (m_bAutoExportEnabled) {
Exporter e;
Exporter e{ mProject };
MissingAliasFilesDialog::SetShouldShow(true);
bExportOK = e.ProcessFromTimerRecording(
pProject, false, 0.0, TrackList::Get( *pProject ).GetEndTime(),
false, 0.0, TrackList::Get( *pProject ).GetEndTime(),
m_fnAutoExportFile, m_iAutoExportFormat,
m_iAutoExportSubFormat, m_iAutoExportFilterIndex);
}
@ -930,7 +931,7 @@ void TimerRecordDialog::PopulateOrExchange(ShuttleGui& S)
S.StartMultiColumn(3, wxEXPAND);
{
TranslatableString sInitialValue;
AudacityProject* pProject = GetActiveProject();
AudacityProject* pProject = &mProject;
auto sSaveValue = pProject->GetFileName();
if (!sSaveValue.empty()) {
m_fnAutoSaveFile.Assign(sSaveValue);

View File

@ -38,6 +38,8 @@ enum TimerRecordCompletedActions {
TR_ACTION_EXPORTED = 0x00000002
};
class AudacityProject;
class TimerRecordPathCtrl final : public wxTextCtrl
{
// MY: Class that inherits from the wxTextCtrl class.
@ -64,7 +66,8 @@ public:
class TimerRecordDialog final : public wxDialogWrapper
{
public:
TimerRecordDialog(wxWindow* parent, bool bAlreadySaved);
TimerRecordDialog(
wxWindow* parent, AudacityProject &project, bool bAlreadySaved);
~TimerRecordDialog();
void OnTimer(wxTimerEvent& event);
@ -114,6 +117,8 @@ private:
ProgressResult PreActionDelay(int iActionIndex, TimerRecordCompletedActions eCompletedActions);
private:
AudacityProject &mProject;
wxDateTime m_DateTime_Start;
wxDateTime m_DateTime_End;
wxTimeSpan m_TimeSpan_Duration;

View File

@ -1098,11 +1098,8 @@ void WaveTrack::SyncLockAdjust(double oldT1, double newT1)
else {
// AWD: Could just use InsertSilence() on its own here, but it doesn't
// follow EditClipCanMove rules (Paste() does it right)
AudacityProject *p = GetActiveProject();
if (!p)
THROW_INCONSISTENCY_EXCEPTION;
auto &factory = TrackFactory::Get( *p );
auto tmp = factory.NewWaveTrack( GetSampleFormat(), GetRate() );
auto tmp = std::make_shared<WaveTrack>(
mDirManager, GetSampleFormat(), GetRate() );
tmp->InsertSilence(0.0, newT1 - oldT1);
tmp->Flush();

View File

@ -55,7 +55,7 @@ bool BatchEvalCommand::Apply(const CommandContext & context)
wxString macroName = GetString(wxT("MacroName"));
if (!macroName.empty())
{
MacroCommands batch;
MacroCommands batch{ context.project };
batch.ReadMacro(macroName);
return batch.ApplyMacro(catalog);
}
@ -68,7 +68,7 @@ bool BatchEvalCommand::Apply(const CommandContext & context)
: iter->name.Msgid().Stripped();
// Create a Batch that will have just one command in it...
MacroCommands Batch;
MacroCommands Batch{ context.project };
bool bResult = Batch.ApplyCommandInBatchMode(friendly, cmdName, cmdParams, &context);
// Relay messages, if any.
wxString Message = Batch.GetMessage();

View File

@ -80,10 +80,9 @@ bool ExportCommand::Apply(const CommandContext & context)
}
wxString extension = mFileName.Mid(splitAt+1).MakeUpper();
Exporter exporter;
Exporter exporter{ context.project };
bool exportSuccess = exporter.Process(&context.project,
std::max(0, mnChannels),
bool exportSuccess = exporter.Process(std::max(0, mnChannels),
extension, mFileName,
true, t0, t1);

View File

@ -398,7 +398,7 @@ bool SetTrackVisualsCommand::ApplyInner(const CommandContext & context, Track *
mVZoomTop = c + ZOOMLIMIT / 2.0;
}
wt->SetDisplayBounds(mVZoomBottom, mVZoomTop);
auto &tp = TrackPanel::Get( *::GetActiveProject() );
auto &tp = TrackPanel::Get( context.project );
tp.UpdateVRulers();
}

View File

@ -1262,8 +1262,7 @@ bool EffectEqualization::ProcessOne(int count, WaveTrack * t,
sampleCount start, sampleCount len)
{
// create a NEW WaveTrack to hold all of the output, including 'tails' each end
AudacityProject *p = GetActiveProject();
auto output = TrackFactory::Get( *p ).NewWaveTrack(floatSample, t->GetRate());
auto output = mFactory->NewWaveTrack(floatSample, t->GetRate());
wxASSERT(mM - 1 < windowSize);
size_t L = windowSize - (mM - 1); //Process L samples at a go

View File

@ -410,8 +410,7 @@ bool EffectEqualization48x::DeltaTrack(
Floats buffer1{ trackBlockSize };
Floats buffer2{ trackBlockSize };
AudacityProject *p = GetActiveProject();
auto output = TrackFactory::Get( *p ).NewWaveTrack(floatSample, t->GetRate());
auto output = mEffectEqualization->mFactory->NewWaveTrack(floatSample, t->GetRate());
auto originalLen = len;
auto currentSample = start;
@ -633,8 +632,7 @@ bool EffectEqualization48x::ProcessOne1x(int count, WaveTrack * t,
auto trackBlockSize = t->GetMaxBlockSize();
AudacityProject *p = GetActiveProject();
auto output = TrackFactory::Get( *p ).NewWaveTrack(floatSample, t->GetRate());
auto output = mEffectEqualization->mFactory->NewWaveTrack(floatSample, t->GetRate());
mEffectEqualization->TrackProgress(count, 0.0);
int subBufferSize=mBufferCount==8?(mSubBufferSize>>1):mSubBufferSize; // half the buffers if avx is active
@ -820,8 +818,7 @@ bool EffectEqualization48x::ProcessOne4x(int count, WaveTrack * t,
auto trackBlockSize = t->GetMaxBlockSize();
AudacityProject *p = GetActiveProject();
auto output = TrackFactory::Get( *p ).NewWaveTrack(floatSample, t->GetRate());
auto output = mEffectEqualization->mFactory->NewWaveTrack(floatSample, t->GetRate());
mEffectEqualization->TrackProgress(count, 0.0);
auto bigRuns = len/(subBufferSize-mBlockSize);
@ -910,8 +907,7 @@ bool EffectEqualization48x::ProcessOne1x4xThreaded(int count, WaveTrack * t,
for(int i=0;i<mThreadCount;i++)
mEQWorkers[i].mProcessingType=processingType;
AudacityProject *p = GetActiveProject();
auto output = TrackFactory::Get( *p ).NewWaveTrack(floatSample, t->GetRate());
auto output = mEffectEqualization->mFactory->NewWaveTrack(floatSample, t->GetRate());
auto trackBlockSize = t->GetMaxBlockSize();
mEffectEqualization->TrackProgress(count, 0.0);
@ -1156,8 +1152,7 @@ bool EffectEqualization48x::ProcessOne8x(int count, WaveTrack * t,
auto trackBlockSize = t->GetMaxBlockSize();
AudacityProject *p = GetActiveProject();
auto output = TrackFactory::Get( *p ).NewWaveTrack(floatSample, t->GetRate());
auto output = mEffectEqualization->mFactory->NewWaveTrack(floatSample, t->GetRate());
mEffectEqualization->TrackProgress(count, 0.0);
int bigRuns=len/(mSubBufferSize-mBlockSize);
@ -1208,8 +1203,7 @@ bool EffectEqualization48x::ProcessOne8xThreaded(int count, WaveTrack * t,
if(mThreadCount<=0 || blockCount<256) // dont do it without cores or big data
return ProcessOne4x(count, t, start, len);
AudacityProject *p = GetActiveProject();
auto output = TrackFactory::Get( *p ).NewWaveTrack(floatSample, t->GetRate());
auto output = mEffectEqualization->mFactory->NewWaveTrack(floatSample, t->GetRate());
auto trackBlockSize = t->GetMaxBlockSize();
mEffectEqualization->TrackProgress(count, 0.0);

View File

@ -133,9 +133,8 @@ bool EffectStereoToMono::ProcessOne(int count)
Floats rightBuffer{ idealBlockLen };
bool bResult = true;
AudacityProject *p = GetActiveProject();
auto outTrack =
TrackFactory::Get( *p ).NewWaveTrack(floatSample, mLeftTrack->GetRate());
mFactory->NewWaveTrack(floatSample, mLeftTrack->GetRate());
while (index < mEnd) {
bResult &= mLeftTrack->Get((samplePtr)leftBuffer.get(), floatSample, index, idealBlockLen);

View File

@ -297,7 +297,8 @@ Exporter::RegisteredExportPlugin::RegisteredExportPlugin(
sFactories().emplace_back( factory );
}
Exporter::Exporter()
Exporter::Exporter( AudacityProject &project )
: mProject{ &project }
{
mMixerSpec = NULL;
mBook = NULL;
@ -342,7 +343,7 @@ void Exporter::OnExtensionChanged(wxCommandEvent &evt) {
void Exporter::OnHelp(wxCommandEvent& WXUNUSED(evt))
{
wxWindow * pWin = FindProjectFrame( GetActiveProject() );
wxWindow * pWin = FindProjectFrame( mProject );
HelpSystem::ShowHelp(pWin, wxT("File_Export_Dialog"), true);
}
@ -400,10 +401,9 @@ bool Exporter::DoEditMetadata(AudacityProject &project,
return false;
}
bool Exporter::Process(AudacityProject *project, bool selectedOnly, double t0, double t1)
bool Exporter::Process(bool selectedOnly, double t0, double t1)
{
// Save parms
mProject = project;
mSelectedOnly = selectedOnly;
mT0 = t0;
mT1 = t1;
@ -425,7 +425,7 @@ bool Exporter::Process(AudacityProject *project, bool selectedOnly, double t0, d
// Let user edit MetaData
if (mPlugins[mFormat]->GetCanMetaData(mSubFormat)) {
if (!DoEditMetadata( *project,
if (!DoEditMetadata( *mProject,
XO("Edit Metadata Tags"), XO("Exported Tags"),
ProjectSettings::Get( *mProject ).GetShowId3Dialog())) {
return false;
@ -446,12 +446,11 @@ bool Exporter::Process(AudacityProject *project, bool selectedOnly, double t0, d
return success;
}
bool Exporter::Process(AudacityProject *project, unsigned numChannels,
bool Exporter::Process(unsigned numChannels,
const FileExtension &type, const wxString & filename,
bool selectedOnly, double t0, double t1)
{
// Save parms
mProject = project;
mChannels = numChannels;
mFilename = filename;
mSelectedOnly = selectedOnly;
@ -1018,8 +1017,7 @@ void Exporter::OnFilterChanged(wxFileCtrlEvent & evt)
mBook->ChangeSelection(index);
}
bool Exporter::ProcessFromTimerRecording(AudacityProject *project,
bool selectedOnly,
bool Exporter::ProcessFromTimerRecording(bool selectedOnly,
double t0,
double t1,
wxFileName fnFile,
@ -1028,7 +1026,6 @@ bool Exporter::ProcessFromTimerRecording(AudacityProject *project,
int iFilterIndex)
{
// Save parms
mProject = project;
mSelectedOnly = selectedOnly;
mT0 = t0;
mT1 = t1;
@ -1079,16 +1076,15 @@ wxFileName Exporter::GetAutoExportFileName() {
return mFilename;
}
bool Exporter::SetAutoExportOptions(AudacityProject *project) {
bool Exporter::SetAutoExportOptions() {
mFormat = -1;
mProject = project;
if( GetFilename()==false )
return false;
// Let user edit MetaData
if (mPlugins[mFormat]->GetCanMetaData(mSubFormat)) {
if (!DoEditMetadata( *project,
if (!DoEditMetadata( *mProject,
XO("Edit Metadata Tags"),
XO("Exported Tags"),
ProjectSettings::Get(*mProject).GetShowId3Dialog())) {

View File

@ -181,15 +181,15 @@ public:
const TranslatableString &title,
const TranslatableString &shortUndoDescription, bool force);
Exporter();
Exporter( AudacityProject &project );
virtual ~Exporter();
void SetFileDialogTitle( const TranslatableString & DialogTitle );
void SetDefaultFormat( const FileExtension & Format ){ mFormatName = Format;};
bool Process(AudacityProject *project, bool selectedOnly,
bool Process(bool selectedOnly,
double t0, double t1);
bool Process(AudacityProject *project, unsigned numChannels,
bool Process(unsigned numChannels,
const FileExtension &type, const wxString & filename,
bool selectedOnly, double t0, double t1);
@ -199,15 +199,14 @@ public:
const ExportPluginArray &GetPlugins();
// Auto Export from Timer Recording
bool ProcessFromTimerRecording(AudacityProject *project,
bool selectedOnly,
bool ProcessFromTimerRecording(bool selectedOnly,
double t0,
double t1,
wxFileName fnFile,
int iFormat,
int iSubFormat,
int iFilterIndex);
bool SetAutoExportOptions(AudacityProject *project);
bool SetAutoExportOptions();
int GetAutoExportFormat();
int GetAutoExportSubFormat();
int GetAutoExportFilterIndex();

View File

@ -131,6 +131,7 @@ END_EVENT_TABLE()
ExportMultipleDialog::ExportMultipleDialog(AudacityProject *project)
: wxDialogWrapper( &GetProjectFrame( *project ),
wxID_ANY, XO("Export Multiple") )
, mExporter{ *project }
, mSelectionState{ SelectionState::Get( *project ) }
{
SetName();

View File

@ -409,13 +409,14 @@ std::unique_ptr<ExtImportItem> Importer::CreateDefaultImportItem()
}
// returns number of tracks imported
bool Importer::Import(const FilePath &fName,
bool Importer::Import( AudacityProject &project,
const FilePath &fName,
TrackFactory *trackFactory,
TrackHolders &tracks,
Tags *tags,
TranslatableString &errorMessage)
{
AudacityProject *pProj = GetActiveProject();
AudacityProject *pProj = &project;
auto cleanup = valueRestorer( pProj->mbBusyImporting, true );
const FileExtension extension{ fName.AfterLast(wxT('.')) };
@ -589,7 +590,7 @@ bool Importer::Import(const FilePath &fName,
{
// Try to open the file with this plugin (probe it)
wxLogMessage(wxT("Opening with %s"),plugin->GetPluginStringID());
auto inFile = plugin->Open(fName);
auto inFile = plugin->Open(fName, pProj);
if ( (inFile != NULL) && (inFile->GetStreamCount() > 0) )
{
wxLogMessage(wxT("Open(%s) succeeded"), fName);

View File

@ -22,6 +22,7 @@
class wxArrayString;
class wxListBox;
class AudacityProject;
class Tags;
class TrackFactory;
class Track;
@ -158,7 +159,8 @@ public:
std::unique_ptr<ExtImportItem> CreateDefaultImportItem();
// if false, the import failed and errorMessage will be set.
bool Import(const FilePath &fName,
bool Import( AudacityProject &project,
const FilePath &fName,
TrackFactory *trackFactory,
TrackHolders &tracks,
Tags *tags,

View File

@ -183,7 +183,8 @@ public:
TranslatableString GetPluginFormatDescription() override;
///! Probes the file and opens it if appropriate
std::unique_ptr<ImportFileHandle> Open(const FilePath &Filename) override;
std::unique_ptr<ImportFileHandle> Open(
const FilePath &Filename, AudacityProject*) override;
unsigned SequenceNumber() const override;
};
@ -291,7 +292,8 @@ TranslatableString FFmpegImportPlugin::GetPluginFormatDescription()
return DESC;
}
std::unique_ptr<ImportFileHandle> FFmpegImportPlugin::Open(const FilePath &filename)
std::unique_ptr<ImportFileHandle> FFmpegImportPlugin::Open(
const FilePath &filename, AudacityProject*)
{
auto handle = std::make_unique<FFmpegImportFileHandle>(filename);

View File

@ -135,7 +135,8 @@ class FLACImportPlugin final : public ImportPlugin
wxString GetPluginStringID() override { return wxT("libflac"); }
TranslatableString GetPluginFormatDescription() override;
std::unique_ptr<ImportFileHandle> Open(const FilePath &Filename) override;
std::unique_ptr<ImportFileHandle> Open(
const FilePath &Filename, AudacityProject*) override;
unsigned SequenceNumber() const override;
};
@ -291,7 +292,8 @@ TranslatableString FLACImportPlugin::GetPluginFormatDescription()
}
std::unique_ptr<ImportFileHandle> FLACImportPlugin::Open(const FilePath &filename)
std::unique_ptr<ImportFileHandle> FLACImportPlugin::Open(
const FilePath &filename, AudacityProject*)
{
// First check if it really is a FLAC file

View File

@ -247,7 +247,8 @@ public:
FileExtensions GetSupportedExtensions() override;
///! Probes the file and opens it if appropriate
std::unique_ptr<ImportFileHandle> Open(const wxString &Filename) override;
std::unique_ptr<ImportFileHandle> Open(
const wxString &Filename, AudacityProject*) override;
unsigned SequenceNumber() const override;
};
@ -409,7 +410,8 @@ GStreamerImportPlugin::GetSupportedExtensions()
// ----------------------------------------------------------------------------
// Open the file and return an importer "file handle"
std::unique_ptr<ImportFileHandle> GStreamerImportPlugin::Open(const wxString &filename)
std::unique_ptr<ImportFileHandle> GStreamerImportPlugin::Open(
const wxString &filename, AudacityProject*)
{
auto handle = std::make_unique<GStreamerImportFileHandle>(filename);

View File

@ -114,7 +114,8 @@ public:
wxString GetPluginStringID() override { return wxT("lof"); }
TranslatableString GetPluginFormatDescription() override;
std::unique_ptr<ImportFileHandle> Open(const FilePath &Filename) override;
std::unique_ptr<ImportFileHandle> Open(
const FilePath &Filename, AudacityProject *pProject) override;
unsigned SequenceNumber() const override;
};
@ -123,7 +124,8 @@ public:
class LOFImportFileHandle final : public ImportFileHandle
{
public:
LOFImportFileHandle(const FilePath & name, std::unique_ptr<wxTextFile> &&file);
LOFImportFileHandle( AudacityProject *pProject,
const FilePath & name, std::unique_ptr<wxTextFile> &&file);
~LOFImportFileHandle();
TranslatableString GetFileDescription() override;
@ -150,7 +152,7 @@ private:
std::unique_ptr<wxTextFile> mTextFile;
wxFileName mLOFFileName; /**< The name of the LOF file, which is used to
interpret relative paths in it */
AudacityProject *mProject{ GetActiveProject() };
AudacityProject *mProject{};
// In order to know whether or not to create a NEW window
bool windowCalledOnce{ false };
@ -164,11 +166,12 @@ private:
double scrollOffset{ 0 };
};
LOFImportFileHandle::LOFImportFileHandle
(const FilePath & name, std::unique_ptr<wxTextFile> &&file)
: ImportFileHandle(name),
mTextFile(std::move(file))
LOFImportFileHandle::LOFImportFileHandle( AudacityProject *pProject,
const FilePath & name, std::unique_ptr<wxTextFile> &&file)
: ImportFileHandle(name)
, mTextFile(std::move(file))
, mLOFFileName{name}
, mProject{ pProject }
{
}
@ -177,7 +180,8 @@ TranslatableString LOFImportPlugin::GetPluginFormatDescription()
return DESC;
}
std::unique_ptr<ImportFileHandle> LOFImportPlugin::Open(const FilePath &filename)
std::unique_ptr<ImportFileHandle> LOFImportPlugin::Open(
const FilePath &filename, AudacityProject *pProject)
{
// Check if it is a binary file
{
@ -208,7 +212,8 @@ std::unique_ptr<ImportFileHandle> LOFImportPlugin::Open(const FilePath &filename
if (!file->IsOpened())
return nullptr;
return std::make_unique<LOFImportFileHandle>(filename, std::move(file));
return std::make_unique<LOFImportFileHandle>(
pProject, filename, std::move(file));
}
TranslatableString LOFImportFileHandle::GetFileDescription()

View File

@ -115,7 +115,8 @@ public:
wxString GetPluginStringID() override { return wxT("libmad"); }
TranslatableString GetPluginFormatDescription() override;
std::unique_ptr<ImportFileHandle> Open(const FilePath &Filename) override;
std::unique_ptr<ImportFileHandle> Open(
const FilePath &Filename, AudacityProject*) override;
unsigned SequenceNumber() const override;
};
@ -177,7 +178,8 @@ TranslatableString MP3ImportPlugin::GetPluginFormatDescription()
return DESC;
}
std::unique_ptr<ImportFileHandle> MP3ImportPlugin::Open(const FilePath &Filename)
std::unique_ptr<ImportFileHandle> MP3ImportPlugin::Open(
const FilePath &Filename, AudacityProject*)
{
auto file = std::make_unique<wxFile>(Filename);

View File

@ -89,7 +89,8 @@ public:
wxString GetPluginStringID() override { return wxT("liboggvorbis"); }
TranslatableString GetPluginFormatDescription() override;
std::unique_ptr<ImportFileHandle> Open(const FilePath &Filename) override;
std::unique_ptr<ImportFileHandle> Open(
const FilePath &Filename, AudacityProject*) override;
unsigned SequenceNumber() const override;
};
@ -167,7 +168,8 @@ TranslatableString OggImportPlugin::GetPluginFormatDescription()
return DESC;
}
std::unique_ptr<ImportFileHandle> OggImportPlugin::Open(const FilePath &filename)
std::unique_ptr<ImportFileHandle> OggImportPlugin::Open(
const FilePath &filename, AudacityProject*)
{
// Suppress some compiler warnings about unused global variables in the library header
wxUnusedVar(OV_CALLBACKS_DEFAULT);

View File

@ -87,7 +87,8 @@ public:
wxString GetPluginStringID() override { return wxT("libsndfile"); }
TranslatableString GetPluginFormatDescription() override;
std::unique_ptr<ImportFileHandle> Open(const FilePath &Filename) override;
std::unique_ptr<ImportFileHandle> Open(
const FilePath &Filename, AudacityProject*) override;
unsigned SequenceNumber() const override;
};
@ -126,7 +127,8 @@ TranslatableString PCMImportPlugin::GetPluginFormatDescription()
return DESC;
}
std::unique_ptr<ImportFileHandle> PCMImportPlugin::Open(const FilePath &filename)
std::unique_ptr<ImportFileHandle> PCMImportPlugin::Open(
const FilePath &filename, AudacityProject*)
{
SF_INFO info;
wxFile f; // will be closed when it goes out of scope

View File

@ -52,6 +52,7 @@ but little else.
#include "ImportRaw.h" // defines TrackHolders
class AudacityProject;
class wxArrayString;
class ProgressDialog;
enum class ProgressResult : unsigned;
@ -92,7 +93,8 @@ public:
// Open the given file, returning true if it is in a recognized
// format, false otherwise. This puts the importer into the open
// state.
virtual std::unique_ptr<ImportFileHandle> Open(const FilePath &Filename) = 0;
virtual std::unique_ptr<ImportFileHandle> Open(
const FilePath &Filename, AudacityProject*) = 0;
virtual unsigned SequenceNumber() const = 0;

View File

@ -122,7 +122,8 @@ class QTImportPlugin final : public ImportPlugin
wxString GetPluginStringID() override { return wxT("quicktime"); }
TranslatableString GetPluginFormatDescription() override;
std::unique_ptr<ImportFileHandle> Open(const wxString & Filename) override;
std::unique_ptr<ImportFileHandle> Open(
const wxString & Filename, AudacityProject*) override;
unsigned SequenceNumber() const override;
@ -180,7 +181,8 @@ TranslatableString QTImportPlugin::GetPluginFormatDescription()
return DESC;
}
std::unique_ptr<ImportFileHandle> QTImportPlugin::Open(const wxString & Filename)
std::unique_ptr<ImportFileHandle> QTImportPlugin::Open(
const wxString & Filename, AudacityProject*)
{
OSErr err;
FSRef inRef;

View File

@ -40,7 +40,7 @@ void DoExport( AudacityProject &project, const FileExtension & Format )
{
auto &tracks = TrackList::Get( project );
Exporter e;
Exporter e{ project };
MissingAliasFilesDialog::SetShouldShow(true);
double t0 = 0.0;
@ -85,16 +85,15 @@ void DoExport( AudacityProject &project, const FileExtension & Format )
{
// Do export with prompting.
e.SetDefaultFormat(Format);
e.Process(&project, false, t0, t1);
e.Process(false, t0, t1);
}
else
{
FileHistory::Global().AddFileToHistory(filename);
// We're in batch mode, the file does not exist already.
// We really can proceed without prompting.
int nChannels = MacroCommands::IsMono() ? 1 : 2;
int nChannels = MacroCommands::IsMono( &project ) ? 1 : 2;
e.Process(
&project, // AudacityProject
nChannels, // numChannels,
Format, // type,
filename, // filename,
@ -201,11 +200,11 @@ void OnExportSelection(const CommandContext &context)
{
auto &project = context.project;
auto &selectedRegion = ViewInfo::Get( project ).selectedRegion;
Exporter e;
Exporter e{ project };
MissingAliasFilesDialog::SetShouldShow(true);
e.SetFileDialogTitle( XO("Export Selected Audio") );
e.Process(&project, true, selectedRegion.t0(),
e.Process(true, selectedRegion.t0(),
selectedRegion.t1());
}

View File

@ -47,7 +47,7 @@ AudacityProject::AttachedWindows::RegisteredFactory sMacrosWindowKey{
[]( AudacityProject &parent ) -> wxWeakRef< wxWindow > {
auto &window = ProjectWindow::Get( parent );
return safenew MacrosWindow(
&window, true
&window, parent, true
);
}
};
@ -543,7 +543,7 @@ void OnApplyMacroDirectly(const CommandContext &context )
auto &window = ProjectWindow::Get( project );
//wxLogDebug( "Macro was: %s", context.parameter);
ApplyMacroDialog dlg( &window );
ApplyMacroDialog dlg( &window, project );
const auto &Name = context.parameter;
// We used numbers previously, but macros could get renumbered, making

View File

@ -1029,10 +1029,10 @@ void OnScoreAlign(const CommandContext &context)
params.mAudioStart, params.mAudioEnd) );
} else if (result == SA_CANCEL) {
// wrong way to recover...
//GetActiveProject()->OnUndo(); // recover any changes to note track
//project.OnUndo(); // recover any changes to note track
return; // no message when user cancels alignment
} else {
//GetActiveProject()->OnUndo(); // recover any changes to note track
//project.OnUndo(); // recover any changes to note track
AudacityMessageBox( XO("Internal error reported by alignment process.") );
}
}

View File

@ -326,7 +326,7 @@ void OnTimerRecord(const CommandContext &context)
//and therefore remove the newly inserted track.
TimerRecordDialog dialog(
&window, bProjectSaved); /* parent, project saved? */
&window, project, bProjectSaved); /* parent, project, project saved? */
int modalResult = dialog.ShowModal();
if (modalResult == wxID_CANCEL)
{

View File

@ -26,7 +26,6 @@ Paul Licameli split from TrackPanel.cpp
#include "../../../include/audacity/Types.h"
class AudacityProject;
extern AudacityProject *GetActiveProject();
class TranslatableString;
// Conditionally compile either a separate thead, or else use a timer in the main
@ -127,7 +126,7 @@ public:
// Convenience wrapper for the above
template<void (Scrubber::*pfn)(const CommandContext&)>
void Thunk(wxCommandEvent &)
{ (this->*pfn)(*GetActiveProject()); }
{ (this->*pfn)(*mProject); }
// A string to put in the leftmost part of the status bar
// when scrub or seek is in progress, or else empty.

View File

@ -96,7 +96,7 @@ UIHandle::Result TrackSelectHandle::Click
result |= Cancelled;
else {
mRearrangeCount = 0;
CalculateRearrangingThresholds(event);
CalculateRearrangingThresholds(event, pProject);
}
SelectUtilities::DoListSelection(*pProject,
@ -135,7 +135,7 @@ UIHandle::Result TrackSelectHandle::Drag
// JH: if we moved up or down, recalculate the thresholds and make sure the
// track is fully on-screen.
CalculateRearrangingThresholds(event);
CalculateRearrangingThresholds(event, pProject);
result |= EnsureVisible | RefreshAll;
return result;
@ -154,7 +154,7 @@ HitTestPreview TrackSelectHandle::Preview
::MakeCursor(wxCURSOR_HAND, RearrangeCursorXpm, 16, 16);
const bool unsafe =
ProjectAudioIO::Get( *GetActiveProject() ).IsAudioActive();
ProjectAudioIO::Get( *project ).IsAudioActive();
return {
message,
(unsafe
@ -176,12 +176,11 @@ HitTestPreview TrackSelectHandle::Preview
}
UIHandle::Result TrackSelectHandle::Release
(const TrackPanelMouseEvent &, AudacityProject *, wxWindow *)
(const TrackPanelMouseEvent &, AudacityProject *project, wxWindow *)
{
// If we're releasing, surely we are dragging a track?
wxASSERT( mpTrack );
if (mRearrangeCount != 0) {
AudacityProject *const project = ::GetActiveProject();
ProjectHistory::Get( *project ).PushState(
/* i18n-hint: will substitute name of track for %s */
( mRearrangeCount < 0 ? XO("Moved '%s' up") : XO("Moved '%s' down") )
@ -207,13 +206,13 @@ UIHandle::Result TrackSelectHandle::Cancel(AudacityProject *pProject)
/// Figure out how far the user must drag the mouse up or down
/// before the track will swap with the one above or below
void TrackSelectHandle::CalculateRearrangingThresholds(const wxMouseEvent & event)
void TrackSelectHandle::CalculateRearrangingThresholds(
const wxMouseEvent & event, AudacityProject *project)
{
// JH: this will probably need to be tweaked a bit, I'm just
// not sure what formula will have the best feel for the
// user.
AudacityProject *const project = ::GetActiveProject();
auto &tracks = TrackList::Get( *project );
if (tracks.CanMoveUp(mpTrack.get()))

View File

@ -59,7 +59,8 @@ private:
int mMoveDownThreshold {};
int mRearrangeCount {};
void CalculateRearrangingThresholds(const wxMouseEvent & event);
void CalculateRearrangingThresholds(
const wxMouseEvent & event, AudacityProject *project);
};
#endif