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

Eliminate GetActiveProject from WaveTrack.cpp

This commit is contained in:
Paul Licameli 2020-01-07 16:00:36 -05:00
parent 7bce0a643b
commit 852c07bc58
8 changed files with 32 additions and 27 deletions

View File

@ -1627,7 +1627,7 @@ bool AudacityApp::OnInit()
{
if (parser->Found(wxT("t")))
{
RunBenchmark(NULL);
RunBenchmark( nullptr, ProjectSettings::Get( *project ) );
QuitAudacity(true);
}

View File

@ -41,6 +41,7 @@ of the BlockFile system.
#include "WaveTrack.h"
#include "Sequence.h"
#include "Prefs.h"
#include "ProjectSettings.h"
#include "ViewInfo.h"
#include "FileNames.h"
@ -51,7 +52,7 @@ class BenchmarkDialog final : public wxDialogWrapper
{
public:
// constructors and destructors
BenchmarkDialog( wxWindow *parent );
BenchmarkDialog( wxWindow *parent, const ProjectSettings &settings );
void MakeBenchmarkDialog();
@ -66,6 +67,8 @@ private:
void HoldPrint(bool hold);
void FlushPrint();
const ProjectSettings &mSettings;
bool mHoldPrint;
wxString mToPrint;
@ -83,7 +86,7 @@ private:
DECLARE_EVENT_TABLE()
};
void RunBenchmark(wxWindow *parent)
void RunBenchmark( wxWindow *parent, const ProjectSettings &settings )
{
/*
int action = AudacityMessageBox(
@ -99,7 +102,7 @@ XO("This will close all project windows (without saving)\nand open the Audacity
GetProjectFrame( *pProject ).Close();
*/
BenchmarkDialog dlog(parent);
BenchmarkDialog dlog{ parent, settings };
dlog.CentreOnParent();
@ -128,12 +131,15 @@ BEGIN_EVENT_TABLE(BenchmarkDialog, wxDialogWrapper)
EVT_BUTTON( wxID_CANCEL, BenchmarkDialog::OnClose )
END_EVENT_TABLE()
BenchmarkDialog::BenchmarkDialog(wxWindow *parent):
BenchmarkDialog::BenchmarkDialog(
wxWindow *parent, const ProjectSettings &settings)
:
/* i18n-hint: Benchmark means a software speed test */
wxDialogWrapper( parent, 0, XO("Benchmark"),
wxDefaultPosition, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE |
wxRESIZE_BORDER)
, mSettings{ settings }
{
SetName();
@ -362,7 +368,8 @@ void BenchmarkDialog::OnRun( wxCommandEvent & WXUNUSED(event))
ZoomInfo zoomInfo(0.0, ZoomInfo::GetDefaultZoom());
auto dd = DirManager::Create();
const auto t = TrackFactory{ dd, &zoomInfo }.NewWaveTrack(int16Sample);
const auto t =
TrackFactory{ mSettings, dd, &zoomInfo }.NewWaveTrack(int16Sample);
t->SetRate(1);

View File

@ -11,6 +11,8 @@
#ifndef __AUDACITY_BENCHMARK__
#define __AUDACITY_BENCHMARK__
void RunBenchmark(wxWindow *parent);
class ProjectSettings;
void RunBenchmark( wxWindow *parent, const ProjectSettings &settings );
#endif // define __AUDACITY_BENCHMARK__

View File

@ -1288,6 +1288,7 @@ static auto TrackFactoryFactory = []( AudacityProject &project ) {
auto &dirManager = DirManager::Get( project );
auto &viewInfo = ViewInfo::Get( project );
return std::make_shared< TrackFactory >(
ProjectSettings::Get( project ),
dirManager.shared_from_this(), &viewInfo );
};

View File

@ -34,6 +34,7 @@ class DirManager;
class Track;
class AudioTrack;
class PlayableTrack;
class ProjectSettings;
class LabelTrack;
class TimeTrack;
class TrackControls;
@ -1582,8 +1583,10 @@ class AUDACITY_DLL_API TrackFactory final
static TrackFactory &Reset( AudacityProject &project );
static void Destroy( AudacityProject &project );
TrackFactory(const std::shared_ptr<DirManager> &dirManager, const ZoomInfo *zoomInfo):
mDirManager(dirManager)
TrackFactory( const ProjectSettings &settings,
const std::shared_ptr<DirManager> &dirManager, const ZoomInfo *zoomInfo)
: mSettings{ settings }
, mDirManager(dirManager)
, mZoomInfo(zoomInfo)
{
}
@ -1591,11 +1594,10 @@ class AUDACITY_DLL_API TrackFactory final
TrackFactory &operator=( const TrackFactory & ) PROHIBITED;
private:
const ProjectSettings &mSettings;
const std::shared_ptr<DirManager> mDirManager;
const ZoomInfo *const mZoomInfo;
friend class AudacityProject;
friend class BenchmarkDialog;
public:
// These methods are defined in WaveTrack.cpp, NoteTrack.cpp,
// LabelTrack.cpp, and TimeTrack.cpp respectively

View File

@ -79,24 +79,16 @@ WaveTrack::Holder TrackFactory::DuplicateWaveTrack(const WaveTrack &orig)
WaveTrack::Holder TrackFactory::NewWaveTrack(sampleFormat format, double rate)
{
if (format == (sampleFormat)0)
format = mSettings.GetDefaultFormat();
if (rate == 0)
rate = mSettings.GetRate();
return std::make_shared<WaveTrack> ( mDirManager, format, rate );
}
WaveTrack::WaveTrack(const std::shared_ptr<DirManager> &projDirManager, sampleFormat format, double rate) :
PlayableTrack(projDirManager)
{
{
const auto &settings = ProjectSettings::Get( *GetActiveProject() );
if (format == (sampleFormat)0)
{
format = settings.GetDefaultFormat();
}
if (rate == 0)
{
rate = settings.GetRate();
}
}
mLegacyProjectFileOffset = 0;
mFormat = format;
@ -535,7 +527,7 @@ Track::Holder WaveTrack::Copy(double t0, double t1, bool forClipboard) const
if (t1 < t0)
THROW_INCONSISTENCY_EXCEPTION;
auto result = std::make_shared<WaveTrack>( mDirManager );
auto result = std::make_shared<WaveTrack>( mDirManager, mFormat, mRate );
WaveTrack *newTrack = result.get();
newTrack->Init(*this);

View File

@ -69,8 +69,7 @@ public:
//
WaveTrack(const std::shared_ptr<DirManager> &projDirManager,
sampleFormat format = (sampleFormat)0,
double rate = 0);
sampleFormat format, double rate);
WaveTrack(const WaveTrack &orig);
// overwrite data excluding the sample sequence but including display

View File

@ -10,6 +10,7 @@
#include "../PluginManager.h"
#include "../Prefs.h"
#include "../Project.h"
#include "../ProjectSettings.h"
#include "../ProjectWindow.h"
#include "../Screenshot.h"
#include "../commands/CommandContext.h"
@ -512,8 +513,9 @@ void OnScreenshot(const CommandContext &context )
void OnBenchmark(const CommandContext &context)
{
auto &project = context.project;
auto &settings = ProjectSettings::Get( project );
auto &window = GetProjectFrame( project );
::RunBenchmark(&window);
::RunBenchmark( &window, settings );
}
void OnSimulateRecordingErrors(const CommandContext &context)