supercollider icon indicating copy to clipboard operation
supercollider copied to clipboard

Add the parent argument to all .plot and .plotAudio methods to easily place them in a parent window.

Open prko opened this issue 1 year ago • 7 comments

Purpose and Motivation

To display one or more cycles of a waveform statically in a window or view.

Some examples:

  • In the following code, I want to display the quasi-real-time waveform of the configuration: https://sccode.org/1-5hC
  • Embedding a Stethoscope is possible, but statically adapting the waveform to the scope view area is not easy. https://scsynth.org/t/a-simple-way-or-formula-to-set-a-cycle-of-waveform-per-cps-for-stethoscope/8861
  • Function.plot cannot currently be embedded in a Window or View. For example, if I am not mistaken, the following plotted result cannot be placed in a Window:
    { SinOsc.ar }.plot(0.01)
    

With this PR, the plotted result above can be embedded as follows:

(
var w = Window("The parent of a plotter").front;
{ SinOsc.ar }.plot(0.01, parent: w)
)

Types of changes

  • Documentation
  • New feature

To-do list

  • [x] Code is tested
  • [x] All tests are passing
  • [x] Updated documentation
  • [x] This PR is ready for review

prko avatar Jan 25 '24 18:01 prko

AbstractFunction will also need this, and I would say that Env, Buffer, Wavetable, Bus, ArrayedCollection should have it too. Maybe others I could have missed.

The whole interface of plot is messy, because it has a long history. One day, we can maybe have a different method that is the same everywhere.

But until then, we should keep it as reasonable as possible ...

telephon avatar Mar 09 '24 11:03 telephon

@telephon Thank you for your kind comments!

I have added the parent argument to all plot and plotAudio methods in the plotView.sc file. I also updated the WaveTable, Buffer and Env documentation for the corresponding parts. For ArrayedCollection and Bus, there are no argument explanations, so I did not change them.

The following code blocks are the test code:

testing plotAudio

(
var w = Window("parent");
var busAudio = Bus.audio(s, 2);
busAudio.plotAudio(parent: w);
w.front
)

(
var w = Window("parent");
var busCotrol = Bus.control(s, 1).set(0.1);
busCotrol.plotAudio(parent: w);
w.front
)

testing plot with a routine

(
s.waitForBoot {
	var w = Window("parent");
	var testItems = (
		anArrayedCollection: [1, 2, 3],
		aFunction: { SinOsc.ar },
		aBusAudio: Bus.audio(s, 2),
		aBusControl: Bus.control(s, 1).set(0.1),
		aWaveTable: Wavetable.sineFill(512, 1.0 / [1, 2, 3, 4, 5, 6]),
		aBuffer: Buffer.read(s, Platform.resourceDir +/+ "sounds/sinedPink.aiff"),
		anEnv: Env.perc
	);
	
	s.sync;
	
	w.front;
	testItems.do { |item|
		item.plot(parent: w);
		1.wait
	};
}
)

testing individual plot methods

(
var w = Window("parent");
[1, 2, 3].plot(parent: w);
w.front
)

(
var w = Window("parent");
{SinOsc.ar}.plot(parent: w);
w.front
)

(
var w = Window("parent");
var busAudio = Bus.audio(s, 2);
busAudio.plot(parent: w);
w.front
)

(
var w = Window("parent");
var busCotrol = Bus.control(s, 1).set(0.1);
busCotrol.plot(parent: w);
w.front
)

(
var w = Window("parent");
Wavetable.sineFill(512, 1.0/[1, 2, 3, 4, 5, 6]).plot(parent: w);
w.front
)

(
s.waitForBoot {
	var w = Window("parent");
	var buf = Buffer.read(s, Platform.resourceDir +/+ "sounds/sinedPink.aiff");
	s.sync;
	buf.plot(parent: w);
	w.front
	
}
)

(
var w = Window("parent");
Env.perc.plot(parent: w);
w.front
)

prko avatar Mar 09 '24 15:03 prko

@telephon An example that shows an audio bus and the physical stereo output busses would be good. Will the examples in the following thread do the job? One thing I am afraid of is the 0.135.wait; part. It works on my laptop, but will be different on other machines. https://scsynth.org/t/plotaudio-and-the-practical-use-case-for-plotting-an-audio-bus/9143/3?u=prko

prko avatar Mar 15 '24 06:03 prko

https://scsynth.org/t/plotaudio-and-the-practical-use-case-for-plotting-an-audio-bus/9143/3?u=prko

@telephon Thank you! The example is added! Your example clarified three things that were a bit unclear to me!

prko avatar Mar 15 '24 09:03 prko

@telephon Added additional explanation to Bus.audio and Bus.new for easy understanding of these methods.

prko avatar Mar 15 '24 12:03 prko

I realised that I missed updating AbstractFunction.schelp. Also, I realised that there was a conflict, so I resolved it.

prko avatar Apr 02 '24 22:04 prko

Sorry for not checking this carefully. I added the parent argument to BusPlug. In the following screenshots you can see what I did:

  • Screenshot 2024-05-06 at 22 25 43
  • Screenshot 2024-05-06 at 22 25 22

prko avatar May 06 '24 13:05 prko

@capital-G Thanks! I resolved this!

prko avatar Jul 04 '24 02:07 prko