From 44758f04ef2aa17ce809f823715d7265f24257dc Mon Sep 17 00:00:00 2001 From: Paul Walker Date: Sat, 17 Aug 2024 19:49:18 -0400 Subject: [PATCH] Reset also resets busses Reset reset the parts but not the mixer. Fix that. Closes #1124 Also fix a multi load problem which ASAN caught reading beyond a chunk in a string construction. --- src/engine/bus.h | 10 ++++++++++ src/engine/patch.h | 7 ++++++- src/patch_io/patch_io.cpp | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/engine/bus.h b/src/engine/bus.h index a09d313c..41933e6f 100644 --- a/src/engine/bus.h +++ b/src/engine/bus.h @@ -134,6 +134,16 @@ struct Bus : MoveableOnly, SampleRateSupport assert(address != DEFAULT_BUS && address != ERROR_BUS); } + void resetBus() + { + busSendStorage = BusSendStorage(); + for (int i = 0; i < maxEffectsPerBus; ++i) + { + busEffectStorage[i] = BusEffectStorage(); + busEffects[i].reset(); + } + } + float output alignas(16)[2][blockSize]; float outputOS alignas(16)[2][blockSize << 1]; bool hasOSSignal{false}, previousHadOSSignal{false}; diff --git a/src/engine/patch.h b/src/engine/patch.h index ca30c968..3f410f16 100644 --- a/src/engine/patch.h +++ b/src/engine/patch.h @@ -43,13 +43,16 @@ struct Patch : MoveableOnly, SampleRateSupport // TODO - does this really belong in the patch? I think it probably does struct Busses { - Busses() : mainBus(MAIN_0) + Busses() : mainBus(MAIN_0) { initialize(); } + void initialize() { std::fill(partToVSTRouting.begin(), partToVSTRouting.end(), 0); std::fill(auxToVSTRouting.begin(), auxToVSTRouting.end(), 0); int adr = PART_0; + mainBus.resetBus(); for (auto &p : partBusses) { + p.resetBus(); p.address = (BusAddress)adr; p.busSendStorage.supportsSends = true; adr++; @@ -57,6 +60,7 @@ struct Patch : MoveableOnly, SampleRateSupport adr = AUX_0; for (auto &p : auxBusses) { + p.resetBus(); p.address = (BusAddress)adr; adr++; } @@ -168,6 +172,7 @@ struct Patch : MoveableOnly, SampleRateSupport parts[i] = std::make_unique(i); parts[i]->parentPatch = this; } + busses.initialize(); setSampleRate(1); } diff --git a/src/patch_io/patch_io.cpp b/src/patch_io/patch_io.cpp index 93950286..a545340b 100644 --- a/src/patch_io/patch_io.cpp +++ b/src/patch_io/patch_io.cpp @@ -60,7 +60,7 @@ void addSCManifest(const std::unique_ptr &f, const std::string &type std::unordered_map readSCManifest(const std::unique_ptr &f) { auto c1 = f->GetSubChunk('scmf'); - std::string s((char *)c1->LoadChunkData()); + std::string s((char *)c1->LoadChunkData(), c1->GetSize()); tao::json::events::transformer> consumer; tao::json::events::from_string(consumer, s);