|
@@ -0,0 +1,71 @@
|
|
|
+// @osc: the OSC client
|
|
|
+
|
|
|
+package main
|
|
|
+
|
|
|
+import (
|
|
|
+ "log"
|
|
|
+ "os"
|
|
|
+ "strconv"
|
|
|
+ "github.com/hypebeast/go-osc/osc"
|
|
|
+)
|
|
|
+
|
|
|
+func main() {
|
|
|
+ // Check if we have all the required argumets to send the OSC message
|
|
|
+ if len(os.Args) < 2 {
|
|
|
+ log.New(os.Stderr, "", 0).Fatal("Usage: ", os.Args[0], " /osc/address [message...]")
|
|
|
+ }
|
|
|
+
|
|
|
+ host := os.Getenv("athost")
|
|
|
+ if host == "" {
|
|
|
+ host = "localhost"
|
|
|
+ }
|
|
|
+ atport := os.Getenv("atport")
|
|
|
+ port, err := strconv.Atoi(atport)
|
|
|
+ if err != nil {
|
|
|
+ port = 9137
|
|
|
+ }
|
|
|
+
|
|
|
+ client := osc.NewClient(host, port)
|
|
|
+ msg := osc.NewMessage(os.Args[1])
|
|
|
+
|
|
|
+ have_string := false
|
|
|
+ have_blob := false
|
|
|
+ for _, arg := range os.Args[2:] {
|
|
|
+ if have_string {
|
|
|
+ msg.Append(arg)
|
|
|
+ have_string = false
|
|
|
+ //log.Println("Parsed string:", arg)
|
|
|
+ } else if arg == "-s" {
|
|
|
+ have_string = true
|
|
|
+ } else if have_blob {
|
|
|
+ content, err := os.ReadFile(arg)
|
|
|
+ if err != nil {
|
|
|
+ log.Print(err)
|
|
|
+ }
|
|
|
+ msg.Append(content)
|
|
|
+ have_blob = false
|
|
|
+ //log.Println("Parsed blob...")
|
|
|
+ } else if arg == "-b" {
|
|
|
+ have_blob = true
|
|
|
+ } else if arg == "true" {
|
|
|
+ msg.Append(true)
|
|
|
+ //log.Println("Parsed bool:", true)
|
|
|
+ } else if arg == "false" {
|
|
|
+ msg.Append(false)
|
|
|
+ //log.Println("Parsed bool:", false)
|
|
|
+ } else if i, err := strconv.Atoi(arg); err == nil {
|
|
|
+ msg.Append(int32(i))
|
|
|
+ //log.Println("Parsed int:", i)
|
|
|
+ } else if f, err := strconv.ParseFloat(arg, 64); err == nil {
|
|
|
+ msg.Append(float32(f))
|
|
|
+ //log.Println("Parsed float:", f)
|
|
|
+ } else {
|
|
|
+ msg.Append(arg)
|
|
|
+ //log.Println("Parsed string:", arg)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if err := client.Send(msg); err != nil {
|
|
|
+ log.Fatal(err)
|
|
|
+ }
|
|
|
+}
|