gen~ "parameter is not defined"


    Apr 21 2016 | 7:36 pm
    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?

    • Apr 21 2016 | 7:51 pm
      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.
    • Apr 21 2016 | 8:05 pm
      (can you try initializing 'srate' with '44100' like you did in your object version on the right side of the pic? 'param srate 44100'? maybe the variable needs to be initialized to something?)
    • Apr 21 2016 | 8:10 pm
      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)
    • Apr 25 2016 | 12:45 pm
      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.
    • Apr 25 2016 | 2:42 pm
      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.
    • Apr 25 2016 | 2:48 pm
      I read in the gen documentation that delay is not yet supported in the codebox realm. Maybe that's causing some problems?
    • Apr 25 2016 | 3:17 pm
      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);
    • Apr 27 2016 | 12:37 pm
      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?
    • Apr 27 2016 | 12:44 pm
      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 ;-)
    • May 11 2016 | 10:27 am
      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.
    • May 12 2016 | 6:34 pm
      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.
    • Aug 16 2017 | 7:12 pm
      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
    • Aug 16 2017 | 7:31 pm
      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.
    • Aug 16 2017 | 7:38 pm
      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);
    • Aug 16 2017 | 7:48 pm
      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.
    • Aug 16 2017 | 8:17 pm
      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:
    • Aug 16 2017 | 8:17 pm
      Here's your patcher from above, with just a [peek] object in gen~.
    • Aug 16 2017 | 8:20 pm
      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.
    • Aug 16 2017 | 8:24 pm
      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!
    • Aug 16 2017 | 8:26 pm
      Oh keep in mind you need to offset the channel argument. and the syntax I gave earlier does indeed work.
    • Aug 16 2017 | 8:28 pm
      hey evan, yeah I guess I was confused with the zero based channel index. best c.
    • Aug 16 2017 | 8:33 pm
      Looks like Graham beat me to it - sorry for posting likely the same thing Graham did. Good luck!
    • Aug 16 2017 | 8:34 pm
      thanks, so much, both of you guys. Let's enter the gen world ...