mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-17 08:30:06 +02:00
Bug2537: graph of sharing of block objects needs recreation on open (#652)
This commit is contained in:
parent
e5c548f76d
commit
f137a1ed3e
@ -145,6 +145,12 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
const std::shared_ptr<ConnectionPtr> mppConnection;
|
const std::shared_ptr<ConnectionPtr> mppConnection;
|
||||||
|
|
||||||
|
// Track all blocks that this factory has created, but don't control
|
||||||
|
// their lifetimes (so use weak_ptr)
|
||||||
|
using AllBlocksMap =
|
||||||
|
std::map< SampleBlockID, std::weak_ptr< SqliteSampleBlock > >;
|
||||||
|
AllBlocksMap mAllBlocks;
|
||||||
};
|
};
|
||||||
|
|
||||||
SqliteSampleBlockFactory::SqliteSampleBlockFactory( AudacityProject &project )
|
SqliteSampleBlockFactory::SqliteSampleBlockFactory( AudacityProject &project )
|
||||||
@ -160,6 +166,8 @@ SampleBlockPtr SqliteSampleBlockFactory::DoCreate(
|
|||||||
{
|
{
|
||||||
auto sb = std::make_shared<SqliteSampleBlock>(mppConnection);
|
auto sb = std::make_shared<SqliteSampleBlock>(mppConnection);
|
||||||
sb->SetSamples(src, numsamples, srcformat);
|
sb->SetSamples(src, numsamples, srcformat);
|
||||||
|
// block id has now been assigned
|
||||||
|
mAllBlocks[ sb->GetBlockID() ] = sb;
|
||||||
return sb;
|
return sb;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,6 +176,8 @@ SampleBlockPtr SqliteSampleBlockFactory::DoCreateSilent(
|
|||||||
{
|
{
|
||||||
auto sb = std::make_shared<SqliteSampleBlock>(mppConnection);
|
auto sb = std::make_shared<SqliteSampleBlock>(mppConnection);
|
||||||
sb->SetSilent(numsamples, srcformat);
|
sb->SetSilent(numsamples, srcformat);
|
||||||
|
// block id has now been assigned
|
||||||
|
mAllBlocks[ sb->GetBlockID() ] = sb;
|
||||||
return sb;
|
return sb;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,8 +185,7 @@ SampleBlockPtr SqliteSampleBlockFactory::DoCreateSilent(
|
|||||||
SampleBlockPtr SqliteSampleBlockFactory::DoCreateFromXML(
|
SampleBlockPtr SqliteSampleBlockFactory::DoCreateFromXML(
|
||||||
sampleFormat srcformat, const wxChar **attrs )
|
sampleFormat srcformat, const wxChar **attrs )
|
||||||
{
|
{
|
||||||
auto sb = std::make_shared<SqliteSampleBlock>(mppConnection);
|
std::shared_ptr<SqliteSampleBlock> sb;
|
||||||
sb->mSampleFormat = srcformat;
|
|
||||||
|
|
||||||
int found = 0;
|
int found = 0;
|
||||||
|
|
||||||
@ -199,8 +208,21 @@ SampleBlockPtr SqliteSampleBlockFactory::DoCreateFromXML(
|
|||||||
{
|
{
|
||||||
if (wxStrcmp(attr, wxT("blockid")) == 0)
|
if (wxStrcmp(attr, wxT("blockid")) == 0)
|
||||||
{
|
{
|
||||||
|
// Note that we depend on finding "blockid" before
|
||||||
|
// the other attributes, to assign sb first
|
||||||
|
// But first see if this block id was previously loaded
|
||||||
|
auto &wb = mAllBlocks[ nValue ];
|
||||||
|
auto pb = wb.lock();
|
||||||
|
if (pb)
|
||||||
|
// Reuse the block
|
||||||
|
sb = pb;
|
||||||
|
else {
|
||||||
|
// First sight of this id
|
||||||
|
wb = sb = std::make_shared<SqliteSampleBlock>(mppConnection);
|
||||||
|
sb->mSampleFormat = srcformat;
|
||||||
// This may throw
|
// This may throw
|
||||||
sb->Load((SampleBlockID) nValue);
|
sb->Load((SampleBlockID) nValue);
|
||||||
|
}
|
||||||
found++;
|
found++;
|
||||||
}
|
}
|
||||||
else if (wxStrcmp(attr, wxT("samplecount")) == 0)
|
else if (wxStrcmp(attr, wxT("samplecount")) == 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user