mirror of
https://github.com/jwetzell/osc-go.git
synced 2026-08-17 20:43:58 +00:00
switch to an OSC library
This commit is contained in:
+14
-27
@@ -6,7 +6,7 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/jwetzell/osc-go/pkg/osc"
|
||||
"github.com/chabad360/go-osc/osc"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -31,47 +31,35 @@ func main() {
|
||||
rootCmd.Execute()
|
||||
}
|
||||
|
||||
func argToTypedArg(rawArg string, oscType string) osc.OSCArg {
|
||||
func argToTypedArg(rawArg string, oscType string) any {
|
||||
switch oscType {
|
||||
case "s":
|
||||
return osc.OSCArg{
|
||||
Type: "s",
|
||||
Value: rawArg,
|
||||
}
|
||||
return rawArg
|
||||
case "i":
|
||||
number, err := strconv.ParseInt(rawArg, 10, 32)
|
||||
if err != nil {
|
||||
// ... handle error
|
||||
panic(err)
|
||||
}
|
||||
return osc.OSCArg{
|
||||
Type: "i",
|
||||
Value: int32(number),
|
||||
}
|
||||
return int32(number)
|
||||
case "f":
|
||||
number, err := strconv.ParseFloat(rawArg, 32)
|
||||
if err != nil {
|
||||
// ... handle error
|
||||
panic(err)
|
||||
}
|
||||
return osc.OSCArg{
|
||||
Type: "f",
|
||||
Value: float32(number),
|
||||
}
|
||||
return float32(number)
|
||||
case "b":
|
||||
data, err := hex.DecodeString(rawArg)
|
||||
if err != nil {
|
||||
// ... handle error
|
||||
panic(err)
|
||||
}
|
||||
return osc.OSCArg{
|
||||
Type: "b",
|
||||
Value: data,
|
||||
}
|
||||
return data
|
||||
default:
|
||||
fmt.Print("unhandled osc type: ")
|
||||
fmt.Printf("%s.\n", oscType)
|
||||
return osc.OSCArg{}
|
||||
return rawArg
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +87,7 @@ func slipEncode(bytes []byte) []byte {
|
||||
|
||||
func make(address string, args []string, types []string, slip bool) {
|
||||
|
||||
oscArgs := []osc.OSCArg{}
|
||||
oscMessage := osc.NewMessage(address)
|
||||
|
||||
for index, arg := range args {
|
||||
oscType := "s"
|
||||
@@ -107,21 +95,20 @@ func make(address string, args []string, types []string, slip bool) {
|
||||
oscType = types[index]
|
||||
}
|
||||
|
||||
oscArgs = append(oscArgs, argToTypedArg(arg, oscType))
|
||||
oscMessage.Append(argToTypedArg(arg, oscType))
|
||||
}
|
||||
|
||||
oscMessage := osc.OSCMessage{
|
||||
Address: address,
|
||||
Args: oscArgs,
|
||||
}
|
||||
oscMessageBuffer, err := oscMessage.MarshalBinary()
|
||||
|
||||
oscMessageBuffer := osc.ToBytes(oscMessage)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if slip {
|
||||
oscMessageBuffer = slipEncode(oscMessageBuffer)
|
||||
}
|
||||
|
||||
//TODO write buffer to stdout
|
||||
os.Stdout.Write(oscMessageBuffer[:])
|
||||
os.Stdout.Write(oscMessageBuffer)
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/jwetzell/osc-go/pkg/osc"
|
||||
"github.com/chabad360/go-osc/osc"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -50,7 +50,7 @@ func listen(netAddress string) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
oscMessage, err := osc.FromBytes(buffer[0:bytesRead])
|
||||
oscMessage, err := osc.NewMessageFromData(buffer[0:bytesRead])
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
+13
-26
@@ -6,7 +6,7 @@ import (
|
||||
"net"
|
||||
"strconv"
|
||||
|
||||
"github.com/jwetzell/osc-go/pkg/osc"
|
||||
"github.com/chabad360/go-osc/osc"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -39,47 +39,35 @@ func main() {
|
||||
rootCmd.Execute()
|
||||
}
|
||||
|
||||
func argToTypedArg(rawArg string, oscType string) osc.OSCArg {
|
||||
func argToTypedArg(rawArg string, oscType string) any {
|
||||
switch oscType {
|
||||
case "s":
|
||||
return osc.OSCArg{
|
||||
Type: "s",
|
||||
Value: rawArg,
|
||||
}
|
||||
return rawArg
|
||||
case "i":
|
||||
number, err := strconv.ParseInt(rawArg, 10, 32)
|
||||
if err != nil {
|
||||
// ... handle error
|
||||
panic(err)
|
||||
}
|
||||
return osc.OSCArg{
|
||||
Type: "i",
|
||||
Value: int32(number),
|
||||
}
|
||||
return int32(number)
|
||||
case "f":
|
||||
number, err := strconv.ParseFloat(rawArg, 32)
|
||||
if err != nil {
|
||||
// ... handle error
|
||||
panic(err)
|
||||
}
|
||||
return osc.OSCArg{
|
||||
Type: "f",
|
||||
Value: float32(number),
|
||||
}
|
||||
return float32(number)
|
||||
case "b":
|
||||
data, err := hex.DecodeString(rawArg)
|
||||
if err != nil {
|
||||
// ... handle error
|
||||
panic(err)
|
||||
}
|
||||
return osc.OSCArg{
|
||||
Type: "b",
|
||||
Value: data,
|
||||
}
|
||||
return data
|
||||
default:
|
||||
fmt.Print("unhandled osc type: ")
|
||||
fmt.Printf("%s.\n", oscType)
|
||||
return osc.OSCArg{}
|
||||
return rawArg
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +95,7 @@ func slipEncode(bytes []byte) []byte {
|
||||
|
||||
func send(host string, port int32, address string, args []string, types []string, protocol string, slip bool) {
|
||||
|
||||
oscArgs := []osc.OSCArg{}
|
||||
oscMessage := osc.NewMessage(address)
|
||||
|
||||
for index, arg := range args {
|
||||
oscType := "s"
|
||||
@@ -115,15 +103,14 @@ func send(host string, port int32, address string, args []string, types []string
|
||||
oscType = types[index]
|
||||
}
|
||||
|
||||
oscArgs = append(oscArgs, argToTypedArg(arg, oscType))
|
||||
oscMessage.Append(argToTypedArg(arg, oscType))
|
||||
}
|
||||
|
||||
oscMessage := osc.OSCMessage{
|
||||
Address: address,
|
||||
Args: oscArgs,
|
||||
}
|
||||
oscMessageBuffer, err := oscMessage.MarshalBinary()
|
||||
|
||||
oscMessageBuffer := osc.ToBytes(oscMessage)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if slip {
|
||||
oscMessageBuffer = slipEncode(oscMessageBuffer)
|
||||
|
||||
Reference in New Issue
Block a user