.. Call the function SamplesToFloats instead, or in one place, where source
is also always float, just do memcpy.
Dithering never happened in these cases.
Bug 2673 was an important multi-threading issue, and so I added
comments about the code. Also a LogDebug to track cache use.
Bug 2673 was also a crash with no error message reported.
That is something to revisit later and deserved a comment.
It's believed that the underlying issue is fixed now.
The 'ANSWER-MEs' can be answered in 3.0.1.
I've added the comment 'REVIEW:' where I have some concern that
the database and our copy of it could get out of step, or simply that
we fail to report a problem to the user.
I'd like these reviewed and turned into comments that make it
easier to check for correctness, for example saying where an
error is reported, or why it is OK to do no further recovery action.
... Start Audacity; generate some noise; shift clip with Time-Shift tool;
command+Q to exit; say No to save changes.
The scope of a GuardedCall needs to be expanded, because Conn() can throw,
so that no exceptions escape the destructor of SqliteSampleBlock.
But now there is an error dialog on exit instead of a crash.
The error icon was gone because we are now using the ErrorDialog, which didn't have it. So added back explicitly. I decided to go with wxART_WARNING rather than wxART_ERROR because nearly all of these present as warnings.
... You may see this also when abandoning lots of redo history, and not only
when doing compaction.
If in compaction you discard much undo and also much redo, you may see two
progresses.
It's debatable whether this might have been better implemented by reuse of
ProjectFileIO::DeleteBlocks instead, putting callbacks to a progress indicator
in the function InSet(). But I wanted to avoid more dependency onto
ProjectFileIO.
Doing real work in DeleteBlocks() is supposed to happen only if there is a bug
elsewhere that allowed orphans. So, still no progress indicator there.
... This is a more adventurous fix. It avoids changing the schema.
Use non-positive values of SqliteSampleBlock::mBlockID to store lengths of
blocks of silence. Keep SqliteSampleBlock structures in memory (sharing where
possible for recurring block lengths) but do not make corresponding rows in
the database table.
Reviewed all uses of mBlockID, and of SqliteSampleBlock::GetBlockID() which
returns it, and of XML attribute "blockid" which persists it.
* Revert "[Bug 2533] New: Extreme space inefficiency importing silence from an AUP file"...
... It did not fix the symptoms. Using a zero blob only gives temporary
in-memory space efficiency when adding a row to the database, not space savings
in the file.
This reverts commit d9047dfd25.
* Remove unused SampleBlockFactory::Get
* Eliminate some repetition and magic numbers
* Lower some common steps into GetSummary(); removed unused argument
* mSummary256Bytes and mSummary64kBytes not needed after initialization
* Satisfy sample and summary requests for silent blocks without using db
... Don't have special knowledge of "blockid" in ProjectSerializer, which should
be very low-level.
Instead, we can deserialize the project first, and use the block ids collected
by the sample block factory since f137a1e.
... with database columns, so stop writing them and save some space.
This won't break loading of existing .aup3 files.
This required a bug fix in a SQL command too!
Several improvements in determining how much actual disk space a
sampleblock uses. This allows us to provide how much space will
be recovered when using File -> Compact Project.
In addition, the History window now provides better space estimates.
* Change usage of AutoCommitTransaction::Rollback...
... It is the more useful pattern (as in many finally blocks) for the failure
path in the destructor (which rolls back) to be the default, but an explicit
call must inform it of success.
This corrects the early return paths in Effect::DoEffect().
Throw inconsistency exception if Commit() is called again after having been
called once, successfully
Also remove a friend declaration
* UndoManager's interface uses consistent 0-based indexing of states...
... Returned by GetCurrentState() and used by SetStateTo(),
GetLongDescription(), GetShortDescription()
* SampleBlock::GetBlockID is const
* Generalized function to visit sample blocks used in a TrackList...
... Eliminating some duplication; put it in WaveTrack, not Track, to avoid
a dependency cycle.
* Eliminate more repetition with BlockSpaceUsageAccumulator
* Function to delete all blocks of/not-of a given set in one command
* DBConnection doesn't use ProjectFileIO or need friendship...
... Instead, it is given its own weak_ptr to the project
* Demote the bypass flag into DBConnection...
... So SqliteSampleBlock needs ProjectFileIO only to get the DBConnection
* Accessor functions for the connection objects for SqliteSampleBlock
* Another level of indirection to get to the DBConnection object...
... The document holds the unique_ptr to DBConnection in an attached object;
later we want the SqliteSampleBlockFactory to locate the same pointer without
using ProjectFileIO
* SqliteSampleBlock and its factory don't use class ProjectFileIO...
... Instead they share a pointer to the pointer to the current DBConnection.
This means they no longer know how to invoke the lazy opening of that
connection.
So just require that this be done before any operations on blocks happen. If
it hasn't, throw and let the application recover.
* ProjectFileIO no longer needs weak_ptr to Project for safety...
... so eliminate much ugliness from 127696879d
* Move DBConnection to new files...
... And SqliteSampleBlock does not depend on ProjectFileIO.
* SampleBlock.h doesn't need ClientData.h
* Function ProjectFileIO::Conn() isn't needed
SqliteSampleBlock now uses already prepared SQL statements for
all DB usage. This means that the statements won't have to be
compiled each time they are used.
The "Project file size" field in the History dialog didn't work
because it didn't take the journal size into account. So, I removed
the field and improved the size calculation a bit for the sample
blocks.
* Need only CloseLock now, not old Lock and Unlock...
... which were for cross-project cut and paste, but they no longer work and we
need another solution. So delete much old code.
* Fix dangling reference to AudacityProject completely! ...
... in SqliteSampleBlockFactory: retain ONLY the shared pointer to
ProjectFileIO, then pass that, not project, to constructors of blocks.
completing the work of 127696879d
* Restore part of the Bug2436 fix...
... which needs the non-default arguments to WaveTrack::EmptyCopy that got lost
at d39590cf41
So that pasted WaveTracks refer to the correct SampleBlockFactory and database
for their project
But this is not yet a sufficient re-fix for the bug
* Complete the fix for cross-project copies and 2436...
... by duplicating sample blocks, in Sequence.cpp, when it is wrong just to
share them.
And to determine which case it is, see whether source and destination Sequences
have the same sample block factories when doing Copy or Paste. Duplicate
when the factories are different. Otherwise sharing is safe and more space
efficient.
This does the analogous to what DirManager::CopyBlockFile did before commit
d39590c.
* Null checks on return from std::make_shared are unnecessary...
... instead std::bad_alloc would be thrown in case of memory exhaustion, which
we don't try to recover from.
* Restore uses of the mayThrow arguments in Sequence...
... that became unused at commit d39590cf41.
It's important to ignore exceptions from SampleBlocks when only displaying, not
editing or playing, and just treat missing data as silence.
Pass the boolean into the SampleBlock routines. But the throwing of exceptions
is not yet implemented.
* SampleBlockFactory functions guaranteed to return non-null or throw...
... which corrects Sequence.cpp, which was assuming non-null results.
This supplies the throw statements that the previous commit comment says were
still lacking.
This corrects the absence of checks of returns from sql_bind_... function calls
in SqliteSampleBlock.cpp. (Other calls remain to be checked elsewhere.)
User visible error messages, carried by the exceptions, might be improved.
* Restore the try/catch in AutoSaveFile::Decode...
... which was introduced at 2ba17c78d6
but removed at d39590cf41, yet without removing
the throw statement
which left the program vulnerable to abrupt termination instead of graceful
failure, when uninterpretable auto save contents are detected.
* 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).