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() {
var Address string
var Args []string
var Types []string
var Slip bool
cmd := &cli.Command{
Name: "makeosc",
Usage: "make osc bytes",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "address",
Value: "",
Usage: "OSC address",
Destination: &Address,
Required: true,
Name: "address",
Value: "",
Usage: "OSC address",
Required: true,
},
&cli.StringSliceFlag{
Name: "arg",
Usage: "OSC args",
Destination: &Args,
Name: "arg",
Usage: "OSC args",
},
&cli.StringSliceFlag{
Name: "type",
Usage: "OSC types",
Destination: &Types,
Name: "type",
Usage: "OSC types",
},
&cli.BoolFlag{
Name: "slip",
Value: false,
Usage: "whether to slip encode the OSC Message bytes",
Destination: &Slip,
Name: "slip",
Value: false,
Usage: "whether to slip encode the OSC Message bytes",
},
},
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
},
}
@@ -158,7 +154,7 @@ func slipEncode(bytes []byte) []byte {
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{
Address: address,
+26 -30
View File
@@ -12,33 +12,25 @@ import (
)
func main() {
var IP string
var Port int32
var Protocol string
var Format string
var Slip bool
cmd := &cli.Command{
Name: "receiveosc",
Usage: "receive OSC messages via UDP or TCP",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "ip",
Usage: "ip to receive OSC messages on",
Value: "0.0.0.0",
Destination: &IP,
Name: "ip",
Usage: "ip to receive OSC messages on",
Value: "0.0.0.0",
},
&cli.Int32Flag{
Name: "port",
Usage: "port to receive OSC messages on",
Destination: &Port,
Value: 8888,
Name: "port",
Usage: "port to receive OSC messages on",
Value: 8888,
},
&cli.StringFlag{
Name: "protocol",
Usage: "protocol to use to receive (tcp or udp)",
Value: "udp",
Destination: &Protocol,
Name: "protocol",
Usage: "protocol to use to receive (tcp or udp)",
Value: "udp",
Validator: func(flag string) error {
if flag != "udp" && flag != "tcp" {
return fmt.Errorf("protocol must be either 'udp' or 'tcp'")
@@ -47,10 +39,9 @@ func main() {
},
},
&cli.StringFlag{
Name: "format",
Usage: "format for messages to be output in ('json')",
Value: "json",
Destination: &Format,
Name: "format",
Usage: "format for messages to be output in ('json')",
Value: "json",
Validator: func(flag string) error {
if flag != "json" {
return fmt.Errorf("format must be 'json'")
@@ -59,22 +50,27 @@ func main() {
},
},
&cli.BoolFlag{
Name: "slip",
Value: false,
Usage: "whether to slip encode the OSC Message bytes",
Destination: &Slip,
Name: "slip",
Value: false,
Usage: "whether to slip encode the OSC Message bytes",
},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
netAddress := fmt.Sprintf("%s:%d", IP, Port)
switch Protocol {
ip := cmd.String("ip")
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":
listenUDP(netAddress, Format)
listenUDP(netAddress, format)
case "tcp":
if !Slip {
if !slip {
return fmt.Errorf("OSC 1.0 over TCP is not supported yet")
}
listenTCP(netAddress, Slip, Format)
listenTCP(netAddress, slip, format)
}
return nil
},
+29 -36
View File
@@ -15,35 +15,25 @@ import (
)
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{
Name: "sendosc",
Usage: "send OSC messages via UDP or TCP",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "host",
Usage: "host to send OSC message to",
Destination: &Host,
Required: true,
Name: "host",
Usage: "host to send OSC message to",
Required: true,
},
&cli.Int32Flag{
Name: "port",
Usage: "port to send OSC message to",
Destination: &Port,
Required: true,
Name: "port",
Usage: "port to send OSC message to",
Required: true,
},
&cli.StringFlag{
Name: "protocol",
Usage: "protocol to use to send (tcp or udp)",
Value: "udp",
Destination: &Protocol,
Name: "protocol",
Usage: "protocol to use to send (tcp or udp)",
Value: "udp",
Validator: func(flag string) error {
if flag != "udp" && flag != "tcp" {
return fmt.Errorf("protocol must be either 'udp' or 'tcp'")
@@ -52,32 +42,35 @@ func main() {
},
},
&cli.StringFlag{
Name: "address",
Usage: "OSC address",
Destination: &Address,
Required: true,
Name: "address",
Usage: "OSC address",
Required: true,
},
&cli.StringSliceFlag{
Name: "arg",
Usage: "OSC args",
Value: []string{},
Destination: &Args,
Name: "arg",
Usage: "OSC args",
Value: []string{},
},
&cli.StringSliceFlag{
Name: "type",
Usage: "OSC types",
Value: []string{},
Destination: &Types,
Name: "type",
Usage: "OSC types",
Value: []string{},
},
&cli.BoolFlag{
Name: "slip",
Value: false,
Usage: "whether to slip encode the OSC Message bytes",
Destination: &Slip,
Name: "slip",
Value: false,
Usage: "whether to slip encode the OSC Message bytes",
},
},
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
},
}