Nodes are sensitive to data type. Vuo works with various types of data, such as integer (whole) numbers, real (decimal) numbers, Boolean (logical) values, text, 3D points, images, and more.
For example, the Count Characters node’s Text input port has data type text, and its Character Count output port has data type integer. If you see a Count Characters node that has a cable connected to its Character Count port, then you can know that the port at the other end of the cable must also have type integer.
What if you want to connect the Count Character node’s integer output port to a text input port? If you start to drag a cable from the Character Count port, any ports in the composition that the cable can connect to are highlighted. This includes not just ports of type integer, but also ports of type text. If you drag the cable to a text input port and release the mouse, then a type converter node will be automatically added to convert the integer data to text data.
The Quartz Composer equivalent to a type-converter is represented as a darker red line in QC. The benefit of exposing these conversions is greater control over how your data is interpreted.
A type converter node is just a node that happens to have a single input port of one data type and a single output port of another data type. Whenever you want to connect a port of one data type to a port of another data type, you can try drawing the cable to find out if any type converters can be inserted automatically. Or you can search the Node Library using the term “convert” for a node that has an input port of the type that you want to convert from to an output port of the type that you want to convert to. When you drag a convert node onto the canvas and connect it up, it will collapse to only show the original data type name and the data type the data is converted to.
For some types, there’s more than one way to do the conversion. For example, if you want to convert from a real number to an integer, you can round the real number to the nearest integer, round it down to the integer below, or round it up to the integer above. If you try to connect a cable from a real-number output port to an integer input port, a menu will pop up allowing you to pick the conversion you want to use.
The composition below, Play Movie (
), shows a type converter from a movie frame to an image.
Some nodes can work with many different types of data. For example, a Hold Value node could hold an integer, an image, a 3D point… or really, any type of data. Rather than cluttering up the Node Library with a separate Hold Value node for each data type, Vuo lists a single Hold Value node that can be made to work with any type.
When you drag a Hold Value node from the Node Library onto the canvas, each of the node’s ports has a generic data type. This means that the data type for these ports hasn’t been decided yet. Right now, each of the Hold Value node’s ports has the potential to connect to any type of port in the composition. You can see that a port is generic by hovering over it with the mouse and reading the port popover that pops up.
When you connect one of the Hold Value node’s ports to a non-generic port, then all of the Hold Value node’s generic ports change to non-generic ports with the same type as the connected port. For example, if you connect the Hold Value node’s Held Value port to a Count Character node’s Text port, then all of the Hold Value node’s generic ports change to text ports, matching the Text port.
Another way to change a generic port to a non-generic port is to right-click on the port, go to the
menu that pops up, and choose a data type.If you want to change the port back to generic, you can right-click on the port and select the
menu item. (This will delete any cables between non-generic ports and ports changed back to generic.)Some generic nodes can work with several different types of data, but not all types. For example, the Add node can work with with integers, real numbers, 2D points, 3D points, and 4D points, but not text or images. Some generic nodes are automatically turned into non-generic nodes when first created. For example, when you drag an Add node from the Node Library onto the canvas, its ports are automatically changed from generic to real numbers, because real numbers are usually a suitable choice for the Add node. But if you want to work with integers instead, you can use the command and then the menu to change the ports to integers.
When you drag an Measure Distance between Points node from the Node Library onto the canvas, its A port is generic, but it can only connect to a port of type 2D point, 3D point, or 4D point. You can see the list of compatible types for a generic port by looking at the port popover.
You can connect a generic port to another generic port, as long as they work with compatible types of data. For example, you can connect a Hold Value node to an Add node, since the Hold Value node is compatible with any type. However, you can’t connect the output of a Find Maximum node to a Measure Distance between Points node, since the Find Maximum node is only compatible with integers and reals while the Measure Distance between Points node is only compatible with 2D, 3D, and 4D points.
A generic node can have ports that each work with a different generic type. For example, the Get Message Values node in the vuo.osc node set has several output ports with independent generic types. You can change one output port’s generic type to integer and another output port’s generic type to text, for example. You can see if a node’s generic ports use the same generic type or different generic types by looking at the port popover. The port popover displays a name for the port’s generic type, such as “generic #1” or “generic #2”. If two generic ports have the same name for their type (including if they’re on separate nodes connected by cables), then changing the generic type of one port will also change the other port. If two generic ports have different names for their type, then changing one will not affect the other.