Why are the multiple plots in a routine affected by the last plot duration when using a single function defined as a variable?

Hello,

I thought the following two code blocks will output the same graphics, but the sig in the second code block terminated when the duration of the last plot is reached. Why does it happen?

(
s.waitForBoot {
		var freq=440, sig1 = { SinOsc.ar }, sig2 = { SinOsc.ar };
		sig1.plot(freq.reciprocal * 9, bounds: Rect(0, 250, 400, 250));
		sig2.plot(freq.reciprocal, bounds: Rect(0, 530, 400, 250))
}
)

(
s.waitForBoot {
		var freq=440, sig = { SinOsc.ar };
		sig.plot(freq.reciprocal * 9, bounds: Rect(0, 250, 400, 250)); // plot 1.
		sig.plot(freq.reciprocal, bounds: Rect(0, 530, 400, 250)) // plot 2.
		// The duration of plot 2 affects the `sig` in plot 1. why? 
}
)

If you insert a ‘s.sync’ between plots, it works as in the first example, not that I am able to explain why.

1 Like

The SynthDefs are named after the .hash of the function(s), and the plot duration is encoded into the SynthDef(s). In the second case, the shorter duration synthdef overwrites the longer-duration one.

EDIT: I just put in a PR – Classlib: Simplify Function:plot 'dur' redundancy by jamshark70 · Pull Request #6200 · supercollider/supercollider · GitHub

hjh

2 Likes

@Thor_Madsen Thank you for your solution!
@jamshark70 Thank you for the explanation and the PR!