Package or Item Type (metaclass)

Packages and item types (which are Package servers with a special tag) can be implemented as metaclasses.

Basics

The very most basic way to do this is just to declare the metaclass using the base class itself. This is useful if you don’t need to override any of the basic item behaviors, which is fairly common.

1
static CLxMeta_Package<CLxPackage>  pkg_meta ("myPackageServerName");

This package will have no channels and no special behaviors, but it will exist as a server. To make it an item type it just needs to have the supertype set on the metaclass:

1
        pkg_meta.set_supertype (LXsITYPE_LOCATOR);

Channels

Channels for a package are found by looking for a Channels metaclass. The channels defined by the metaclass will be added to the package. It can be under the package, but more commonly it’s added into the tree as a sibling:

1
2
3
4
5
 root
  |
  +--- channels
  |
  +--- package

If the channels have UI settings then a ChannelUI metaclass will need to be added. This can be done using a template method on the package metaclass.

1
        pkg_meta.add_channel_ui<CLxChannelUI> ();

Basic Behaviors

Basic item behaviors (those defined by the PackageInstance interface) can be implemented using a CLxPackage subclass. For example if your item wants to have a custom default name, you would override the synth_name() method:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
class MyPackage : public CLxPackage
{
    public:
        void    synth_name (std::string &name)           LXx_OVERRIDE
        {
                ...
        }
};

static CLxMeta_Package<MyPackage>  pkg_meta ("myPackageServerName");

3D Drawing

To display your item in the 3D viewport, or to do other things related to the ViewItem3D interface, you can create a metaclass for this behavior. Note that I’m using my Channels metaclass to read the channels for the item.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
class MyViewItem3D : public CLxViewItem3D
{
    public:
                void
        draw (
                CLxUser_Item            &item,
                CLxUser_ChannelRead     &chan,
                CLxUser_StrokeDraw      &stroke,
                int                      selFlags,
                LXtVector                color)       LXx_OVERRIDE
        {
                MyChannels               my;

                chan_meta->chan_read (chan, item, &my);
                ...
        }
};

static CLxMeta_ViewItem3D<MyViewItem3D> v3d_meta;

Metaclasses that add new interfaces to the Package – like this one – are placed under the package metaclass in the tree.

1
2
3
4
5
6
7
 root
  |
  +--- channels
  |
  +--- package
         |
         +--- view3D
1
        pkg_meta.add (&v3d_meta);