How can I hide the scope windows called by the function definition?

When evaluating the following code snippet, four scope windows appear: two are inactive and two are active:

(
var midiPitchNum = 36;
var freqs = midiPitchNum.midicps * [4, 5, 6];
var numFreqs = freqs.size;
var phases = { rrand(0, 2pi) } ! numFreqs;
var synths = { 
	var synths = numFreqs.collect { |i| 
		SinOsc.ar(freqs[i], phases[i]) / numFreqs
	};
	synths.scope ++ synths.sum.scope
};
phases.postln;
synths.plot(freqs.minItem.reciprocal * 15);
{ Pan2.ar(synths.()[numFreqs]) }.play
)

How can I get sclang to hide the first two scope windows called by the function definition?

Thank you in advance!

Hello,

maybe like this ?

(
var midiPitchNum = 36;
var freqs = midiPitchNum.midicps * [4, 5, 6];
var numFreqs = freqs.size;
var phases = { rrand(0, 2pi) } ! numFreqs;
var synths = { 
	numFreqs.collect { |i| 
		SinOsc.ar(freqs[i], phases[i]) / numFreqs
	};
};
var scopeSynth = { arg synth;
	synth.scope ++ synth.sum.scope;
};
phases.postln;
{synths.() ++ synths.().sum}.plot(freqs.minItem.reciprocal * 15);
{
	scopeSynth.(synths.());
	Pan2.ar(synths.().last) 
}.play
)
1 Like

Ah, thank you for your help!

I have slightly modified your code snippet as follows, since scopeSynth only appears once:

(
var midiPitchNum = 36;
var freqs = midiPitchNum.midicps * [4, 5, 6];
var numFreqs = freqs.size;
var phases = { rrand(0, 2pi) } ! numFreqs;
var synths = { 
	numFreqs.collect { |i| 
		SinOsc.ar(freqs[i], phases[i]) / numFreqs
	}
};
phases.postln;
{ synths.() ++ synths.().sum }.plot(15 / freqs.minItem);
{
	synths.().scope ++ synths.().sum.scope;
	Pan2.ar(synths.().sum) 
}.play;
)

Thanks again!