// param_merge.cpp — see param_merge.h.

#include "core/instrument/param/param_merge.h"

#include "core/instrument/param/param_live.h"

namespace reasampler::instrument::param {

void mergeAutomation(engine::LiveValues& block, AutomationSlot* slots, std::size_t count,
                     int sampleRate) {
    for (std::size_t i = 0; i < count; ++i) {
        AutomationSlot& slot = slots[i];
        if (!slot.held) continue;
        if (slot.folded) {
            // Nothing to patch: `block` was read from the model, and the model is what the fold
            // wrote this point into. Dropping the hold here is the whole release.
            slot.held = false;
            slot.folded = false;
            continue;
        }
        applyLiveParam(block, static_cast<DeckParam>(i), slot.norm, sampleRate);
    }
}

}  // namespace reasampler::instrument::param
