Home

Awesome

osc-min

simple utilities for open sound control in node.js

This package provides some node.js utilities for working with OSC, a format for sound and systems control.
Here we implement the OSC 1.1 specification. OSC is a transport-independent protocol, so we don't provide any server objects, as you should be able to use OSC over any transport you like. The most common is probably udp, but tcp is not unheard of.


Examples

Further examples available in the examples folder.

A simple OSC server that prints any received messages

<!-- doc-gen CODE src="examples/printosc.mjs" lines="8-16" syntax="js" -->
const sock = udp.createSocket("udp4", (msg) => {
  try {
    console.log(osc.fromBuffer(msg));
  } catch (e) {
    console.log("invalid OSC packet", e);
  }
});

sock.bind(inport);
<!-- end-doc-gen -->

Send a message containing multiple arguments every 2 seconds

<!-- doc-gen CODE src="examples/oscheartbeat.mjs" lines="9-25" syntax="js" -->
const sendHeartbeat = () => {
  const buf = toBuffer({
    address: "/heartbeat",
    args: [
      12,
      "sttttring",
      new TextEncoder().encode("beat"),
      {
        type: "integer",
        value: 7,
      },
    ],
  });
  return udp.send(buf, 0, buf.byteLength, outport, "localhost");
};

setInterval(sendHeartbeat, 2000);
<!-- end-doc-gen -->

A simple OSC re-director

<!-- doc-gen CODE src="examples/osc-redirect.mjs" lines="10-28" syntax="js"-->
const sock = dgram.createSocket("udp4", (msg) => {
  try {
    const redirected = osc.applyAddressTransform(
      msg,
      (address) => `/redirect${address}`
    );
    return sock.send(
      redirected,
      0,
      redirected.byteLength,
      outport,
      "localhost"
    );
  } catch (e) {
    return console.log(`error redirecting: ${e}`);
  }
});

sock.bind(inport);
<!-- end-doc-gen -->

Javascript representations of the OSC types.

See the [spec][spec] for more information on the OSC types.

Where args is an array of OSC Arguments. oscType is optional. args can be a single element.

Where the type is one of the following:

Note that type is always a string - i.e. "true" rather than true.

The following non-standard types are also supported:

For messages sent to the toBuffer function, type is optional. If the argument is not an object, it will be interpreted as either string, float, array or blob, depending on its javascript type (String, Number, Array, Buffer, respectively)

oscType "bundle"

timetag is one of:

elements is an Array of either OSC Message or OSC Bundle

[spec]: http://opensoundcontrol.org/spec-1_0

Migrating from 1.0

There have been a few breaking changes from the 1.0 version:

License

Licensed under the terms found in COPYING (zlib license)