ITM and time objects

Feb 12, 2011 at 1:05pm

ITM and time objects

Hi there,

I would like to implement some ITM functionality in one of my objects.
To start off, I’d like to implement some basic features similar to what speedlim does.

So, I would like to have 3 attributes:
1 – ‘threshold’: to set a time threshold between which messages can be passed.
2 – ‘quantize’: to be able to quantize incoming messages to a transport
3 – ‘defer’: to put messages in the low-priority queue.

So far I have something like:

In main:

//...
class_time_addattr(c,      "threshold",   "Time Threshold", TIME_FLAGS_USECLOCK | TIME_FLAGS_POSITIVE);
CLASS_ATTR_DEFAULT_SAVE(c, "threshold",   ATTR_FLAGS_NONE, "0.0");

class_time_addattr(c,      "quantize",     "Time Quantization", TIME_FLAGS_TICKSONLY | TIME_FLAGS_POSITIVE);
CLASS_ATTR_DEFAULT_SAVE(c, "quantize",    ATTR_FLAGS_NONE, "0.0");

CLASS_ATTR_CHAR(c,         "defer",       ATTR_FLAGS_NONE, t_myobj, defer);
CLASS_ATTR_STYLE_LABEL(c,  "defer",       ATTR_FLAGS_NONE, "onoff", "Defer Output To Low-Priority Queue");
CLASS_ATTR_DEFAULT_SAVE(c, "defer",       ATTR_FLAGS_NONE, "0");
//...

In myobject_new():

// ...
x->threshold = (t_timeobject *)time_new((t_object *)x, gensym("threshold"), (method)myobj_timefn, TIME_FLAGS_USECLOCK | TIME_FLAGS_POSITIVE);
x->quantize = (t_timeobject *)time_new((t_object *)x, gensym("quantize"), NULL, TIME_FLAGS_TICKSONLY | TIME_FLAGS_POSITIVE);
// ...

then:

void myobj_timefn(t_myobj *x)
{
    // ...
    if (x->something) {
        myobj_output(x);
    }
}

and finally:

void myobj_free(t_myobj *x)
{
    object_free(x->threshold);
    object_free(x->quantize);
}

The above code works well.

My doubts come when implementing the option to defer messages to low-priority.
I see that the ITM API does have a TIME_FLAGS_USEQELEM flag to do just that.

What’s the right strategy to go about it?
1 – Should I create two different timeobject, one with the TIME_FLAGS_USEQELEM flag already set and the other without it, then switch between the two?
2 – If there is a way to toggle the flag after the timeobject has been created, could I just do that? (it seems that would be the best option)
3 – Or should I just call defer_low() in my time function in the usual way ?

For example:

void myobj_timefn(t_myobj *x)
{
// ...
    if (x->something) {
        if (x->defer) {
            defer_low(x, (method)myobj_output, NULL, 0, NULL);
        } else {
            myobj_output(x);
        }
    }
}

How is it done in speelim ?

Waiting for enlightment…

Thank you.

- Luigi

#54917

You must be logged in to reply to this topic.