-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (45 loc) · 949 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"flag"
"fmt"
"net"
"github.com/scgolang/osc"
)
type Config struct {
Addr string
}
func main() {
var config Config
flag.StringVar(&config.Addr, "l", "0.0.0.0:57120", "listening address")
flag.Parse()
addr, err := net.ResolveUDPAddr("udp", config.Addr)
if err != nil {
panic(err)
}
srv, err := osc.ListenUDP("udp", addr)
if err != nil {
panic(err)
}
app := &App{Config: config}
fmt.Printf("listening for OSC data on %s\n", config.Addr)
if err := srv.Serve(1, app); err != nil {
panic(err)
}
}
type App struct {
Config
}
func (app *App) Dispatch(bundle osc.Bundle, exactMatch bool) error {
return nil
}
func (app *App) Invoke(msg osc.Message, exactMatch bool) error {
args := make([]any, len(msg.Arguments)+1)
args[0] = msg.Address
formatString := "%s"
for i, arg := range msg.Arguments {
args[i+1] = arg
formatString += " %s"
}
fmt.Printf(formatString+"\n", args...)
return nil
}