mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-16 16:10:06 +02:00
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.
This commit is contained in:
parent
1e3885730f
commit
92d7ee38e5
@ -1539,10 +1539,8 @@ bool ProjectFileIO::ImportProject(const FilePath &fileName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
wxString project;
|
wxString project;
|
||||||
BlockIDs blockids;
|
|
||||||
|
|
||||||
// Decode it while capturing the associated sample blockids
|
project = ProjectSerializer::Decode(buffer);
|
||||||
project = ProjectSerializer::Decode(buffer, blockids);
|
|
||||||
if (project.size() == 0)
|
if (project.size() == 0)
|
||||||
{
|
{
|
||||||
SetError(XO("Unable to decode project document"));
|
SetError(XO("Unable to decode project document"));
|
||||||
@ -1788,7 +1786,6 @@ bool ProjectFileIO::LoadProject(const FilePath &fileName)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockIDs blockids;
|
|
||||||
wxString project;
|
wxString project;
|
||||||
wxMemoryBuffer buffer;
|
wxMemoryBuffer buffer;
|
||||||
bool usedAutosave = true;
|
bool usedAutosave = true;
|
||||||
@ -1821,8 +1818,7 @@ bool ProjectFileIO::LoadProject(const FilePath &fileName)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Decode it while capturing the associated sample blockids
|
project = ProjectSerializer::Decode(buffer);
|
||||||
project = ProjectSerializer::Decode(buffer, blockids);
|
|
||||||
if (project.empty())
|
if (project.empty())
|
||||||
{
|
{
|
||||||
SetError(XO("Unable to decode project document"));
|
SetError(XO("Unable to decode project document"));
|
||||||
@ -1830,15 +1826,6 @@ bool ProjectFileIO::LoadProject(const FilePath &fileName)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for orphans blocks...sets mRecovered if any were deleted
|
|
||||||
if (blockids.size() > 0)
|
|
||||||
{
|
|
||||||
if (!DeleteBlocks(blockids, true))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
XMLFileReader xmlFile;
|
XMLFileReader xmlFile;
|
||||||
|
|
||||||
// Load 'er up
|
// Load 'er up
|
||||||
@ -1852,6 +1839,19 @@ bool ProjectFileIO::LoadProject(const FilePath &fileName)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check for orphans blocks...sets mRecovered if any were deleted
|
||||||
|
|
||||||
|
auto blockids = WaveTrackFactory::Get( mProject )
|
||||||
|
.GetSampleBlockFactory()
|
||||||
|
->GetActiveBlockIDs();
|
||||||
|
if (blockids.size() > 0)
|
||||||
|
{
|
||||||
|
if (!DeleteBlocks(blockids, true))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Remember if we used autosave or not
|
// Remember if we used autosave or not
|
||||||
if (usedAutosave)
|
if (usedAutosave)
|
||||||
{
|
{
|
||||||
|
@ -383,7 +383,7 @@ bool ProjectSerializer::DictChanged() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// See ProjectFileIO::LoadProject() for explanation of the blockids arg
|
// See ProjectFileIO::LoadProject() for explanation of the blockids arg
|
||||||
wxString ProjectSerializer::Decode(const wxMemoryBuffer &buffer, BlockIDs &blockids)
|
wxString ProjectSerializer::Decode(const wxMemoryBuffer &buffer)
|
||||||
{
|
{
|
||||||
wxMemoryInputStream in(buffer.GetData(), buffer.GetDataLen());
|
wxMemoryInputStream in(buffer.GetData(), buffer.GetDataLen());
|
||||||
|
|
||||||
@ -549,16 +549,6 @@ wxString ProjectSerializer::Decode(const wxMemoryBuffer &buffer, BlockIDs &block
|
|||||||
{
|
{
|
||||||
id = ReadUShort( in );
|
id = ReadUShort( in );
|
||||||
long long val = ReadLongLong( in );
|
long long val = ReadLongLong( in );
|
||||||
|
|
||||||
// Look for and save the "blockid" values to support orphan
|
|
||||||
// block checking. This should be removed once serialization
|
|
||||||
// and related blocks become part of the same transaction.
|
|
||||||
const wxString &name = Lookup(id);
|
|
||||||
if (name.IsSameAs(wxT("blockid")))
|
|
||||||
{
|
|
||||||
blockids.insert(val);
|
|
||||||
}
|
|
||||||
|
|
||||||
out.WriteAttr(Lookup(id), val);
|
out.WriteAttr(Lookup(id), val);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -22,9 +22,6 @@
|
|||||||
// From SampleBlock.h
|
// From SampleBlock.h
|
||||||
using SampleBlockID = long long;
|
using SampleBlockID = long long;
|
||||||
|
|
||||||
// From ProjectFileiIO.h
|
|
||||||
using BlockIDs = std::unordered_set<SampleBlockID>;
|
|
||||||
|
|
||||||
///
|
///
|
||||||
/// ProjectSerializer
|
/// ProjectSerializer
|
||||||
///
|
///
|
||||||
@ -69,7 +66,7 @@ public:
|
|||||||
bool DictChanged() const;
|
bool DictChanged() const;
|
||||||
|
|
||||||
// Returns empty string if decoding fails
|
// Returns empty string if decoding fails
|
||||||
static wxString Decode(const wxMemoryBuffer &buffer, BlockIDs &blockids);
|
static wxString Decode(const wxMemoryBuffer &buffer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void WriteName(const wxString & name);
|
void WriteName(const wxString & name);
|
||||||
|
@ -13,6 +13,7 @@ SampleBlock.h
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
class AudacityProject;
|
class AudacityProject;
|
||||||
class ProjectFileIO;
|
class ProjectFileIO;
|
||||||
@ -133,6 +134,10 @@ public:
|
|||||||
sampleFormat srcformat,
|
sampleFormat srcformat,
|
||||||
const wxChar **attrs);
|
const wxChar **attrs);
|
||||||
|
|
||||||
|
using SampleBlockIDs = std::unordered_set<SampleBlockID>;
|
||||||
|
/*! @return ids of all sample blocks created by this factory and still extant */
|
||||||
|
virtual SampleBlockIDs GetActiveBlockIDs() = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// The override should throw more informative exceptions on error than the
|
// The override should throw more informative exceptions on error than the
|
||||||
// default InconsistencyException thrown by Create
|
// default InconsistencyException thrown by Create
|
||||||
|
@ -129,6 +129,8 @@ public:
|
|||||||
|
|
||||||
~SqliteSampleBlockFactory() override;
|
~SqliteSampleBlockFactory() override;
|
||||||
|
|
||||||
|
SampleBlockIDs GetActiveBlockIDs() override;
|
||||||
|
|
||||||
SampleBlockPtr DoGet(SampleBlockID sbid) override;
|
SampleBlockPtr DoGet(SampleBlockID sbid) override;
|
||||||
|
|
||||||
SampleBlockPtr DoCreate(samplePtr src,
|
SampleBlockPtr DoCreate(samplePtr src,
|
||||||
@ -171,6 +173,21 @@ SampleBlockPtr SqliteSampleBlockFactory::DoCreate(
|
|||||||
return sb;
|
return sb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto SqliteSampleBlockFactory::GetActiveBlockIDs() -> SampleBlockIDs
|
||||||
|
{
|
||||||
|
SampleBlockIDs result;
|
||||||
|
for (auto end = mAllBlocks.end(), it = mAllBlocks.begin(); it != end;) {
|
||||||
|
if (it->second.expired())
|
||||||
|
// Tighten up the map
|
||||||
|
it = mAllBlocks.erase(it);
|
||||||
|
else {
|
||||||
|
result.insert( it->first );
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
SampleBlockPtr SqliteSampleBlockFactory::DoCreateSilent(
|
SampleBlockPtr SqliteSampleBlockFactory::DoCreateSilent(
|
||||||
size_t numsamples, sampleFormat srcformat )
|
size_t numsamples, sampleFormat srcformat )
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user