feat: a signal switched off switches its dependent math channels off too

A derived channel cannot be computed from a signal nobody acquires: `Source` resolves to a
*channel*, and a disabled signal has none -- so a channel that reads one silently computed
nothing, which is what "all math signals depending on it do not compute anymore" looked like
from outside.

Rather than leave it enabled and blank, the channels that read the signal follow it off:
`disable_dependent_math_channels()` walks the graphs to a **fixpoint**, because one math
channel may name another, and the switch goes through the same path the pane's own toggle
uses -- `MathChannel::enabled` then `apply_math_channels()`, the single writer -- so the
pane's switches follow. Their traces leave the plots with the signal's, and the notice says
both halves.

The channels that do *not* read it are untouched, which is the assertion's other half:

    [enable-all-probe] switched 'sine' off: traces_left=0 (want 0)
        math_off=[math x2,math3] math_on=[math lp]
        notice=''sine' is off: 1 trace left the plots; math off: math x2 and 1 more'

`math x2` and `math3` both source `sine`; `math lp` sources `noise` and stays on. The probe's
switch step now runs late enough that a math probe armed behind it has installed its graphs,
which is why the earlier reading was empty -- `app.math` had nothing in it yet, not
"no dependants".

Re-enabling the signal does not switch them back on, for the same reason it does not restore
the traces: that is the user's decision, and the rule is written down in
invariants-math-channels.md.
This commit is contained in:
Martino Ferrari committed 2026-10-12 22:25:15 +02:00
1 parent 5eb20f3cdb
commit b02419dee3
6 files changed
+92 -9

No files matched your search

+36
View File
@@ -2534,6 +2534,42 @@ void remove_trace(App& app, int row, int slot) {
app.rows->assign(row, slot, std::string(), std::string(), 0);
}
/// Disables every math channel that (transitively) reads `name`, and answers with their names.
///
/// A derived channel cannot be computed from a signal nobody acquires: `Source` resolves to a *channel*, and a
/// disabled signal has none -- so a channel left enabled would silently compute nothing. The rule is that the
/// channels which depend on a signal follow it off, which is also what the pane's own switch would do by hand.
/// The dependency is transitive: one math channel may name another, so a channel reading a disabled one goes
/// too, and the loop runs to a fixpoint for that.
std::vector<std::string> disable_dependent_math_channels(App& app, const std::string& name) {
std::vector<std::string> off;
if (name.empty()) return off;
const auto math_index_of = [&app](const std::string& n) -> int {
for (std::size_t k = 0; k < app.math.size(); ++k) {
if (app.math[k].name == n) return static_cast<int>(k);
}
return -1;
};
for (bool moved = true; moved;) {
moved = false;
for (MathChannel& channel : app.math) {
if (!channel.enabled) continue;
for (const MathNode& node : channel.nodes) {
if (node.op != MathOp::Source) continue;
const int k = math_index_of(node.source);
const bool reads_it = node.source == name;
const bool reads_a_disabled_one = k >= 0 && !app.math[static_cast<std::size_t>(k)].enabled;
if (!reads_it && !reads_a_disabled_one) continue;
channel.enabled = false;
off.push_back(channel.name);
moved = true;
break;
}
}
}
return off;
}
/// Takes a signal off every plot, and says how many traces went.
///
/// Switching a signal off means "do not acquire this", so a trace of it left on a plot draws nothing: a slot