Skip to content

256dpi/max-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

max-go

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/max-go
go get -u github.com/256dpi/max-go/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 zig toolchain:

brew install zig

Usage

Add the following file to an empty directory:

package main

import  "github.com/256dpi/max-go"

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

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

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

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

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

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

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

func init() {
	// initialize Max class
	max.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