Vuo
0.4.6
|
Vuo provides some built-in data types that you can use when writing node classes. For example, the Make RGB Color node class uses the VuoReal type for its input ports and the VuoColor type for its output port. If Vuo's built-in types are not enough, you can define your own custom type.
To write a type in C, you need to:
[your type]_jsonFromValue
and [your type]_valueFromJson
functions to convert a value to and from a JSON-C object.[your type]_summaryFromValue
function to provide a brief textual description of a value.[your type]_interprocessStringFromValue
function to convert a value from a string, if the conversion differs depending on whether the string came from the current process or a separate process.Read on for details.
The easiest way to begin a new type is with the Qt Creator wizard.
One reason you might need to define your own type is to allow a port to have one of a small set of values. For example, the VuoGradientNoise type has two possible values: VuoGradientNoise_Perlin
and VuoGradientNoise_Simplex
. The Make Gradient Noise 1D node class has an input port of type VuoGradientNoise, which allows the user to choose between Perlin noise and simplex noise.
Let's look at the VuoGradientNoise type as an example.
VuoGradientNoise.h declares the type and the required functions:
Notice that each function name is prefixed by the type name, VuoGradientNoise
.
VuoGradientNoise.c defines the functions and provides some additional information. Let's look at some of its code.
Every type needs this line. Among other things, type.h includes the JSON-C library.
This is metadata to help developers know how to use your type. For more information, see type.h.
This function is used when creating a VuoGradientNoise value from its serialized (string) representation. Vuo converts the string to a json_object
, then passes the json_object
to this function. This function is first called when the composition starts running, to initialize the value in each VuoGradientNoise port. While the composition is running, this function is called again each time the composition receives a message from the VuoRunner to change an input port's value (for example, when a Vuo Editor user changes an input port value).
For types with heap-allocated data (such as VuoText, which contains a C string), the return value should be registered by calling vuoRegister
.
This function is used when serializing a VuoGradientNoise value to a string. Vuo calls this function to convert a value to a json_object
, then Vuo converts the returned json_object
to a string. While the composition is running, this function is called each time the composition receives a message from the VuoRunner to retrieve an output port's value.
This function is used when providing a brief description of the value to the VuoRunner. This function is called each time a node with a VuoGradientNoise port executes. Be sure to keep the returned string brief, so that it can be sent efficiently many times per second to the VuoRunner.
The returned string should be heap-allocated (for example, using malloc
or strdup
), since it will be freed by the caller.
Modules | |
Type Metadata | |
Name, version, and other metadata to be defined by types. | |
Type Methods | |
Functions to serialize, unserialize, and summarize values of the type. | |