diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 2d7f2a92..d11c10a0 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -898,26 +898,6 @@ void Synth::setSampleRate(float sampleRate) noexcept } } -void Synth::Impl::updateRegions() noexcept -{ - std::unique_lock lock { regionUpdatesMutex_, std::try_to_lock }; - if (!lock.owns_lock()) - return; - - absl::c_sort(regionUpdates_, [](const OpcodeUpdate& lhs, const OpcodeUpdate& rhs) { - return lhs.delay < rhs.delay; - }); - - for (auto& update: regionUpdates_) { - if (!update.region) - continue; - - update.region->parseOpcode(update.opcode, false); - } - - regionUpdates_.clear(); -} - void Synth::renderBlock(AudioSpan buffer) noexcept { Impl& impl = *impl_; @@ -947,8 +927,6 @@ void Synth::renderBlock(AudioSpan buffer) noexcept impl.resources_.filePool.triggerGarbageCollection(); } - impl.updateRegions(); - auto tempSpan = impl.resources_.bufferPool.getStereoBuffer(numFrames); auto tempMixSpan = impl.resources_.bufferPool.getStereoBuffer(numFrames); auto rampSpan = impl.resources_.bufferPool.getBuffer(numFrames); diff --git a/src/sfizz/SynthMessaging.cpp b/src/sfizz/SynthMessaging.cpp index fd5de3fb..8ba1a216 100644 --- a/src/sfizz/SynthMessaging.cpp +++ b/src/sfizz/SynthMessaging.cpp @@ -1364,45 +1364,54 @@ void sfz::Synth::dispatchMessage(Client& client, int delay, const char* path, co Layer& layer = *impl.layers_[idx]; \ Region& region = layer.getRegion(); + #define GET_FILTER_OR_BREAK(idx) \ + if (idx >= region.filters.size()) \ + break; \ + auto& filter = region.filters[idx]; + + #define GET_LFO_OR_BREAK(idx) \ + if (idx >= region.lfos.size()) \ + break; \ + auto& lfo = region.lfos[idx]; + + #define GET_LFO_SUB_OR_BREAK(idx) \ + if (idx >= lfo.sub.size()) \ + break; \ + auto& sub = lfo.sub[idx]; + MATCH("/region&/pitch_keycenter", "i") { GET_REGION_OR_BREAK(indices[0]) - std::lock_guard lock { impl.regionUpdatesMutex_ }; - Impl::OpcodeUpdate update { delay, ®ion, - Opcode { "pitch_keycenter", std::to_string(args[0].i) } }; - impl.regionUpdates_.emplace_back(update); + region.pitchKeycenter = Opcode::transform(Default::key, args[0].i); } break; MATCH("/region&/loop_mode", "s") { GET_REGION_OR_BREAK(indices[0]) - std::lock_guard lock { impl.regionUpdatesMutex_ }; - Impl::OpcodeUpdate update { delay, ®ion, - Opcode { "loop_mode", args[0].s } }; - impl.regionUpdates_.emplace_back(update); + region.loopMode = Opcode::readOptional(Default::loopMode, args[0].s); } break; MATCH("/region&/filter&/type", "s") { GET_REGION_OR_BREAK(indices[0]) - if (indices[1] >= region.filters.size()) - break; - - std::lock_guard lock { impl.regionUpdatesMutex_ }; - Impl::OpcodeUpdate update { delay, ®ion, - Opcode { absl::StrCat("fil", indices[1] + 1 , "_type "), args[0].s } }; - impl.regionUpdates_.emplace_back(update); + GET_FILTER_OR_BREAK(indices[1]) + filter.type = Opcode::read(Default::filter, args[0].s); } break; MATCH("/region&/lfo&/wave", "i") { - GET_REGION_OR_BREAK(indices[0]) - if (indices[1] >= region.lfos.size()) - break; + indices[2] = 0; + goto set_lfoN_wave; + } - std::lock_guard lock { impl.regionUpdatesMutex_ }; - Impl::OpcodeUpdate update { delay, ®ion, - Opcode { absl::StrCat("lfo", indices[1] + 1, "_wave1"), std::to_string(args[0].i) } }; - impl.regionUpdates_.emplace_back(update); + MATCH("/region&/lfo&/wave&", "i") { + set_lfoN_wave: + GET_REGION_OR_BREAK(indices[0]) + GET_LFO_OR_BREAK(indices[1]) + GET_LFO_SUB_OR_BREAK(indices[2]) + sub.wave = Opcode::transform(Default::lfoWave, args[0].i); } break; #undef GET_REGION_OR_BREAK + #undef GET_FILTER_OR_BREAK + #undef GET_LFO_OR_BREAK + #undef GET_LFO_SUB_OR_BREAK //---------------------------------------------------------------------- // Voices diff --git a/src/sfizz/SynthPrivate.h b/src/sfizz/SynthPrivate.h index 1b8b85d3..157bba4b 100644 --- a/src/sfizz/SynthPrivate.h +++ b/src/sfizz/SynthPrivate.h @@ -180,12 +180,6 @@ struct Synth::Impl final: public Parser::Listener { */ void finalizeSfzLoad(); - /** - * @brief Update the regions with the opcodes received through OSC if necessary - * - */ - void updateRegions() noexcept; - template static void collectUsedCCsFromCCMap(BitArray& usedCCs, const CCMap map) noexcept { @@ -348,16 +342,6 @@ struct Synth::Impl final: public Parser::Listener { } bool playheadMoved_ { false }; - - struct OpcodeUpdate - { - int delay; - Region* region; - Opcode opcode; - }; - - std::vector regionUpdates_; - SpinMutex regionUpdatesMutex_; }; } // namespace sfz