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.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 =, 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.