Merge branch 'hotfix/file-switching'

This commit is contained in:
paulfd 2019-09-28 15:57:43 +02:00
commit 2e7b3e0cd7
3 changed files with 13 additions and 6 deletions

View file

@ -145,16 +145,17 @@ void sfz::FilePool::loadingThread() noexcept
void sfz::FilePool::garbageThread() noexcept void sfz::FilePool::garbageThread() noexcept
{ {
while (!quitThread) { while (!quitThread) {
fileHandleMutex.lock();
for (auto handle = fileHandles.begin(); handle < fileHandles.end();) { for (auto handle = fileHandles.begin(); handle < fileHandles.end();) {
if (handle->use_count() == 1) { if (handle->use_count() == 1) {
handle->reset(); handle->reset();
std::lock_guard<std::mutex> guard { fileHandleMutex };
std::iter_swap(handle, fileHandles.end() - 1); std::iter_swap(handle, fileHandles.end() - 1);
fileHandles.pop_back(); fileHandles.pop_back();
} else { } else {
handle++; handle++;
} }
} }
fileHandleMutex.unlock();
std::this_thread::sleep_for(200ms); std::this_thread::sleep_for(200ms);
} }
} }

View file

@ -72,11 +72,11 @@ private:
void loadingThread() noexcept; void loadingThread() noexcept;
void garbageThread() noexcept; void garbageThread() noexcept;
bool quitThread { false }; bool quitThread { false };
std::mutex fileHandleMutex;
std::vector<std::shared_ptr<AudioBuffer<float>>> fileHandles;
absl::flat_hash_map<absl::string_view, std::shared_ptr<AudioBuffer<float>>> preloadedData;
std::thread fileLoadingThread { &FilePool::loadingThread, this }; std::thread fileLoadingThread { &FilePool::loadingThread, this };
std::thread garbageCollectionThread { &FilePool::garbageThread, this }; std::thread garbageCollectionThread { &FilePool::garbageThread, this };
std::vector<std::shared_ptr<AudioBuffer<float>>> fileHandles;
std::mutex fileHandleMutex;
absl::flat_hash_map<absl::string_view, std::shared_ptr<AudioBuffer<float>>> preloadedData;
LEAK_DETECTOR(FilePool); LEAK_DETECTOR(FilePool);
}; };
} }

View file

@ -108,6 +108,14 @@ void sfz::Synth::buildRegion(const std::vector<Opcode>& regionOpcodes)
void sfz::Synth::clear() void sfz::Synth::clear()
{ {
for (auto &voice: voices)
voice->reset();
for (auto& list: noteActivationLists)
list.clear();
for (auto& list: ccActivationLists)
list.clear();
regions.clear();
filePool.clear();
hasGlobal = false; hasGlobal = false;
hasControl = false; hasControl = false;
numGroups = 0; numGroups = 0;
@ -121,8 +129,6 @@ void sfz::Synth::clear()
globalOpcodes.clear(); globalOpcodes.clear();
masterOpcodes.clear(); masterOpcodes.clear();
groupOpcodes.clear(); groupOpcodes.clear();
regions.clear();
filePool.clear();
} }
void sfz::Synth::handleGlobalOpcodes(const std::vector<Opcode>& members) void sfz::Synth::handleGlobalOpcodes(const std::vector<Opcode>& members)