github.com/256dpi/max-go@v0.7.0/README.md (about) 1 # max-go 2 3 [![GoDoc](https://godoc.org/github.com/256dpi/max-go?status.svg)](http://godoc.org/github.com/256dpi/max-go) 4 [![Release](https://img.shields.io/github/release/256dpi/max-go.svg)](https://github.com/256dpi/max-go/releases) 5 [![Go Report Card](https://goreportcard.com/badge/github.com/256dpi/max-go)](https://goreportcard.com/report/github.com/256dpi/max-go) 6 7 **Toolkit for building Max externals with Go.** 8 9 ## Installation 10 11 First you need to ensure you have recent version of [Go](https://golang.org) installed. On macOS simply install it using [brew](https://brew.sh): 12 13 ```sh 14 brew install go 15 ``` 16 17 Then you can install the package and CLI using Go's module management: 18 19 ```sh 20 go get -u github.com/256dpi/max-go 21 go get -u github.com/256dpi/max-go/cmd/maxgo 22 ``` 23 24 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: 25 26 ```sh 27 echo 'export PATH=~/go/bin:$PATH' >> ~/.zprofile # for zsh 28 ``` 29 30 Cross compilation on macOS for Windows additionally requires the `zig` toolchain: 31 32 ```sh 33 brew install zig 34 ``` 35 36 ## Usage 37 38 Add the following file to an empty directory: 39 40 ```go 41 package main 42 43 import "github.com/256dpi/max-go" 44 45 type instance struct { 46 in1 *max.Inlet 47 in2 *max.Inlet 48 out1 *max.Outlet 49 out2 *max.Outlet 50 } 51 52 func (i *instance) Init(obj *max.Object, args []max.Atom) { 53 // print to Max console 54 max.Pretty("init", args) 55 56 // declare inlets 57 i.in1 = obj.Inlet(max.Any, "example inlet 1", true) 58 i.in2 = obj.Inlet(max.Float, "example inlet 2", false) 59 60 // declare outlets 61 i.out1 = obj.Outlet(max.Any, "example outlet 1") 62 i.out2 = obj.Outlet(max.Bang, "example outlet 2") 63 } 64 65 func (i *instance) Handle(inlet int, msg string, data []max.Atom) { 66 // print to Max console 67 max.Pretty("handle", inlet, msg, data) 68 69 // send to first outlet 70 i.out1.Any(msg, data) 71 } 72 73 func (i *instance) Free() { 74 // print to Max console 75 max.Pretty("free") 76 } 77 78 func init() { 79 // initialize Max class 80 max.Register("example", &instance{}) 81 } 82 83 func main() { 84 // not called 85 } 86 ``` 87 88 Compile the external to the `dist` directory: 89 90 ``` 91 maxgo -name example -out dist 92 ``` 93 94 You can also cross compile (macOS only) and install the external: 95 96 ``` 97 maxgo -name example -out dist -cross -install example 98 ```