Commit Graph

43 Commits

Author SHA1 Message Date
Dmitry Vedenko 950d170ae6 Adds context to SQLite3 exceptions 2021-06-08 08:08:26 -07:00
Dmitry Vedenko 690772ccb0 Use ShowExceptionDialog when we want to show ErrorReportDialog 2021-06-08 08:08:26 -07:00
Paul Licameli 4fcb8bffbf Comments about dithering in SqliteSampleBlock 2021-05-27 11:38:10 -04:00
Paul Licameli 6eb5f3ac5b Eliminate CopySamples calls where destination is always float...
.. Call the function SamplesToFloats instead, or in one place, where source
is also always float, just do memcpy.

Dithering never happened in these cases.
2021-05-27 11:38:09 -04:00
Leland Lucius 125114cfe7 Bug 2700 - "Failed to open the project database"
Only information gathering changes...not a fix
2021-03-27 14:26:30 -05:00
James Crook cc9d53df04 Add Comments (for Bug 2673 fix)
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.
2021-02-23 12:24:41 +00:00
James Crook 42a105ee0a Review DB/Data safety.
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.
2021-01-23 19:00:36 +00:00
Paul Licameli 41eb66fccf Where CurConn() is used, don't assume it is non-null 2020-12-06 21:31:06 -05:00
Paul Licameli 9d6dd45973 More use of constSamplePtr instead of samplePtr 2020-11-29 19:45:18 -05:00
Paul Licameli a9bd2100bb Bug2551: Fix misread of silent sample blocks & memory overwrites 2020-10-07 18:58:34 -04:00
Paul Licameli 4ca09d55a1 Null checks on SqliteSampleBlock::mpFactory 2020-10-07 15:33:13 -04:00
Paul Licameli cbd21c5fff Fix crash on exit, which could be seen at least on Mac, if you...
... 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.
2020-09-14 15:14:19 -04:00
James Crook caf4eadb97 Help button for many warning messages; Restored warning icon.
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.
2020-09-14 17:43:28 +01:00
Paul Licameli 8a86fe139f Bug2531: need progress indication when discarding undo history...
... 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.
2020-09-06 17:54:14 -04:00
Paul Licameli dfd313f8fa SqliteSampleBlock has back-pointer to its factory...
... and thence to its database connection, indirectly.
2020-09-06 17:09:51 -04:00
Paul Licameli 55bf357b8e Remove an assertion 2020-09-04 13:02:12 -04:00
Paul Licameli 9129a19c8a Remove unnecessary assertion 2020-09-03 11:47:17 -04:00
Paul Licameli cca20f4e68 Bug2533: Optimize storage of silent blocks...
... 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.
2020-09-02 21:43:20 -04:00
Paul Licameli 64c50e57da
Sample block cleanups (#657)
* 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
2020-09-02 13:11:30 -05:00
Paul Licameli b32670b0bc Remove Doxygen comments for nonexistent parameters 2020-09-02 10:53:32 -04:00
Paul Licameli a093f5b2cf Remove unused member 2020-09-01 13:36:41 -04:00
Paul Licameli 92d7ee38e5
Do orphan block checking differently... (#655)
... 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.
2020-09-01 10:54:36 -05:00
Paul Licameli 0785a82e2b
bug2537 addendum: XML block attributes are redundant... (#653)
... 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!
2020-08-31 20:30:59 -05:00
Paul Licameli f137a1ed3e
Bug2537: graph of sharing of block objects needs recreation on open (#652) 2020-08-31 19:30:47 -05:00
Paul Licameli e5c548f76d Fix spelling in comments 2020-08-31 15:04:42 -04:00
Leland Lucius d9047dfd25 [Bug 2533] New: Extreme space inefficiency importing silence from an AUP file 2020-08-30 21:21:45 -05:00
Paul Licameli 70175acaf4 Fix infinite loop of error messages trying to draw corrupt project...
... As reported by Steve.

Don't throw exceptions when trying only to display a track and the samples
can't be found in the database.
2020-08-26 21:49:39 -04:00
Paul Licameli 2389b191f6 Bug2513: Disk exhaustion error message should be as was pre-Unitary 2020-08-26 16:56:03 -04:00
Paul Licameli 0c4514efb0 Avoid some unexpected recursions because of yields to event loop...
... See code comments.

Not proved to be a cause of data loss bugs, but they caused surprises when
trying to step in the debugger.
2020-08-26 16:01:54 -04:00
Leland Lucius 8943494f8a AUP3: Better space usage calculations
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.
2020-08-01 04:25:42 -05:00
Paul Licameli a8fd6c6ce8
Preliminaries for grouped block deletion (#628)
* 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
2020-07-23 11:17:29 -05:00
Paul Licameli a3fcd611b5
Dependency cleanup (#627)
* 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
2020-07-23 01:04:46 -05:00
Leland Lucius 7bb2417db3 AUP3: Fix flushing of tracks/clips in AUP importer 2020-07-22 14:40:14 -05:00
Leland Lucius 6f771d1783 AUP3: Fix previous commit and rework db handling
This moves direct handling of the sqlite3 DB handle into it's own
class, along with the checkpointing thread and prepared statement
cache.
2020-07-22 11:41:03 -05:00
Leland Lucius 6c70cb86ee AUP3: Use persistent prepared statements
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.
2020-07-21 09:04:50 -05:00
Leland Lucius 3954998083 AUP3: UP-33 History window shows misleading "space 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.
2020-07-15 09:43:48 -05:00
Leland Lucius 632ad6efcf AUP3: Better orphan block handling
This replaces my previous attempt since it didn't account
for all the situations where orphans blocks could occur.
2020-07-09 13:14:12 -05:00
Leland Lucius af6a23696b AUP3: Detect and delete orphan blocks at startup 2020-07-08 00:18:05 -05:00
Paul Licameli 875e8e0984
Cross project copy data loss (#604)
* 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.
2020-07-07 15:41:50 -05:00
Paul Licameli 3d0e86a8f8 Correct substitution of long long values into SQL queries...
... Reviewed all sqlite3_snprintf and only these had problems
2020-07-05 17:25:16 -04:00
Paul Licameli 8b3f9fae58
Sqlite errors (#601)
* 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.
2020-07-05 14:13:30 -05:00
Leland Lucius 48287e9b0d AUP3: Provides relief from slow shutdown
This is a hack to fix the long delay at Audacity shutdown
after editing large files and tossing the results (not
saving).
2020-07-02 22:08:39 -05:00
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