Hello list,
Back in March we had a discussion about getting signal inlets other than
the main one to use floats as messages rather than signals.
I found a way to simulate this behavior (only for floats, not for
anythings). A little background:
If you have a signal inlet, when you send a float to it, it stores that
float in a field that the ugen graph function retrieves if it notices that
inlet has no signal connection: if there's at least one signal connected,
those are used, but if not, the float scalar is promoted to a signal. You
can update that scalar even while a signal is connected.
You need to #include "g_canvas.h" to get started.
So the idea here is:
1) in the new() routine, get access to the float scalar for your inlet from
within your object class.
2) in the new() routine, optionally set the scalar field with a default or
a creation arg.
3) check manually in your dsp() routine to see if that inlet has a signal
connection feeding it. If so, then the scalar is ignored and you can use
the signal as is. However, if you want the inlet to have zeroes when
there's no signal inlet, rather than the scalar, you have to let your
perform() routine know.
4) in the perform() routine, poll the scalar field for changes.
-------------------------------------------
Before you can do 1) and 2), you need to keep the t_inlet pointer returned
from inlet_new, something like:
x->x_rightinlet = inlet_new((t_object *)x, (t_pd *)x, &s_signal, &s_signal);
For 1), get a pointer to the float field and save it:
x->x_signalscalar = obj_findsignalscalar(x, 1); // second arg is the inlet
index
Then to use it simply dereference it:
float scalar = *x->x_signalscalar; // this probably goes in your perform()
routine
---------------------------------------------
For 2), you want to set the float in the field, so you can just call the
default float routine for inlets:
pd_float((t_pd *)x->x_rightinlet, f); // first arg is your inlet, cast as a
(t_pd *), and the second is the input float
---------------------------------------------
3) is the trickiest part. The cyclone code does it this way:
int forky_hasfeeders(t_object *x, t_glist *glist, int inno, t_symbol
*outsym)
{
t_linetraverser t;
linetraverser_start(&t, glist);
while (linetraverser_next(&t))
if (t.tr_ob2 == x && t.tr_inno == inno
&& (!outsym || outsym == outlet_getsymbol(t.tr_outlet))
)
return (1);
return (0);
}
Which is called like so:
forky_hasfeeders((t_object *)x, x->x_glist, 1, &s_signal);
This basically says "if there's a connection to the inlet in the 3rd arg,
and it's from a signal outlet, return true." x->x_glist is set this way in
the new() routine:
x->x_glist = canvas_getcurrent();
--------------------------------------------
4) now in your perform() routine you can poll for changes:
t_float scalar = *x->x_signalscalar;
if (scalar != x->x_scalar)
{
x->x_scalar = scalar;
// do other stuff, call functions, etc.
}
I don't have time right now, but I'll make a minimal object later to
illustrate.