SuperCollider CLASSES (extension)

SplineGen

Like EnvGen but for Splines
Source: /home/egor/.local/share/SuperCollider/downloaded-quarks/splines/SplineOsc.sc
Inherits from: Object
Subclasses: SplineOsc

Description

Plays a spline along one dimension for use in automation and control rate modulation. This is the equivalent of EnvGen

This technique interpolates the spline along one dimension (usually X) producing values for Y that are then passed to a LocalBuf and embeded in the SynthDef and played with a BufRd.

A SplineInterpolator class is planned that will allow live updating from the gui to a buffer on the server. At present I am using SplineFr (frame rate device) and playing the spline in the language, messaging control changes to the server. This allows relocating and live editing and patching. The cost is more communication with the server. I run it at 24/fps.

Class Methods

*new (spline, dimension: 0, loop: false)

Arguments:

spline

any Spline subclass.

dimension

The dimension that represents time. Usually 0

loop

boolean: can loop the control back to the beginning

Returns:

(returnvalue)

Inherited class methods

Instance Methods

-spline

-spline = value

get/set spline

Returns:

(returnvalue)

-dimension

-dimension = value

get/set the dimension that represents time. Usually 0. The value dimension is then considered to be 1.

Returns:

Integer

-loop

-loop = value

get/set loop

Returns:

Boolean

-storeArgs

(describe method here)

Returns:

(returnvalue)

-duration

Total time length of the spline. Using the default values for the play methods kr etc. then time will be in seconds.

Returns:

float

-asLocalBuf (divisions: 512)

Returns a LocalBuf with the spline as an interpolated lookup table. Must be called from within a SynthDef

Arguments:

divisions

Number of interpolated values in the Buffer.

Returns:

a LocalBuf

-kr (timeScale: 1, doneAction: 0, divisions: 512)

Like EnvGen.kr(env), this plays the spline.

Arguments:

timeScale

If timeScale is tempo then the x values are beats. eg. Tempo.tempo

doneAction

Like EnvGen etc.

divisions

Total number of points in the interpolation

Returns:

control rate (a BufRd.kr)

s.boot;

// BSpline
(
b = BSpline([ [ 0, 2.275 ], [ 1, 1 ], [ 2.5102880658436, 3.1 ], [ 4, 4 ] ], 2.0, false);

b.gui(nil,1000@300);

)

(
{
    PinkNoise.ar * SplineGen(b).kr(doneAction:2)
}.play
)



// Linear
(

b = LinearSpline( Array.fill(60,{ arg i; [ i,1.0.rand ] }) );

b.gui(nil,1200@300);


)
(
{
    PinkNoise.ar * SplineGen(b).kr(doneAction:2)
}.play
)

-readKr (position, timeScale: 1, divisions: 512)

Plays the spline with a modulatable position input.

Arguments:

position

kr modulator in X units (seconds)

timeScale

Default 1.0 means that x units are seconds. If timeScale is tempo (bps) then the x values are beats. eg. Tempo.tempo

divisions

Total number of points in the interpolation

Returns:

control rate (a BufRd.kr)

-xyKr (speed, divisions: 512, rate: 'kr')

Returns an array of kr following each dimension. Returns as many dimensions as your spline have, not just xy as the name implies.

Time is the path along the spine of the spline. The total tangent length along spline could be summed to figure out the length of time needed for one oscillation, but that would only be calculatable if it is 2 dimensions. So just crank the speed up until you like it.

Arguments:

speed

float. how fast. range ? that depends

divisions

Total number of points in the interpolation

rate

'kr' or 'ar' see also SplineOsc

Returns:

control or audio rate BufRd

(
b = BSpline( Array.fill(8,{ arg i; [ exprand(40,500),1.0.rand ] }), 3.0,false );

b.gui(nil,1200@300);

)

(
{
    # f , w = SplineGen(b,0,loop:true).xyKr(MouseY.kr(0.1,20),32);
    Pulse.ar(f.clip(40,500),w.clip(0.0,1.0),0.4).dup
}.play
)

b.interpolate(32).flop.plot

Inherited instance methods

Examples

(
//Its not the spline that loops (that would be a loop in 2 dimensional space) but the SplineGen that is set to loop.

// the spline does NOT loop,
b = BSpline( Array.fill(16,{ arg i; [ i * 0.25,1.0.rand ] }), 3.0,false );

b.gui(nil,1200@300);


)
(
// the SplineGen loops
{
    Saw.ar(SplineGen(b,loop:true).kr.linexp(0.0,1.0,40,500).clip(40,500)).dup * 0.4
}.play
)