Skip to content

Instantly share code, notes, and snippets.

@hosackm
Created June 15, 2016 04:48
Show Gist options
  • Save hosackm/59d510104fae432967fde642b82a0953 to your computer and use it in GitHub Desktop.
Save hosackm/59d510104fae432967fde642b82a0953 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/hypebeast/go-osc/osc"
"github.com/rakyll/portmidi"
)
const (
NOTEOFF = 0x80
NOTEON = 0x90
KNOB = 0xB0
)
func ListenForever(client *osc.Client, ch <-chan portmidi.Event) {
for {
event := <-ch
HandleEvent(client, &event)
}
}
func HandleEvent(client *osc.Client, event *portmidi.Event) {
msg := osc.NewMessage("/message/address")
msg.Append(int32(event.Status))
msg.Append(int32(event.Data1))
msg.Append(int32(event.Data2))
client.Send(msg)
}
func main() {
portmidi.Initialize()
defer portmidi.Terminate()
in, err := portmidi.NewInputStream(portmidi.DefaultInputDeviceID(), 1024)
if err != nil {
panic(err)
}
defer in.Close()
done := make(<-chan bool)
client := osc.NewClient("localhost", 8765)
go ListenForever(client, in.Listen())
<-done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment