-
Notifications
You must be signed in to change notification settings - Fork 757
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
Refactor Function plot and loadToFloatArray #3047
Refactor Function plot and loadToFloatArray #3047
Conversation
This allows us to load a function into an array, too. Also the code is cleaned up now.
After this refactoring, you can now just get a buffer from a function directly.
Just a convenience, but will prove very useful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks so much! lgtm except for a few small things
HelpSource/Classes/Function.schelp
Outdated
@@ -448,6 +448,32 @@ 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. | |||
|
|||
|
|||
method::asBuffer | |||
Calculates duration in seconds worth of the output of this function, and returns it in a link::Classes/Buffer:: of the number of channels. This method immediately returns a buffer, which takes code::duration:: seconds to become filled with data. Then the action function is called. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably better to say "which is filled asynchronously" - it may take slightly longer than the duration of the buffer for the data to move around.
HelpSource/Classes/Function.schelp
Outdated
A function that is called when the buffer is filled. It is passed the buffer as argument. | ||
|
||
argument::fadeTime | ||
A fade in and out time in seconds. (Only) when given, an envelope is applied to the signal to avoid clicks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering about the functionality of this... what if we make the default value 0
, and then check if fadeTime
is == 0? IIRC EnvGen still does a single control period of interpolation if a segment time is 0, so it would be good to catch this case, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea!
inEnvir { |envir| | ||
envir ?? { envir = currentEnvironment }; | ||
^{ |... args| envir.use({ this.valueArray(args) }) } | ||
} | ||
|
||
loadToFloatArray { arg duration = 0.01, server, action; | ||
var buffer, def, synth, name, numChannels, val, rate; | ||
asBuffer { |duration = 0.01, server, action, fadeTime| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see my note above about using fadeTime = 0
|
||
^buffer | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please remove the extra whitespace here?
loadToFloatArray { arg duration = 0.01, server, action; | ||
var buffer, def, synth, name, numChannels, val, rate; | ||
asBuffer { |duration = 0.01, server, action, fadeTime| | ||
var buffer, def, synth, name, numChannels, rate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great, thanks!
Fixes #2996.