Please use triple backticks (```) for a block of code or single backticks (`) for inline code. Otherwise void getparameter(CommonState *cself, long index, t_param *value) , the t_param *value "input"
shows up as void getparameter(CommonState cself, long index, t_param value) , the t_param *value "input"
(that is: the *
is interpreted as a markdown formatting symbol which triggers the italic font.
tsambou er. Do I always need to set "NULL" in the "void* ref"
You do need it, but I have no idea what it means. It is not used in the function.
tsambou void getparameter(CommonState *cself, long index, t_param *value)
, the t_param *value
"input" of the function, what does it have to be?
It is where the current value of the parameter will be stored. You see that the function is returning a void
, which means it does not return a value. Instead, you pass it a pointer to a location in memory (t_param* value
) and the function writes the value of parameter index
into the memory location value
, as you can see from the function implementation:
/// Get the value of a parameter of a State object
void getparameter(CommonState *cself, long index, t_param *value) {
State *self = (State *)cself;
switch (index) {
case 0: *value = self->m_damp_1; break;
case 1: *value = self->m_fb_2; break;
case 2: *value = self->m_fb_4; break;
case 3: *value = self->m_spread_3; break;
default: break;
}
}
tsambou Also I would really need to be able to get more outputs from the gen_exported into the render to control LEDs and other things. How could I receive the value of an output of the gen into the render except from the two first (which go to the audio output)?
The analog inputs of Bela can be "easily" connected as parameters, e.g.:
for(int index = 0; index < context->analogInChannels; ++index)
gen_exported::setparameter(gState, index, analogRead(context, 0, index), NULL); // sets parameter `index` with the corresponding analog input
a similar approach can be used for digital inputs, using digitalRead
instead, (and of course changing the for
statement).
Similarly, you could get the value of a parameter and send it to the analog outputs:
for(int index = 0; index < context->analogOutChannels; ++index)
{
t_param value;
gen_exported::getparameter(gState, index, &value); // get parameter for `index` and store it in `value`
analogWrite(context, 0, index, value);
}
Again, this can be changed to use digitalWrite
instead.
A different approach is needed if you want the analog/digital inputs/outputs to be handled as signals instead of parameters (similarly to what we do for Pd). In this amended render.cpp
, you have 10 "signal" inputs into gen~ (2 audio + 8 analog), and 10 (or 2 on BelaMini) "signal" outputs from gen~ (2 audio + 8 (on Bela only) analog). Digitals are a bit more complicated to be handled as signals, though it's certainly doable.
Giulio