1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 16:10:06 +02:00
audacity/src/TrackFactory.h
Paul Licameli 127696879d
Unitary changes (#599)
* Define SampleBlockFactory replacing static members of SampleBlock...

... This will become an abstract base class

* Sequence and WaveTrack only store SampleBlockFactory not Project...

... This adds a dependency from Track to SampleBlock which temporarily enlarges
a cycle in the dependency graph

* Register a global factory of SampleBlockFactory...

... so that later we can make an abstract SampleBlockFactory, separate from the
concrete implementation in terms of sqlite, and inject the dependency at startup
avoiding static dependency

* New concrete classes SqliteSampleBlock, SqliteSampleBlockFactory...

... separated from abstract base classes and put into a new source file,
breaking dependency cycles, and perhaps allowing easy reimplementation for other
databases in the future.

Note that the new file is a header-less plug-in!  Nothing depends on it.  It
uses static initialization to influence the program's behavior.

* Compile dependency on sqlite3.h limited to just two .cpp files...

... these are ProjectFileIO.cpp and SqliteSampleBlock.cpp.

But there is still close cooperation of ProjectFileIO and SqliteSampleBlock.cpp.
This suggests that these files ought to be merged, and perhaps ProjectFileIO
also needs to be split into abstract and concrete classes, and there should be
another injection of a factory function at startup.  That will make the choice
of database implementation even more modular.

Also removed one unnecessary inclusion of ProjectFileIO.h

* Fix crashes cutting and pasting cross-project...

... in case the source project is closed before the paste happens.

This caused destruction of the ProjectFileIO object and a closing of the sqlite
database with the sample data in it, leaving dangling references in the
SqliteSampleBlock objects.

The fix is that the SqliteSampleBlockFactory object holds a shared_ptr to the
ProjectFileIO object.  So the clipboard may own WaveTracks, which own WaveClips,
which own Sequences, which own SqliteSampleBlockFactories, which keep the
ProjectFileIO and the database connection alive until the clipboard is cleared.

The consequence of the fix is delayed closing of the entire database associated
with the source project.

If the source project is reopened before the clipboard is cleared, will there
be correct concurrent access to the same persistent store?  My preliminary
trials suggest this is so (reopening a saved project, deleting from it, closing
it again -- the clipboard contents are still unchanged and available).
2020-07-02 18:11:38 -05:00

57 lines
1.6 KiB
C++

/**********************************************************************
Audacity: A Digital Audio Editor
TrackFactory.h
Paul Licameli -- split from Track.h
**********************************************************************/
#ifndef __AUDACITY_TRACK_FACTORY__
#define __AUDACITY_TRACK_FACTORY__
#include "ClientData.h" // to inherit
class AudacityProject;
class AUDACITY_DLL_API TrackFactory final
: public ClientData::Base
{
public:
static TrackFactory &Get( AudacityProject &project );
static const TrackFactory &Get( const AudacityProject &project );
static TrackFactory &Reset( AudacityProject &project );
static void Destroy( AudacityProject &project );
TrackFactory( const ProjectSettings &settings,
AudacityProject &project, const ZoomInfo *zoomInfo)
: mSettings{ settings }
, mProject(project)
, mZoomInfo(zoomInfo)
{
}
TrackFactory( const TrackFactory & ) PROHIBITED;
TrackFactory &operator=( const TrackFactory & ) PROHIBITED;
private:
const ProjectSettings &mSettings;
AudacityProject &mProject;
const ZoomInfo *const mZoomInfo;
friend class AudacityProject;
public:
// These methods are defined in WaveTrack.cpp, NoteTrack.cpp,
// LabelTrack.cpp, and TimeTrack.cpp respectively
std::shared_ptr<WaveTrack> DuplicateWaveTrack(const WaveTrack &orig);
std::shared_ptr<WaveTrack> NewWaveTrack(sampleFormat format = (sampleFormat)0,
double rate = 0);
std::shared_ptr<LabelTrack> NewLabelTrack();
std::shared_ptr<TimeTrack> NewTimeTrack();
#if defined(USE_MIDI)
std::shared_ptr<NoteTrack> NewNoteTrack();
#endif
};
#endif