Passing Gen data to UI

Stone's icon

Hello,

I am experimenting with exporting c++ from gen into JUCE to create plugins using the gen-plugin-export templates here; https://github.com/cycling74/gen-plugin-export.

I have created a UI in JUCE to control parameters in the dsp but I would like to pass a calculated value from the dsp to the UI. It seems logical to use [setparam "paramname"], but that doesn't show up in the exported code.

It seems the only way to get out of gen is via an outlet but that equals "gen_xxxx" in the exported code.

I know very little about c++ syntax so I'm wondering if there is any object to do this in gen~ instead of messing with the exported c++.

Thanks in advance.

chris stratos's icon

Hello,
trying to do exactly the same....
i am a few steps back though...
how do you import a patch into gen in order to get the code?
i keep getting error : not found in gen doamin dsp.gen

vichug's icon

"how do you import a patch into gen in order to get the code?"

you just can't do that
other than that, i don't know.

Graham Wakefield's icon

@Stone,

If you're trying to create some UI that reflects some internal state of the audio algorithm, I recommend using named History objects. Set the value of a named history for anything you want to display in the UI. All named history objects exist as numbers (doubles) in the C++ state struct, which you can safely read from any thread. So your UI draw routine can just use these values directly. E.g. if the history is called "freq_value" then you can just grab it in C++ from the state pointer with state->freq_value.

(The [setparam] message is only for within gen patching, it's just a way to set the values of [param] objects embedded within subpatchers; since patchers are only an editing structure, they're optimized away in the generated code.)

@Chris,

I couldn't quite understand your question; you can create and edit gen patchers in Max by double-clicking on the [gen~] object -- and you can do that on any gen~ examples in Max or that you find shared here. Any gen~ object's code can be exported using the "exportcode" message.

Graham

alexmstahl's icon

Thanks for the named history tip, Graham! When I try it, the names are changed: e.g. history t2Dist in a gen patch, shows up as t_sample m_t2Dist_22 in the exported code. Param names are similarly altered, but they have helper functions to get and set them using the unaltered gen names. Curious what's up, thanks.

-alex

Graham Wakefield's icon

The main reason for renaming is to defend against clashing with some other c++ symbol, e.g. a gen param called "new"... and with exported code being used in other contexts, it's not possible to predict what names might clash, so we just rename them all to greatly reduce the chance of this happening.