Logo

ZLB



Posts Tagged ‘supercollider’

SC hint #4

Monday, December 28th, 2009

VCAs in SC : a question of summing. VCAs are usefull in order not to spend cpu cycles adjusting levels with a dedicated synth, but still keeping full range on your controlling faders, knobs, etc.

(~vca = 0;
w=FlowView.new;
g = EZSlider(	w,  	// parent
		390@20,	// bounds
		"The VCA ",	// label
		\db.asSpec, 	// controlSpec
		{|ez| ~vca = ez.value;i.value  = ~vca + h.value } // action
).value_(0);
h = EZSlider(	w,  	// parent
		390@20,	// bounds
		"The fader ",	// label
		\db.asSpec, 	// controlSpec
		{|ez| i.value  = ~vca + ez.value} // action
);
i = EZSlider(	w,  	// parent
		390@20,	// bounds
		"Result ",	// label
		\db.asSpec, 	// controlSpec
		{|ez| } // action
);
)

SC Hint #3 - Block - Break

Tuesday, December 22nd, 2009

if you need to break from the middle of a iteration, because let’s say you had an error and you shouldn’t continue, then you can use:

block{ |break| 10.do{ |i| if(i==5){ break.value(999) } } }

SC Hint #2 - get the Rect with the size of View

Friday, December 18th, 2009

If you have a view and you want to get a Rect with it’s width and height you can do:

Rect(0,0,view.bounds.width,view.bounds.height)

But it’s more compact to do:

view.bounds.extent.asRect

SC Hint #1 - reduce

Thursday, November 26th, 2009

A great way to apply a binary operator successively  to the elements of an array is to use reduce.

e.g.

[true,false,true].reduce('&&')
["This ","is ","a string."].reduce('++')

Dealing with multiple gui windows in supercollider

Friday, May 29th, 2009

Let’s say one has a data class MyCircle and a gui Class MyCircleGui which displays controls for this class.  The gui is constructed by calling aMyCircle.edit; 

MyCircle {

edit { ^MyCircleGui(this) }

}

Now, if I call  .edit again on a MyCircle I don’t want it to construct a new gui window if there is one already open: one must keep track of which windows are open. My solution to this problem was to have an IdentityDictionary as a class variable where I add the window of a MyCircleGui when the class is created and delete it when the window is closed.

MyCircle {

classvar <>instances;

*new{ |aMyCircle|

instances = instances ?? {IdentityDictionary.new};

if(instances.keys.includes(aMyCircle).not){

var view,window,flow;

window = Window(…)

// add guis to window here.

window.front;

window.onClose_{instances.removeAt(aMyCircle)}; instances.put(aMyCircle,window);

}

{ instances[aMyCircle].front }

}

*closeAll{

       instances.do{ |window| if(window.isClosed.not){window.close} }

}

edit { ^MyCircleGui(this) }

}

This takes care of the open windows, and if I want to close all the current open windows I just call MyCircleGui.closeAll.

ToolsMenu

Monday, May 18th, 2009

imagem-2

I’ve made a class to add some common used functions of supercollider in a menu using SCMenuItem.

It allows to choose soundcard for each server or all at the same time,  EQ, record window, auto sintax colorize on current document, color picker, open quarks, Init Midi, check current midi messages, run a file with cmd^r .

Finally it adds a menu tree with all files in predetermined folders for easy access. When working on a project I’m always editing the same files, closing and opening the files, and I got fed up and decided to just put them in the menu bar for easy access.

I hope this might be useful for someone else, I think specially newbies will appreciate being able to change the sound card (thanks for someone who posted the code in the list) and record from a gui (thanks Wouter Snoei for ServerRecordWindow !).

Needs:
supercollider 3.3
wslib Quark

info_at_friendlyvirus.org
sales_at_friendlyvirus.org
www.myspace.com/friendlyvirus/