npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

osc-min

v2.1.1

Published

Simple utilities for open sound control in node.js

Downloads

2,922

Readme

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

const sock = udp.createSocket("udp4", (msg) => {
  try {
    console.log(osc.fromBuffer(msg));
  } catch (e) {
    console.log("invalid OSC packet", e);
  }
});

sock.bind(inport);

Send a message containing multiple arguments every 2 seconds

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);

A simple OSC re-director

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);

Javascript representations of the OSC types.

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

  • An OSC Packet is an OSC Message or an OSC Bundle.

  • An OSC Message:

     {
         oscType : "message"
         address : "/address/pattern/might/have/wildcards"
         args : [arg1,arg2]
     }

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

  • An OSC Argument is represented as a javascript object with the following layout:

     {
         type : "string"
         value : "value"
     }

Where the type is one of the following:

  • string - string value
  • float - numeric value
  • integer - numeric value
  • color - JS object containing red, green, blue, alpha in range 0-255
  • midi - four-element array of numbers representing a midi packet of data
  • symbol - string value
  • character - a single-character string
  • double - numeric value
  • bigint - 64-bit bigint value (watch out, this will be truncated to 64 bits!)
  • blob - ArrayBuffer, DataView, TypedArray or node.js Buffer
  • true - value is boolean true
  • false - value is boolean false
  • null - no value
  • bang - no value (this is the I type tag)
  • timetag - Javascript Date
  • array - array of OSC Arguments

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

The following non-standard types are also supported:

  • double - numeric value (encodes to a float64 value)

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)

  • An OSC Bundle is represented as a javascript object with the following fields:

     {
         oscType : "bundle"
         timetag : 7
         elements : [element1, element]
     }

oscType "bundle"

timetag is one of:

  • Date - a JavaScript Date object
  • Array - [numberOfSecondsSince1900, fractionalSeconds] Both values are numbers. This gives full timing accuracy of 1/(2^32) seconds.

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:

  • We now provide type declarations for typescript compatibility
  • We always enable the previously optional "strict" errors
  • Many explicit error messages for passing in data of the wrong type have been removed. We encourage you to use typescript to prevent these sorts of errors.
  • Functions that used to return Buffer now return DataView
  • TimeTags must be specified as Dates or [number, number] arrays, and are always returned as [number, number] arrays. To convert between arrays and Dates, use dateToTimetag and timetagToDate.
  • The two-argument version of toBuffer has been removed.

License

Licensed under the terms found in COPYING (zlib license)