mirror of
https://github.com/jwetzell/osc-go.git
synced 2026-07-26 10:28:42 +00:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1ad942e489 | |||
| e748adfa1c | |||
| 74a62f6287 | |||
| a1a550b4bb | |||
| c039245298 | |||
| 085bd082b4 | |||
| 0a4eff30b3 | |||
| 6482158fd6 | |||
| 6808c36e88 | |||
| 257465d216 | |||
| ce5e65e8f8 | |||
| e519f2d53c | |||
| 048eb57d5a | |||
| 039d4e6f1a | |||
| 87853b8ccb | |||
| d03f032e72 | |||
| 2f4b90fc16 | |||
| 278435e066 | |||
| b50dc9969f | |||
| 30ffe3a965 | |||
| 06e8ca7da3 |
@@ -1,5 +1,9 @@
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: 'github-actions'
|
||||
directory: '/'
|
||||
schedule:
|
||||
interval: 'weekly'
|
||||
- package-ecosystem: gomod
|
||||
directory: /
|
||||
schedule:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: "release go binaries for multiple os/arch"
|
||||
name: "release go binaries for makeosc"
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -36,13 +36,13 @@ jobs:
|
||||
- goarch: "386"
|
||||
goos: darwin
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: wangyoucao577/go-release-action@v1
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
goos: ${{ matrix.goos }}
|
||||
goarch: ${{ matrix.goarch }}
|
||||
goversion: "1.23.1"
|
||||
goversion: "1.25.1"
|
||||
project_path: "./cmd/makeosc"
|
||||
binary_name: "makeosc"
|
||||
asset_name: makeosc-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: "release go binaries for multiple os/arch"
|
||||
name: "release go binaries for receiveosc"
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -36,13 +36,13 @@ jobs:
|
||||
- goarch: "386"
|
||||
goos: darwin
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: wangyoucao577/go-release-action@v1
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
goos: ${{ matrix.goos }}
|
||||
goarch: ${{ matrix.goarch }}
|
||||
goversion: "1.23.1"
|
||||
goversion: "1.25.1"
|
||||
project_path: "./cmd/receiveosc"
|
||||
binary_name: "receiveosc"
|
||||
asset_name: receiveosc-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name: "release go binaries for multiple os/arch"
|
||||
name: "release go binaries for sendosc"
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -36,13 +36,13 @@ jobs:
|
||||
- goarch: "386"
|
||||
goos: darwin
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/checkout@v5
|
||||
- uses: wangyoucao577/go-release-action@v1
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
goos: ${{ matrix.goos }}
|
||||
goarch: ${{ matrix.goarch }}
|
||||
goversion: "1.23.1"
|
||||
goversion: "1.25.1"
|
||||
project_path: "./cmd/sendosc"
|
||||
binary_name: "sendosc"
|
||||
asset_name: sendosc-${{ matrix.goos }}-${{ matrix.goarch }}
|
||||
|
||||
+37
-11
@@ -1,13 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
osc "github.com/jwetzell/osc-go"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -16,18 +17,43 @@ func main() {
|
||||
var Types []string
|
||||
var Slip bool
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "sendosc",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmd := &cli.Command{
|
||||
Name: "makeosc",
|
||||
Usage: "make osc bytes",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "address",
|
||||
Value: "",
|
||||
Usage: "OSC address",
|
||||
Destination: &Address,
|
||||
Required: true,
|
||||
},
|
||||
&cli.StringSliceFlag{
|
||||
Name: "arg",
|
||||
Usage: "OSC args",
|
||||
Destination: &Args,
|
||||
},
|
||||
&cli.StringSliceFlag{
|
||||
Name: "type",
|
||||
Usage: "OSC types",
|
||||
Destination: &Types,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "slip",
|
||||
Value: false,
|
||||
Usage: "whether to slip encode the OSC Message bytes",
|
||||
Destination: &Slip,
|
||||
},
|
||||
},
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
make(Address, Args, Types, Slip)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
rootCmd.Flags().StringVar(&Address, "address", "", "OSC address")
|
||||
rootCmd.Flags().StringArrayVar(&Args, "arg", []string{}, "OSC args")
|
||||
rootCmd.Flags().StringArrayVar(&Types, "type", []string{}, "OSC types")
|
||||
rootCmd.Flags().BoolVar(&Slip, "slip", false, "whether to slip encode the OSC Message bytes")
|
||||
rootCmd.MarkFlagRequired("address")
|
||||
rootCmd.Execute()
|
||||
|
||||
if err := cmd.Run(context.Background(), os.Args); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func argToTypedArg(rawArg string, oscType string) osc.OSCArg {
|
||||
@@ -117,7 +143,7 @@ func slipEncode(bytes []byte) []byte {
|
||||
ESC_END := byte(0xdc)
|
||||
ESC_ESC := byte(0xdd)
|
||||
|
||||
var encodedBytes = []byte{}
|
||||
var encodedBytes = []byte{END}
|
||||
|
||||
for _, byteToEncode := range bytes {
|
||||
if byteToEncode == END {
|
||||
|
||||
@@ -1,36 +1,80 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
|
||||
osc "github.com/jwetzell/osc-go"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var Host string
|
||||
var Port string
|
||||
var Port int32
|
||||
var Protocol string
|
||||
var Format string
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "sendosc",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
netAddress := Host + ":" + Port
|
||||
cmd := &cli.Command{
|
||||
Name: "receiveosc",
|
||||
Usage: "receive OSC messages via UDP or TCP",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "host",
|
||||
Usage: "host to send OSC message to",
|
||||
Value: "127.0.0.1",
|
||||
Destination: &Host,
|
||||
},
|
||||
&cli.Int32Flag{
|
||||
Name: "port",
|
||||
Usage: "port to send OSC message to",
|
||||
Destination: &Port,
|
||||
Value: 8888,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "protocol",
|
||||
Usage: "protocol to use to send (tcp or udp)",
|
||||
Value: "udp",
|
||||
Destination: &Protocol,
|
||||
Validator: func(flag string) error {
|
||||
if flag != "udp" && flag != "tcp" {
|
||||
return fmt.Errorf("protocol must be either 'udp' or 'tcp'")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "format",
|
||||
Usage: "format for messages to be output in ('json')",
|
||||
Value: "json",
|
||||
Destination: &Format,
|
||||
Validator: func(flag string) error {
|
||||
if flag != "json" {
|
||||
return fmt.Errorf("format must be 'json'")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
},
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
netAddress := fmt.Sprintf("%s:%d", Host, Port)
|
||||
if Protocol == "udp" {
|
||||
listenUDP(netAddress)
|
||||
listenUDP(netAddress, Format)
|
||||
} else if Protocol == "tcp" {
|
||||
listenTCP(netAddress)
|
||||
listenTCP(netAddress, Format)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
rootCmd.Flags().StringVar(&Host, "host", "127.0.0.1", "host to send OSC message to")
|
||||
rootCmd.Flags().StringVar(&Port, "port", "8888", "port to send OSC message to")
|
||||
rootCmd.Flags().StringVar(&Protocol, "protocol", "udp", "protocol to use to send (tcp or udp)")
|
||||
rootCmd.Execute()
|
||||
|
||||
if err := cmd.Run(context.Background(), os.Args); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func listenTCP(netAddress string) {
|
||||
func listenTCP(netAddress string, format string) {
|
||||
socket, err := net.Listen("tcp4", netAddress)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
@@ -39,15 +83,13 @@ func listenTCP(netAddress string) {
|
||||
|
||||
defer socket.Close()
|
||||
|
||||
fmt.Printf("listening on %s (tcp w/ SLIP)\n", netAddress)
|
||||
|
||||
for {
|
||||
conn, err := socket.Accept()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
go handleConnection(conn)
|
||||
go handleConnection(conn, format)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +120,10 @@ func (s *SLIP) decode(bytes []byte) {
|
||||
}
|
||||
escapeNext = false
|
||||
} else if packetByte == END {
|
||||
if len(s.pendingBytes) > 0 {
|
||||
if len(s.pendingBytes) == 0 {
|
||||
// opening END byte, can discard
|
||||
continue
|
||||
} else {
|
||||
message, err := osc.MessageFromBytes(s.pendingBytes)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
@@ -94,18 +139,18 @@ func (s *SLIP) decode(bytes []byte) {
|
||||
|
||||
}
|
||||
|
||||
func handleMessages(slip SLIP) {
|
||||
func handleSLIP(slip SLIP, format string) {
|
||||
for message := range slip.Messages {
|
||||
fmt.Printf("%v\n", message)
|
||||
handleMessage(message, format)
|
||||
}
|
||||
}
|
||||
|
||||
func handleConnection(conn net.Conn) {
|
||||
func handleConnection(conn net.Conn, format string) {
|
||||
slip := SLIP{
|
||||
pendingBytes: []byte{},
|
||||
Messages: make(chan osc.OSCMessage),
|
||||
}
|
||||
go handleMessages(slip)
|
||||
go handleSLIP(slip, format)
|
||||
|
||||
defer conn.Close()
|
||||
buffer := make([]byte, 1024)
|
||||
@@ -121,7 +166,16 @@ func handleConnection(conn net.Conn) {
|
||||
}
|
||||
}
|
||||
|
||||
func listenUDP(netAddress string) {
|
||||
func handleMessage(message osc.OSCMessage, format string) {
|
||||
if format == "json" {
|
||||
jsonData, _ := json.Marshal(message)
|
||||
fmt.Println(string(jsonData))
|
||||
} else {
|
||||
fmt.Printf("%v\n", message)
|
||||
}
|
||||
}
|
||||
|
||||
func listenUDP(netAddress string, format string) {
|
||||
|
||||
s, err := net.ResolveUDPAddr("udp4", netAddress)
|
||||
if err != nil {
|
||||
@@ -135,8 +189,6 @@ func listenUDP(netAddress string) {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("listening on %s (udp)\n", netAddress)
|
||||
|
||||
defer connection.Close()
|
||||
buffer := make([]byte, 1024)
|
||||
|
||||
@@ -152,6 +204,6 @@ func listenUDP(netAddress string) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fmt.Println(oscMessage)
|
||||
handleMessage(oscMessage, format)
|
||||
}
|
||||
}
|
||||
|
||||
+63
-16
@@ -1,14 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
osc "github.com/jwetzell/osc-go"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -20,23 +22,68 @@ func main() {
|
||||
var Types []string
|
||||
var Slip bool
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "sendosc",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
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,
|
||||
},
|
||||
&cli.Int32Flag{
|
||||
Name: "port",
|
||||
Usage: "port to send OSC message to",
|
||||
Destination: &Port,
|
||||
Required: true,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "protocol",
|
||||
Usage: "protocol to use to send (tcp or udp)",
|
||||
Value: "udp",
|
||||
Destination: &Protocol,
|
||||
Validator: func(flag string) error {
|
||||
if flag != "udp" && flag != "tcp" {
|
||||
return fmt.Errorf("protocol must be either 'udp' or 'tcp'")
|
||||
}
|
||||
return nil
|
||||
},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "address",
|
||||
Usage: "OSC address",
|
||||
Destination: &Address,
|
||||
Required: true,
|
||||
},
|
||||
&cli.StringSliceFlag{
|
||||
Name: "arg",
|
||||
Usage: "OSC args",
|
||||
Value: []string{},
|
||||
Destination: &Args,
|
||||
},
|
||||
&cli.StringSliceFlag{
|
||||
Name: "type",
|
||||
Usage: "OSC types",
|
||||
Value: []string{},
|
||||
Destination: &Types,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "slip",
|
||||
Value: false,
|
||||
Usage: "whether to slip encode the OSC Message bytes",
|
||||
Destination: &Slip,
|
||||
},
|
||||
},
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
send(Host, Port, Address, Args, Types, Protocol, Slip)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
rootCmd.Flags().StringVar(&Host, "host", "", "host to send OSC message to")
|
||||
rootCmd.Flags().Int32Var(&Port, "port", 9999, "port to send OSC message to")
|
||||
rootCmd.Flags().StringVar(&Address, "address", "", "OSC address")
|
||||
rootCmd.Flags().StringVar(&Protocol, "protocol", "udp", "protocol to use to send (tcp or udp)")
|
||||
rootCmd.Flags().StringArrayVar(&Args, "arg", []string{}, "OSC args")
|
||||
rootCmd.Flags().StringArrayVar(&Types, "type", []string{}, "OSC types")
|
||||
rootCmd.Flags().BoolVar(&Slip, "slip", false, "whether to slip encode the OSC Message bytes")
|
||||
rootCmd.MarkFlagRequired("host")
|
||||
rootCmd.MarkFlagRequired("port")
|
||||
rootCmd.MarkFlagRequired("address")
|
||||
rootCmd.Execute()
|
||||
|
||||
if err := cmd.Run(context.Background(), os.Args); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func argToTypedArg(rawArg string, oscType string) osc.OSCArg {
|
||||
@@ -126,7 +173,7 @@ func slipEncode(bytes []byte) []byte {
|
||||
ESC_END := byte(0xdc)
|
||||
ESC_ESC := byte(0xdd)
|
||||
|
||||
var encodedBytes = []byte{}
|
||||
var encodedBytes = []byte{END}
|
||||
|
||||
for _, byteToEncode := range bytes {
|
||||
if byteToEncode == END {
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
module github.com/jwetzell/osc-go
|
||||
|
||||
go 1.23.1
|
||||
go 1.25.1
|
||||
|
||||
require github.com/spf13/cobra v1.8.1
|
||||
|
||||
require (
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
)
|
||||
require github.com/urfave/cli/v3 v3.4.1
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
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=
|
||||
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
|
||||
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/urfave/cli/v3 v3.4.1 h1:1M9UOCy5bLmGnuu1yn3t3CB4rG79Rtoxuv1sPhnm6qM=
|
||||
github.com/urfave/cli/v3 v3.4.1/go.mod h1:FJSKtM/9AiiTOJL4fJ6TbMUkxBXn7GO9guZqoZtpYpo=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
@@ -5,18 +5,18 @@ type OSCPacket interface {
|
||||
}
|
||||
|
||||
type OSCBundle struct {
|
||||
Contents []OSCPacket
|
||||
TimeTag OSCTimeTag
|
||||
Contents []OSCPacket `json:"contents"`
|
||||
TimeTag OSCTimeTag `json:"timeTag"`
|
||||
}
|
||||
|
||||
type OSCArg struct {
|
||||
Value any
|
||||
Type string
|
||||
Value any `json:"value"`
|
||||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type OSCMessage struct {
|
||||
Address string
|
||||
Args []OSCArg
|
||||
Address string `json:"address"`
|
||||
Args []OSCArg `json:"args"`
|
||||
}
|
||||
|
||||
type OSCColor struct {
|
||||
|
||||
Reference in New Issue
Block a user