Bz Synth - SuperCollider

s.boot;

(
var res = 20, scrsize = 200, val, set, win, scr, currentColor = Color.gray, setColor;

SynthDef(\sinbz, { |out, freq = 800, pan = 1|

    var snd;
    snd = SinOsc.ar(freq,0,0.5);
    Out.ar(out, Pan2.ar(snd, pan , \amp.kr(0.1)));
}).add;

SynthDef(\sawbz, { |out, freq = 800, pan = 1|

    var snd;
    snd = Saw.ar(freq,1);
    Out.ar(out, Pan2.ar(snd, pan , \amp.kr(0.1)));
}).add;


x = Synth(\sinbz, [freq: 440]);
y = Synth(\sawbz, [freq: 220]);

win = Window.new("Bz Synth",Rect(400, 400, 2*scrsize+20, scrsize),false).front;

//win.view.background_(Color.white);

scr = UserView.new(win,Rect(scrsize+20, 0, scrsize, scrsize));
scr.background_(Color.white);

setColor = {|x, y, val, postVal=false|
    //x = x/scrsize;
    //y = y/scrsize;

    currentColor = Color.hsv(min(0.999, x), min(0.999, 1-y), val, 1);
    postVal.if{
//        ("Color.hsv("++(x)++", "++(1-y)++", "++val.value++", 1)").postln;
        "Color.new255(%, %, %)".format(*(currentColor.asArray*255)).postln;
    };

    scr.background_(
        Color.hsv(min(0.999, x), min(0.999, 1-y), val.value, 1)
    );
};

val = Slider(win, Rect(scrsize, 0, 20, scrsize)).value_(1).action_({|view|
    setColor.(m.x.postln, m.y, view.value);
    val.value.postln;
    x.set(\freq, val.value * 400);
    win.refresh
});

m = Slider2D(win, Rect(0, 0, scrsize, scrsize))
    .mouseDownAction_({|view|
        setColor.(view.x, view.y, val.value);
        win.refresh
    })
    .mouseMoveAction_({|view|
        setColor.(view.x, view.y, val.value);
    x.set(\pan, (view.x*(-2)) + 1);
    y.set(\freq, view.y * 400);
        view.x.postln;
        win.refresh
    }).mouseUpAction_({|view|
        setColor.(view.x, view.y, val.value, true);
        win.refresh
    });

win.front;
)

Leave a Reply