Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1 Rewite #3

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
60740b5
rewriting decoding
chabad360 Jan 28, 2022
3084e55
Seperated copy logic into public api wrappers
chabad360 Jan 30, 2022
1ed733f
reworked the message encoding (had to touch bundles as a side effect).
chabad360 Jan 31, 2022
d0114f2
check this commit to see how I got down to just a single copy with th…
chabad360 Jan 31, 2022
7959545
Never forget to test (still have more to write), and never, ever forg…
chabad360 Jan 31, 2022
a3803bf
Slowly fixing up some stuff, added a codegen that can take raw sample…
chabad360 Feb 1, 2022
893d80a
added and moved around a number of tests. Gonna do a double check and…
chabad360 Feb 2, 2022
727f4f6
caught a few small things, and added some tests for time tags, I'll a…
chabad360 Feb 3, 2022
fe87912
caught a bug, and started work on the server system.
chabad360 Feb 3, 2022
6b4ac5f
Reworked the dispatcher and kinda touched a lot of other stuff my acc…
chabad360 Feb 9, 2022
943feb9
Make new dispatcher tests and catch some bugs in the process
chabad360 Feb 11, 2022
7bdeb94
As much as I hate the server tests, I don't really have patience to r…
chabad360 Feb 16, 2022
a866abb
decided to play with fuzzing.
chabad360 Feb 16, 2022
2ffe7a7
fixed up the errors a lot.
chabad360 Feb 16, 2022
69da862
Rewrote the client, not sure if it's the best, but the original versi…
chabad360 Feb 16, 2022
6d06794
update examples
chabad360 Feb 16, 2022
8bd37a2
tidied things up
chabad360 Feb 16, 2022
0f69c83
made this example look nicer
chabad360 Feb 16, 2022
8894d29
update readme a little
chabad360 Feb 16, 2022
1229c4f
don't write if the conn is nil
chabad360 Feb 17, 2022
c2e3ef7
look more like the httpserver design
chabad360 May 5, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
branches: [ master ]

jobs:

build:
runs-on: ubuntu-latest
steps:
Expand All @@ -22,4 +21,10 @@ jobs:
run: go build -v ./osc

- name: Test
run: go test -v ./osc
run: go test -json ./osc > test.json

- name: Annotate tests
if: always()
uses: guyarb/[email protected]
with:
test-results: test.json
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,5 @@
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Ignore coverage reports
coverage.out
# IntelliJ Files
.idea/
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

5 changes: 0 additions & 5 deletions CHANGELOG.md

This file was deleted.

1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
The MIT License (MIT)

Copyright (c) 2014 - 2015 Sebastian Ruml <[email protected]>
Copyright (c) 2021 - 2022 Mendel Greenberg <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
40 changes: 0 additions & 40 deletions Makefile

This file was deleted.

69 changes: 29 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,40 @@
# GoOSC

