Jelajahi Sumber

Engine: one worker-pool round per device block cut in pieces (round 190kz, sched)

A block the renderer cuts in pieces (the automation's 128-sample grid on the export's 512 grid, pattern events) ran
one task-graph round per piece: at a 480 block about 4.4 rounds, each with its wake-ups, spins and the wait for the
last task. processBatched now runs every piece's serial part first (chunkPrelude, processChunk's code unchanged), each
into its own slot of the per-chunk state, then ONE round in which each channel and insert renders its pieces one
after another (piece k with slot k's state, its own plugin-parameter bindings for that piece, its buffers at the
piece's offset), then the Master's pieces in order. Every unit gets the same calls, sizes, values and order as
before, so the samples are the same bit for bit (perfbench hashes: Thief 480/128/64, Exoplanet, Patience, the
synthetic scenarios, one thread and 3 workers, rounds=chunk and rounds=block; 20 FL demos + Patience at 480).

- Per-chunk state in per-piece slots picked by a thread_local slot (0 outside a batched block, so every other path
  reads what it read before): PieceValue / PieceArray / PieceEvents, per-piece host play heads.
- processChunk split into chunkPrelude / chunkSchedule / chunkUnits / chunkMaster (same statements, same order);
  applyPluginParams' body is applyPluginParam; updateAutomation defers it to the units inside a batched block.
- batchable keeps the per-piece path where a piece's serial part depends on the previous piece's units or a unit
  reaches outside its task (live controllers, MIDI between units, launchers, render-ahead split, extra outputs,
  cross-unit bindings, effects following the Channel rack's held notes with their settings or automated ones,
  sample-accurate plugin params, the "When recording or not playing" switch, more than 8 pieces); reasons counted
  (batchRefusedCount; perfbench "sched:" lines).
- Effect::followsHeldNotes / followsHeldNotesWith (Compressor, Shifter, Comb, Pitcher, containers).
- A/B: LYNX_POOL="rounds=chunk" (or rounds=0) = one round per piece as before; "rounds=block" = default
  (WorkerPool::Tuning::blockRounds, the only pool change).

Thief at 480 with 3 workers, paced: 4.43 -> 1.00 rounds per block, process CPU ~54 % -> ~37 % of a core.
Tests: tests/Sched190kzTests.inc.
Ka1-S 2 minggu lalu
induk
melakukan
274ca41b94

+ 5 - 0
src/core/DynamicsSuite.cpp

@@ -795,6 +795,11 @@ public:
         held = channels;
         heldCount = count;
     }
+    bool followsHeldNotes() const noexcept override { return true; } // (round 190kz)
+    bool followsHeldNotesWith (const EffectParams& p) const noexcept override // (the MIDI trigger on a channel: chunk())
+    {
+        return triggerOf (p[trigger]) == Trigger::midi && triggerChannelOf (p[triggerChannel]) >= 0;
+    }
 
     void process (float* l, float* r, int n, const EffectParams& p, double bpm) noexcept override
     {

+ 13 - 0
src/core/Effects.cpp

@@ -2361,6 +2361,11 @@ public:
         held = channels;
         heldCount = count;
     }
+    bool followsHeldNotes() const noexcept override { return true; } // (round 190kz)
+    bool followsHeldNotesWith (const EffectParams& p) const noexcept override // (process(): unless the MIDI port routes its notes)
+    {
+        return ! (p[(std::size_t) pcorr::portRoutingParam] > 0.5f);
+    }
 
     // round 190ee: a note from the MIDI Out channels on the Pitcher's port (FL: note in 0x180007a40, velocity / 127)
     void midiNote (int key, int velocity, int) noexcept override
@@ -2614,6 +2619,14 @@ public:
             for (auto& c : b.chain)
                 c.effect->setHeldNotes (channels, count);
     }
+    bool followsHeldNotes() const noexcept override // (round 190kz)
+    {
+        for (const auto& b : branches)
+            for (const auto& c : b.chain)
+                if (c.effect != nullptr && c.effect->followsHeldNotes())
+                    return true;
+        return false;
+    }
 
     void process (float* l, float* r, int n, const EffectParams&, double bpm) noexcept override
     {

+ 6 - 0
src/core/Effects.h

@@ -161,6 +161,12 @@ public:
     // The notes held on every Channel Rack channel (`count` masks, by channel index) during the next process(); the
     // pointer stays valid until the next call. Effects that follow notes (LYNX Tune's MIDI targets) keep it.
     virtual void setHeldNotes (const NoteMask* /*channels*/, int /*count*/) noexcept {}
+    // Round 190kz: true for an effect that can read those held notes (setHeldNotes) while it processes; it reads every
+    // channel's, so the renderer keeps such a slot's block piece by piece (RackRenderer::processBatched) — when its
+    // parameters are automated, or when followsHeldNotesWith says these settings read them
+    virtual bool followsHeldNotes() const noexcept { return false; }
+    // ... with these parameter values (the slot's own): does it read them? (default: whenever it can)
+    virtual bool followsHeldNotesWith (const EffectParams& /*params*/) const noexcept { return followsHeldNotes(); }
     // Round 190ee: a note reaching the effect through its MIDI input port (FL: a MIDI Out channel on the port the
     // effect listens to), before the process() that follows. `velocity` 1…127, 0 = note off; `midiChannel` 0…15.
     // Audio thread. Effects that take notes: Gross Beat (slot selection), Pitcher (MIDI mode / Harmonize).

+ 9 - 0
src/core/Patcher.cpp

@@ -839,6 +839,14 @@ void Graph::setHeldNotes (const NoteMask* channels, int count) noexcept
             n->effect->setHeldNotes (channels, count);
 }
 
+bool Graph::followsHeldNotes() const noexcept
+{
+    for (const auto& n : nodes)
+        if (n->effect != nullptr && n->effect->followsHeldNotes())
+            return true;
+    return false;
+}
+
 void Graph::noteOn (int key, float velocity) noexcept { deliver (0, true, key, velocity, -1); }
 void Graph::noteOff (int key) noexcept { deliver (0, false, key, 0.0f, -1); }
 void Graph::noteOnMidi (int key, float velocity, int midiChannel) noexcept { deliver (0, true, key, velocity, midiChannel); }
@@ -1689,6 +1697,7 @@ public:
         side = l != nullptr && r != nullptr;
     }
     void setHeldNotes (const NoteMask* channels, int count) noexcept override { graph.setHeldNotes (channels, count); }
+    bool followsHeldNotes() const noexcept override { return graph.followsHeldNotes(); } // (round 190kz)
     int latencySamples() const noexcept override { return graph.latencySamples(); }
 
     Graph graph;

+ 1 - 0
src/core/Patcher.h

@@ -92,6 +92,7 @@ public:
     void setSongPosition (double ticks) noexcept;
     void setPlaying (bool playing) noexcept;
     void setHeldNotes (const NoteMask* channels, int count) noexcept;
+    bool followsHeldNotes() const noexcept; // (round 190kz: a node's effect reads them)
 
     // One block: the host's input (and side-chain, may be null) in, the main output out (may alias the input);
     // the extra outputs land in auxOutput(). Any n (split into pieces).

+ 2 - 0
src/core/PocketFxD.cpp

@@ -258,6 +258,8 @@ public:
         held = channels;
         heldCount = count;
     }
+    bool followsHeldNotes() const noexcept override { return true; } // (round 190kz)
+    bool followsHeldNotesWith (const EffectParams& p) const noexcept override { return combMode (p[0]) == 1; } // (process(): mode 1)
     void process (float* left, float* right, int n, const EffectParams& p, double) noexcept override
     {
         if (tapes[0].w.points.empty())

+ 591 - 53
src/core/RackRenderer.cpp

@@ -2639,7 +2639,8 @@ void RackRenderer::prepare (double sr, int maxBlockSize)
     lowLatencySkipped.assign ((std::size_t) maxMixerTracks * maxEffectSlots, 0);
     goalGlideAmount.assign ((std::size_t) maxMixerTracks * maxEffectSlots, std::numeric_limits<float>::quiet_NaN());
     goalGlideEffect.assign ((std::size_t) maxMixerTracks * maxEffectSlots, nullptr);
-    automationValues.fill (std::numeric_limits<float>::quiet_NaN());
+    for (auto& slot : automationValues.v) // (round 190kz: every piece's slot)
+        slot.fill (std::numeric_limits<float>::quiet_NaN());
     lastTrackGain.fill ({ std::numeric_limits<float>::quiet_NaN(), 0.0f, 0.0f, 0.0f });
     lastTapGain.fill ({ std::numeric_limits<float>::quiet_NaN(), 0.0f, 0.0f, 0.0f });
     lastMeterGain.fill ({ std::numeric_limits<float>::quiet_NaN(), 0.0f, 0.0f, 0.0f });
@@ -2667,7 +2668,12 @@ void RackRenderer::prepare (double sr, int maxBlockSize)
         bufferExchange.publish (makeBuffers (channels, tracks, frames));
     }
     // (round 190gp: the lazy-zero flags of the inserts and the shared silent block a reader of an unwritten insert gets)
-    trackUnwritten.assign ((std::size_t) maxMixerTracks, 0);
+    for (auto& slot : trackUnwritten.v)
+        slot.fill (0);
+    // round 190kz: the units' plugin parameter bindings (built on the audio thread for each state: no allocation there)
+    unitParamStart.assign ((std::size_t) maxChannels + maxMixerTracks + 1, 0);
+    unitParams.assign (4096, 0);
+    unitParamsState = nullptr;
     zeroBlock.assign ((std::size_t) blockCapacity, 0.0f);
     hwScratch.assign (2 * (std::size_t) blockCapacity, 0.0f);
     layerPick.assign ((std::size_t) maxChannels * 128, (std::int16_t) -1);
@@ -2691,7 +2697,7 @@ void RackRenderer::prepare (double sr, int maxBlockSize)
 
 float* RackRenderer::rawTrackBuffer (int track, int channel) noexcept
 {
-    return buffers->mix.data() + ((std::size_t) track * 2 + (std::size_t) channel) * (std::size_t) buffers->frames;
+    return buffers->mix.data() + ((std::size_t) track * 2 + (std::size_t) channel) * (std::size_t) buffers->frames + (std::size_t) pieceOffset.get();
 }
 
 std::unique_ptr<const RackRenderer::Buffers> RackRenderer::makeBuffers (int channels, int tracks, int frames)
@@ -2777,7 +2783,7 @@ const float* RackRenderer::trackInput (int track, int channel) noexcept
 
 float* RackRenderer::tapBuffer (int tap, int side) noexcept
 {
-    return tapBuffers.data() + ((std::size_t) tap * 2 + (std::size_t) side) * chunkCapacity;
+    return tapBuffers.data() + ((std::size_t) tap * 2 + (std::size_t) side) * chunkCapacity + (std::size_t) pieceOffset.get();
 }
 
 float RackRenderer::automated (int automation, float base) const noexcept
@@ -2957,7 +2963,7 @@ void RackRenderer::updateAutomation (const RackState& state, double startTick) n
         // only the plugin parameters driven by pattern events and by live controllers (links: FL's work in any mode,
         // round 165)
         if (! state.eventLanes.empty() || ! state.liveAutomations.empty())
-            applyPluginParams (state, std::min<int> ((int) song.automations.size(), RackState::maxAutomations), true);
+            applyOrDeferParams (state, std::min<int> ((int) song.automations.size(), RackState::maxAutomations), true);
         return;
     }
 
@@ -3009,7 +3015,22 @@ void RackRenderer::updateAutomation (const RackState& state, double startTick) n
                                    ? bpm / 60.0 * (double) ppq / state.sampleRate
                                    : 0.0;
     clearOverriddenValues();
-    applyPluginParams (state, 0);
+    applyOrDeferParams (state, 0, false);
+}
+
+// Round 190kz: in a batched block's serial part (processBatched) the bindings are applied later, by each unit for its
+// piece; elsewhere now, as before
+void RackRenderer::applyOrDeferParams (const RackState& state, int firstSlot, bool andLive) noexcept
+{
+    if (! deferParams)
+    {
+        applyPluginParams (state, firstSlot, andLive);
+        return;
+    }
+    auto& piece = pieces[(std::size_t) pieceSlot()];
+    piece.params = true;
+    piece.paramsFirst = firstSlot;
+    piece.paramsLive = andLive;
 }
 
 void RackRenderer::updateModulators (const RackState& state, double tick, int numSamples) noexcept
