|
|
@@ -14,6 +14,7 @@
|
|
|
#include <map>
|
|
|
#include <tuple>
|
|
|
|
|
|
+#include "core/FacetEq.h"
|
|
|
#include "core/FlSynths.h"
|
|
|
#include "core/FrequencySplitter.h"
|
|
|
#include "core/HardwareInsert.h"
|
|
|
@@ -218,6 +219,40 @@ bool sameStructure (const PatcherDoc& a, const PatcherDoc& b)
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
+namespace
|
|
|
+{
|
|
|
+// Round 190ts: a built-in device whose silence LYNX can tell (Graph::setStoppedSleep): not a hosted plugin or a nested
|
|
|
+// Patcher (that one sleeps by itself), nor what the mixer's smart disable leaves out (RackState::planSlot): Gross Beat and
|
|
|
+// Edison record the silence, Newtone / Newtime / the Scratcher play whatever the input, a hardware insert has outboard
|
|
|
+// tails, controllers move whatever the sound, analysers and the tuner follow the signal into silence, Facet EQ playing
|
|
|
+// its comparative target.
|
|
|
+bool sleepableDevice (const EffectSlot& slot) noexcept
|
|
|
+{
|
|
|
+ switch (slot.kind)
|
|
|
+ {
|
|
|
+ case EffectKind::plugin: case EffectKind::patcher: case EffectKind::grossBeat: case EffectKind::newtone:
|
|
|
+ case EffectKind::newtime: case EffectKind::scratcher: case EffectKind::edison: case EffectKind::hardwareInsert:
|
|
|
+ case EffectKind::formulaController: case EffectKind::xyController: case EffectKind::xyzController:
|
|
|
+ case EffectKind::controlSurface: case EffectKind::peakController: case EffectKind::waveCandy:
|
|
|
+ case EffectKind::visualizer: case EffectKind::tuner:
|
|
|
+ return false;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return ! (slot.kind == EffectKind::facetEq && facet::listensToTarget (slot.params));
|
|
|
+}
|
|
|
+
|
|
|
+constexpr float sleepLevel = 1.5849e-5f; // -96 dBFS (RackRenderer::silenceLevel)
|
|
|
+
|
|
|
+bool quietBlock (const float* l, const float* r, int n) noexcept
|
|
|
+{
|
|
|
+ float peak = 0.0f;
|
|
|
+ for (int k = 0; k < n; ++k)
|
|
|
+ peak = std::max (peak, std::max (std::abs (l[k]), std::abs (r[k])));
|
|
|
+ return peak < sleepLevel;
|
|
|
+}
|
|
|
+} // namespace
|
|
|
+
|
|
|
struct Graph::Node
|
|
|
{
|
|
|
bool generator = false;
|
|
|
@@ -246,6 +281,12 @@ struct Graph::Node
|
|
|
std::vector<int> mainInputs, sideInputs; // wire indices
|
|
|
std::atomic<float> peak { 0.0f }; // round 190ld: main-output peak and process time while watched (Graph::watch)
|
|
|
std::atomic<std::uint64_t> ns { 0 };
|
|
|
+ // round 190ts (Graph::setStoppedSleep): may sleep while stopped (LYNX's own devices / an instrument that says idle);
|
|
|
+ // a nested Patcher sleeps by itself (its graph), and counts as asleep when it is
|
|
|
+ bool sleeps = false;
|
|
|
+ Graph* nested = nullptr;
|
|
|
+ int silentSamples = 0; // input and output silent that long (effect nodes)
|
|
|
+ bool asleep = false; // not called in the last piece
|
|
|
};
|
|
|
|
|
|
struct Graph::AudioWire
|
|
|
@@ -655,6 +696,37 @@ Graph::Graph (const PatcherDoc& doc, double sampleRate, const Factories& factori
|
|
|
if (wires[k].to == patchToHost && wires[k].toBus < (int) outputs.size())
|
|
|
outputs[(std::size_t) wires[k].toBus].push_back ((int) k);
|
|
|
|
|
|
+ // round 190ts (setStoppedSleep): which nodes may sleep while stopped
|
|
|
+ canWholeSleep = ! hardwareNodes;
|
|
|
+ for (int i = 0; i < count; ++i)
|
|
|
+ {
|
|
|
+ auto& node = *nodes[(std::size_t) i];
|
|
|
+ const auto& src = doc.nodes[(std::size_t) i];
|
|
|
+ if (node.generator)
|
|
|
+ {
|
|
|
+ // (a hosted generator keeps running: its idle() is FL's smart disable, which the rack asks itself)
|
|
|
+ node.nested = graphOf (node.instrument.get());
|
|
|
+ node.sleeps = node.instrument != nullptr && node.vfx == nullptr && ! node.plugin && node.nested == nullptr;
|
|
|
+ if (node.nested != nullptr)
|
|
|
+ nestedGraphs.push_back (node.nested);
|
|
|
+ else if (! node.sleeps && node.vfx == nullptr)
|
|
|
+ canWholeSleep = false;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ node.nested = src.effect.kind == EffectKind::patcher ? graphOf (node.effect.get()) : nullptr;
|
|
|
+ if (node.nested != nullptr)
|
|
|
+ {
|
|
|
+ nestedGraphs.push_back (node.nested);
|
|
|
+ if (node.sidechain)
|
|
|
+ canWholeSleep = false;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ const auto drivesControls = std::any_of (controls.begin(), controls.end(), [i] (const ControlWire& c) { return c.from == i; });
|
|
|
+ node.sleeps = node.effect != nullptr && ! node.sidechain && ! node.hardware && ! drivesControls && sleepableDevice (src.effect)
|
|
|
+ && std::all_of (node.heads.begin(), node.heads.end(), [] (const Node::Head& h) { return h.effect == nullptr || sleepableDevice (h.slot); });
|
|
|
+ canWholeSleep = canWholeSleep && node.sleeps;
|
|
|
+ }
|
|
|
+
|
|
|
for (auto& s : scratch)
|
|
|
s.assign ((std::size_t) capacity, 0.0f);
|
|
|
zeros.assign ((std::size_t) capacity, 0.0f);
|
|
|
@@ -838,6 +910,39 @@ void Graph::setPlaying (bool on) noexcept
|
|
|
n->effect->setPlaying (on);
|
|
|
}
|
|
|
|
|
|
+void Graph::setStoppedSleep (bool on) noexcept
|
|
|
+{
|
|
|
+ if (on == sleepOk)
|
|
|
+ return;
|
|
|
+ sleepOk = on;
|
|
|
+ wholeAsleep = allNodesAsleep = false;
|
|
|
+ quietSamples = 0;
|
|
|
+ for (auto& n : nodes)
|
|
|
+ {
|
|
|
+ n->silentSamples = 0;
|
|
|
+ n->asleep = false;
|
|
|
+ }
|
|
|
+ for (auto* g : nestedGraphs)
|
|
|
+ g->setStoppedSleep (on);
|
|
|
+}
|
|
|
+
|
|
|
+int Graph::sleepHold (const Node& node) const noexcept
|
|
|
+{
|
|
|
+ // (as the mixer's smart disable takes a built-in's declared tail, round 190gp; an undeclared one waits 4 s of silence:
|
|
|
+ // the plugins' hold, longer than the mixer's 1 s for built-ins, so a long echo or reverb never stops early)
|
|
|
+ const auto fixed = (int) (rate * 4.0);
|
|
|
+ if (! declaredTails() || node.effect == nullptr)
|
|
|
+ return fixed;
|
|
|
+ auto tail = node.effect->tailSamples();
|
|
|
+ for (const auto& h : node.heads)
|
|
|
+ if (h.effect != nullptr)
|
|
|
+ {
|
|
|
+ const auto t = h.effect->tailSamples();
|
|
|
+ tail = tail < 0 || t < 0 ? -1 : std::max (tail, t);
|
|
|
+ }
|
|
|
+ return tail < 0 ? fixed : std::clamp (tail, 1, fixed);
|
|
|
+}
|
|
|
+
|
|
|
void Graph::setHeldNotes (const NoteMask* channels, int count) noexcept
|
|
|
{
|
|
|
for (auto& n : nodes)
|
|
|
@@ -994,6 +1099,8 @@ bool Graph::zoneGate (int zone, bool on, int& key, int midiChannel, float& veloc
|
|
|
|
|
|
void Graph::deliver (int pin, bool on, int key, float velocityIn, int midiChannel) noexcept
|
|
|
{
|
|
|
+ wholeAsleep = false; // (round 190ts: something comes in: awake, idle() says so at once)
|
|
|
+ quietSamples = 0;
|
|
|
if (pin < 0 || pin >= (int) pinTargets.size())
|
|
|
return;
|
|
|
forLayeredTargets (pinTargets[(std::size_t) pin], on ? 1 : 0, key, [&] (const MidiTarget& t, int k, float gain, float pan, float cents, bool viaLayer) {
|
|
|
@@ -1058,6 +1165,8 @@ void Graph::noteOffPort (int port, int key, int midiChannel) noexcept
|
|
|
|
|
|
void Graph::queueTimed (int pin, int key, float velocity, int midiChannel, int offset) noexcept
|
|
|
{
|
|
|
+ wholeAsleep = false; // (round 190ts: something comes in: awake, idle() says so at once)
|
|
|
+ quietSamples = 0;
|
|
|
if (pin < 0 || pin >= (int) pinTargets.size() || pinTargets[(std::size_t) pin].empty() || timedCount >= timedCapacity)
|
|
|
return;
|
|
|
timed[(std::size_t) timedCount++] = { pin, key, midiChannel, std::max (0, offset), velocity };
|
|
|
@@ -1120,6 +1229,8 @@ void Graph::forNoteTargets (F&& f) noexcept
|
|
|
|
|
|
void Graph::midiMessage (const std::uint8_t* bytes, int size) noexcept
|
|
|
{
|
|
|
+ wholeAsleep = false; // (round 190ts: something comes in: awake, idle() says so at once)
|
|
|
+ quietSamples = 0;
|
|
|
forNoteTargets ([&] (Instrument& i) { i.midiMessage (bytes, size); });
|
|
|
}
|
|
|
void Graph::pitchBend (float semitones) noexcept
|
|
|
@@ -1458,6 +1569,26 @@ void Graph::processPiece (const float* inL, const float* inR, const float* scL,
|
|
|
}
|
|
|
if (hasVfx)
|
|
|
runVfx (n, bpm);
|
|
|
+ // round 190ts (setStoppedSleep): every node asleep, nothing coming in and the delays emptied: the graph is skipped
|
|
|
+ // (not while an editor watches its nodes: View › Activity / Performance)
|
|
|
+ if (sleepOk && watchLeft.load (std::memory_order_relaxed) > 0)
|
|
|
+ setStoppedSleep (false);
|
|
|
+ if (sleepOk && canWholeSleep)
|
|
|
+ {
|
|
|
+ const auto quiet = allNodesAsleep && noteOuts.empty() && timedCount == 0 && quietBlock (inL, inR, n)
|
|
|
+ && (scL == nullptr || scR == nullptr || quietBlock (scL, scR, n)) && instrumentsIdle();
|
|
|
+ quietSamples = quiet ? quietSamples + n : 0;
|
|
|
+ wholeAsleep = quiet && quietSamples > latency;
|
|
|
+ if (wholeAsleep)
|
|
|
+ {
|
|
|
+ std::fill (outL, outL + n, 0.0f);
|
|
|
+ std::fill (outR, outR + n, 0.0f);
|
|
|
+ for (auto& a : aux)
|
|
|
+ for (auto& side : a)
|
|
|
+ std::fill (side.begin(), side.begin() + n, 0.0f);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
if (noteOuts.empty())
|
|
|
{
|
|
|
renderNodes (inL, inR, scL, scR, outL, outR, 0, n, bpm);
|
|
|
@@ -1672,7 +1803,10 @@ void Graph::renderNodes (const float* inL, const float* inR, const float* scL, c
|
|
|
{
|
|
|
std::fill (oL, oL + n, 0.0f);
|
|
|
std::fill (oR, oR + n, 0.0f);
|
|
|
- if (node.instrument != nullptr)
|
|
|
+ // (round 190ts, stopped: an idle instrument is not rendered, as the rack skips an idle channel)
|
|
|
+ node.asleep = sleepOk && (node.nested != nullptr ? node.nested->asleep() || node.instrument->idle()
|
|
|
+ : node.sleeps && node.instrument->idle());
|
|
|
+ if (node.instrument != nullptr && ! node.asleep)
|
|
|
node.instrument->render (oL, oR, n, 1.0f, 1.0f);
|
|
|
if (watched)
|
|
|
measured (node, oL, oR);
|
|
|
@@ -1682,7 +1816,19 @@ void Graph::renderNodes (const float* inL, const float* inR, const float* scL, c
|
|
|
gather (node.mainInputs, inBufL, inBufR);
|
|
|
std::copy (inBufL, inBufL + n, oL);
|
|
|
std::copy (inBufR, inBufR + n, oR);
|
|
|
- if (v.enabled && v.mix > 0.0f)
|
|
|
+ // round 190ts (setStoppedSleep): stopped, a device whose input and output stayed silent past its tail passes its
|
|
|
+ // input through without being called
|
|
|
+ auto quietIn = false, skip = false;
|
|
|
+ if (sleepOk && node.sleeps)
|
|
|
+ {
|
|
|
+ quietIn = quietBlock (inBufL, inBufR, n);
|
|
|
+ if (! quietIn)
|
|
|
+ node.silentSamples = 0;
|
|
|
+ else if (node.silentSamples >= sleepHold (node))
|
|
|
+ skip = true;
|
|
|
+ }
|
|
|
+ node.asleep = skip;
|
|
|
+ if (v.enabled && v.mix > 0.0f && ! skip)
|
|
|
{
|
|
|
if (node.sidechain)
|
|
|
{
|
|
|
@@ -1705,7 +1851,7 @@ void Graph::renderNodes (const float* inL, const float* inR, const float* scL, c
|
|
|
auto* hR = node.out[1 + h][1].data() + start;
|
|
|
std::copy (inBufL, inBufL + n, hL);
|
|
|
std::copy (inBufR, inBufR + n, hR);
|
|
|
- if (node.heads[h].effect != nullptr)
|
|
|
+ if (node.heads[h].effect != nullptr && ! skip)
|
|
|
node.heads[h].effect->process (hL, hR, n, v.heads[h], bpm);
|
|
|
const auto g = v.headGains[h];
|
|
|
if (g != 1.0f)
|
|
|
@@ -1715,9 +1861,21 @@ void Graph::renderNodes (const float* inL, const float* inR, const float* scL, c
|
|
|
hR[k] *= g;
|
|
|
}
|
|
|
}
|
|
|
+ if (sleepOk && node.sleeps && ! skip)
|
|
|
+ {
|
|
|
+ // (its tail: silent input and silent outputs count towards the hold)
|
|
|
+ auto quietOut = quietIn && quietBlock (oL, oR, n);
|
|
|
+ for (std::size_t h = 0; h < node.heads.size() && quietOut; ++h)
|
|
|
+ quietOut = quietBlock (node.out[1 + h][0].data() + start, node.out[1 + h][1].data() + start, n);
|
|
|
+ node.silentSamples = quietOut ? node.silentSamples + n : 0;
|
|
|
+ }
|
|
|
+ else if (sleepOk && node.nested != nullptr)
|
|
|
+ node.asleep = node.nested->asleep();
|
|
|
if (watched)
|
|
|
measured (node, oL, oR);
|
|
|
}
|
|
|
+ if (sleepOk)
|
|
|
+ allNodesAsleep = std::all_of (nodes.begin(), nodes.end(), [] (const auto& x) { return x->asleep || x->vfx != nullptr; });
|
|
|
|
|
|
// "To LYNX SHARE": the main output and the extra ones
|
|
|
gather (outputs[0], inBufL, inBufR);
|
|
|
@@ -1776,6 +1934,7 @@ public:
|
|
|
void setParameter (int index, float value) noexcept override { graph.setPublished (index, value); }
|
|
|
void setSongPosition (double ticks) noexcept override { graph.setSongPosition (ticks); }
|
|
|
void setPlaying (bool playing) noexcept override { graph.setPlaying (playing); }
|
|
|
+ void setStoppedSleep (bool on) noexcept override { graph.setStoppedSleep (on); } // (round 190ts)
|
|
|
void setSidechain (const float* l, const float* r) noexcept override
|
|
|
{
|
|
|
sideL = l;
|
|
|
@@ -1842,7 +2001,12 @@ public:
|
|
|
void setSongPosition (double ticks) noexcept override { graph.setSongPosition (ticks); }
|
|
|
void setParameter (int index, float value) noexcept override { graph.setPublished (index, value); }
|
|
|
int latencySamples() const noexcept override { return graph.latencySamples(); }
|
|
|
- bool idle() const noexcept override { return idleWhenQuiet.load (std::memory_order_relaxed) && graph.instrumentsIdle(); }
|
|
|
+ // (round 190ts: or its graph sleeps while stopped, Graph::setStoppedSleep)
|
|
|
+ bool idle() const noexcept override
|
|
|
+ {
|
|
|
+ return (idleWhenQuiet.load (std::memory_order_relaxed) && graph.instrumentsIdle()) || graph.asleep();
|
|
|
+ }
|
|
|
+ void setStoppedSleep (bool on) noexcept override { graph.setStoppedSleep (on); }
|
|
|
|
|
|
// (UI thread, while the audio thread renders: only atomics change here; the graph swaps its values itself)
|
|
|
void configure (const ChannelDef& channel, double bpm) noexcept override
|