maxgo

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2020 License: MIT Imports: 7 Imported by: 0

README

maxgo

GoDoc Release Go Report Card

Toolkit for building Max externals with Go.

Installation

First you need to ensure you have recent version of Go installed. On macOS simply install it using brew:

brew install go

Then you can install the package and CLI using Go's module management:

go get -u github.com/256dpi/maxgo
go get -u github.com/256dpi/maxgo/cmd/maxgo

This will install the maxgo command line utility. You may need to add Go's bin directory tou your PATH variable to access the CLI in the terminal:

echo 'export PATH=~/go/bin:$PATH' >> ~/.zprofile # for zsh

Cross compilation on macOS for Windows additionally requires the mingw-w64 toolchain:

brew install mingw-w64

Usage

Add the following file to an empty directory:

package main

import  "github.com/256dpi/maxgo"

type instance struct {
	in1   *maxgo.Inlet
	in2   *maxgo.Inlet
	out1  *maxgo.Outlet
	out2  *maxgo.Outlet
}

func (i *instance) Init(obj *maxgo.Object, args []maxgo.Atom) {
	// print to Max console
	maxgo.Pretty("init", args)

	// declare inlets
	i.in1 = obj.Inlet(maxgo.Any, "example inlet 1", true)
	i.in2 = obj.Inlet(maxgo.Float, "example inlet 2", false)

	// declare outlets
	i.out1 = obj.Outlet(maxgo.Any, "example outlet 1")
	i.out2 = obj.Outlet(maxgo.Bang, "example outlet 2")
}

func (i *instance) Handle(msg string, inlet int, data []maxgo.Atom) {
	// print to Max console
	maxgo.Pretty("handle", msg, inlet, data)

	// send to first outlet
	i.out1.Any(msg, data)
}

func (i *instance) Free() {
	// print to Max console
	maxgo.Pretty("free")
}

func init() {
	// initialize Max class
	maxgo.Register("example", &instance{})
}

func main() {
	// not called
}

Compile the external to the dist directory:

maxgo -name example -out dist

You can also cross compile (macOS only) and install the external:

maxgo -name example -out dist -cross -install example

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alert

func Alert(format string, args ...interface{})

Alert will show an alert dialog.

func Defer

func Defer(fn func())

Defer will run the provided function on the Max main thread.

func Error

func Error(format string, args ...interface{})

Error will print an error to the max console.

func Init

func Init(name string, init func(*Object, []Atom) bool, handler func(*Object, string, int, []Atom), free func(*Object))

Init will initialize the Max class with the specified name using the provided callbacks to initialize and free objects. This function must be called from the main packages init() function as the main() function is never called by a Max external.

The provided callbacks are called to initialize and object, handle messages and free the object when it is not used anymore. The callbacks are usually called on the Max main thread. However, the handler may be called from and unknown thread in parallel to the other callbacks.

func IsMainThread

func IsMainThread() bool

IsMainThread will return if the Max main thead is executing.

func Log

func Log(format string, args ...interface{})

Log will print a message to the max console.

func Pretty

func Pretty(a ...interface{})

Pretty will pretty print the provided values.

func Register

func Register(name string, prototype Instance)

Register will initialize the Max class using the provided instance. This function must be called from the main packages init() function as the main() function is never called by a Max external.

The callbacks on the instance are never called in parallel.

Types

type Atom

type Atom = interface{}

Atom is a Max atom of type int64, float64 or string.

type Inlet

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

Inlet is a single Max inlet.

func (*Inlet) Label

func (i *Inlet) Label() string

Label will return the inlets label.

func (*Inlet) Type

func (i *Inlet) Type() Type

Type will return the inlets type.

type Instance

type Instance interface {
	Init(obj *Object, args []Atom) bool
	Handle(msg string, inlet int, data []Atom)
	Free()
}

Instance is a generic object instance.

type Object

type Object struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Object is single Max object.

func (*Object) Inlet

func (o *Object) Inlet(typ Type, label string, hot bool) *Inlet

Inlet will declare an inlet. If no inlets are added to an object it will have a default inlet to receive messages.

func (*Object) Outlet

func (o *Object) Outlet(typ Type, label string) *Outlet

Outlet will declare an outlet.

type Outlet

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

Outlet is a single MAx outlet.

func (*Outlet) Any

func (o *Outlet) Any(msg string, atoms []Atom)

Any will send any message.

func (*Outlet) Bang

func (o *Outlet) Bang()

Bang will send a bang.

func (*Outlet) Float

func (o *Outlet) Float(n float64)

Float will send a float.

func (*Outlet) Int

func (o *Outlet) Int(n int64)

Int will send and int.

func (*Outlet) Label

func (o *Outlet) Label() string

Label will return the outlets label.

func (*Outlet) List

func (o *Outlet) List(atoms []Atom)

List will send a list.

func (*Outlet) Type

func (o *Outlet) Type() Type

Type will return the outlets type.

type Type

type Type string

Type describes an inlet or outlet type.

const (
	Any   Type = "any"
	Bang  Type = "bang"
	Int   Type = "int"
	Float Type = "float"
	List  Type = "list"
)

The available inlet and outlet types.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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