mirror of
https://github.com/jwetzell/osc-go.git
synced 2026-08-09 00:53:38 +00:00
switch to using the actual osc library here
This commit is contained in:
+47
-20
@@ -6,8 +6,7 @@ import (
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"github.com/hypebeast/go-osc/osc"
|
||||
|
||||
osc "github.com/jwetzell/osc-go"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -31,55 +30,84 @@ func main() {
|
||||
rootCmd.Execute()
|
||||
}
|
||||
|
||||
func argToTypedArg(rawArg string, oscType string) any {
|
||||
func argToTypedArg(rawArg string, oscType string) osc.OSCArg {
|
||||
|
||||
switch oscType {
|
||||
case "s":
|
||||
return rawArg
|
||||
return osc.OSCArg{
|
||||
Value: rawArg,
|
||||
Type: "s",
|
||||
}
|
||||
case "i":
|
||||
number, err := strconv.ParseInt(rawArg, 10, 32)
|
||||
if err != nil {
|
||||
// ... handle error
|
||||
panic(err)
|
||||
}
|
||||
return int32(number)
|
||||
return osc.OSCArg{
|
||||
Value: int32(number),
|
||||
Type: "i",
|
||||
}
|
||||
case "f":
|
||||
number, err := strconv.ParseFloat(rawArg, 32)
|
||||
if err != nil {
|
||||
// ... handle error
|
||||
panic(err)
|
||||
}
|
||||
return float32(number)
|
||||
return osc.OSCArg{
|
||||
Value: float32(number),
|
||||
Type: "f",
|
||||
}
|
||||
case "b":
|
||||
data, err := hex.DecodeString(rawArg)
|
||||
if err != nil {
|
||||
// ... handle error
|
||||
panic(err)
|
||||
}
|
||||
return data
|
||||
return osc.OSCArg{
|
||||
Value: data,
|
||||
Type: "b",
|
||||
}
|
||||
case "h":
|
||||
number, err := strconv.ParseInt(rawArg, 10, 64)
|
||||
if err != nil {
|
||||
// ... handle error
|
||||
panic(err)
|
||||
}
|
||||
return int64(number)
|
||||
return osc.OSCArg{
|
||||
Value: int64(number),
|
||||
Type: "h",
|
||||
}
|
||||
case "d":
|
||||
number, err := strconv.ParseFloat(rawArg, 64)
|
||||
if err != nil {
|
||||
// ... handle error
|
||||
panic(err)
|
||||
}
|
||||
return float64(number)
|
||||
return osc.OSCArg{
|
||||
Value: float64(number),
|
||||
Type: "d",
|
||||
}
|
||||
case "T":
|
||||
return true
|
||||
return osc.OSCArg{
|
||||
Value: true,
|
||||
Type: "T",
|
||||
}
|
||||
case "F":
|
||||
return false
|
||||
return osc.OSCArg{
|
||||
Value: false,
|
||||
Type: "F",
|
||||
}
|
||||
case "N":
|
||||
return nil
|
||||
return osc.OSCArg{
|
||||
Value: nil,
|
||||
Type: "N",
|
||||
}
|
||||
default:
|
||||
fmt.Print("unhandled osc type: ")
|
||||
fmt.Printf("%s.\n", oscType)
|
||||
return rawArg
|
||||
// TODO(jwetzell): something better than this like actual nil, err thing
|
||||
return osc.OSCArg{}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -107,7 +135,10 @@ func slipEncode(bytes []byte) []byte {
|
||||
|
||||
func make(address string, args []string, types []string, slip bool) {
|
||||
|
||||
oscMessage := osc.NewMessage(address)
|
||||
oscMessage := osc.OSCMessage{
|
||||
Address: address,
|
||||
Args: []osc.OSCArg{},
|
||||
}
|
||||
|
||||
for index, arg := range args {
|
||||
oscType := "s"
|
||||
@@ -115,14 +146,10 @@ func make(address string, args []string, types []string, slip bool) {
|
||||
oscType = types[index]
|
||||
}
|
||||
|
||||
oscMessage.Append(argToTypedArg(arg, oscType))
|
||||
oscMessage.Args = append(oscMessage.Args, argToTypedArg(arg, oscType))
|
||||
}
|
||||
|
||||
oscMessageBuffer, err := oscMessage.MarshalBinary()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
oscMessageBuffer := oscMessage.ToBytes()
|
||||
|
||||
if slip {
|
||||
oscMessageBuffer = slipEncode(oscMessageBuffer)
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/chabad360/go-osc/osc"
|
||||
osc "github.com/jwetzell/osc-go"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -50,7 +50,7 @@ func listen(netAddress string) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
oscMessage, err := osc.NewMessageFromData(buffer[0:bytesRead])
|
||||
oscMessage, err := osc.MessageFromBytes(buffer[0:bytesRead])
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
+49
-19
@@ -6,7 +6,7 @@ import (
|
||||
"net"
|
||||
"strconv"
|
||||
|
||||
"github.com/hypebeast/go-osc/osc"
|
||||
osc "github.com/jwetzell/osc-go"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
@@ -39,55 +39,84 @@ func main() {
|
||||
rootCmd.Execute()
|
||||
}
|
||||
|
||||
func argToTypedArg(rawArg string, oscType string) any {
|
||||
func argToTypedArg(rawArg string, oscType string) osc.OSCArg {
|
||||
|
||||
switch oscType {
|
||||
case "s":
|
||||
return rawArg
|
||||
return osc.OSCArg{
|
||||
Value: rawArg,
|
||||
Type: "s",
|
||||
}
|
||||
case "i":
|
||||
number, err := strconv.ParseInt(rawArg, 10, 32)
|
||||
if err != nil {
|
||||
// ... handle error
|
||||
panic(err)
|
||||
}
|
||||
return int32(number)
|
||||
return osc.OSCArg{
|
||||
Value: int32(number),
|
||||
Type: "i",
|
||||
}
|
||||
case "f":
|
||||
number, err := strconv.ParseFloat(rawArg, 32)
|
||||
if err != nil {
|
||||
// ... handle error
|
||||
panic(err)
|
||||
}
|
||||
return float32(number)
|
||||
return osc.OSCArg{
|
||||
Value: float32(number),
|
||||
Type: "f",
|
||||
}
|
||||
case "b":
|
||||
data, err := hex.DecodeString(rawArg)
|
||||
if err != nil {
|
||||
// ... handle error
|
||||
panic(err)
|
||||
}
|
||||
return data
|
||||
return osc.OSCArg{
|
||||
Value: data,
|
||||
Type: "b",
|
||||
}
|
||||
case "h":
|
||||
number, err := strconv.ParseInt(rawArg, 10, 64)
|
||||
if err != nil {
|
||||
// ... handle error
|
||||
panic(err)
|
||||
}
|
||||
return int64(number)
|
||||
return osc.OSCArg{
|
||||
Value: int64(number),
|
||||
Type: "h",
|
||||
}
|
||||
case "d":
|
||||
number, err := strconv.ParseFloat(rawArg, 64)
|
||||
if err != nil {
|
||||
// ... handle error
|
||||
panic(err)
|
||||
}
|
||||
return float64(number)
|
||||
return osc.OSCArg{
|
||||
Value: float64(number),
|
||||
Type: "d",
|
||||
}
|
||||
case "T":
|
||||
return true
|
||||
return osc.OSCArg{
|
||||
Value: true,
|
||||
Type: "T",
|
||||
}
|
||||
case "F":
|
||||
return false
|
||||
return osc.OSCArg{
|
||||
Value: false,
|
||||
Type: "F",
|
||||
}
|
||||
case "N":
|
||||
return nil
|
||||
return osc.OSCArg{
|
||||
Value: nil,
|
||||
Type: "N",
|
||||
}
|
||||
default:
|
||||
fmt.Print("unhandled osc type: ")
|
||||
fmt.Printf("%s.\n", oscType)
|
||||
return rawArg
|
||||
// TODO(jwetzell): something better than this like actual nil, err thing
|
||||
return osc.OSCArg{}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,22 +144,23 @@ func slipEncode(bytes []byte) []byte {
|
||||
|
||||
func send(host string, port int32, address string, args []string, types []string, protocol string, slip bool) {
|
||||
|
||||
oscMessage := osc.NewMessage(address)
|
||||
oscMessage := osc.OSCMessage{
|
||||
Address: address,
|
||||
Args: []osc.OSCArg{},
|
||||
}
|
||||
|
||||
for index, arg := range args {
|
||||
oscType := "s"
|
||||
if len(types) > index {
|
||||
oscType = types[index]
|
||||
}
|
||||
arg := argToTypedArg(arg, oscType)
|
||||
|
||||
oscMessage.Args = append(oscMessage.Args, arg)
|
||||
|
||||
oscMessage.Append(argToTypedArg(arg, oscType))
|
||||
}
|
||||
|
||||
oscMessageBuffer, err := oscMessage.MarshalBinary()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
oscMessageBuffer := oscMessage.ToBytes()
|
||||
|
||||
if slip {
|
||||
oscMessageBuffer = slipEncode(oscMessageBuffer)
|
||||
|
||||
@@ -2,11 +2,7 @@ module github.com/jwetzell/osc-go
|
||||
|
||||
go 1.23.1
|
||||
|
||||
require (
|
||||
github.com/chabad360/go-osc v0.0.0-20220502185613-216f362cdf0a
|
||||
github.com/hypebeast/go-osc v0.0.0-20220308234300-cec5a8a1e5f5
|
||||
github.com/spf13/cobra v1.8.1
|
||||
)
|
||||
require github.com/spf13/cobra v1.8.1
|
||||
|
||||
require (
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
github.com/chabad360/go-osc v0.0.0-20220502185613-216f362cdf0a h1:MTor/GgULww+hISVbeiNuC5vyT1mc2xa6/14ib0lvyc=
|
||||
github.com/chabad360/go-osc v0.0.0-20220502185613-216f362cdf0a/go.mod h1:/aAn5LNn+s7zq33XItIcYLr6aOntVkWckHPAG40yeUc=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/hypebeast/go-osc v0.0.0-20220308234300-cec5a8a1e5f5 h1:fqwINudmUrvGCuw+e3tedZ2UJ0hklSw6t8UPomctKyQ=
|
||||
github.com/hypebeast/go-osc v0.0.0-20220308234300-cec5a8a1e5f5/go.mod h1:lqMjoCs0y0GoRRujSPZRBaGb4c5ER6TfkFKSClxkMbY=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
|
||||
Reference in New Issue
Block a user