stop using destination

This commit is contained in:
Joel Wetzell
2026-05-09 14:06:33 -05:00
parent a86a9b3121
commit d6d4ac4419
3 changed files with 72 additions and 87 deletions
+17 -21
View File
@@ -12,41 +12,37 @@ import (
) )
func main() { func main() {
var Address string
var Args []string
var Types []string
var Slip bool
cmd := &cli.Command{ cmd := &cli.Command{
Name: "makeosc", Name: "makeosc",
Usage: "make osc bytes", Usage: "make osc bytes",
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: "address", Name: "address",
Value: "", Value: "",
Usage: "OSC address", Usage: "OSC address",
Destination: &Address, Required: true,
Required: true,
}, },
&cli.StringSliceFlag{ &cli.StringSliceFlag{
Name: "arg", Name: "arg",
Usage: "OSC args", Usage: "OSC args",
Destination: &Args,
}, },
&cli.StringSliceFlag{ &cli.StringSliceFlag{
Name: "type", Name: "type",
Usage: "OSC types", Usage: "OSC types",
Destination: &Types,
}, },
&cli.BoolFlag{ &cli.BoolFlag{
Name: "slip", Name: "slip",
Value: false, Value: false,
Usage: "whether to slip encode the OSC Message bytes", Usage: "whether to slip encode the OSC Message bytes",
Destination: &Slip,
}, },
}, },
Action: func(ctx context.Context, cmd *cli.Command) error { Action: func(ctx context.Context, cmd *cli.Command) error {
make(Address, Args, Types, Slip) address := cmd.String("address")
args := cmd.StringSlice("arg")
types := cmd.StringSlice("type")
slip := cmd.Bool("slip")
makeMsg(address, args, types, slip)
return nil return nil
}, },
} }
@@ -158,7 +154,7 @@ func slipEncode(bytes []byte) []byte {
return encodedBytes return encodedBytes
} }
func make(address string, args []string, types []string, slip bool) { func makeMsg(address string, args []string, types []string, slip bool) {
oscMessage := osc.OSCMessage{ oscMessage := osc.OSCMessage{
Address: address, Address: address,
+26 -30
View File
@@ -12,33 +12,25 @@ import (
) )
func main() { func main() {
var IP string
var Port int32
var Protocol string
var Format string
var Slip bool
cmd := &cli.Command{ cmd := &cli.Command{
Name: "receiveosc", Name: "receiveosc",
Usage: "receive OSC messages via UDP or TCP", Usage: "receive OSC messages via UDP or TCP",
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: "ip", Name: "ip",
Usage: "ip to receive OSC messages on", Usage: "ip to receive OSC messages on",
Value: "0.0.0.0", Value: "0.0.0.0",
Destination: &IP,
}, },
&cli.Int32Flag{ &cli.Int32Flag{
Name: "port", Name: "port",
Usage: "port to receive OSC messages on", Usage: "port to receive OSC messages on",
Destination: &Port, Value: 8888,
Value: 8888,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "protocol", Name: "protocol",
Usage: "protocol to use to receive (tcp or udp)", Usage: "protocol to use to receive (tcp or udp)",
Value: "udp", Value: "udp",
Destination: &Protocol,
Validator: func(flag string) error { Validator: func(flag string) error {
if flag != "udp" && flag != "tcp" { if flag != "udp" && flag != "tcp" {
return fmt.Errorf("protocol must be either 'udp' or 'tcp'") return fmt.Errorf("protocol must be either 'udp' or 'tcp'")
@@ -47,10 +39,9 @@ func main() {
}, },
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "format", Name: "format",
Usage: "format for messages to be output in ('json')", Usage: "format for messages to be output in ('json')",
Value: "json", Value: "json",
Destination: &Format,
Validator: func(flag string) error { Validator: func(flag string) error {
if flag != "json" { if flag != "json" {
return fmt.Errorf("format must be 'json'") return fmt.Errorf("format must be 'json'")
@@ -59,22 +50,27 @@ func main() {
}, },
}, },
&cli.BoolFlag{ &cli.BoolFlag{
Name: "slip", Name: "slip",
Value: false, Value: false,
Usage: "whether to slip encode the OSC Message bytes", Usage: "whether to slip encode the OSC Message bytes",
Destination: &Slip,
}, },
}, },
Action: func(ctx context.Context, cmd *cli.Command) error { Action: func(ctx context.Context, cmd *cli.Command) error {
netAddress := fmt.Sprintf("%s:%d", IP, Port) ip := cmd.String("ip")
switch Protocol { port := cmd.Int32("port")
protocol := cmd.String("protocol")
format := cmd.String("format")
slip := cmd.Bool("slip")
netAddress := fmt.Sprintf("%s:%d", ip, port)
switch protocol {
case "udp": case "udp":
listenUDP(netAddress, Format) listenUDP(netAddress, format)
case "tcp": case "tcp":
if !Slip { if !slip {
return fmt.Errorf("OSC 1.0 over TCP is not supported yet") return fmt.Errorf("OSC 1.0 over TCP is not supported yet")
} }
listenTCP(netAddress, Slip, Format) listenTCP(netAddress, slip, format)
} }
return nil return nil
}, },
+29 -36
View File
@@ -15,35 +15,25 @@ import (
) )
func main() { func main() {
var Host string
var Port int32
var Address string
var Protocol string
var Args []string
var Types []string
var Slip bool
cmd := &cli.Command{ cmd := &cli.Command{
Name: "sendosc", Name: "sendosc",
Usage: "send OSC messages via UDP or TCP", Usage: "send OSC messages via UDP or TCP",
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: "host", Name: "host",
Usage: "host to send OSC message to", Usage: "host to send OSC message to",
Destination: &Host, Required: true,
Required: true,
}, },
&cli.Int32Flag{ &cli.Int32Flag{
Name: "port", Name: "port",
Usage: "port to send OSC message to", Usage: "port to send OSC message to",
Destination: &Port, Required: true,
Required: true,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "protocol", Name: "protocol",
Usage: "protocol to use to send (tcp or udp)", Usage: "protocol to use to send (tcp or udp)",
Value: "udp", Value: "udp",
Destination: &Protocol,
Validator: func(flag string) error { Validator: func(flag string) error {
if flag != "udp" && flag != "tcp" { if flag != "udp" && flag != "tcp" {
return fmt.Errorf("protocol must be either 'udp' or 'tcp'") return fmt.Errorf("protocol must be either 'udp' or 'tcp'")
@@ -52,32 +42,35 @@ func main() {
}, },
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "address", Name: "address",
Usage: "OSC address", Usage: "OSC address",
Destination: &Address, Required: true,
Required: true,
}, },
&cli.StringSliceFlag{ &cli.StringSliceFlag{
Name: "arg", Name: "arg",
Usage: "OSC args", Usage: "OSC args",
Value: []string{}, Value: []string{},
Destination: &Args,
}, },
&cli.StringSliceFlag{ &cli.StringSliceFlag{
Name: "type", Name: "type",
Usage: "OSC types", Usage: "OSC types",
Value: []string{}, Value: []string{},
Destination: &Types,
}, },
&cli.BoolFlag{ &cli.BoolFlag{
Name: "slip", Name: "slip",
Value: false, Value: false,
Usage: "whether to slip encode the OSC Message bytes", Usage: "whether to slip encode the OSC Message bytes",
Destination: &Slip,
}, },
}, },
Action: func(ctx context.Context, cmd *cli.Command) error { Action: func(ctx context.Context, cmd *cli.Command) error {
send(Host, Port, Address, Args, Types, Protocol, Slip) host := cmd.String("host")
port := cmd.Int32("port")
address := cmd.String("address")
args := cmd.StringSlice("arg")
types := cmd.StringSlice("type")
protocol := cmd.String("protocol")
slip := cmd.Bool("slip")
send(host, port, address, args, types, protocol, slip)
return nil return nil
}, },
} }