[![Build Status](https://travis-ci.org/hypebeast/go-osc.png?branch=master)](https://travis-ci.org/hypebeast/go-osc) [![GoDoc](https://godoc.org/github.com/hypebeast/go-osc/osc?status.svg)](https://godoc.org/github.com/hypebeast/go-osc/osc) [![Coverage Status](https://coveralls.io/repos/github/hypebeast/go-osc/badge.svg?branch=master)](https://coveralls.io/github/hypebeast/go-osc?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/hypebeast/go-osc)](https://goreportcard.com/report/github.com/hypebeast/go-osc)
[![GoDoc](https://godoc.org/github.com/chabad360/go-osc?status.svg)](https://godoc.org/github.com/chabad360/go-osc)
[![Go](https://github.com/chabad360/go-osc/actions/workflows/go.yml/badge.svg)](https://github.com/chabad360/go-osc/actions/workflows/go.yml)

[Open Sound Control (OSC)](http://opensoundcontrol.org/introduction-osc) library for Golang. Implemented in pure Go.

## Features

- OSC Bundles, including timetags
- OSC Bundles
- OSC Messages
- OSC Client
- OSC Server
- Support for OSC address pattern matching
- Supports the following OSC argument types:
- 'i' (Int32)
- 'f' (Float32)
- 's' (string)
- 'b' (blob / binary data)
- 'h' (Int64)
- 't' (OSC timetag)
- 'd' (Double/int64)
- 'T' (True)
- 'F' (False)
- 'N' (Nil)
- Support for OSC address pattern including '\*', '?', '{,}' and '[]' wildcards

## Install

```shell
go get github.com/hypebeast/go-osc
```

- `i` (Int32)
- `f` (Float32)
- `s` (string)
- `b` (blob / binary data)
- `h` (Int64)
- `t` (OSC timetag)
- `d` (Double/int64)
- `T` (True)
- `F` (False)
- `N` (Nil)

## Usage

### Client

```go
import "github.com/hypebeast/go-osc/osc"
package main

import "github.com/chabad360/go-osc/osc"

func main() {
client := osc.NewClient("localhost", 8765)
msg := osc.NewMessage("/osc/address")
msg.Append(int32(111))
msg.Append(true)
msg.Append("hello")
client, _ := osc.Dial("localhost:8765")
msg := osc.NewMessage("/osc/address", int32(111), true, "hello")
client.Send(msg)
}
```
Expand All @@ -52,25 +44,22 @@ func main() {
```go
package main

import "github.com/hypebeast/go-osc/osc"
import (
"fmt"
"github.com/chabad360/go-osc/osc"
)

func main() {
addr := "127.0.0.1:8765"
d := osc.NewStandardDispatcher()
d.AddMsgHandler("/message/address", func(msg *osc.Message) {
osc.PrintMessage(msg)
d := &osc.Dispatcher{}
d.AddMethod("/message/address", func(msg *osc.Message) {
fmt.Println(msg)
})

server := &osc.Server{
Addr: addr,
Dispatcher:d,
Addr: addr,
Handler: d.Dispatch,
}
server.ListenAndServe()
}
```

## Tests

```shell
make test
```
68 changes: 17 additions & 51 deletions examples/basic_server/basic_server.go
Original file line number Diff line number Diff line change
@@ -1,67 +1,33 @@
package main

import (
"bufio"
"fmt"
"net"
"os"

"github.com/chabad360/go-osc/osc"
"net"
)

func main() {
addr := "127.0.0.1:8765"
server := &osc.Server{}
conn, err := net.ListenPacket("udp", addr)
if err != nil {
fmt.Println("Couldn't listen: ", err)
}
defer conn.Close()

fmt.Println("### Welcome to go-osc receiver demo")
fmt.Println("Press \"q\" to exit")

go func() {
fmt.Println("Start listening on", addr)
addr := "127.0.0.1:7001"

for {
packet, err := server.ReceivePacket(conn)
if err != nil {
fmt.Println("Server error: " + err.Error())
os.Exit(1)
}
fmt.Println("### Welcome to go-osc server demo")

if packet != nil {
switch packet.(type) {
default:
fmt.Println("Unknow packet type!")

case *osc.Message:
fmt.Printf("-- OSC Message: ")
osc.PrintMessage(packet.(*osc.Message))

case *osc.Bundle:
fmt.Println("-- OSC Bundle:")
bundle := packet.(*osc.Bundle)
for i, message := range bundle.Messages {
fmt.Printf(" -- OSC Message #%d: ", i+1)
osc.PrintMessage(message)
}
}
}
}
}()
fmt.Println("Start listening on", addr)
fmt.Println(osc.ListenAndServe(addr, handle))
}

reader := bufio.NewReader(os.Stdin)
func handle(packet osc.Packet, addr net.Addr) {
switch p := packet.(type) {
default:
fmt.Println("Unknown packet type!")

for {
c, err := reader.ReadByte()
if err != nil {
os.Exit(0)
}
case *osc.Message:
fmt.Printf("-- OSC Message (%s):\tAddress: \"%s\"\tArguments: %v\n", addr, p.Address, p.Arguments)

if c == 'q' {
os.Exit(0)
case *osc.Bundle:
fmt.Printf("-- OSC Bundle (%s):\tTimeTag: %v\tElements: %d\n", addr, p.Timetag.Time(), len(p.Elements))
for _, p := range p.Elements {
fmt.Printf("\t")
handle(p, addr)
}
}
}
41 changes: 14 additions & 27 deletions examples/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ package main
import (
"bufio"
"fmt"
"github.com/chabad360/go-osc/osc"
"io"
"os"
"strings"
"time"

"github.com/chabad360/go-osc/osc"
)

// TODO: Revise the client!
func main() {
ip := "localhost"
port := 8765
client := osc.NewClient(ip, port)
addr := "localhost:8765"
client, err := osc.Dial(addr)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

fmt.Println("### Welcome to go-osc transmitter demo")
fmt.Println("Please, select the OSC packet type you would like to send:")
Expand All @@ -38,28 +39,14 @@ func main() {

sline := strings.TrimRight(string(line), "\n")
if sline == "m" {
message := osc.NewMessage("/message/address")
message.Append(int32(12345))
message.Append("teststring")
message.Append(true)
message.Append(false)
client.Send(message)
message := osc.NewMessage("/message/address", int32(12345), "teststring", true, false)
fmt.Println(client.Send(message))
} else if sline == "b" {
bundle := osc.NewBundle(time.Now())
message1 := osc.NewMessage("/bundle/message/1")
message1.Append(int32(12345))
message1.Append("teststring")
message1.Append(true)
message1.Append(false)
message2 := osc.NewMessage("/bundle/message/2")
message2.Append(int32(3344))
message2.Append(float32(101.9))
message2.Append("string1")
message2.Append("string2")
message2.Append(true)
bundle.Append(message1)
bundle.Append(message2)
client.Send(bundle)
message1 := osc.NewMessage("/bundle/message/1", int32(12345), "teststring", true, false)
message2 := osc.NewMessage("/bundle/message/2", int32(3344), float32(101.9), "string1", "string2", true)

bundle := osc.NewBundle(message1, message2)
fmt.Println(client.Send(bundle))
} else if sline == "q" {
fmt.Println("Exit!")
os.Exit(0)
Expand Down
20 changes: 8 additions & 12 deletions examples/dispatching_server/dispatching_server.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package main

import "github.com/chabad360/go-osc/osc"
import (
"fmt"
"github.com/chabad360/go-osc/osc"
)

func main() {
addr := "127.0.0.1:8765"

d := osc.NewStandardDispatcher()
d.AddMsgHandler("/message/address", func(msg *osc.Message) {
osc.PrintMessage(msg)
d := &osc.Dispatcher{}
d.AddMethodFunc("/message/address", func(msg *osc.Message) {
fmt.Println(msg.Address, msg.Arguments)
})
server := &osc.Server{
Addr: addr,
Dispatcher: d,
}

server.ListenAndServe()
osc.ListenAndServe("127.0.0.1:8765", d.Dispatch)
}
10 changes: 0 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
module github.com/chabad360/go-osc

go 1.17

require (
github.com/dvyukov/go-fuzz v0.0.0-20210914135545-4980593459a1 // indirect
github.com/elazarl/go-bindata-assetfs v1.0.1 // indirect
github.com/stephens2424/writerset v1.0.2 // indirect
golang.org/x/mod v0.5.1 // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
golang.org/x/tools v0.1.8 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
)
Loading