Vuo  0.4.8
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Modules | Files

Description

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:

Read on for details.

Getting started

The easiest way to begin a new type is with the Qt Creator wizard.

Todo:
: Qt Creator wizard for custom types - https://b33p.net/kosada/node/4015. Describe how to create a type header and implementation file, how to build, how to install.

Example

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:

typedef enum {
VuoGradientNoise_Perlin,
VuoGradientNoise_Simplex
struct json_object * VuoGradientNoise_jsonFromValue(const VuoGradientNoise value);

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.

#include "type.h"

Every type needs this line. Among other things, type.h includes the JSON-C library.

#ifdef VUO_COMPILER
"name" : "Gradient Noise",
"description" : "A method for generating gradient noise.",
"keywords" : [ "perlin", "simplex" ],
"version" : "1.0.0",
"dependencies : [ "c" ],
});
#endif

This is metadata to help developers know how to use your type. For more information, see module.h (which is included by type.h).

{
const char *valueAsString = "";
if (json_object_get_type(js) == json_type_string)
valueAsString = json_object_get_string(js);
VuoGradientNoise gn = VuoGradientNoise_Perlin;
if (strcmp(valueAsString, "perlin") == 0) {
gn = VuoGradientNoise_Perlin;
} else if (strcmp(valueAsString, "simplex") == 0) {
gn = VuoGradientNoise_Simplex;
}
return gn;
}

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.

{
char * valueAsString = "";
switch (value) {
case VuoGradientNoise_Perlin:
valueAsString = "perlin";
break;
case VuoGradientNoise_Simplex:
valueAsString = "simplex";
break;
}
return json_object_new_string(valueAsString);
}

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.

{
switch (value) {
case VuoGradientNoise_Perlin:
default:
return strdup("Perlin");
case VuoGradientNoise_Simplex:
return strdup("Simplex");
}
}

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.

Intraprocess and interprocess serialization

Todo:
https://b33p.net/kosada/node/5611

Modules

 Type Methods
 Functions to serialize, unserialize, and summarize values of the type.
 

Files

file  module.h
 Prototypes for node class, type, and library module implementations.