osc

package module
v0.0.0-...-a0a2d14 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2020 License: Apache-2.0 Imports: 7 Imported by: 3

README

osc

OSC (Open Sound Control) package for Go.
A part of The Open Sound Control 1.0 Specification has been implemented in pure Go.
You can work with OSC in macOS, Windows, Linux (also work with Raspberry Pi).

Features

Type

These types are supported.

  • int32
  • float32
  • string

The other types are NOT supported.

Message or Bundle

Only OSC Message is implemented.
OSC Bundle is NOT supported.

Install

go get github.com/AkiyukiOkayasu/osc

Usage example

Send
package main

import (
	"log"

	"github.com/AkiyukiOkayasu/osc"
)

const (
	ip      string = "127.0.0.1" // You can also use "localhost"
	port    int    = 8080
	address string = "/test"
)

func main() {
	sender := osc.NewSender(ip, port)
	message := osc.NewMessage(address)

	// Add OSC arguments by type
	message.AddInt(123)
	message.AddFloat(3.14)
	message.AddString("foo")

	// Send OSC
	if err := sender.Send(message); err != nil {
		log.Fatalln(err)
	}
}
Receive
package main

import (
	"context"
	"fmt"
	"time"

	"github.com/AkiyukiOkayasu/osc"
)

const port int = 8080

func main() {
	// context to cancel OSC receiving gorouting
	c := context.Background()
	ctx, cancel := context.WithCancel(c)

	// OSC handler for /foo
	mux := osc.NewServeMux()
	mux.Handle("/foo", func(m *osc.Message) {
		fmt.Println("OSC Address: " + m.Address())
		for _, a := range m.Arguments {
			switch a.Type() {
			case 'i':
				if v, ok := a.Int(); ok {
					fmt.Printf("Foo Int: %d\n", v)
				}
			case 'f':
				if v, ok := a.Float(); ok {
					fmt.Printf("Foo Float: %3f\n", v)
				}
			case 's':
				if v, ok := a.String(); ok {
					fmt.Println("Foo String: " + v)
				}
			default:
				fmt.Printf("Unexpected type: %v\n", a.Type())
			}
		}
	})

	// Another OSC handler for /bar
	mux.Handle("/bar", func(m *osc.Message) {
		fmt.Println("OSC Address: " + m.Address())
		for _, a := range m.Arguments {
			switch a.Type() {
			case 'i':
				if v, ok := a.Int(); ok {
					fmt.Printf("Bar Int: %d\n", v)
				}
			case 'f':
				if v, ok := a.Float(); ok {
					fmt.Printf("Bar Float: %3f\n", v)
				}
			case 's':
				if v, ok := a.String(); ok {
					fmt.Println("Bar String: " + v)
				}
			default:
				fmt.Printf("Unexpected type: %v\n", a.Type())
			}
		}
	})

	r := osc.NewReceiver(port, *mux)
	go r.Receive(ctx) // Start OSC receiving

	// Something to do...
	time.Sleep(30 * time.Second) // Sleep 30 seconds

	cancel() // Stop receiving OSC
}

Command line OSC tool

gosc is a command line tool to send OSC.

Send
gosc send localhost 8080 /test 123 3.14 foo

Any number of OSC arguments can be added.
Type is automatically determined (int32, float32, string only).

Contribution

Contributions are welcome.
Please send a pull request if you have any ideas.

LICENSE

Apache 2.0
LICENSE

Documentation

Overview

Package osc is package send and receive OSC(Open Sound Control)

Package osc is package send and receive OSC(Open Sound Control)

Package osc is package send and receive OSC(Open Sound Control)

Package osc is package send and receive OSC(Open Sound Control)

Package osc is package send and receive OSC(Open Sound Control)

Package osc is package send and receive OSC(Open Sound Control)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Argument

type Argument struct {
	// contains filtered or unexported fields
}

Argument OSC argument Typetag: OSC typetag Argument: OSC argument

func (*Argument) Float

func (a *Argument) Float() (float32, bool)

Float return value of float type OSC argument

func (*Argument) Int

func (a *Argument) Int() (int32, bool)

Int return value of int type OSC argument

func (*Argument) String

func (a *Argument) String() (string, bool)

String return value of string type OSC argument

func (*Argument) Type

func (a *Argument) Type() rune

Type return OSC typetag

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client OSC client

func NewSender

func NewSender(ip string, port int) *Client

NewSender Sender作成

func (*Client) Send

func (c *Client) Send(m *Message) error

Send OSC送信

type Handler

type Handler interface {
	// contains filtered or unexported methods
}

Handler OSC messege handler

type HandlerFunc

type HandlerFunc func(*Message)

HandlerFunc is created to meet the requirements of Handler interface in the definition of the Lambda function.

type Message

type Message struct {
	Arguments []Argument
	// contains filtered or unexported fields
}

Message OSC address and Arguments array

func NewMessage

func NewMessage(address string) *Message

NewMessage TODO add description

func (*Message) AddFloat

func (m *Message) AddFloat(arg float32)

AddFloat add float to message

func (*Message) AddInt

func (m *Message) AddInt(arg int32)

AddInt add int to message

func (*Message) AddString

func (m *Message) AddString(arg string)

AddString add string to message

func (*Message) Address

func (m *Message) Address() string

Address return OSC address

func (*Message) Bytes

func (m *Message) Bytes() []byte

Bytes return OSC typetag and argument in []byte

type ServeMux

type ServeMux struct {
	// contains filtered or unexported fields
}

ServeMux OSC handler mux key: OSC address value: handler function

func NewServeMux

func NewServeMux() *ServeMux

NewServeMux return ServeMux

func (*ServeMux) Handle

func (s *ServeMux) Handle(pattern string, handler HandlerFunc)

Handle add handler for an OSC address

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server OSC server

func NewReceiver

func NewReceiver(port int, mux ServeMux) *Server

NewReceiver Receiver作成

func (*Server) Receive

func (s *Server) Receive(ctx context.Context) error

Receive OSC受信

Directories

Path Synopsis
cmd
example

Jump to

Keyboard shortcuts

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