Channels (metaclass)

The Channels metaclass is shared between multiple metaclasses that define or work over channels. Most of the work is done by the CLxAttributeDesc class, which can also be used for command arguments and other attribute lists. The most basic usage looks something like this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
class MyChannels : public CLxChannels
{
    public:
        double     cv_float;
        int        cv_int;

        void       init_chan (CLxAttributeDesc &desc)         LXx_OVERRIDE
        {
                MyChannels *my = 0;

                desc.add ("fChan", LXsTYPE_FLOAT);
                desc.struct_offset (&my->cv_float);

                desc.add ("iChan", LXsTYPE_INTEGER);
                desc.struct_offset (&my->cv_int);
        }
};

static CLxMeta_Channels<MyChannels>  chan_meta;

The client’s CLxChannels subclass is both a container for channel values, and a description of the channels and their properties. It’s a description by implementing the init_chan() method and listing the channels to be included for this item. It’s a container because it has member variables that correspond to channels and are configured (using ‘’struct_offset()’’) so that values can be read directly into them. The metaclass for channels can then be added to the meta tree so it can be found by the other metaclasses that use it.

To set all the common settings for channels at once the add_channel() method can be used.

Values

There are settings for default value and ranges for float and int channels. If the optional ‘clamp’ argument on the min & max values is true then the values will be clamped when read into the structure. In this example the channel value will be clamped to zero if the value is negative, but the max will be allowed to go higher than 24 even if the UI doesn’t allow it.

1
2
3
        desc.default_val (12.0);
        desc.set_min (0.0, true);
        desc.set_max (24.0);

UI State

The UI state of channels can be controlled fairly precisely, but it requires that a ChannelUI metaclass be added to an appropriate server, like a Package or ValueTexture. Min and max ranges on values requires a ChannelUI. This is normally done using a template method on the metaclass.

1
        server_meta.add_channel_ui<CLxChannelUI> ();

The plug-in can also override the CLxChannelUI class to get per-item enable and dynamic icon.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
class MyChannelUI : public CLxChannelUI
{
    public:
        bool    item_enabled (CLxUser_Item &item, CLxUser_Message &msg)      LXx_OVERRIDE
        {
                ...
        }
};
...
        server_meta.add_channel_ui<MyChannelUI> ();

Individual channels can also be enabled and disabled using CLxCustomChannelUI subclasses. Suppose we have a channel that depends on two other channels on the same item: “enable” and “strength”. If enable is false or strength is zero then this channel is disabled. That would be done by creating a custom channel class to test the enable state, and dependencies on the other two channels.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
class cCustomEnable : public CLxCustomChannelUI
{
    public:
        bool    enabled (CLxUser_Item &item, CLxUser_ChannelRead &read, CLxUser_Message &msg)      LXx_OVERRIDE
        {
                if (read.IValue (item, "enable") && read.FValue (item, "strength") > 0.0)
                        return true;
                ...
                return false;
        }
};
...
        desc.chan_set_custom (new cCustomEnable);
        desc.chan_add_dependency ("enable");
        desc.chan_add_dependency ("strength");