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

Re: [sc-users] Filling buffers with envelopes



yes, it's not so straightforward.  EnvelopeView want times as absolutes, Env as delta times.  with integrate and differentiate you can go back and forth between these.

(
var arrSize = 10, times, values, updateEnv;
times = Array.fill(arrSize, {|m|0.1}).integrate;
values = Array.fill(arrSize, {1.0.rand});
w = Window("envelope", Rect(150 , Window.screenBounds.height - 250, 250, 100)).front;

b = EnvelopeView(w, Rect(0, 0, 230, 80))
.drawLines_(true)
.selectionColor_(Color.red)
.drawRects_(true)
.resize_(5)
.step_(0.0001)
.action_({arg b; updateEnv.value(b.value[1], b.value[0])})
.thumbSize_(9)
.value_([times, values]);
w.front;

updateEnv= {|values, times|
	var startingValue= values[0];
	[values, times].postln;
	times= times.differentiate*512/s.sampleRate;  //take back times to delta (opposite of integrate)
	~env = Env([startingValue]++values, times, \lin);  //duplicate first level so that one more level
};
updateEnv.value(values, times);  //make sure ~env is updated when code first run
)

k = Buffer.loadCollection(s, ~env.asSignal);
k.plot;


and here's a slightly simpler/better variant using setEnv...

(
var arrSize = 10, times, values, updateEnv;
times= Array.fill(arrSize, {|m|0.1});
values= Array.fill(arrSize, {1.0.rand});
w = Window("envelope2", Rect(150 , Window.screenBounds.height - 250, 250, 100)).front;
~env= Env([values[0]]++values, times);
b = EnvelopeView(w, Rect(0, 0, 230, 80))
.drawLines_(true)
.selectionColor_(Color.red)
.drawRects_(true)
.resize_(5)
.step_(0.0001)
.action_({arg b;
	~env= Env([b.value[1][0]]++b.value[1], b.value[0].differentiate);
})
.thumbSize_(9)
.setEnv(~env);
w.front;
)

k = Buffer.loadCollection(s, ~env.asSignal);
k.plot;

_f

