Forums > Gen

Peek/poke inside loop structures


Nov 16 2012 | 1:25 pm

Hey,

I’ve been playing with the new control structures in GenExpr, trying to push their limits a bit. For some reason, I can’t read/write to a data or buffer object from within the loop. Is this a bug or a known limitation? I’m hoping that future versions support this, as it’d enable some really useful additions to Gen’s current functionality (oversampling, for example). Any insight anyone?

-J

Nov 16 2012 | 8:21 pm

this is a current limitation. a shame as i agree could be very powerful. i asked the devs about it and it is on the general feature request radar as far as i know.

best.

Nov 18 2012 | 3:04 am

Yes, unfortunately this is a known issue at the moment, but it will be resolved in the next update. This issue also affects the use of Data etc. within functions currently.

Apr 27 2016 | 5:50 am

HI Graham, I see you answered this post before, I am trying this:

Data somedata(32);
Data moredata(32,32);
y =0;
for (x =0;x<32; x+=1) {
somedata.poke(1);
y += somedata.peek(1);//works…
somedata.poke(1,x);
y += somedata.peek(1,x);//doesn’t work.
}
out1 = y;

Now gen supports any number of channels, the latter would be extremely useful for array operations :)

Apr 27 2016 | 10:40 pm

^i don’t think you wrote that quite right(in your code there, you’ve only used ‘somedata’ and never use the ‘moredata’ multichannel array). but even if you did write ‘moredata’ into the last 2 lines which don’t work for you, it doesn’t seem like it would be using a proper set of arguments.

here’s a simple example that shows how the multi-channel ‘data’-array would work, though it probably isn’t very useful by itself, it performs a simple way of recording powers-of-2 with additions into the multichannel data, and then providing inputs to read/index everything, just to show every single sample within the 32 channels of a 32-index ‘data’ does work properly:


Data somedata(32);
Data moredata(32,32);
x = 0; y = 0;
for (i = 0; i < 32; i+=1)
{
somedata.poke(noise(),i);
x = somedata.peek(i);
}
out1 = x;
for (j = 0; j < 32; j+=1) 
{
	for (k = 0; k < 32; k+=1) 
	{
		moredata.poke(pow(k,2)+j,j,k);
	}
}
out2 = moredata.peek(in1,in2);

And here’s a patch to demo based on the above:

— Pasted Max Patch, click to expand. —

Hope it helps.

Apr 27 2016 | 10:50 pm

(^and halfway through writing it, i decided not to even bother using the variable ‘y’, so you could also take out the ‘x’ there and assign ‘somedata.peek(i);’ directly to out1… but whatevs, you get the idea :)
also, see here where Graham at the end states to use ‘codeview’, whenever i’m confused, that’s what i do too, for example, create a ‘poke bs’ object, and the inlets in order from left-to-right form the arguments for the codebox version, example: ‘bs.poke(arg1,arg2,arg3,arg4) )

Apr 27 2016 | 11:01 pm

whoops forgot to include the link to Graham’s words of wisdom:
https://cycling74.com/forums/topic/gen-parameter-is-not-defined/

Viewing 7 posts - 1 through 7 (of 7 total)

Forums > Gen