[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[sc-users] Re: Changing GUI inside OSCFunc



Hey Omer,

Well, there's a couple of things to see.

The first is that for any GUI updating process you need to use a deferred
clock so the more important processes (audio related things) run smoothly.
In some GUI objects you can use the .defer method for that, while in this
case I think the easiest is to use the AppClock and schedule your window
updating.

The other thing is that when you do something like:

(
var x =200, y = 300;
...
)

is not the same as saying:
x = 200; y = 300;

One is a local variable (var x = something) the other is an environment
variable (x = something)
so in order to update x outside the scope of the GUI code as you are trying
to do, you have to take this into consideration because as you wrote it the
OSCFunc will not update the x you intend. 

The last thing is that you need to scale the range of your Sines to 0,360
degrees, as that would be a full rotation.

Try this:

(
SynthDef.new(\QuadSine, { |out = 0, freq = 0.25|
	var cosx, sinx;
	cosx = SinOsc.kr(freq, pi/2).range(0,360);
	sinx = SinOsc.kr(freq).range(0,360);
	SendReply.kr(Impulse.kr(2), '/reply', [cosx, sinx]);
	Out.kr(out, [cosx, sinx]);
}).add;
)

(
var speakerList, targx=200, targy=150;
var atorad = (2pi) / 360, rtoang = 360.0 / (2pi);
var targRotate, actRotate, targPoint, actPoint;
var maxShiftPerFrame = 20, frameInterval = 0.01;
var resched = false, count = 0;
var panBus, widthBus, recButton;
var a, b, c, e;

maxShiftPerFrame = maxShiftPerFrame * atorad;
actPoint = Point(x, y) - Point(200, 200);
panBus = Bus.control;
widthBus = Bus.control.set(60);

w = Window.new("Quad Spatializer", Rect(128, 64, 400, 450)).front;
w.view.background_(Color.grey(0.3));
w.view.decorator = FlowLayout(w.view.bounds);
speakerList = [[-50, "L"], [50, "R"], [-130, "Ls"], [130, "Rs"]];
c = UserView.new(w,Rect(0, 0, 400, 380));
c.canFocus = false;

c.drawFunc = {
   Color.grey(0.8).set;
   // draw the speaker layout
   Pen.translate(200,200);
   ((actPoint.theta + (0.5pi)).wrap2(pi) *
rtoang).round(0.01).asString.drawCenteredIn(Rect.aboutPoint(0@170, 30, 10),
Font.new("Arial", 10), Color.grey(0.8));
   Pen.strokeOval(Rect.aboutPoint(0@0, 150, 150));
   Pen.rotate(pi);
   speakerList.do({|spkr|
       Pen.use({
           Pen.rotate(spkr[0] * atorad);
           Pen.moveTo(0@170);
           Pen.strokeRect(r = Rect.aboutPoint(0@170, 30, 10));
           if(spkr[0].abs < 90, {
               Pen.use({
                   Pen.translate(0, 170);
                   Pen.rotate(pi);
                   spkr[1].drawCenteredIn(Rect.aboutPoint(0@0, 30, 10),
                       GUI.font.new("Arial", 10), Color.grey(0.8));
               });
           },{
               spkr[1].drawCenteredIn(r, GUI.font.new("Arial", 10),
Color.grey(0.8));
           });
       });
   });

   Pen.moveTo(0@0);

   // draw the pan point
   Pen.rotate(actPoint.theta + 0.5pi);
   targPoint = Point(x, y) - Point(200, 200);
   // trunc to avoid loops due to fp math
   targRotate = (targPoint.theta - actPoint.theta).trunc(1e-15);
   // wrap around
   if(targRotate.abs > pi, {targRotate = (2pi - targRotate.abs) *
targRotate.sign.neg});
   actRotate = targRotate.clip2(maxShiftPerFrame).trunc(1e-15);
   actPoint = actPoint.rotate(actRotate);
   Pen.rotate(actRotate);
   Pen.lineTo(0@150);
   Pen.stroke;
   Pen.fillOval(Rect.aboutPoint(0@150, 7, 7));
   Pen.addWedge(0@0, 140, neg(e.value * 0.5) * atorad + 0.5pi, e.value *
atorad);
   Pen.stroke;
   Color.grey(0.8).alpha_(0.1).set;
   Pen.addWedge(0@0, 140, neg(e.value * 0.5) * atorad + 0.5pi, e.value *
atorad);
   Pen.fill;

   if((actRotate.abs > 0), {AppClock.sched(frameInterval, {w.refresh})},
{count = 0;});
   if(count%4 == 0, {panBus.set((actPoint.theta + (0.5pi)).wrap2(pi) *
rtoang)});
};

e = EZSlider.new(w, 380@20, "Stereo Width", [0, 180].asSpec, {arg ez;
widthBus.set(ez.value); w.refresh}, labelWidth: 80);
e.labelView.setProperty(\stringColor,Color.grey(0.8));

w.refresh;
)


(
OSCFunc.new({ |internalMsg|
	x = internalMsg[3]; y = internalMsg[4]; AppClock.sched(0.0, {w.refresh});
	},
	'/reply'
);
)

t = Synth.new(\QuadSine, [\freq, 0.2])

Best,
Darien




--
View this message in context: http://new-supercollider-mailing-lists-forums-use-these.2681727.n2.nabble.com/Changing-GUI-inside-OSCFunc-tp7621864p7621867.html
Sent from the SuperCollider Users New (Use this!!!!) mailing list archive at Nabble.com.

_______________________________________________
sc-users mailing list

info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/