[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[sc-users] timing problems when a Task plays and plots
SC folks --
I'm attempting to sonify a data set while plotting it in a GUI window.
The methodology is:
o Use a Task to iterate through the set, mapping its values appropriately.
o Create an empty List; with each iteration, add the current data
value to the List, then plot the List as an Array into a
compositeView.
(I couldn't find a way to add a point to a pre-existing view, thus I
take the inelegant step of re-plotting the ever-growing List as an
Array with each iteration.)
I find that after about 90 iterations, the timing slows down
considerably, despite the wait time in the Task.
Is there a better way to do this that anyone knows of?
Here's a code example:
s=Server.local;
s.boot
(
//dummy data set
a=Array.fill(500, {rrand(350, 500)});
~thusFar=List.new;
~timeIncrement=0.05;
SynthDef("sinetest", {arg freq=440, dur=0.3;
o=PanAz.ar(2, SinOsc.ar(freq, 0, 0.2));
e=Env.sine(dur);
Out.ar(0, o*(EnvGen.kr(e, doneAction:2)));
}).send(s);
w = GUI.window.new( "plot the dummy", Rect( 128, 64, 340, 400 ));
~playbutton=GUI.button.new(w, Rect(10, 23, 100, 50));
~playbutton.states=[ ["play", Color.blue, Color.new255(204,206,226) ] ];
~playbutton.action = { ~testTask.start(AppClock); };
~stopbutton=GUI.button.new(w, Rect(150, 24, 100, 50));
~stopbutton.states=[ ["stop/reset", Color.blue, Color.new255(204,206,226) ] ];
~stopbutton.action = { ~testTask.stop; };
~plotWindow=GUI.compositeView.new(w,Rect(10,75,300,300));
w.front;
~testTask = Task({
a.size.do({ arg i;
i.postln;
f=a.at(i);
s.sendMsg("/s_new", "sinetest",
s.nextNodeID, 0, 0,
"freq", f,
"dur", ~timeIncrement);
~thusFar.add(f);
~thusFar.asArray.plot(parent:~plotWindow);
~timeIncrement.wait;
})
});
)
TIA --
Mark
_______________________________________________
sc-users mailing list
info (subscription, etc.): http://www.beast.bham.ac.uk/research/sc_mailing_lists.shtml
archive: https://listarc.bham.ac.uk/marchives/sc-users/
search: https://listarc.bham.ac.uk/lists/sc-users/search/