mirror of
https://github.com/audacity/audacity-project-tools.git
synced 2026-02-03 19:46:27 -06:00
commit
40322b0650
9
.gitignore
vendored
9
.gitignore
vendored
@ -36,3 +36,12 @@ build/**
|
|||||||
out/**
|
out/**
|
||||||
.venv/**
|
.venv/**
|
||||||
CMakeUserPresets.json
|
CMakeUserPresets.json
|
||||||
|
|
||||||
|
# Audacity files
|
||||||
|
|
||||||
|
*.aup3
|
||||||
|
*.aup4
|
||||||
|
*.aup3-shm
|
||||||
|
*.aup3-wal
|
||||||
|
*.aup4-shm
|
||||||
|
*.aup4-wal
|
||||||
|
|||||||
@ -132,6 +132,12 @@ AudacityDatabase::AudacityDatabase(
|
|||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AudacityDatabase::~AudacityDatabase()
|
||||||
|
{
|
||||||
|
mDatabase.reset();
|
||||||
|
removeJournalFiles(mReadOnly ? mProjectPath : mWritablePath);
|
||||||
|
}
|
||||||
|
|
||||||
void AudacityDatabase::reopenReadonlyAsWritable()
|
void AudacityDatabase::reopenReadonlyAsWritable()
|
||||||
{
|
{
|
||||||
if (!mReadOnly)
|
if (!mReadOnly)
|
||||||
@ -466,22 +472,26 @@ void AudacityDatabase::extractTrack(
|
|||||||
waveFile.writeFile();
|
waveFile.writeFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AudacityDatabase::removeJournalFiles(const std::filesystem::path& dbPath)
|
||||||
|
{
|
||||||
|
auto walFile = dbPath;
|
||||||
|
walFile.replace_extension("aup3-wal");
|
||||||
|
|
||||||
|
if (std::filesystem::exists(walFile))
|
||||||
|
std::filesystem::remove(walFile);
|
||||||
|
|
||||||
|
auto shmFile = dbPath;
|
||||||
|
shmFile.replace_extension("aup3-shm");
|
||||||
|
|
||||||
|
if (std::filesystem::exists(shmFile))
|
||||||
|
std::filesystem::remove(shmFile);
|
||||||
|
}
|
||||||
|
|
||||||
void AudacityDatabase::removeOldFiles()
|
void AudacityDatabase::removeOldFiles()
|
||||||
{
|
{
|
||||||
if (std::filesystem::exists(mWritablePath))
|
if (std::filesystem::exists(mWritablePath))
|
||||||
{
|
{
|
||||||
std::filesystem::remove(mWritablePath);
|
std::filesystem::remove(mWritablePath);
|
||||||
|
removeJournalFiles(mWritablePath);
|
||||||
auto walFile = mWritablePath;
|
|
||||||
walFile.replace_extension("aup3-wal");
|
|
||||||
|
|
||||||
if (std::filesystem::exists(walFile))
|
|
||||||
std::filesystem::remove(walFile);
|
|
||||||
|
|
||||||
auto shmFile = mWritablePath;
|
|
||||||
shmFile.replace_extension("aup3-shm");
|
|
||||||
|
|
||||||
if (std::filesystem::exists(shmFile))
|
|
||||||
std::filesystem::remove(shmFile);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,7 @@ class AudacityDatabase final
|
|||||||
public:
|
public:
|
||||||
explicit AudacityDatabase(
|
explicit AudacityDatabase(
|
||||||
const std::filesystem::path& path, RecoveryConfig recoveryConfig);
|
const std::filesystem::path& path, RecoveryConfig recoveryConfig);
|
||||||
|
~AudacityDatabase();
|
||||||
|
|
||||||
void reopenReadonlyAsWritable();
|
void reopenReadonlyAsWritable();
|
||||||
void recoverDatabase();
|
void recoverDatabase();
|
||||||
@ -43,6 +44,7 @@ public:
|
|||||||
void extractTrack(SampleFormat format, int32_t sampleRate, bool asStereo);
|
void extractTrack(SampleFormat format, int32_t sampleRate, bool asStereo);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static void removeJournalFiles(const std::filesystem::path& dbPath);
|
||||||
void removeOldFiles();
|
void removeOldFiles();
|
||||||
|
|
||||||
std::unique_ptr<SQLite::Database> mDatabase;
|
std::unique_ptr<SQLite::Database> mDatabase;
|
||||||
|
|||||||
@ -281,17 +281,10 @@ class IdsLookup final
|
|||||||
public:
|
public:
|
||||||
void store(uint16_t index, std::string value)
|
void store(uint16_t index, std::string value)
|
||||||
{
|
{
|
||||||
const auto size = mIds.size();
|
if (index >= mIds.size())
|
||||||
|
mIds.resize(index + 1);
|
||||||
|
|
||||||
if (index == size)
|
mIds[index] = std::move(value);
|
||||||
mIds.push_back(std::move(value));
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ((index + 1) < size)
|
|
||||||
mIds.resize(index);
|
|
||||||
|
|
||||||
mIds[index] = std::move(value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view get(uint16_t index)
|
std::string_view get(uint16_t index)
|
||||||
|
|||||||
@ -86,6 +86,7 @@ Buffer::read(void* data, size_t offset, size_t size) const noexcept
|
|||||||
offset = 0;
|
offset = 0;
|
||||||
bytesLeft -= chunkSize;
|
bytesLeft -= chunkSize;
|
||||||
outPtr += chunkSize;
|
outPtr += chunkSize;
|
||||||
|
++chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
|
|||||||
@ -48,12 +48,12 @@ public:
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
const size_t chunkIndex = offset / BUFFER_SIZE;
|
const size_t chunkIndex = offset / BUFFER_SIZE;
|
||||||
offset = offset - BUFFER_SIZE * chunkIndex;
|
const size_t chunkOffset = offset - BUFFER_SIZE * chunkIndex;
|
||||||
|
|
||||||
if (BUFFER_SIZE < (offset + size))
|
if (BUFFER_SIZE < (chunkOffset + size))
|
||||||
return read(&data, offset, size);
|
return read(&data, offset, size);
|
||||||
|
|
||||||
const void* ptr = mChunks[chunkIndex].data() + offset;
|
const void* ptr = mChunks[chunkIndex].data() + chunkOffset;
|
||||||
|
|
||||||
data = *static_cast<const T*>(ptr);
|
data = *static_cast<const T*>(ptr);
|
||||||
|
|
||||||
|
|||||||
@ -483,15 +483,22 @@ void AudacityProject::removeUnusedBlocks()
|
|||||||
|
|
||||||
readBlocksList.reset();
|
readBlocksList.reset();
|
||||||
|
|
||||||
std::set<int64_t> orphanedBlocks;
|
std::set<int64_t> usedBlocks;
|
||||||
|
|
||||||
for (const auto block : mWaveBlocks)
|
for (const auto& block : mWaveBlocks)
|
||||||
{
|
{
|
||||||
if (block.isSilence())
|
if (block.isSilence())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (availableBlocks.count(block.getBlockId()) == 0)
|
usedBlocks.emplace(block.getBlockId());
|
||||||
orphanedBlocks.emplace(block.getBlockId());
|
}
|
||||||
|
|
||||||
|
std::set<int64_t> orphanedBlocks;
|
||||||
|
|
||||||
|
for (auto blockId : availableBlocks)
|
||||||
|
{
|
||||||
|
if (usedBlocks.count(blockId) == 0)
|
||||||
|
orphanedBlocks.emplace(blockId);
|
||||||
}
|
}
|
||||||
|
|
||||||
mDb.reopenReadonlyAsWritable();
|
mDb.reopenReadonlyAsWritable();
|
||||||
|
|||||||
@ -55,7 +55,7 @@ void GetAttributeValue(const AttributeValue& attr, Ret& result)
|
|||||||
{
|
{
|
||||||
if constexpr (std::is_same_v<Ret, bool>)
|
if constexpr (std::is_same_v<Ret, bool>)
|
||||||
{
|
{
|
||||||
result = arg == "true" || arg == "0";
|
result = arg == "true" || arg == "1";
|
||||||
}
|
}
|
||||||
else if constexpr (std::is_floating_point_v<Ret>)
|
else if constexpr (std::is_floating_point_v<Ret>)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user