@@ -3061,55 +3082,60 @@ float RackRenderer::automatedLevel (const RackState& state, int automation, floa
 
 void RackRenderer::applyPluginParams (const RackState& state, int firstSlot, bool andLive) noexcept
 {
-    for (const auto& b : state.pluginParams)
-    {
-        if (b.automation < firstSlot
-            && ! (andLive && (std::size_t) b.automation < state.song.automations.size() && state.song.automations[(std::size_t) b.automation].isLive()))
-            continue;
+    for (std::size_t k = 0; k < state.pluginParams.size(); ++k)
+        applyPluginParam (state, k, firstSlot, andLive);
+}
 
-        const auto v = automationValues[(std::size_t) b.automation];
+// one binding of applyPluginParams (round 190kz: processBatched applies each unit's own inside its task)
+void RackRenderer::applyPluginParam (const RackState& state, std::size_t index, int firstSlot, bool andLive) noexcept
+{
+    const auto& b = state.pluginParams[index];
+    if (b.automation < firstSlot
+        && ! (andLive && (std::size_t) b.automation < state.song.automations.size() && state.song.automations[(std::size_t) b.automation].isLive()))
+        return;
 
-        if (std::isnan (v) || (b.channel >= 0 ? foreignChannel (b.channel) : foreignTrack (b.track)))
-            continue;
+    const auto v = automationValues[(std::size_t) b.automation];
 
-        if (b.channel >= 0)
+    if (std::isnan (v) || (b.channel >= 0 ? foreignChannel (b.channel) : foreignTrack (b.track)))
+        return;
+
+    if (b.channel >= 0)
+    {
+        const auto kind = (std::size_t) b.channel < state.song.channels.size() ? state.song.channels[(std::size_t) b.channel].instrument
+                                                                                : InstrumentKind::plugin;
+        if (midictl::isPitchBend (b.param) && kind != InstrumentKind::plugin && kind != InstrumentKind::midiOut
+            && b.channel < (int) state.instruments.size() && b.channel < maxChannels)
         {
-            const auto kind = (std::size_t) b.channel < state.song.channels.size() ? state.song.channels[(std::size_t) b.channel].instrument
-                                                                                    : InstrumentKind::plugin;
-            if (midictl::isPitchBend (b.param) && kind != InstrumentKind::plugin && kind != InstrumentKind::midiOut
-                && b.channel < (int) state.instruments.size() && b.channel < maxChannels)
+            // LYNX's own instruments: the bend as the controller's wheel plays it (applyLiveControl), when it changes
+            if (! automatedBendReset)
             {
-                // LYNX's own instruments: the bend as the controller's wheel plays it (applyLiveControl), when it changes
-                if (! automatedBendReset)
-                {
-                    automatedBend.fill (std::numeric_limits<float>::quiet_NaN());
-                    automatedBendReset = true;
-                }
-                auto& last = automatedBend[(std::size_t) b.channel];
-                if (! (last == v) && state.instruments[(std::size_t) b.channel] != nullptr)
-                {
-                    last = v;
-                    NoteEvent e;
-                    e.type = NoteEvent::Type::control;
-                    e.channel = b.channel;
-                    e.key = NoteEvent::controlPitchBend;
-                    e.velocity = std::clamp (v, 0.0f, 1.0f) * 2.0f - 1.0f;
-                    applyLiveControl (state, e);
-                }
-                continue;
+                automatedBend.fill (std::numeric_limits<float>::quiet_NaN());
+                automatedBendReset = true;
             }
-            if (b.channel < (int) state.instruments.size())
-                state.instruments[(std::size_t) b.channel]->setParameter (b.param, v);
-            // a MIDI Out's controls reach the plugins on its port
-            if ((std::size_t) b.channel < state.midiTargets.size() && midictl::isMidiParam (b.param)) // (a Dashboard's outputs stay its own)
-                for (const auto t : state.midiTargets[(std::size_t) b.channel])
-                    if (t < (int) state.instruments.size())
-                        state.instruments[(std::size_t) t]->setParameter (b.param, v);
-        }
-        else if (b.track < (int) state.effects.size() && b.slot < (int) state.effects[(std::size_t) b.track].size())
-        {
-            state.effects[(std::size_t) b.track][(std::size_t) b.slot]->setParameter (b.param, compensatedAutomation (state, b.automation, b.track, b.slot, v));
+            auto& last = automatedBend[(std::size_t) b.channel];
+            if (! (last == v) && state.instruments[(std::size_t) b.channel] != nullptr)
+            {
+                last = v;
+                NoteEvent e;
+                e.type = NoteEvent::Type::control;
+                e.channel = b.channel;
+                e.key = NoteEvent::controlPitchBend;
+                e.velocity = std::clamp (v, 0.0f, 1.0f) * 2.0f - 1.0f;
+                applyLiveControl (state, e);
+            }
+            return;
         }
+        if (b.channel < (int) state.instruments.size())
+            state.instruments[(std::size_t) b.channel]->setParameter (b.param, v);
+        // a MIDI Out's controls reach the plugins on its port
+        if ((std::size_t) b.channel < state.midiTargets.size() && midictl::isMidiParam (b.param)) // (a Dashboard's outputs stay its own)
+            for (const auto t : state.midiTargets[(std::size_t) b.channel])
+                if (t < (int) state.instruments.size())
+                    state.instruments[(std::size_t) t]->setParameter (b.param, v);
+    }
+    else if (b.track < (int) state.effects.size() && b.slot < (int) state.effects[(std::size_t) b.track].size())
+    {
+        state.effects[(std::size_t) b.track][(std::size_t) b.slot]->setParameter (b.param, compensatedAutomation (state, b.automation, b.track, b.slot, v));
     }
 }
 
@@ -3279,7 +3305,7 @@ void RackRenderer::deliverToEffects (const RackState& state, const NoteEvent& e)
 
 float* RackRenderer::channelBuffer (int channel, int side) noexcept
 {
-    return buffers->channel.data() + ((std::size_t) channel * 2 + (std::size_t) side) * chunkCapacity;
+    return buffers->channel.data() + ((std::size_t) channel * 2 + (std::size_t) side) * chunkCapacity + (std::size_t) pieceOffset.get();
 }
 
 float* RackRenderer::trackScratch (int track, int side) noexcept
@@ -3581,7 +3607,7 @@ void RackRenderer::renderChannel (const RackState& state, int i, int n) noexcept
                                        + (c.misc.mainPitch && c.instrument != InstrumentKind::audioClip ? state.song.masterPitch : 0.0f);
                 // FL's channel Mono / Porta (round 168l): a Mono note over a held one moves the sounding voice instead
                 const auto mode = polyMode (c, instrument);
-                const auto glideSamples = (float) (channelpoly::glideBeats (mode.portaBeats) * ppq / std::max (1.0e-9, chunkTps));
+                const auto glideSamples = (float) (channelpoly::glideBeats (mode.portaBeats) * ppq / std::max (1.0e-9, chunkTps.get()));
                 auto& poly = polyLayers[(std::size_t) i];
                 // (an echo delay's repeats are FL's generated voices: they don't enter the Mono list)
                 const auto on = e.echo ? channelpoly::On {} : poly.noteOn (mode, e.key, noteCents, e.porta, e.colour);
@@ -3659,7 +3685,7 @@ void RackRenderer::renderChannel (const RackState& state, int i, int n) noexcept
             const auto off = e.echo ? channelpoly::Off { e.key } : polyLayers[(std::size_t) i].noteOff (mode, e.key, e.colour);
             if (off.slide)
                 instrument.slideTo (off.key, off.cents,
-                                    (float) (channelpoly::glideBeats (mode.portaBeats) * ppq / std::max (1.0e-9, chunkTps)));
+                                    (float) (channelpoly::glideBeats (mode.portaBeats) * ppq / std::max (1.0e-9, chunkTps.get())));
             if (off.release >= 0)
             {
                 // FL ends the note's own voice (round 190ej); a Mono channel's shared voice ends with its last note
@@ -4611,6 +4637,13 @@ void RackRenderer::process (const RackState* state,
     else if (gridNextTick < 0.0 || std::abs (startTick - gridNextTick) > 1.0e-3)
         gridSample = pieceStart = 0; // started, or jumped (a seek, the loop)
 
+    // round 190kz (sched): the same pieces with one task-graph round for the whole block, where that is exact
+    const auto batch = batchable (*state, numSamples);
+    if (batch && planPieces (*state, playing, startTick, numSamples, tps, chunk, grid))
+        processBatched (*state, playing, numSamples, left, right, meters);
+    else if (batch && pieceCount < 0) // (more than maxPieces: pattern events close together)
+        ++batchRefused[(std::size_t) BatchRefusal::manyPieces];
+    else
     for (int done = 0; done < numSamples;)
     {
         auto n = std::min (chunk, numSamples - done);
@@ -5094,6 +5127,15 @@ void RackRenderer::processChunk (const RackState& state, bool playing, double st
                                  float* left, float* right, MeterBank* meters, bool continuing) noexcept
 {
     const auto chunkStartNs = workers != nullptr ? ProcessTimes::now() : 0;
+    chunkPrelude (state, playing, startTick, numSamples, continuing);
+    auto* const pool = chunkSchedule (state, numSamples, events.size());
+    chunkUnits (state, playing, numSamples, meters);
+    chunkMaster (state, numSamples, left, right, meters, pool, chunkStartNs);
+}
+
+// (round 190kz: processChunk's parts, in its order; processBatched runs them piece by piece around one round)
+void RackRenderer::chunkPrelude (const RackState& state, bool playing, double startTick, int numSamples, bool continuing) noexcept
+{
     chunkTick = startTick;
     chunkPlaying = playing;
     // FL: playback starting puts every control the user moved back under its automation (issue #125)
@@ -5384,13 +5426,18 @@ void RackRenderer::processChunk (const RackState& state, bool playing, double st
     if (state.hasEffectMidiRoutes)
         for (int k = 0; k < events.size(); ++k)
             deliverToEffects (state, events[k]);
+}
 
+WorkerPool* RackRenderer::chunkSchedule (const RackState& state, int numSamples, int eventCount) noexcept
+{
+    const auto& song = state.song;
+    const auto tracks = std::max<int> (1, (int) song.mixer.size());
     // Round 190ge: no note or event in this chunk, no live input, and the last one took under 60 µs (an idle project:
     // the channels idle, the effects smart-disabled): the workers stay asleep. Waking them per chunk cost an idle
     // project with 3 workers ~15 % of a core at 64 samples, ten times the work itself. Serial and parallel give the
     // same samples (the task graph and the layers only change who computes what); the next note runs in parallel.
     auto* const pool = workers;
-    if (pool != nullptr && events.size() == 0 && lastChunkNs < lightChunkNs && (liveInput == nullptr || liveInput->numChannels == 0))
+    if (pool != nullptr && eventCount == 0 && lastChunkNs < lightChunkNs && (liveInput == nullptr || liveInput->numChannels == 0))
         workers = nullptr;
     // A7 (round 190gq): the same when the work the chunk's units did last time comes to less than handing it out costs
     // (waking the workers, their spinning, the last one's wait), and nothing starts in this chunk: a chunk where notes
@@ -5417,7 +5464,7 @@ void RackRenderer::processChunk (const RackState& state, bool playing, double st
         const auto chunkNs = sampleRate > 0.0 ? 1.0e9 * numSamples / sampleRate : 0.0;
         parallelChunk = state.parallel || (double) work >= parallelShare * chunkNs;
         lastWorkShareValue = chunkNs > 0.0 ? (double) work / chunkNs : 0.0;
-        if (events.size() == 0 && work < serialWorkNs && (liveInput == nullptr || liveInput->numChannels == 0))
+        if (eventCount == 0 && work < serialWorkNs && (liveInput == nullptr || liveInput->numChannels == 0))
             workers = nullptr;
         // round 190kr: as many workers woken as the work needs (WorkerPool::Tuning::helpPercent): ~1 ms of Thief's work in a
         // 2.9 ms chunk woke all five
@@ -5426,7 +5473,13 @@ void RackRenderer::processChunk (const RackState& state, bool playing, double st
         else
             pool->setWakeLimit (-1);
     }
+    return pool;
+}
 
+void RackRenderer::chunkUnits (const RackState& state, bool playing, int numSamples, MeterBank* meters) noexcept
+{
+    const auto& song = state.song;
+    const auto tracks = std::max<int> (1, (int) song.mixer.size());
     // 1) channels, each with its own notes at the exact sample (in parallel when worth it)
     const auto channels = std::min<int> ({ (int) state.instruments.size(), (int) song.channels.size(), maxChannels });
     auto channel = [this, &state, numSamples] (int c) {
@@ -5575,6 +5628,12 @@ void RackRenderer::processChunk (const RackState& state, bool playing, double st
         }
     }
 
+}
+
+void RackRenderer::chunkMaster (const RackState& state, int numSamples, float* left, float* right, MeterBank* meters, WorkerPool* pool,
+                                std::uint64_t chunkStartNs) noexcept
+{
+    const auto& song = state.song;
     workers = pool;
 
     // render-ahead (round 190gq): what the live part takes from this one goes out now; the Master is the live part's
@@ -5946,6 +6005,485 @@ bool RackRenderer::runTaskGraph (const RackState& state, bool playing, int chann
     return true;
 }
 
+// ---- Round 190kz (sched): one task-graph round per device callback ----------------------------------------------------
+// A block the loop in process() cuts in pieces (with automation: pieces of 128 on the export's grid of 512, and wherever
+// a pattern event falls) ran one worker-pool round per piece: at a device block of 480, about four wake-ups, spins and
+// waits for the last task per block, half of the audio CPU on Windows. A batched block runs
+//   1. every piece's serial part (chunkPrelude: the automation's values, the transport, the notes and events), in order,
+//      each into its own slot of the per-chunk state (PieceValue / PieceArray / PieceEvents, pieceTimelines);
+//   2. ONE round of the task graph in which each channel and insert renders its pieces one after another, piece k with
+//      slot k's state and its own plugin parameter bindings for that piece (applyUnitParams: what updateAutomation's
+//      applyPluginParams did for that unit at that piece), into its buffers at the piece's offset;
+//   3. the Master's pieces, in order (chunkMaster), and the last piece's state becomes the renderer's again.
+// Every unit gets exactly the calls it got piece by piece before — the same sizes, values and order, its inputs' same
+// samples — so the output is the same bit for bit; only what runs at the same time changes (as with the task graph
+// itself). It is used only where nothing a piece's serial part does depends on the previous piece's units, or reaches
+// a unit outside its own task (batchable): no MIDI a unit sends to the next chunk (wrapper output ports, VFX, Dashboards,
+// hardware MIDI, mixer-slot MIDI routes), no live controllers (they read a unit's output), no effect that follows the
+// Channel rack's held notes, no sample-accurate plugin parameters, no launchers, no render-ahead split, no PDC "when
+// recording or not playing" switch, no generator extra outputs, no binding that reaches another unit; at most maxPieces
+// pieces and one mixer buffer of samples. Anything else plays piece by piece as before.
+// LYNX_POOL="rounds=chunk" (or rounds=0): one round per piece, as before (A/B); "rounds=block" (1, the default): batched.
+namespace
+{
+bool taskGraphEnabled() noexcept
+{
+    static const bool enabled = [] { const char* e = std::getenv ("LYNX_TASKGRAPH"); return e == nullptr || std::atoi (e) != 0; }();
+    return enabled;
+}
+
+void copyTimeline (const HostTimeline& from, HostTimeline& to) noexcept
+{
+    constexpr auto r = std::memory_order_relaxed;
+    to.tick.store (from.tick.load (r), r);
+    to.loopStart.store (from.loopStart.load (r), r);
+    to.loopEnd.store (from.loopEnd.load (r), r);
+    to.looping.store (from.looping.load (r), r);
+    to.bpm.store (from.bpm.load (r), r);
+    to.sampleRate.store (from.sampleRate.load (r), r);
+    to.playing.store (from.playing.load (r), r);
+    to.beatsPerBar.store (from.beatsPerBar.load (r), r);
+    to.beatUnit.store (from.beatUnit.load (r), r);
+    to.ticksPerSample.store (from.ticksPerSample.load (r), r);
+    to.chunk.store (from.chunk.load (r), r);
+}
+} // namespace
+
+bool RackRenderer::buildUnitParams (const RackState& state) noexcept
+{
+    const auto& song = state.song;
+    const auto channels = std::min<int> ({ (int) state.instruments.size(), (int) song.channels.size(), maxChannels });
+    const auto tracks = std::max<int> (1, (int) song.mixer.size());
+    const auto units = (std::size_t) maxChannels + maxMixerTracks;
+    unitParamsBend = unitParamsTimed = unitParamsHeld = false;
+    if (unitParamStart.size() < units + 1 || state.pluginParams.size() > unitParams.size())
+        return false;
+    // each binding's unit, as applyPluginParam reaches it: -1 = it sets nothing, -2 = it reaches another unit (or one
+    // that is not rendered as a task): not batched
+    auto unitOf = [&] (const RackState::PluginParamBinding& b) noexcept -> int {
+        if (b.channel >= 0)
+        {
+            const auto c = (std::size_t) b.channel;
+            if (c < state.midiTargets.size() && midictl::isMidiParam (b.param) && ! state.midiTargets[c].empty())
+                return -2; // (a MIDI Out's controls reach the plugins on its port)
+            const auto kind = c < song.channels.size() ? song.channels[c].instrument : InstrumentKind::plugin;
+            if (midictl::isPitchBend (b.param) && kind != InstrumentKind::plugin && kind != InstrumentKind::midiOut
+                && b.channel < (int) state.instruments.size() && b.channel < maxChannels)
+            {
+                // (applyLiveControl: a Layer's children, a MIDI Out's port)
+                if (kind == InstrumentKind::layer || (state.hasMidiRoutes && c < state.midiTargets.size() && ! state.midiTargets[c].empty()))
+                    return -2;
+                unitParamsBend = true;
+                return b.channel < channels ? b.channel : -2;
+            }
+            if (b.channel >= (int) state.instruments.size())
+                return -1;
+            if (const auto* instrument = state.instruments[c].get(); instrument != nullptr && instrument->takesTimedParameters())
+                unitParamsTimed = true;
+            return b.channel < channels ? b.channel : -2;
+        }
+        if (b.track < 0)
+            return -2;
+        if (b.track >= (int) state.effects.size() || b.slot < 0 || b.slot >= (int) state.effects[(std::size_t) b.track].size())
+            return b.slot < 0 ? -2 : -1;
+        if (const auto* effect = state.effects[(std::size_t) b.track][(std::size_t) b.slot].get(); effect != nullptr && effect->takesTimedParameters())
+            unitParamsTimed = true;
+        return b.track < tracks && b.track < maxMixerTracks ? maxChannels + b.track : -2;
+    };
+    std::fill (unitParamStart.begin(), unitParamStart.begin() + (std::ptrdiff_t) units + 1, 0);
+    for (const auto& b : state.pluginParams)
+    {
+        const auto u = unitOf (b);
+        if (u == -2)
+            return false;
+        if (u >= 0)
+            ++unitParamStart[(std::size_t) u + 1];
+    }
+    for (std::size_t u = 0; u < units; ++u)
+        unitParamStart[u + 1] += unitParamStart[u];
+    // (a second pass, in the bindings' order: each unit keeps applyPluginParams' order; unitParamStart[u] moves on to its
+    // end as it fills, then back)
+    for (std::size_t k = 0; k < state.pluginParams.size(); ++k)
+        if (const auto u = unitOf (state.pluginParams[k]); u >= 0)
+            unitParams[(std::size_t) unitParamStart[(std::size_t) u]++] = (int) k;
+    for (std::size_t u = units; u > 0; --u)
+        unitParamStart[u] = unitParamStart[u - 1];
+    unitParamStart[0] = 0;
+    // the effects that follow the Channel rack's held notes read every channel's at their piece: not batched — a slot
+    // whose settings read them, or one that can and has automated parameters (its settings may turn that on mid-block)
+    for (std::size_t t = 0; t < state.effects.size() && t < song.mixer.size(); ++t)
+        for (std::size_t s = 0; s < state.effects[t].size() && s < song.mixer[t].effects.size(); ++s)
+        {
+            const auto* effect = state.effects[t][s].get();
+            if (effect == nullptr || ! effect->followsHeldNotes())
+                continue;
+            auto automated = false;
+            if (t < state.effectParamAuto.size() && s < state.effectParamAuto[t].size())
+                for (const auto a : state.effectParamAuto[t][s])
+                    automated = automated || a >= 0;
+            for (const auto& b : state.pluginParams)
+                automated = automated || (b.channel < 0 && b.track == (int) t && b.slot == (int) s);
+            if (automated || effect->followsHeldNotesWith (song.mixer[t].effects[s].params))
+                unitParamsHeld = true;
+        }
+    return true;
+}
+
+void RackRenderer::applyUnitParams (const RackState& state, int unit, const Piece& piece) noexcept
+{
+    if (! piece.params || unit < 0 || (std::size_t) unit + 1 >= unitParamStart.size())
+        return;
+    for (auto k = unitParamStart[(std::size_t) unit]; k < unitParamStart[(std::size_t) unit + 1]; ++k)
+        applyPluginParam (state, (std::size_t) unitParams[(std::size_t) k], piece.paramsFirst, piece.paramsLive);
+}
+
+bool RackRenderer::batchable (const RackState& state, int numSamples) noexcept
+{
+    const auto refuse = [this] (BatchRefusal why) noexcept {
+        ++batchRefused[(std::size_t) why];
+        return false;
+    };
+    if (WorkerPool::tuning().blockRounds.load (std::memory_order_relaxed) == 0)
+        return refuse (BatchRefusal::switchedOff);
+    if (workers == nullptr || workers->workers() == 0 || split != nullptr || ownTimeline != nullptr || buffers == nullptr || ! taskGraphEnabled() || ! state.graphOk)
+        return refuse (BatchRefusal::noGraph);
+    if (! flsettings::options().multithreadGenerators.load (std::memory_order_relaxed) || ! flsettings::options().multithreadMixer.load (std::memory_order_relaxed))
+        return refuse (BatchRefusal::noGraph);
+    if (numSamples > chunkCapacity || numSamples > buffers->frames || numSamples > (int) zeroBlock.size())
+        return refuse (BatchRefusal::bigBlock);
+    if (! state.liveAutomations.empty())
+        return refuse (BatchRefusal::liveControllers);
+    if (state.hasMidiOutputs || ! state.portEventChannels.empty() || ! state.dashboardChannels.empty() || ! state.vfxChannels.empty()
+        || state.hasEffectMidiRoutes || ! state.hardwareMidiChannels.empty())
+        return refuse (BatchRefusal::midiBetweenUnits);
+    if (state.anyBypassWhenIdle)
+        return refuse (BatchRefusal::other);
+    if (state.launchers || launchersRunning || runningLauncher != nullptr || ! state.performanceZone.empty() || perfRunning
+        || (perfLive != nullptr && perfLive->anyPlaying.load (std::memory_order_relaxed)))
+        return refuse (BatchRefusal::launchers);
+    const auto channels = std::min<int> ({ (int) state.instruments.size(), (int) state.song.channels.size(), maxChannels });
+    const auto tracks = std::max<int> (1, (int) state.song.mixer.size());
+    const auto tasks = channels + tracks - 1;
+    if (state.graphChannels != channels || tasks <= 0 || tasks > graphCapacity || (int) state.graphIndegree.size() != tasks)
+        return refuse (BatchRefusal::noGraph);
+    for (int c = 0; c < channels; ++c) // (runTaskGraph's check: a generator's extra outputs go to inserts known only now)
+        if (state.instruments[(std::size_t) c] != nullptr && state.instruments[(std::size_t) c]->auxOutputCount() > 0)
+            return refuse (BatchRefusal::noGraph);
+    if (&state != unitParamsState || state.serial != unitParamsSerial)
+    {
+        unitParamsOk = buildUnitParams (state);
+        unitParamsState = &state;
+        unitParamsSerial = state.serial;
+    }
+    if (! unitParamsOk)
+        return refuse (BatchRefusal::bindings);
+    if (unitParamsHeld)
+        return refuse (BatchRefusal::heldNotes);
+    // (an editor previewing a slot's settings: they are not the slot's own, which buildUnitParams judged)
+    if (overrideParams != nullptr && overrideTrack >= 0 && (std::size_t) overrideTrack < state.effects.size() && overrideSlot >= 0
+        && (std::size_t) overrideSlot < state.effects[(std::size_t) overrideTrack].size()
+        && state.effects[(std::size_t) overrideTrack][(std::size_t) overrideSlot] != nullptr
+        && state.effects[(std::size_t) overrideTrack][(std::size_t) overrideSlot]->followsHeldNotes())
+        return refuse (BatchRefusal::heldNotes);
+    if (unitParamsTimed && sampleAccurateAutomation())
+        return refuse (BatchRefusal::timedParams);
+    return true;
+}
+
+bool RackRenderer::planPieces (const RackState& state, bool playing, double startTick, int numSamples, double tps, int chunk, bool grid) noexcept
+{
+    // (process()'s loop, without rendering: the same pieces, the same moves of pieceStart; undone when not batched)
+    constexpr int piece = 128, exportBlock = 512;
+    const auto pieceStartBefore = pieceStart;
+    pieceCount = 0;
+    for (int done = 0; done < numSamples;)
+    {
+        if (pieceCount == maxPieces)
+        {
+            pieceStart = pieceStartBefore;
+            pieceCount = -1; // (counted as a refusal by process())
+            return false;
+        }
+        auto n = std::min (chunk, numSamples - done);
+        auto continuing = false;
+        const auto pos = gridSample + done;
+        if (grid)
+        {
+            const auto blockEnd = (pos / exportBlock + 1) * exportBlock;
+            auto pieceEnd = std::min<std::int64_t> (pieceStart + piece, blockEnd);
+            if (pos >= pieceEnd)
+            {
+                pieceStart = pos;
+                pieceEnd = std::min<std::int64_t> (pos + piece, blockEnd);
+            }
+            continuing = pos > pieceStart;
+            n = (int) std::min<std::int64_t> (std::min (blockCapacity, numSamples - done), pieceEnd - pos);
+        }
+        auto atEvent = false;
+        if (playing && ! state.eventLanes.empty() && tps > 0.0)
+        {
+            const auto ahead = ticksToNextEvent (state, startTick + done * tps);
+            if (ahead < (double) n * tps)
+            {
+                n = std::max (1, (int) std::ceil (ahead / tps - 1.0e-9));
+                atEvent = true;
+            }
+        }
+        auto& p = pieces[(std::size_t) pieceCount++];
+        p = Piece {};
+        p.samples = n;
+        p.offset = done;
+        p.startTick = startTick + done * tps;
+        p.continuing = continuing;
+        p.gridPos = grid ? pos : -1;
+        done += n;
+        if (grid && atEvent)
+            pieceStart = pos + n;
+    }
+    if (pieceCount < 2) // (one piece: one round either way)
+    {
+        pieceStart = pieceStartBefore;
+        pieceCount = 0;
+        return false;
+    }
+    return true;
+}
+
+void RackRenderer::carryPieceState (int from, int to) noexcept
+{
+    trackUnwritten.carry (from, to);
+    trackSamples.carry (from, to);
+    automationValues.carry (from, to);
+    trackActive.carry (from, to);
+    tapActive.carry (from, to);
+    channelSilent.carry (from, to);
+    chunkStartTick.carry (from, to);
+    chunkTps.carry (from, to);
+    clipEnvTableShown.carry (from, to);
+    liveInputOffset.carry (from, to);
+    chunkTick.carry (from, to);
+    chunkPlaying.carry (from, to);
+    pdcBypassNow.carry (from, to);
+    compensateTick.carry (from, to);
+    compensateTicksPerSample.carry (from, to);
+}
+
+void RackRenderer::processBatched (const RackState& state, bool playing, int numSamples, float* left, float* right, MeterBank* meters) noexcept
+{
+    const auto chunkStartNs = ProcessTimes::now();
+    auto& shared = hostTimeline(); // (this thread's play head: the shared one, batchable wants no own one)
+    ++batchedBlocks;
+
+    // 1) the pieces' serial parts, in order, each in its slot
+    int eventCount = 0;
+    for (int k = 0; k < pieceCount; ++k)
+    {
+        auto& piece = pieces[(std::size_t) k];
+        const ScopedPiece slot (k);
+        if (k > 0)
+            carryPieceState (k - 1, k);
+        copyTimeline (k == 0 ? shared : pieceTimelines[(std::size_t) k - 1], pieceTimelines[(std::size_t) k]);
+        const ScopedHostTimeline timelineScope (&pieceTimelines[(std::size_t) k]);
+        pieceOffset = piece.offset;
+        liveInputOffset = piece.offset;
+        timedGridPos = piece.gridPos;
+        deferParams = true;
+        chunkPrelude (state, playing, piece.startTick, piece.samples, piece.continuing);
+        deferParams = false;
+        eventCount += events.size();
+        piece.live = liveInput != nullptr && liveInput->numChannels > 0;
+        piece.recording = piece.live && liveInput->recording.load (std::memory_order_relaxed);
+        resumeAudio = false;
+        chaseNotes = false;
+    }
+
+    // 2) the units: A7's choice for the block (its pieces' average size, all their events), then one round, or each
+    // piece on this thread as before
+    auto* const pool = chunkSchedule (state, std::max (1, numSamples / pieceCount), eventCount);
+    auto* const chosen = workers;
+    if (unitParamsBend && ! automatedBendReset) // (applyPluginParam's first bend, made here: tasks run it at once)
+    {
+        automatedBend.fill (std::numeric_limits<float>::quiet_NaN());
+        automatedBendReset = true;
+    }
+    const auto channels = std::min<int> ({ (int) state.instruments.size(), (int) state.song.channels.size(), maxChannels });
+    if (runBatchedGraph (state, playing, channels, meters))
+    {
+        ++batchedRounds;
+        for (int k = 0; k < pieceCount; ++k)
+        {
+            const auto& piece = pieces[(std::size_t) k];
+            const ScopedPiece slot (k);
+            const ScopedHostTimeline timelineScope (&pieceTimelines[(std::size_t) k]);
+            applyUnitParams (state, maxChannels, piece); // (the Master's own bindings)
+            // (runTaskGraph's end: the Master's own channels and input)
+            sumChannelsInto (state, 0, channels, piece.samples);
+            if (piece.live)
+                mixLiveInputTrack (state, 0, piece.recording, playing, piece.samples);
+            mixMetronome (state, 0, piece.samples);
+            chunkMaster (state, piece.samples, left + piece.offset, right + piece.offset, meters, pool, chunkStartNs);
+        }
+    }
+    else
+        for (int k = 0; k < pieceCount; ++k)
+        {
+            const auto& piece = pieces[(std::size_t) k];
+            const ScopedPiece slot (k);
+            const ScopedHostTimeline timelineScope (&pieceTimelines[(std::size_t) k]);
+            if (piece.params)
+                applyPluginParams (state, piece.paramsFirst, piece.paramsLive);
+            workers = chosen;
+            chunkUnits (state, playing, piece.samples, meters);
+            chunkMaster (state, piece.samples, left + piece.offset, right + piece.offset, meters, pool, chunkStartNs);
+        }
+    workers = pool;
+
+    // 3) the last piece's state is the renderer's (slot 0) again, as after the last chunk of the loop
+    carryPieceState (pieceCount - 1, 0);
+    pieceOffset.v[0] = 0;
+    {
+        const auto& last = events.more[(std::size_t) pieceCount - 2];
+        events.first.clear();
+        for (const auto& e : last)
+            events.first.add (e);
+    }
+    copyTimeline (pieceTimelines[(std::size_t) pieceCount - 1], shared);
+    // (A7's light-chunk rule compares one chunk's time)
+    lastChunkNs = (ProcessTimes::now() - chunkStartNs) / (std::uint64_t) pieceCount;
+}
+
+bool RackRenderer::runBatchedGraph (const RackState& state, bool playing, int channels, MeterBank* meters) noexcept
+{
+    // (runTaskGraph's conditions; batchable checked the rest for the whole block)
+    if (workers == nullptr || ! parallelChunk)
+        return false;
+    const auto tracks = std::max<int> (1, (int) state.song.mixer.size());
+    const auto tasks = channels + tracks - 1;
+
+    for (int k = 0; k < pieceCount; ++k)
+    {
+        const ScopedPiece slot (k);
+        trackActive.fill (0);
+        tapActive.fill (0);
+    }
+    for (int i = 0; i < tasks; ++i)
+    {
+        graphPending[(std::size_t) i].store (state.graphIndegree[(std::size_t) i], std::memory_order_relaxed);
+        graphSlots[(std::size_t) i].store (0, std::memory_order_relaxed);
+    }
+    auto pushed = 0;
+    for (const auto r : state.graphRoots)
+        graphSlots[(std::size_t) pushed++].store (r + 1, std::memory_order_relaxed);
+    graphPushed.store (pushed, std::memory_order_release);
+
+    const auto timing = times->enabled.load (std::memory_order_relaxed);
+    constexpr int handedOver = -1;
+    const auto waitMode = WorkerPool::tuning().waitMode.load (std::memory_order_relaxed);
+    const auto handOffSpin = std::chrono::microseconds (WorkerPool::tuning().waitSpinMicros.load (std::memory_order_relaxed));
+    const auto count = (std::uint64_t) pieceCount;
+    auto task = [&] (int position) {
+        int id = 0;
+        auto& slot = graphSlots[(std::size_t) position];
+        if (waitMode == 2)
+        {
+            if ((id = slot.load (std::memory_order_acquire)) == 0)
+            {
+                const auto start = std::chrono::steady_clock::now();
+                auto handed = false;
+                for (int spins = 0; (id = slot.load (std::memory_order_acquire)) == 0; ++spins)
+                {
+                    WorkerPool::relax();
+                    if ((spins & 63) == 63 && std::chrono::steady_clock::now() - start > handOffSpin)
+                    {
+                        auto expected = 0;
+                        if (slot.compare_exchange_strong (expected, handedOver, std::memory_order_acq_rel))
+                        {
+                            handed = true;
+                            break;
+                        }
+                        id = expected;
+                        break;
+                    }
+                }
+                workers->noteWait ((std::uint64_t) std::chrono::duration_cast<std::chrono::nanoseconds> (std::chrono::steady_clock::now() - start).count(), handed);
+                if (handed)
+                    return;
+            }
+        }
+        else
+            workers->await (position, [&] { return (id = slot.load (std::memory_order_acquire)) != 0; });
+        --id;
+        std::array<int, 32> taken;
+        int takenCount = 0;
+        auto chain = [&] (int first, auto& self) -> void {
+            auto at = first;
+            for (;;)
+            {
+                const auto before = timing || measureUnits ? ProcessTimes::now() : 0;
+                // the unit's pieces, one after another: piece k with slot k's state, its own bindings for that piece
+                for (int k = 0; k < pieceCount; ++k)
+                {
+                    const auto& piece = pieces[(std::size_t) k];
+                    const ScopedPiece pieceScope (k);
+                    const ScopedHostTimeline timelineScope (&pieceTimelines[(std::size_t) k]);
+                    const auto n = piece.samples;
+                    if (at < channels)
+                    {
+                        applyUnitParams (state, at, piece);
+                        renderChannel (state, at, n);
+                    }
+                    else
+                    {
+                        const auto t = at - channels + 1;
+                        applyUnitParams (state, maxChannels + t, piece);
+                        sumChannelsInto (state, t, channels, n);
+                        if (piece.live)
+                            mixLiveInputTrack (state, t, piece.recording, playing, n);
+                        mixMetronome (state, t, n);
+                        mixSideInput (state, t, n);
+                        processTrack (state, t, n, meters);
+                    }
+                }
+                const auto spent = ProcessTimes::now() - before;
+                // (A7 keeps one chunk's cost: the pieces' average)
+                if (at < channels)
+                {
+                    if (timing && at < ProcessTimes::channels)
+                        times->channelNs[(std::size_t) at].fetch_add (spent, std::memory_order_relaxed);
+                    if (measureUnits)
+                        channelCostNs[(std::size_t) at] = (std::uint32_t) std::min<std::uint64_t> (spent / count, 0xffffffffu);
+                }
+                else if (const auto t = at - channels + 1; measureUnits && t < maxMixerTracks)
+                    trackCostNs[(std::size_t) t] = (std::uint32_t) std::min<std::uint64_t> (spent / count, 0xffffffffu);
+                const auto fused = (std::size_t) at < state.graphFused.size() ? state.graphFused[(std::size_t) at] : -1;
+                if (fused < 0)
+                    break;
+                at = fused;
+            }
+            for (auto k = state.graphNextStart[(std::size_t) at]; k < state.graphNextStart[(std::size_t) at + 1]; ++k)
+            {
+                const auto j = state.graphNext[(std::size_t) k];
+                if (graphPending[(std::size_t) j].fetch_sub (1, std::memory_order_acq_rel) == 1)
+                {
+                    const auto pos = graphPushed.fetch_add (1, std::memory_order_acq_rel);
+                    auto expected = 0;
+                    if (graphSlots[(std::size_t) pos].compare_exchange_strong (expected, j + 1, std::memory_order_acq_rel))
+                        workers->notify (pos);
+                    else if (takenCount < (int) taken.size())
+                        taken[(std::size_t) takenCount++] = j;
+                    else
+                        self (j, self);
+                }
+            }
+        };
+        chain (id, chain);
+        while (takenCount > 0)
+            chain (taken[(std::size_t) --takenCount], chain);
+    };
+    workers->parallelFor (tasks - state.graphFusedCount, task);
+    return true;
+}
+
 int RackRenderer::metronomeTarget (const RackState& state) const noexcept
 {
     return metronome::targetTrack (clickTrack, std::min ((int) state.song.mixer.size(), maxMixerTracks));

+ 163 - 15
src/core/RackRenderer.h

@@ -714,6 +714,29 @@ public:
     void forgetState() noexcept { lastState = nullptr; }
     // chunks whose boundary did not line up with the part rendered ahead (the live renderer; diagnostics)
     std::uint64_t splitMismatchCount() const noexcept { return splitMismatches; }
+    // Round 190kz (sched): blocks rendered batched (every piece's serial part first, the units' pieces in one task-graph
+    // round: processBatched), and how many of them did go to the workers in that one round (diagnostics, A/B)
+    std::uint64_t batchedBlockCount() const noexcept { return batchedBlocks; }
+    std::uint64_t batchedRoundCount() const noexcept { return batchedRounds; }
+    // ... and the blocks that could not be, by the first reason found (every block is looked at, one cut in a single
+    // piece too: that one runs one round anyway). Audio thread counters, read them between blocks (diagnostics).
+    enum class BatchRefusal : int
+    {
+        switchedOff,      // LYNX_POOL rounds=chunk
+        noGraph,          // no worker pool or no task graph (render-ahead's split, FL's CPU options, extra outputs...)
+        bigBlock,         // more samples than one mixer buffer holds
+        liveControllers,  // a controller's output (Peak / Formula / envelope controllers...) drives the next piece's values
+        midiBetweenUnits, // MIDI from one unit to another between pieces (wrapper output ports, VFX, Dashboards, MIDI routes
+                          // to mixer slots, hardware MIDI)
+        launchers,        // Performance mode or the clip grid
+        bindings,         // a plugin parameter binding reaching another unit
+        heldNotes,        // an effect that follows the Channel rack's held notes (its settings, or automated ones)
+        timedParams,      // sample-accurate plugin parameters
+        manyPieces,       // more than maxPieces pieces (pattern events close together)
+        other,            // FL's "When recording or not playing" PDC switch
+        count
+    };
+    std::uint64_t batchRefusedCount (BatchRefusal why) const noexcept { return batchRefused[(std::size_t) why]; }
     // A7's measure of the last chunk: its units' summed work as a share of the chunk's real time (0 when not measured,
     // e.g. without workers). Render-ahead skips its probe when one thread could not carry the ahead part anyway.
     double lastWorkShare() const noexcept { return lastWorkShareValue; }
@@ -778,6 +801,128 @@ public:
     float automatedLevel (const RackState& state, int automation, float base, int track) const noexcept;
 
 private:
+    // ---- Round 190kz (sched): one task-graph round per device callback ----------------------------------------------
+    // A block cut in pieces (the automation's 128-sample grid, pattern events) used to run one worker-pool round per
+    // piece. A batched block (processBatched) runs every piece's serial part first, then ONE round in which each channel
+    // and insert renders its pieces one after another, then the Master's pieces: each unit gets exactly the calls, sizes,
+    // values and order it got before (the same samples), but the workers are woken and joined once per block.
+    // What a piece's units read of the renderer's per-chunk state lives in one slot per piece: the thread's pieceSlot()
+    // (0 everywhere except inside a batched block) picks it. PieceValue / PieceArray / PieceEvents behave as the plain
+    // member they replace for code that never sets the slot.
+    static constexpr int maxPieces = 8;
+    static int& pieceSlot() noexcept
+    {
+        thread_local int slot = 0;
+        return slot;
+    }
+    template <typename T>
+    struct PieceValue
+    {
+        explicit PieceValue (T init) noexcept { v.fill (init); }
+        std::array<T, maxPieces> v;
+        T& get() noexcept { return v[(std::size_t) pieceSlot()]; }
+        const T& get() const noexcept { return v[(std::size_t) pieceSlot()]; }
+        operator T() const noexcept { return get(); }
+        PieceValue& operator= (const T& x) noexcept
+        {
+            get() = x;
+            return *this;
+        }
+        PieceValue& operator+= (const T& x) noexcept
+        {
+            get() += x;
+            return *this;
+        }
+        void carry (int from, int to) noexcept { v[(std::size_t) to] = v[(std::size_t) from]; }
+    };
+    template <typename T, std::size_t N>
+    struct PieceArray
+    {
+        std::array<std::array<T, N>, maxPieces> v {};
+        std::array<T, N>& get() noexcept { return v[(std::size_t) pieceSlot()]; }
+        const std::array<T, N>& get() const noexcept { return v[(std::size_t) pieceSlot()]; }
+        T& operator[] (std::size_t i) noexcept { return get()[i]; }
+        const T& operator[] (std::size_t i) const noexcept { return get()[i]; }
+        T* data() noexcept { return get().data(); }
+        static constexpr std::size_t size() noexcept { return N; }
+        void fill (const T& x) noexcept { get().fill (x); }
+        // (the plain array's whole-value copy, as adoptGlobals makes it: this slot from the other's same slot)
+        PieceArray& operator= (const PieceArray& o) noexcept
+        {
+            get() = o.get();
+            return *this;
+        }
+        void carry (int from, int to) noexcept { v[(std::size_t) to] = v[(std::size_t) from]; }
+    };
+    struct PieceEvents
+    {
+        EventBuffer first;
+        std::unique_ptr<EventBuffer[]> more = std::make_unique<EventBuffer[]> ((std::size_t) maxPieces - 1);
+        EventBuffer& get() noexcept { const auto s = pieceSlot(); return s == 0 ? first : more[(std::size_t) s - 1]; }
+        const EventBuffer& get() const noexcept { const auto s = pieceSlot(); return s == 0 ? first : more[(std::size_t) s - 1]; }
+        operator EventBuffer&() noexcept { return get(); }
+        operator const EventBuffer&() const noexcept { return get(); }
+        void clear() noexcept { get().clear(); }
+        void add (const NoteEvent& e) noexcept { get().add (e); }
+        void sortByOffset() noexcept { get().sortByOffset(); }
+        int size() const noexcept { return get().size(); }
+        void resize (int n) noexcept { get().resize (n); }
+        int droppedCount() const noexcept { return get().droppedCount(); }
+        const NoteEvent& operator[] (int i) const noexcept { return get()[i]; }
+        NoteEvent& at (int i) noexcept { return get().at (i); }
+        const NoteEvent* begin() const noexcept { return get().begin(); }
+        const NoteEvent* end() const noexcept { return get().end(); }
+    };
+    // a scope in which this thread works on piece `slot` of a batched block
+    struct ScopedPiece
+    {
+        explicit ScopedPiece (int slot) noexcept : previous (pieceSlot()) { pieceSlot() = slot; }
+        ~ScopedPiece() { pieceSlot() = previous; }
+        ScopedPiece (const ScopedPiece&) = delete;
+        ScopedPiece& operator= (const ScopedPiece&) = delete;
+        const int previous;
+    };
+    // a piece of a batched block: its samples, where it starts in the block, its tick, whether it goes on from the
+    // previous block (automation grid), its place on the export grid
+    struct Piece
+    {
+        int samples = 0, offset = 0;
+        double startTick = 0.0;
+        bool continuing = false;
+        std::int64_t gridPos = -1;
+        bool live = false, recording = false;     // (the live input, as runTaskGraph reads it per chunk)
+        bool params = false, paramsLive = false;  // updateAutomation's applyPluginParams, deferred to the units
+        int paramsFirst = 0;
+    };
+    std::array<Piece, maxPieces> pieces {};
+    int pieceCount = 0;
+    bool deferParams = false; // (processBatched's serial parts: applyPluginParams is recorded in the piece, not run)
+    PieceValue<int> pieceOffset { 0 }; // where the slot's piece starts in the units' buffers
+    std::array<HostTimeline, maxPieces> pieceTimelines {};
+    // the plugin parameter bindings of each unit (channel c: c; insert t: maxChannels + t), in RackState::pluginParams'
+    // order, for a state (processBatched applies each unit's own, per piece, inside its task)
+    std::vector<int> unitParamStart, unitParams;
+    const RackState* unitParamsState = nullptr;
+    std::uint64_t unitParamsSerial = 0;
+    bool unitParamsOk = false; // the state can be batched (see batchable)
+    std::uint64_t batchedBlocks = 0, batchedRounds = 0; // (diagnostics: blocks planned as batched, and run as one round)
+    std::array<std::uint64_t, (std::size_t) BatchRefusal::count> batchRefused {};
+    bool batchable (const RackState& state, int numSamples) noexcept;
+    bool buildUnitParams (const RackState& state) noexcept;
+    void applyUnitParams (const RackState& state, int unit, const Piece& piece) noexcept;
+    // plans the block's pieces as process()'s loop cuts them (false: more than maxPieces, or one piece)
+    bool planPieces (const RackState& state, bool playing, double startTick, int numSamples, double tps, int chunk, bool grid) noexcept;
+    void processBatched (const RackState& state, bool playing, int numSamples, float* left, float* right, MeterBank* meters) noexcept;
+    void carryPieceState (int from, int to) noexcept;
+    bool unitParamsBend = false, unitParamsTimed = false, unitParamsHeld = false;
+    bool runBatchedGraph (const RackState& state, bool playing, int channels, MeterBank* meters) noexcept;
+    // processChunk in its three parts (round 190kz): the serial part before the units, the units, the Master's part.
+    // chunkPrelude returns the pool to restore after the units (chunkSchedule may set `workers` to nullptr)
+    void chunkPrelude (const RackState& state, bool playing, double startTick, int numSamples, bool continuing) noexcept;
+    WorkerPool* chunkSchedule (const RackState& state, int numSamples, int eventCount) noexcept;
+    void chunkUnits (const RackState& state, bool playing, int numSamples, MeterBank* meters) noexcept;
+    void chunkMaster (const RackState& state, int numSamples, float* left, float* right, MeterBank* meters, WorkerPool* pool,
+                      std::uint64_t chunkStartNs) noexcept;
     void processChunk (const RackState& state, bool playing, double startTick, int numSamples,
                        float* left, float* right, MeterBank* meters, bool continuing = false) noexcept;
     // render-ahead (round 190gq): this renderer's part of the rack, the boundary in and out
@@ -828,6 +973,8 @@ private:
     static double ticksToNextEvent (const RackState& state, double tick) noexcept;
     // bindings from this automation slot on (andLive: and those of live controllers, the links)
     void applyPluginParams (const RackState& state, int firstSlot, bool andLive = false) noexcept;
+    void applyPluginParam (const RackState& state, std::size_t index, int firstSlot, bool andLive) noexcept; // (one binding)
+    void applyOrDeferParams (const RackState& state, int firstSlot, bool andLive) noexcept;               // (round 190kz)
     // Round 190jg (sample-accurate automation): the automation's changes inside this chunk for hosted CLAP / VST3
     // plugins (Instrument / Effect::setParameterAt), after the chunk's values. Clip automation and lanes (not pattern
     // events: a chunk already ends at each of those). Checked every timedStep samples of the export grid (a ramp moves
@@ -836,8 +983,8 @@ private:
     static constexpr int timedStep = 16;
     std::int64_t timedGridPos = -1;                                  // the chunk's place on the export grid (-1: no grid)
     std::array<float, RackState::maxAutomations> timedLast {};       // the last value sent per automation slot
-    double compensateTick = -1.0;          // the song position of this block's automation (song mode), −1 = none
-    double compensateTicksPerSample = 0.0; // > 0: compensation on in this block
+    PieceValue<double> compensateTick { -1.0 };          // the song position of this block's automation (song mode), −1 = none
+    PieceValue<double> compensateTicksPerSample { 0.0 }; // > 0: compensation on in this block
     float automated (int automation, float base) const noexcept;
     float* trackBuffer (int track, int channel) noexcept;
     // Round 190gp (lazy-zero track buffers): an insert's buffer nobody has written in this chunk holds zeros without
@@ -847,9 +994,9 @@ private:
     const float* trackInput (int track, int channel) noexcept;
     float* rawTrackBuffer (int track, int channel) noexcept;
     bool trackZeros (int track) const noexcept { return (std::size_t) track < trackUnwritten.size() && trackUnwritten[(std::size_t) track] != 0; }
-    std::vector<std::uint8_t> trackUnwritten;
+    PieceArray<std::uint8_t, maxMixerTracks> trackUnwritten; // (round 190kz: per piece)
     std::vector<float> zeroBlock;
-    int trackSamples = 0; // the chunk's samples (what trackBuffer zeroes)
+    PieceValue<int> trackSamples { 0 }; // the chunk's samples (what trackBuffer zeroes)
 
     double sampleRate = 44100.0;
     double bpm = 120.0;
@@ -865,7 +1012,7 @@ private:
     std::uint64_t lastSerial = 0;
     std::vector<VoiceOrder> voiceOrderScratch;   // (round 168s: moving the note state with moved channels)
     std::vector<NoteMask> heldScratch;
-    EventBuffer events;
+    PieceEvents events; // (round 190kz: per piece)
     // round 190gn (A6): the per-chunk channel and insert buffers, sized by the songs (reserveFor) and handed to the
     // audio thread like the snapshots; `buffers` is the one process() uses (audio thread)
     struct Buffers
@@ -882,7 +1029,7 @@ private:
     std::mutex bufferLock; // the producers of bufferExchange: reserveFor (message thread) and prepare
     std::atomic<int> reservedChannels { 0 }, reservedTracks { 0 }, preparedFrames { 0 };
     std::atomic<bool> reserving { false }; // reserveFor is used: the audio thread never grows them itself
-    std::array<float, RackState::maxAutomations> automationValues {}; // NaN = not evaluated yet
+    PieceArray<float, RackState::maxAutomations> automationValues; // NaN = not evaluated yet (round 190kz: per piece)
     // the pitch bend an automation / event lane last gave each LYNX instrument (0..1; NaN = none yet; issue #12)
     std::array<float, maxChannels> automatedBend {};
     bool automatedBendReset = false;
@@ -897,9 +1044,9 @@ private:
     std::array<MixerMatrix, maxMixerTracks> lastTapGain {};
     // issue #144: the fader ramp of a silenced insert's meter (NaN: none yet)
     std::array<MixerMatrix, maxMixerTracks> lastMeterGain {};
-    std::array<char, maxMixerTracks> trackActive {};        // the track output has sound in this block
+    PieceArray<char, maxMixerTracks> trackActive;           // the track output has sound in this block
     std::vector<float> tapBuffers;                          // RackState::maxSendTaps * 2 * chunkCapacity
-    std::array<char, RackState::maxSendTaps> tapActive {};  // the Fruity Send slot sent something this block
+    PieceArray<char, RackState::maxSendTaps> tapActive;     // the Fruity Send slot sent something this block
     // round 190aq: the mute ramp of each insert's pre-fader send signal (1 = heard, 0 = muted; NaN: none yet)
     std::array<float, maxMixerTracks> lastPreGain {};
     // round 190aq: slots skipped for low latency last block; back in the chain they start from a reset state
@@ -915,7 +1062,7 @@ private:
     // click back to the default, becomes a short glide)
     static constexpr double fullTurnSeconds = 0.25;
     float* tapBuffer (int tap, int side) noexcept;
-    std::array<char, maxChannels> channelSilent {};          // channel skipped in this chunk (idle, no notes)
+    PieceArray<char, maxChannels> channelSilent;             // channel skipped in this chunk (idle, no notes)
     std::array<NoteMask, maxChannels> heldNotes {};          // keys held on each channel (effects that follow notes: LYNX Tune)
     std::array<std::array<std::atomic<std::uint64_t>, 2>, maxChannels> sounding {};
     std::array<std::atomic<std::uint32_t>, maxChannels> strikes {}; // (noteStrikes; written only by publishSoundingKeys)
@@ -940,8 +1087,9 @@ private:
     channelpoly::Mode polyMode (const ChannelDef& c, const Instrument& instrument) const noexcept;
     void clearPolyLayers() noexcept;
     static constexpr int chunkCapacity = 512;               // chunks processed at once
-    double chunkStartTick = 0.0, chunkTps = 1.0;            // of the chunk being rendered (for the arpeggiator)
-    bool clipEnvTableShown = false, clipEnvTableWas = false; // round 190gi: the last chunk's song had clip envelopes
+    PieceValue<double> chunkStartTick { 0.0 }, chunkTps { 1.0 }; // of the chunk being rendered (for the arpeggiator)
+    PieceValue<bool> clipEnvTableShown { false };          // round 190gi: the last chunk's song had clip envelopes
+    bool clipEnvTableWas = false;
     // live-played notes of channels with an arpeggiator, echo delay or key / velocity tracking go through the
     // channel's note path like the scheduled ones (FL, round 149); while stopped the arpeggiator runs on its own clock
     std::array<NoteEvent, 256> liveRouted {};
@@ -977,7 +1125,7 @@ private:
     launcher::Runtime* runningLauncher = nullptr;  // the grid's runtime while it plays
     std::vector<float> hwScratch; // 2 × blockCapacity
     void mixHardwareOutputs (const RackState& state, int n) noexcept;
-    int liveInputOffset = 0; // of the chunk within the process() block
+    PieceValue<int> liveInputOffset { 0 }; // of the chunk within the process() block
     // hardware MIDI outputs (round 190jl)
     std::array<std::atomic<std::uint64_t>, 4> hwPorts {};
     std::atomic<bool> hwPortsAny { false };
@@ -1030,9 +1178,9 @@ private:
         bool running = false;
     };
     std::vector<TrackEqState> trackEqs; // built-in EQ of each track
-    double chunkTick = 0.0;             // start of the block (for the global LFOs)
-    bool chunkPlaying = false;          // the song plays during the block (effects that follow the transport)
-    bool pdcBypassNow = false;          // the "When recording or not playing" tracks skip their PDC delays this chunk
+    PieceValue<double> chunkTick { 0.0 };   // start of the block (for the global LFOs)
+    PieceValue<bool> chunkPlaying { false }; // the song plays during the block (effects that follow the transport)
+    PieceValue<bool> pdcBypassNow { false }; // the "When recording or not playing" tracks skip their PDC delays this chunk
     bool pdcBypassBefore = false;       // ... and did in the previous chunk (back to compensated: their lines are emptied)
     void applyTrackEq (const MixerTrack& track, int t, bool bypassed, float* l, float* r, int n) noexcept;
     static constexpr float silenceLevel = 1.5849e-5f;  // -96 dBFS

+ 2 - 0
src/core/VoiceShift.cpp

@@ -178,6 +178,8 @@ public:
         held = channels;
         heldCount = count;
     }
+    bool followsHeldNotes() const noexcept override { return true; } // (round 190kz)
+    bool followsHeldNotesWith (const EffectParams& p) const noexcept override { return midiChannelIndex (p[midi]) >= 0; } // (process())
 
     void process (float* l, float* r, int n, const EffectParams& p, double) noexcept override
     {

+ 17 - 0
src/core/WorkerPool.cpp

@@ -185,6 +185,23 @@ void WorkerPool::Tuning::apply (const char* spec) noexcept
     waitMode.store (std::clamp (parsedValue (spec, "wait", waitMode.load()), 0, 2));
     waitSpinMicros.store (std::clamp (parsedValue (spec, "waitspin", waitSpinMicros.load()), 0, 10000));
     helpPercent.store (std::clamp (parsedValue (spec, "help", helpPercent.load()), 0, 1000));
+    // (round 190kz: "rounds=chunk" / "rounds=block", or 0 / 1)
+    for (const char* at = spec; at != nullptr && *at != 0;)
+    {
+        if (std::strncmp (at, "rounds=", 7) == 0)
+        {
+            const char* v = at + 7;
+            if (std::strncmp (v, "chunk", 5) == 0)
+                blockRounds.store (0);
+            else if (std::strncmp (v, "block", 5) == 0)
+                blockRounds.store (1);
+            else
+                blockRounds.store (std::atoi (v) != 0 ? 1 : 0);
+        }
+        at = std::strchr (at, ',');
+        if (at != nullptr)
+            ++at;
+    }
 }
 
 WorkerPool::Stats WorkerPool::stats() const noexcept

+ 6 - 1
src/core/WorkerPool.h

@@ -114,7 +114,12 @@ public:
         // cell): 0 = 89-90 % of a core for the process, 25 = 76-81 %, 35 = 78-80 %, 50 = 76-79 %; callbacks over the
         // deadline 0 / 0 / 5 / 15. Default 25; LYNX_POOL="help=0" = every needed sleeper woken (before round 190kr).
         std::atomic<int> helpPercent { 25 };
-        void apply (const char* spec) noexcept; // "spin=60,dry=4,adaptive=1,wait=1,waitspin=30,help=0" (missing keys: unchanged)
+        // Round 190kz (sched): the rounds of a device block cut in pieces (RackRenderer: the automation's 128-sample grid,
+        // pattern events). 1 = one task-graph round for the whole block where that renders the same samples (each unit
+        // runs its pieces one after another inside it); 0 = one round per piece (before round 190kz). LYNX_POOL accepts
+        // "rounds=block" / "rounds=chunk" too.
+        std::atomic<int> blockRounds { 1 };
+        void apply (const char* spec) noexcept; // "spin=60,dry=4,adaptive=1,wait=1,waitspin=30,help=0,rounds=block" (missing keys: unchanged)
     };
     static Tuning& tuning() noexcept;
 

+ 182 - 0
tests/Sched190kzTests.inc

@@ -0,0 +1,182 @@
+// Round 190kz (sched, 0.1.30 perf-first): one worker-pool round per device block. A block the renderer cuts in pieces
+// (the automation's 128-sample grid, pattern events) runs every piece's serial part first, then ONE task-graph round in
+// which each unit renders its pieces one after another (RackRenderer::processBatched). LYNX_POOL="rounds=chunk" = one
+// round per piece, as before. The samples must not change at all.
+
+#include "core/SynthParams.h"
+
+namespace sched190kz
+{
+struct Guard
+{
+    int rounds = lynx::WorkerPool::tuning().blockRounds.load(), help = lynx::WorkerPool::tuning().helpPercent.load();
+    ~Guard()
+    {
+        lynx::WorkerPool::tuning().blockRounds = rounds;
+        lynx::WorkerPool::tuning().helpPercent = help;
+    }
+};
+
+// 35 synth / hat channels on 13 inserts with routes and a reverb (the task graph's test song), played in Song mode with
+// automation clips on a channel's volume, an insert's fader, an insert's pan and the reverb's mix: the 128-sample grid
+lynx::Song song (bool heldNotesEffect, bool compressor = false)
+{
+    using namespace lynx;
+    auto s = Song::makeDefault();
+    s.mixer = Song::defaultMixer (16);
+    for (int i = 5; i < 40; ++i)
+    {
+        ChannelDef c;
+        c.instrument = i % 3 == 0 ? InstrumentKind::hat : InstrumentKind::synth;
+        c.mixerTrack = i % 7 == 0 ? 0 : 1 + i % 13;
+        c.volume = 0.25f;
+        s.channels.push_back (c);
+        for (int step = i % 5; step < 16; step += 2)
+            s.patterns[0].notes.push_back ({ (std::int64_t) step * ticksPerStep + i * 3, 150, i, 40 + i, 0.6f });
+    }
+    s.patterns[0].sortNotes();
+    s.setRoute (3, 7, true, 0.6f);
+    s.setRoute (7, 9, true, 0.5f);
+    s.setRoute (9, 11, true, 0.5f);
+    s.mixer[9].effects.push_back (makeEffectSlot (EffectKind::reverb));
+    if (heldNotesEffect) // (Pitcher reads every channel's held notes: the block stays piece by piece)
+        s.mixer[5].effects.push_back (makeEffectSlot (EffectKind::pitchCorrect));
+    if (compressor) // (LYNX's compressor reads them only with its MIDI trigger on: at its defaults the block is batched)
+        s.mixer[6].effects.push_back (makeEffectSlot (EffectKind::compressor));
+    const auto bars = 4 * 4 * ppq;
+    auto automate = [&s, bars] (AutomationTarget target, float from, float to) {
+        Automation a;
+        a.target = target;
+        a.points = { { 0, from, 0.0f }, { bars / 2, to, 0.0f }, { bars, from, 0.0f } };
+        s.automations.push_back (a);
+        Clip clip;
+        clip.kind = ClipKind::automation;
+        clip.automation = (int) s.automations.size() - 1;
+        clip.track = (int) s.automations.size();
+        clip.length = bars;
+        s.playlist.push_back (clip);
+    };
+    automate ({ AutomationTargetKind::channelVolume, 6, 0, 0 }, 0.2f, 0.9f);
+    automate ({ AutomationTargetKind::mixerVolume, 7, 0, 0 }, 0.3f, 1.0f);
+    automate ({ AutomationTargetKind::mixerPan, 11, 0, 0 }, 0.1f, 0.9f);
+    automate ({ AutomationTargetKind::effectParam, 9, 0, 0 }, 0.0f, 1.0f);
+    // (a LYNX Synth knob: a plugin parameter binding, applied by its channel inside its task)
+    automate ({ AutomationTargetKind::channelParam, 7, 0, synthparam::target (synthparam::cutoff) }, 0.2f, 0.8f);
+    for (int k = 0; k < 4; ++k)
+    {
+        Clip clip;
+        clip.pattern = 0;
+        clip.track = 0;
+        clip.start = (std::int64_t) k * 4 * ppq;
+        clip.length = 4 * ppq;
+        s.playlist.push_back (clip);
+    }
+    s.mode = PlayMode::song;
+    return s;
+}
+
+struct Result
+{
+    std::vector<float> samples;
+    std::uint64_t rounds = 0, batched = 0, batchedRounds = 0, heldRefusals = 0;
+    int blocks = 0;
+};
+
+// the song played from its start in device blocks of `block` samples: alone (no pool) or with 4 workers
+Result render (const lynx::Song& s, int block, bool pool, const char* spec)
+{
+    if (spec != nullptr)
+        lynx::WorkerPool::tuning().apply (spec);
+    lynx::WorkerPool::tuning().helpPercent = 0; // (every needed worker woken: the rounds really go to the workers)
+    auto state = lynx::RackState::build (s, nullptr, 48000.0);
+    lynx::WorkerPool workers (4);
+    lynx::RackRenderer r;
+    r.prepare (48000.0, 512);
+    if (pool)
+        r.setWorkerPool (&workers);
+    Result out;
+    std::vector<float> l ((std::size_t) block), rr ((std::size_t) block);
+    const auto tps = lynx::ticksPerSample (s.bpm, 48000.0);
+    const auto before = workers.stats().rounds;
+    double tick = 0.0;
+    for (int done = 0; done < 2 * 48000; done += block, ++out.blocks)
+    {
+        r.process (state.get(), true, tick, block, l.data(), rr.data());
+        tick += block * tps;
+        out.samples.insert (out.samples.end(), l.begin(), l.end());
+        out.samples.insert (out.samples.end(), rr.begin(), rr.end());
+    }
+    out.rounds = workers.stats().rounds - before;
+    out.batched = r.batchedBlockCount();
+    out.batchedRounds = r.batchedRoundCount();
+    out.heldRefusals = r.batchRefusedCount (lynx::RackRenderer::BatchRefusal::heldNotes);
+    return out;
+}
+} // namespace sched190kz
+
+TEST (sched190kz_tuning_parses_rounds)
+{
+    const sched190kz::Guard guard;
+    auto& t = lynx::WorkerPool::tuning();
+    CHECK (t.blockRounds.load() == 1 || t.blockRounds.load() == 0);
+    t.apply ("rounds=chunk");
+    CHECK (t.blockRounds.load() == 0);
+    t.apply ("help=25");
+    CHECK (t.blockRounds.load() == 0); // (missing key: unchanged)
+    t.apply ("spin=60,rounds=block,help=30");
+    CHECK (t.blockRounds.load() == 1 && t.helpPercent.load() == 30);
+    t.apply ("rounds=0");
+    CHECK (t.blockRounds.load() == 0);
+    t.apply ("rounds=1");
+    CHECK (t.blockRounds.load() == 1);
+}
+
+TEST (sched190kz_one_round_per_block_renders_the_same)
+{
+    // automation on the grid of 128 inside device blocks of 480 / 441 / 256 / 64 (at 64 one piece: nothing to batch):
+    // without a pool, with one round per piece, and with one round per block: bit for bit
+    const sched190kz::Guard guard;
+    const auto s = sched190kz::song (false);
+    for (const auto block : { 480, 441, 256, 64 })
+    {
+        const auto alone = sched190kz::render (s, block, false, nullptr);
+        const auto perPiece = sched190kz::render (s, block, true, "rounds=chunk");
+        const auto perBlock = sched190kz::render (s, block, true, "rounds=block");
+        CHECK (perPiece.samples == alone.samples);
+        CHECK (perBlock.samples == alone.samples);
+        CHECK (perPiece.batched == 0);
+        if (block >= 256)
+        {
+            CHECK (perBlock.batched > 0);        // (the blocks were batched...)
+            CHECK (perBlock.batchedRounds > 0);  // (... and went to the workers in one round)
+            CHECK (perBlock.rounds < perPiece.rounds); // (fewer rounds)
+            CHECK ((double) perBlock.rounds <= 1.05 * perBlock.blocks);
+            std::printf ("  block %d: rounds per block %.2f per piece, %.2f batched (%llu of %d blocks batched)\n", block,
+                         (double) perPiece.rounds / perPiece.blocks, (double) perBlock.rounds / perBlock.blocks,
+                         (unsigned long long) perBlock.batched, perBlock.blocks);
+        }
+        else
+            CHECK (perBlock.batched == 0);
+    }
+    const auto heard = sched190kz::render (s, 480, false, nullptr).samples;
+    CHECK (*std::max_element (heard.begin(), heard.end()) > 0.02f);
+}
+
+TEST (sched190kz_an_effect_following_held_notes_keeps_the_block_piece_by_piece)
+{
+    // Pitcher reads every channel's held notes at its piece: that block is not batched, and renders the same
+    const sched190kz::Guard guard;
+    const auto s = sched190kz::song (true);
+    const auto alone = sched190kz::render (s, 480, false, nullptr);
+    const auto perBlock = sched190kz::render (s, 480, true, "rounds=block");
+    CHECK (perBlock.samples == alone.samples);
+    CHECK (perBlock.batched == 0);
+    CHECK (perBlock.heldRefusals > 0);
+    // a compressor that can follow them but does not with its settings: batched, the same samples
+    const auto c = sched190kz::song (false, true);
+    const auto cAlone = sched190kz::render (c, 480, false, nullptr);
+    const auto cBlock = sched190kz::render (c, 480, true, "rounds=block");
+    CHECK (cBlock.samples == cAlone.samples);
+    CHECK (cBlock.batched > 0);
+    CHECK (cBlock.heldRefusals == 0);
+}

+ 1 - 0
tests/tests.cpp

@@ -17895,6 +17895,7 @@ TEST (fl_low_lifter_matches_fl_engine)
 #include "Flm190jvTests.inc" // round 190jv: FL Studio Mobile racks with several instruments / an effect first (BUILD-LIST 19)
 #include "Spin190kbTests.inc" // round 190kb: the worker pool's waiting (statistics, tuning, bounded task-graph waits, adaptive spin)
 #include "Beat190krTests.inc" // round 190kr: the worker pool wakes only the workers a chunk's work needs; the same samples
+#include "Sched190kzTests.inc" // round 190kz: one worker-pool round per device block cut in pieces; the same samples
 #include "Export190kaTests.inc" // round als190ka-export (owner decision D5): AIFF and M4A (AAC) export
 #include "Issues190jzTests.inc" // round 190jz: issues #192 (docked Browser), #194 (clip fade handles), #195 (Home, W)
 #include "PrChord190kdTests.inc" // round 190kd: FL's chord tool strip (Generate modes, Analyze, Learn from MIDI input, note options)

+ 15 - 0
tools/perfbench.cpp

@@ -587,6 +587,21 @@ int main (int argc, char** argv)
                          per (p.sleeps - pool0.sleeps), per (p.earlyWakes - pool0.earlyWakes), ms (p.waitNs - pool0.waitNs), per (p.waits - pool0.waits),
                          per (p.waitYields - pool0.waitYields), per (p.waitSleeps - pool0.waitSleeps), ms (p.waitSleepNs - pool0.waitSleepNs),
                          ms (p.callerWaitNs - pool0.callerWaitNs), per (p.callerSleeps - pool0.callerSleeps));
+            // round 190kz (sched): rounds per device block, and the blocks rendered batched (one round for all their pieces)
+            const auto blocks = (double) ((totalSamples + (std::size_t) blockSize - 1) / (std::size_t) blockSize);
+            std::printf ("sched: %.2f rounds per block, batched blocks %llu (one round %llu) since start, of %.0f measured blocks\n",
+                         (double) (p.rounds - pool0.rounds) / std::max (1.0, blocks), (unsigned long long) renderer->batchedBlockCount(),
+                         (unsigned long long) renderer->batchedRoundCount(), blocks);
+            {
+                static const char* const why[] = { "switched off", "no graph", "big block", "live controllers", "MIDI between units",
+                                                   "launchers", "bindings", "held notes", "timed params", "many pieces", "other" };
+                std::printf ("sched: not batched:");
+                auto any = false;
+                for (int k = 0; k < (int) RackRenderer::BatchRefusal::count; ++k)
+                    if (const auto c = renderer->batchRefusedCount ((RackRenderer::BatchRefusal) k); c > 0)
+                        std::printf (" %s %llu", why[k], (unsigned long long) c), any = true;
+                std::printf ("%s\n", any ? "" : " none");
+            }
         }
         if (ahead != nullptr)
         {