> 9 jan. 2019 kl. 01:38 skrev lance.bantham@xxxxxxxxx:
> 
> Hey Everyone-
> Thanks for the insights - I'm not sure why I'm still having problems, though..
> 
> The full purpose of the project is simply to load a breakpoint editor into a buffer - and it still seems to be very inconsistent. 
> It seems like changes on the first node mess up the overall buffer situation..
> 
> 
> (
> var arrSize = 10, times, values;
> times = Array.fill(arrSize, {|m|0.1}).integrate;
> values = Array.fill(arrSize+1, {1.0.rand});
> w = Window("envelope", Rect(150 , Window.screenBounds.height - 250, 250, 100)).front;
> w.view.decorator = FlowLayout(w.view.bounds);
> 
> b = EnvelopeView(w, Rect(0, 0, 230, 80))
>     .drawLines_(true)
>     .selectionColor_(Color.red)
>     .drawRects_(true)
>     .resize_(5)
>     .step_(0.0001)
> .action_({arg b, env; [b.index, b.value].postln;
> 	~env = Env(b.value[1], b.value[0]*512/s.sampleRate, \lin);
> })
>     .thumbSize_(9)
>     .value_([times, values]);
> w.front;
> )
> 
> k = Buffer.loadCollection(s, ~env.asSignal);
> k.plot;
> 
> 
> On Tue, Jan 8, 2019 at 5:23 PM <josh@xxxxxxxxxxxxxxxxx> wrote:
> Shouldn’t the value of the view be [values,times] ?
> 
> 
> (
> var arrSize = 10, times, values;
> times = Array.fill(arrSize, {|m|0.1});
> values = Array.fill(arrSize+1, {|m| m/(arrSize+1)});
> w = Window("envelope", Rect(150 , Window.screenBounds.height - 250, 250, 100)).front;
> w.view.decorator = FlowLayout(w.view.bounds);
> 
> b = EnvelopeView(w, Rect(0, 0, 230, 80))
>     .drawLines_(true)
>     .selectionColor_(Color.red)
>     .drawRects_(true)
>     .resize_(5)
>     .step_(0.0001)
> .action_({arg b, env; [b.index, b.value].postln;
> 	env = Env(b.value[1], b.value[0], \lin)
> })
>     .thumbSize_(9)
>     .value_([values,times]);
> w.front;
> )
> 
> Josh
> 
>> On Jan 8, 2019, at 2:00 PM, lance.bantham@xxxxxxxxx wrote:
>> 
>> Thank you for the clarification - but is there a way to convert to absolute times? It seems that EnvelopeView doesn't deal in delta..
>> 
>> (
>> var arrSize = 10, times, values;
>> times = Array.fill(arrSize, {|m|0.1});
>> values = Array.fill(arrSize+1, {|m| m/(arrSize+1)});
>> w = Window("envelope", Rect(150 , Window.screenBounds.height - 250, 250, 100)).front;
>> w.view.decorator = FlowLayout(w.view.bounds);
>> 
>> b = EnvelopeView(w, Rect(0, 0, 230, 80))
>>     .drawLines_(true)
>>     .selectionColor_(Color.red)
>>     .drawRects_(true)
>>     .resize_(5)
>>     .step_(0.0001)
>> .action_({arg b, env; [b.index, b.value].postln;
>> 	env = Env(b.value[1], b.value[0], \lin)
>> })
>>     .thumbSize_(9)
>>     .value_([times,values]);
>> w.front;
>> )
>> 
>> On Tue, Jan 8, 2019 at 4:21 AM <f@xxxxxxxxxxxxxxxxxxx> wrote:
>> hi,
>> first, you'll want to have one more level value than time values for your Env.  or, put another way, from Env help: "There should be one fewer duration than there are levels".
>> anyways, your main problem i think is just a matter of specifying delta instead of absolute times.  like this...
>> e= Env([0, 0.1, 0.2, 0.3, 0.4, 0.5], [0.1, 0.1, 0.1, 0.1, 0.1], \lin);
>> a= Buffer.loadCollection(s, e.asSignal);
>> a.plot;
>> 
>> good luck,
>> _f
>> 
>> > 8 jan. 2019 kl. 08:13 skrev lance.bantham@xxxxxxxxx:
>> > 
>> > Hi there-
>> > Came across this post recently and wanted to try it myself.
>> > 
>> > What I noticed was that with different values, the envelope seems to translate in a pretty non-linear way.  I've added a single frame offset, also - since "frame 0" might not exist.
>> > Any idea how to make this behave correctly?
>> > 
>> > e= Env([0, 0.1, 0.2, 0.3, 0.4, 0.5], ([0, 0.1, 0.2, 0.3, 0.4, 1]*512)+1/s.sampleRate, \lin);
>> > a= Buffer.loadCollection(s, e.asSignal);
>> > a.plot;
>> > 
>> > 
>> > 
>> > On Tue, Oct 9, 2018 at 8:59 PM <klipklipklapklap@xxxxxxxxx> wrote:
>> > Fantastic, thank you Fredrik. This is exactly what I was hoping for. There was no specific reason to use BufWr. I am just learning how to work with buffers
>> > 
>> > Am Di., 9. Okt. 2018 um 08:18 Uhr schrieb <f@xxxxxxxxxxxxxxxxxxx>:
>> > do you have a particular reason to record (BufWr) the envelope into the buffer like that, or will this technique work...
>> > 
>> > e= Env([0, 0, 0.5, 1, -1, 0], [0, 50, 200, 100, 100].normalize*512/s.sampleRate, \lin)
>> > a= Buffer.loadCollection(s, e.asSignal)
>> > a.plot
>> > {|buf| SinOsc.ar*PlayBuf.ar(1, buf, doneAction:2)!2}.play(args: [\buf, a])
>> > 
>> > ?
>> > _f
>> > 
>> > > 9 okt. 2018 kl. 05:45 skrev klipklipklapklap@xxxxxxxxx:
>> > > 
>> > > Dear list,
>> > > 
>> > > This is a beginner question about buffers. I am trying to fill a buffer with an envelope.
>> > > 
>> > > This comes close to the result I am looking for:
>> > > (
>> > > a = Buffer.alloc(s, 512, 1);
>> > > 
>> > > (
>> > > y={arg rate=1;
>> > >     var in;
>> > >     in=EnvGen.ar(
>> > >         Env(
>> > >         [0, 0, 0.5, 1, -1, 0],
>> > >         [0, 50, 200, 100, 100].normalize*512/SampleRate.ir,
>> > >         \lin
>> > >     ), Impulse.ar(100));
>> > >         BufWr.ar(in, a, Phasor.ar(0, BufRateScale.kr(a) * rate, 0, BufFrames.kr(a)));
>> > >     0.0 //quiet
>> > > }.play;
>> > > )
>> > > 
>> > > But would it be possible to write just one cycle of the envelope into the buffer?
>> > > 
>> > > Thank you!
>> > > Max
>> > 
>> > 
>> >   #|
>> >      fredrikolofsson.com     musicalfieldsforever.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/
>> 
>> 
>>   #|
>>      fredrikolofsson.com     musicalfieldsforever.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/
> 


  #|
     fredrikolofsson.com     musicalfieldsforever.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/