Tuesday, February 24, 2009

Gooey

And now a bit more explanation of what I'm doing with my Moog GUI. 

There are a few different ways of creating GUIs and controlling synths in SuperCollider, for now I've gone with a simple approach using Pattern Proxies and the standard Slider class, but I might try something different as I add features. 

Here's some of my GUI code again, 

(
var window = Window.new("Moog",Rect(400, 400, 140, 100)).front;
var cutoffSlider, cutoffRef, resgainSlider;


~cutoffRef = PatternProxy();



cutoffSlider = Slider.new(window,Rect(10, 25, 100, 20));
 cutoffSlider.action_{
 var val;
 val = (10000*(cutoffSlider.value));
 val.postln;
 ~cutoffRef.source_(val);
  };


StaticText.new(window,Rect(10, 5, 100, 20))
 .string_("Cutoff")
 .action_{|v| };


)
This is the bit that creates the window and the filter cutoff slider. 

The first thing I've done is create a window, the parameters passed to it are the title, the initial position it appears in on the screen and the size of the window itself. 

Then I've created a Pattern Proxy, this is the thing that allows me to control my synth with both a GUI and a pattern.  

A Pattern Proxy is an object that can be placed in in a pattern and be changed whilst the pattern is playing. In this case I'm using a GUI to change the value of the Pattern Proxy as the pattern plays. I've set it as a global variable with a ~ so I can use it outside of the function it's created in.

I then create a slider that controls the value of the Pattern Proxy. It's instantiated with the name of the window it is to appear in and values setting it's size and position in the window. 

The action_ method controls the action the slider performs when it's moved. In this case it takes the value of the slider object and multiplies it by 10000. Slider values move between 0 and 1, so to turn it into something usable by the synth I need to change the range. For simple linear values multiplying the output works fine, but for more complex stuff you can use a ControlSpec. 

I then set the modified value to be the source of the Pattern Proxy, the object it takes it's values from. 

After that there's a static text box, created in a similar way to the slider, as a label. 

To actually make use of the Pattern Proxy, I need a pattern, so here it is again. 

(
Pmono("Moog",
 \freq, Pseq([440, 550, 660, 770, 660, 880], inf),
 \dur, 0.2,
 \oscType, Pseq([1,0,1,0,1], inf),
 \oscType2, Pseq([0,0,2,2,1], inf),
 \cutoff, (~cutoffRef),
 \gain, (~resgainRef)

).play


All I've done is drop in the proxies as I would do with any other pattern streams. 

This time I've used a Pmono, which creates only one instance of the synth on ther server and feeds it all the values in turn, instead of creating new ones with each note. This sounds a tad more like a an authentic Moog, plus I need to use a mono pattern with my new version of the synth that features portamento. 

Shazam. 

No comments:

Post a Comment