osc

package module
v0.0.0-...-3a23442 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2019 License: MIT Imports: 8 Imported by: 1

README

GoOSC

Build Status GoDoc Coverage Status Go Report Card

Open Sound Control (OSC) library for Golang. Implemented in pure Go.

Features

  • OSC Bundles, including timetags
  • OSC Messages
  • OSC Client
  • OSC Server
  • Supports the following OSC argument types:
    • 'i' (Int32)
    • 'f' (Float32)
    • 's' (string)
    • 'b' (blob / binary data)
    • 'h' (Int64)
    • 't' (OSC timetag)
    • 'd' (Double/int64)
    • 'T' (True)
    • 'F' (False)
    • 'N' (Nil)
  • Support for OSC address pattern including '*', '?', '{,}' and '[]' wildcards

Install

go get github.com/hypebeast/go-osc

Usage

Client
import "github.com/hypebeast/go-osc/osc"

func main() {
    client := osc.NewClient("localhost", 8765)
    msg := osc.NewMessage("/osc/address")
    msg.Append(int32(111))
    msg.Append(true)
    msg.Append("hello")
    client.Send(msg)
}
Server
package main

import "github.com/hypebeast/go-osc/osc"

func main() {
  addr := "127.0.0.1:8765"
  server := &osc.Server{Addr: addr}

  server.Handle("/message/address", func(msg *osc.Message) {
    osc.PrintMessage(msg)
  })

  server.ListenAndServe()
}

Tests

go test

Documentation

Overview

Package osc provides a client and server for sending and receiving OpenSoundControl messages.

The package is implemented in pure Go.

The implementation is based on the Open Sound Control 1.0 Specification (http://opensoundcontrol.org/spec-1_0).

Open Sound Control (OSC) is an open, transport-independent, message-based protocol developed for communication among computers, sound synthesizers, and other multimedia devices.

Features:

  • Supports OSC messages with 'i' (Int32), 'f' (Float32), 's' (string), 'b' (blob / binary data), 'h' (Int64), 't' (OSC timetag), 'd' (Double/int64), 'T' (True), 'F' (False), 'N' (Nil) types.
  • OSC bundles, including timetags
  • Support for OSC address pattern including '*', '?', '{,}' and '[]' wildcards
  • TODO: Describe registering methods

This OSC implementation uses the UDP protocol for sending and receiving OSC packets.

The unit of transmission of OSC is an OSC Packet. Any application that sends OSC Packets is an OSC Client; any application that receives OSC Packets is an OSC Server.

An OSC packet consists of its contents, a contiguous block of binary data, and its size, the number of 8-bit bytes that comprise the contents. The size of an OSC packet is always a multiple of 4.

OSC packets come in two flavors:

OSC Messages: An OSC message consists of an OSC address pattern, followed by an OSC Type Tag String, and finally by zero or more OSC arguments.

OSC Bundles: An OSC Bundle consists of the string "#bundle" followed by an OSC Time Tag, followed by zero or more OSC bundle elements. Each bundle element can be another OSC bundle (note this recursive definition: bundle may contain bundles) or OSC message.

An OSC bundle element consists of its size and its contents. The size is an int32 representing the number of 8-bit bytes in the contents, and will always be a multiple of 4. The contents are either an OSC Message or an OSC Bundle.

The following argument types are supported: 'i' (Int32), 'f' (Float32), 's' (string), 'b' (blob / binary data), 'h' (Int64), 't' (OSC timetag), 'd' (Double/int64), 'T' (True), 'F' (False), 'N' (Nil).

go-osc supports the following OSC address patterns: - '*', '?', '{,}' and '[]' wildcards.

Usage

OSC client example:

client := osc.NewClient("localhost", 8765)
msg := osc.NewMessage("/osc/address")
msg.Append(int32(111))
msg.Append(true)
msg.Append("hello")
client.Send(msg)

OSC server example:

addr := "127.0.0.1:8765"
server := &osc.Server{Addr: addr}

server.Handle("/message/address", func(msg *osc.Message) {
   osc.PrintMessage(msg)
})

server.ListenAndServe()

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoDiscover

func AutoDiscover(port int, msg *Message) (map[string]*Message, error)

Types

type Client

type Client interface {
	Connect(int) error
	Disconnect() error
	Send(*Message) error
	Receive(time.Duration) (*Message, error)
}

Client exposes Connect, Disconnect, Send Receive.

func NewClient

func NewClient(ip string, port int, localIP string, localPort int) Client

NewClient creates a new OSC client. The Client is used to send OSC messages and OSC bundles over an UDP network connection. The `ip` argument specifies the IP address and `port` defines the target port where the messages and bundles will be send to.

type Message

type Message struct {
	Address   string
	Arguments []interface{}
}

Message represents a single OSC message. An OSC message consists of an OSC address pattern and zero or more arguments.

func NewMessage

func NewMessage(addr string, args ...interface{}) *Message

NewMessage returns a new Message. The address parameter is the OSC address.

func (*Message) Append

func (msg *Message) Append(args ...interface{})

Append appends the given arguments to the arguments list.

func (*Message) MarshalBinary

func (msg *Message) MarshalBinary() ([]byte, error)

MarshalBinary serializes the OSC message to a byte buffer. The byte buffer has the following format: 1. OSC Address Pattern 2. OSC Type Tag String 3. OSC Arguments

func (*Message) String

func (msg *Message) String() string

String implements the fmt.Stringer interface.

type Timetag

type Timetag struct {
	MinValue uint64 // Minimum value of an OSC Time Tag. Is always 1.
	// contains filtered or unexported fields
}

Timetag represents an OSC Time Tag. An OSC Time Tag is defined as follows: Time tags are represented by a 64 bit fixed point number. The first 32 bits specify the number of seconds since midnight on January 1, 1900, and the last 32 bits specify fractional parts of a second to a precision of about 200 picoseconds. This is the representation used by Internet NTP timestamps.

func NewTimetag

func NewTimetag(timeStamp time.Time) *Timetag

NewTimetag returns a new OSC time tag object.

func NewTimetagFromTimetag

func NewTimetagFromTimetag(timetag uint64) *Timetag

NewTimetagFromTimetag creates a new Timetag from the given `timetag`.

func (*Timetag) ExpiresIn

func (t *Timetag) ExpiresIn() time.Duration

ExpiresIn calculates the number of seconds until the current time is the same as the value of the time tag. It returns zero if the value of the time tag is in the past.

func (*Timetag) FractionalSecond

func (t *Timetag) FractionalSecond() uint32

FractionalSecond returns the last 32 bits of the OSC time tag. Specifies the fractional part of a second.

func (*Timetag) MarshalBinary

func (t *Timetag) MarshalBinary() ([]byte, error)

MarshalBinary converts the OSC time tag to a byte array.

func (*Timetag) SecondsSinceEpoch

func (t *Timetag) SecondsSinceEpoch() uint32

SecondsSinceEpoch returns the first 32 bits (the number of seconds since the midnight 1900) from the OSC time tag.

func (*Timetag) SetTime

func (t *Timetag) SetTime(time time.Time)

SetTime sets the value of the OSC time tag.

func (*Timetag) Time

func (t *Timetag) Time() time.Time

Time returns the time.

func (*Timetag) TimeTag

func (t *Timetag) TimeTag() uint64

TimeTag returns the time tag value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL