Connecting OSC devices:
Filter:
Modality-toolkit/Tutorials (extension) | Libraries > Modality

Connecting OSC devices
ExtensionExtension

Handling changing addresses and ports in MKtls

OSC communication and Modality

OSC communication is flexible and widely supported. This tutorial walks through the details of how OSC is integrated in Modality.

While OSC-related networking issues can be frustrating, there are ways to test systematically why an OSC device that worked earlier may not work now.

For a detailed discussion, see OSC Communication.

OSC Basics - sending

How does SuperCollider communicate with an external OSC device?

Each OSC controller device sends either UDP or TCP messages across an IP network. Both UDP and TCP protocols send messages between IP addresses (each network interface -- e.g. WLAN, LAN, loopback -- has a unique one). Each interface has an additional stack of ports that is represented by 16bit numbers.

A connection between two processes goes from the home port through the home IP address to the remote IP address to the remote port, eventually captured by the remote process.

Note that UDP and TCP port numberings are completely separate from each other. A UDP port cannot transmit anything to a TCP port and vice versa.

When sender and receiver are on the same computer, communication can be handled via the loopback device, always associated with the IP address "127.0.0.1".

To connect an OSC controller via UDP to SuperCollider means to open a port on an associated network device (the device has an IP address). Then, messages can be sent from there to a remote IP address, the one associated to the computer SuperCollider runs on where it can be picked up from a port specified by the sender.

Let's create a fake device that sends messages from SuperCollider to SuperCollider.

This tells us what the message itself is, which port it arrived on - there could be multiple listening ports (not the receiving IP), and which address (IP, port) sent it - so we can send back.

Sending on special ports

Some devices send on fixed port numbers. For this case, SC can open more ports:

Listening to messages by address and port

Making an OSCMKtlDevice

This example expands on a basic example from How_to_create_a_description_file_for_OSC. In a first step we create a description for an OSC device which has a single button, and uses specific, non-standard port numbers, therefore emulating a device completely independant of SuperCollider similar to the "fake" senderAddr in the above section.

We then create an MKtl from it. In the next subsection, we will send messages from SC to simulate messages as they would come from an external source, and see that the MKtl correctly receives them.

Simulate sending OSC messages

Adapting to changing ports and addresses

When devices connect and reconnect to a network, they may get different IP addresses. Also devices and processes may get different port numbers when being disconnected and reconnected.

To handle such situations, one can change both addresses and ports in existing MKtls on the fly. For example, make MKtl(\osc1but) listen to messages from within SC:

Similarly, we can update the ip number as well:

Finally, we can also change the receiving port after the fact:

This hopefully covers most complications that may occur when using OSC devices. For more information, see also OSC Communication.