diff --git a/sources/Synth.h b/sources/Synth.h index 3ad41821..8f7100c6 100644 --- a/sources/Synth.h +++ b/sources/Synth.h @@ -23,13 +23,11 @@ public: { for (int i = 0; i < config::numVoices; ++i) voices.push_back(std::make_unique(ccState)); - garbageCollectionThread = std::thread(&Synth::garbageCollection, this); } ~Synth() { - threadsShouldQuit = true; - garbageCollectionThread.join(); + } bool loadSfzFile(const std::filesystem::path& file) final; @@ -131,7 +129,21 @@ public: void pitchWheel(int delay, int channel, int pitch); void aftertouch(int delay, int channel, uint8_t aftertouch); void tempo(int delay, float secondsPerQuarter); + void getNumActiveVoices() const + { + auto activeVoices { 0 }; + for (const auto& voice : voices) { + if (!voice->isFree()) + activeVoices++; + } + } + void garbageCollect() + { + for (auto& voice : voices) { + voice->garbageCollect(); + } + } protected: void callback(std::string_view header, const std::vector& members) final; @@ -146,20 +158,6 @@ private: return freeVoice->get(); } - void garbageCollection() - { - while (!threadsShouldQuit) { - auto activeVoices { 0 }; - for (auto& voice : voices) { - voice->garbageCollect(); - if (!voice->isFree()) - activeVoices++; - } - DBG("Active voices:" << activeVoices << " | Stray buffers: " << FilePool::getFileBuffers()); - std::this_thread::sleep_for(200ms); - } - } - bool hasGlobal { false }; bool hasControl { false }; int numGroups { 0 }; diff --git a/sources/Voice.h b/sources/Voice.h index 66af1ac7..07ba9b37 100644 --- a/sources/Voice.h +++ b/sources/Voice.h @@ -71,7 +71,7 @@ public: dataReady.store(true); } - bool isFree() + bool isFree() const { return (region == nullptr); }