Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

class library: plot relative to target synth #3088

Merged
merged 10 commits into from May 12, 2018
22 changes: 16 additions & 6 deletions HelpSource/Classes/Function.schelp
Expand Up @@ -425,6 +425,9 @@ A zoom value for the scope's X axis. Larger values show more. The default is 1.

method::plot

note::See link::Reference/plot:: for a general reference on plotting::


Calculates duration in seconds worth of the output of this function asynchronously, and plots it in a GUI window. Unlike play and scope it will not work with explicit Out Ugens, so your function should return a UGen or an Array of them. The plot will be calculated in realtime.

code::
Expand All @@ -434,19 +437,26 @@ code::
::



argument::duration
The duration of the function to plot in seconds. The default is 0.01.
argument::server
The Server on which to calculate the plot. This must be running on your local machine, but does not need to be the internal server. If nil the default server will be used.
argument::target
The target node on which to calculate the plot. See link::Reference/asTarget::. If it is a link::Classes/Server::, it must be running on your local machine, but does not need to be the internal server (see link::Classes/Buffer#-loadToFloatArray:: for details).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the implementation really require a local server? Why? getToFloatArray should work or?

Also, it would be useful to explain what's happening (addAfter) with target and why. With Function:plot presumably target only matters if you are reading from a bus. I find 'on which to calculate the plot' a bit enigmatic for newbies.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It uses loadToFloatArray, presumably for speed. In general, the class library seems to avoid getToFloatArray; I'm not sure why.

For the default 100ms plot duration, get... rather than load... will not be any slower -- might even be faster. For longer plots, load... is much faster.

Copy link
Member Author

@telephon telephon Oct 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think getToFloatArray was added later, and everyone, including me, is copying the old one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IAC plotting on remote servers seems desirable.

Copy link
Member Author

@telephon telephon Oct 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I think the getToFloatArray looks more complicated and insecure with the wait and timeout arguments. Also the argument names index and count don't match the ones of loadToFloatArray.

That might be the reason. Maybe we need the same thing as we have for SynthDef, something that tries to send first and if that fails, tries to load? All packed under a clean interface.

code::
(
var synth = { Out.ar(99, SinOsc.ar([300, 700])) }.play;
{ In.ar(99, 2) }.plot(0.02, synth);
)
::

argument::bounds
An instance of Rect or Point indicating the bounds of the plot window.
argument::minval
the minimum value in the plot. Defaults to -1.0.
argument::maxval
the maximum value in the plot. Defaults to 1.0.
argument:: separately
For multi channel signals, set whether to use separate value display ranges or not.
a window to place the plot in. If nil, one will be created for you.
If set to code::true::, for multichannel signals use separate value display ranges.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are these specified?



method::asBuffer
Expand All @@ -455,8 +465,8 @@ Calculates duration in seconds worth of the output of this function asynchronous
argument::duration
The duration of the function to plot in seconds. The default is 0.01.

argument::server
The server on which the function is calculated. The default is code::Server.default::.
argument::target
The synth or group after which the synth runs (see link::Reference/asTarget::). The default is the default group of code::Server.default::.

argument::action
A function that is called when the buffer is filled. It is passed the buffer as argument.
Expand Down
14 changes: 8 additions & 6 deletions SCClassLibrary/Common/Core/Function.sc
Expand Up @@ -263,9 +263,11 @@ Function : AbstractFunction {
^{ |... args| envir.use({ this.valueArray(args) }) }
}

asBuffer { |duration = 0.01, server, action, fadeTime = (0)|
var buffer, def, synth, name, numChannels, rate;
server = server ? Server.default;
asBuffer { |duration = 0.01, target, action, fadeTime = (0)|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also breaking change

var buffer, def, synth, name, numChannels, rate, server;
target = target.asTarget;
server = target.server;


name = this.hash.asString;
def = SynthDef(name, { |bufnum|
Expand Down Expand Up @@ -301,7 +303,7 @@ Function : AbstractFunction {
server.sync;
def.send(server);
server.sync;
synth = Synth(name, [\bufnum, buffer], server);
synth = Synth(name, [\bufnum, buffer], target, \addAfter);
OSCFunc({
action.value(buffer);
server.sendMsg("/d_free", name);
Expand All @@ -311,8 +313,8 @@ Function : AbstractFunction {
^buffer
}

loadToFloatArray { |duration = 0.01, server, action|
this.asBuffer(duration, server, { |buffer|
loadToFloatArray { |duration = 0.01, target, action|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, breaking change

this.asBuffer(duration, target, { |buffer|
buffer.loadToFloatArray(action: { |array|
action.value(array, buffer);
buffer.free
Expand Down
5 changes: 2 additions & 3 deletions SCClassLibrary/Common/GUI/PlusGUI/Math/PlotView.sc
Expand Up @@ -769,14 +769,13 @@ Plotter {


+ Function {
plot { |duration = 0.01, server, bounds, minval, maxval, separately = false|

plot { |duration = 0.01, target, bounds, minval, maxval, separately = false|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing function parameter names is a breaking change...

var name = this.asCompileString, plotter;
if(name.size > 50 or: { name.includes(Char.nl) }) { name = "function plot" };
plotter = Plotter(name, bounds);
plotter.value = [0.0];

this.loadToFloatArray(duration, server, { |array, buf|
this.loadToFloatArray(duration, target, { |array, buf|
var numChan = buf.numChannels;
{
plotter.setValue(
Expand Down