mirror of
https://github.com/jwetzell/osc-go.git
synced 2026-08-19 13:33:56 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1ad942e489 | |||
| e748adfa1c | |||
| 74a62f6287 | |||
| a1a550b4bb | |||
| c039245298 | |||
| 085bd082b4 | |||
| 048eb57d5a |
@@ -1,4 +1,4 @@
|
|||||||
name: "release go binaries for multiple os/arch"
|
name: "release go binaries for makeosc"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -36,7 +36,7 @@ jobs:
|
|||||||
- goarch: "386"
|
- goarch: "386"
|
||||||
goos: darwin
|
goos: darwin
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: wangyoucao577/go-release-action@v1
|
- uses: wangyoucao577/go-release-action@v1
|
||||||
with:
|
with:
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
name: "release go binaries for multiple os/arch"
|
name: "release go binaries for receiveosc"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -36,7 +36,7 @@ jobs:
|
|||||||
- goarch: "386"
|
- goarch: "386"
|
||||||
goos: darwin
|
goos: darwin
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: wangyoucao577/go-release-action@v1
|
- uses: wangyoucao577/go-release-action@v1
|
||||||
with:
|
with:
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
name: "release go binaries for multiple os/arch"
|
name: "release go binaries for sendosc"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -36,7 +36,7 @@ jobs:
|
|||||||
- goarch: "386"
|
- goarch: "386"
|
||||||
goos: darwin
|
goos: darwin
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v5
|
||||||
- uses: wangyoucao577/go-release-action@v1
|
- uses: wangyoucao577/go-release-action@v1
|
||||||
with:
|
with:
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
@@ -14,10 +15,11 @@ func main() {
|
|||||||
var Host string
|
var Host string
|
||||||
var Port int32
|
var Port int32
|
||||||
var Protocol string
|
var Protocol string
|
||||||
|
var Format string
|
||||||
|
|
||||||
cmd := &cli.Command{
|
cmd := &cli.Command{
|
||||||
Name: "makeosc",
|
Name: "receiveosc",
|
||||||
Usage: "make osc bytes",
|
Usage: "receive OSC messages via UDP or TCP",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "host",
|
Name: "host",
|
||||||
@@ -43,13 +45,25 @@ func main() {
|
|||||||
return nil
|
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 {
|
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||||
netAddress := fmt.Sprintf("%s:%d", Host, Port)
|
netAddress := fmt.Sprintf("%s:%d", Host, Port)
|
||||||
if Protocol == "udp" {
|
if Protocol == "udp" {
|
||||||
listenUDP(netAddress)
|
listenUDP(netAddress, Format)
|
||||||
} else if Protocol == "tcp" {
|
} else if Protocol == "tcp" {
|
||||||
listenTCP(netAddress)
|
listenTCP(netAddress, Format)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
@@ -60,7 +74,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func listenTCP(netAddress string) {
|
func listenTCP(netAddress string, format string) {
|
||||||
socket, err := net.Listen("tcp4", netAddress)
|
socket, err := net.Listen("tcp4", netAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
@@ -69,15 +83,13 @@ func listenTCP(netAddress string) {
|
|||||||
|
|
||||||
defer socket.Close()
|
defer socket.Close()
|
||||||
|
|
||||||
fmt.Printf("listening on %s (tcp w/ SLIP)\n", netAddress)
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
conn, err := socket.Accept()
|
conn, err := socket.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
go handleConnection(conn)
|
go handleConnection(conn, format)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,18 +139,18 @@ func (s *SLIP) decode(bytes []byte) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleMessages(slip SLIP) {
|
func handleSLIP(slip SLIP, format string) {
|
||||||
for message := range slip.Messages {
|
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{
|
slip := SLIP{
|
||||||
pendingBytes: []byte{},
|
pendingBytes: []byte{},
|
||||||
Messages: make(chan osc.OSCMessage),
|
Messages: make(chan osc.OSCMessage),
|
||||||
}
|
}
|
||||||
go handleMessages(slip)
|
go handleSLIP(slip, format)
|
||||||
|
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
buffer := make([]byte, 1024)
|
buffer := make([]byte, 1024)
|
||||||
@@ -154,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)
|
s, err := net.ResolveUDPAddr("udp4", netAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -168,8 +189,6 @@ func listenUDP(netAddress string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("listening on %s (udp)\n", netAddress)
|
|
||||||
|
|
||||||
defer connection.Close()
|
defer connection.Close()
|
||||||
buffer := make([]byte, 1024)
|
buffer := make([]byte, 1024)
|
||||||
|
|
||||||
@@ -185,6 +204,6 @@ func listenUDP(netAddress string) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
fmt.Println(oscMessage)
|
handleMessage(oscMessage, format)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ func main() {
|
|||||||
var Slip bool
|
var Slip bool
|
||||||
|
|
||||||
cmd := &cli.Command{
|
cmd := &cli.Command{
|
||||||
Name: "makeosc",
|
Name: "sendosc",
|
||||||
Usage: "make osc bytes",
|
Usage: "send OSC messages via UDP or TCP",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "host",
|
Name: "host",
|
||||||
|
|||||||
@@ -5,18 +5,18 @@ type OSCPacket interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type OSCBundle struct {
|
type OSCBundle struct {
|
||||||
Contents []OSCPacket
|
Contents []OSCPacket `json:"contents"`
|
||||||
TimeTag OSCTimeTag
|
TimeTag OSCTimeTag `json:"timeTag"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OSCArg struct {
|
type OSCArg struct {
|
||||||
Value any
|
Value any `json:"value"`
|
||||||
Type string
|
Type string `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OSCMessage struct {
|
type OSCMessage struct {
|
||||||
Address string
|
Address string `json:"address"`
|
||||||
Args []OSCArg
|
Args []OSCArg `json:"args"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type OSCColor struct {
|
type OSCColor struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user