gen~ "parameter is not defined"

Ernest's icon

I had this gen~ patch working fine, so I started transferring it into codeboxes. Each gen~ subpatch uses a srate parameter (instead of samplerate in fact, because when you change the sample rate, gen's 'samplerate' constant does not update until your reset or restart the patch. So I set it as a parameter externally).

But when I added a second codebox in a second subpatch with the same param, I get this message "variable ... is not defined.") I passed exactly the same param into to the first patch and it has no problem. What do I do?

bug.jpg
jpg
Ernest's icon

Cancel that. it appears one cannot set the maximum delay time with a variable. I don't know why it didn't complain the first time I inserted it, but at least the compiler caught it the second time.

Arabrab's icon

A while ago, I was trying to deal with a similar error mesaje .
A " esoteric " message with an internal variable number ..
It turns out there was a problem of feedback loop ( codeboox allows you to write dsp... "connections" where there should be a history )
I'm not saying that is the case , but in the case of a delay ( with activated feedback)

Ernest's icon

Thanks for the comments. I am frequently getting this message for values even if they are previously explictly set in the codebox itself, if they are in conditions or loops. Still figuring it out.

Regarding the srate idea, it seems better to use the built-in samplerate constant and send a reset to gen when sample rate changes, rather than setting it as a param. It is slightly less run-time CPU and using a param for sample rate frequently causes gen to crash, sometimes unrecoverably, due to divide by zeros from 1/samplerate, triggered when there are other compile errors.

Graham Wakefield's icon

The error message in the img is confusing, I know, but it is because you can't use a param (nor an in8) to set the delay size -- this argument must be a constant expression (and for gen~, "samplerate" functions pretty much like a constant). It really shouldn't be necessary to use a param for the samplerate -- this value should be changing whenever you change the DSP settings in Max. If that isn't happening then there's a bug here that needs reporting.

Is your patcher embedded in a poly~ by any chance?

BTW One other thing is that Param declarations are global to a patcher. If you have [param rate] in your patcher, you can just use the variable name "rate" in codebox, without having to pass it in via an inlet.

dsmd's icon

I read in the gen documentation that delay is not yet supported in the codebox realm.
Maybe that's causing some problems?

Screen-Shot-2016-04-25-at-16.47.52.png
png
Graham Wakefield's icon

The singular "delay()" operator is not supported, but the more elaborated "Delay" declaration is, using "read()" and "write()" methods.

A simple example:

Delay d(10000);

out1 = d.read(10000);
d.write(in1);

Ernest's icon

Thanks. I did get that to work, but I can't figure out if there's a way to access delay or data objects in a codebox with a variable to select the channel?

Graham Wakefield's icon

Yes there is, the sample/peek/etc. and poke etc. operators have a channel input. As does the delay read/write. Honestly I can never remember the syntax for delay and buffer/data reading code in codebox either -- there are too many possible variations. Usually what I do is make a patcher version and then pop open the codeview to remind me. That should be on a gen patching tip sheet I guess ;-)

Ernest's icon

That's funny, I have the same problem with remembering the syntax. I still get alot of crashes even when I do get the syntax right., haven't figured out exactly why, but it appears it is probably some combination of factors in in gen~ subpatches. I'll try to figure out exactly the combination. This peek works ok:

Buffer buf("buf");
var= 256;
chan = 0;
out1 = peek(buf, var, chan, boundmode="clip");
//Not sure about pokes....
offset =256;
buf.poke(in1, offset); // don't know how to choose a channel...

And this delay works ok:

Delay ydelay(44100, 1, feedback=1);
idx = 44100;
out1 = ydelay.read(in1, 0, interp="spline");
ydelay.write(in1);

I think the declaration includes channels as 1-based, and the method includes channels as zero-based, but I'm not sure.

dsmd's icon

For poke you could do the same as you did with peek.
poke(buffer, valueToWrite, index, channel);

Not sure how to do it with the buf.poke syntax.

chrislos's icon

Hey guys. I'm totally stuck with a quite simple task. I'd like to step through a multichannel buffer via gen. But I just can't figure out how to access it.

Would be so happy to get a hint from you. I'm really stuck here...

thanks in advance
Christian

Max Patch
Copy patch and select New From Clipboard in Max.

Evan's icon

Your peek function should look like this:

peek(objects,index,channel);

Buffers don't have a peek function, buffers are an argument to the peek function.

chrislos's icon

Hey Evan,
thanx so much for your reply.
If I change the codebox snippet like this unfortunately it still doesn't do the job. :(

index= in1;
channel = in2;
out1 = peek(objects,index,channel);
chrislos's icon

It's too bad that I haven't found any examples for a multichannel peek situation. It's also a bit weired. It's super easy with the regular object peek~ in max (as you can see in my compressed file). But codebox sometimes makes me nuts.

Graham Wakefield's icon

Best way to figure out the syntax for code box code ("genexpr") is to do it in patching objects, pop open the codeview side bar (the big C), select the objects and see the genexpr code highlighted.

Example below:

Max Patch
Copy patch and select New From Clipboard in Max.

Graham Wakefield's icon

Here's your patcher from above, with just a [peek] object in gen~.

Max Patch
Copy patch and select New From Clipboard in Max.

Graham Wakefield's icon

If you really want to do it with codebox, here's the equivalent (as Evan described). Works fine.

BTW note that the channel index for gen~ buffer readers is always zero-based. So for channel 5 you want to send the value 4.

Max Patch
Copy patch and select New From Clipboard in Max.

chrislos's icon

Graham,
thanx 10000 times!!! Everything works perfect.
Yeah this peek thingy was just a tiny part of a more complex project I already built without gen.
I thought I could give it a try to build a clean codebox app. (Having the comfort of for loops etc. ).

Anyway. Thanks so much!

Evan's icon

Oh keep in mind you need to offset the channel argument. and the syntax I gave earlier does indeed work.

Max Patch
Copy patch and select New From Clipboard in Max.

chrislos's icon

hey evan, yeah I guess I was confused with the zero based channel index.
best
c.

Evan's icon

Looks like Graham beat me to it - sorry for posting likely the same thing Graham did. Good luck!

chrislos's icon

thanks, so much, both of you guys.
Let's enter the gen world ...