main.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // @osc: the OSC client
  2. package main
  3. import (
  4. "log"
  5. "os"
  6. "strconv"
  7. "github.com/hypebeast/go-osc/osc"
  8. )
  9. func main() {
  10. // Check if we have all the required argumets to send the OSC message
  11. if len(os.Args) < 2 {
  12. log.New(os.Stderr, "", 0).Fatal("Usage: ", os.Args[0], " /osc/address [message...]")
  13. }
  14. host := os.Getenv("athost")
  15. if host == "" {
  16. host = "localhost"
  17. }
  18. atport := os.Getenv("atport")
  19. port, err := strconv.Atoi(atport)
  20. if err != nil {
  21. port = 9137
  22. }
  23. client := osc.NewClient(host, port)
  24. msg := osc.NewMessage(os.Args[1])
  25. have_string := false
  26. have_blob := false
  27. for _, arg := range os.Args[2:] {
  28. if have_string {
  29. msg.Append(arg)
  30. have_string = false
  31. } else if arg == "-s" {
  32. have_string = true
  33. } else if have_blob {
  34. content, err := os.ReadFile(arg)
  35. if err != nil {
  36. log.Print(err)
  37. }
  38. msg.Append(content)
  39. have_blob = false
  40. } else if arg == "-b" {
  41. have_blob = true
  42. } else if arg == "true" {
  43. msg.Append(true)
  44. } else if arg == "false" {
  45. msg.Append(false)
  46. } else if i, err := strconv.Atoi(arg); err == nil {
  47. msg.Append(int32(i))
  48. } else if f, err := strconv.ParseFloat(arg, 64); err == nil {
  49. msg.Append(float32(f))
  50. } else {
  51. msg.Append(arg)
  52. }
  53. }
  54. if err := client.Send(msg); err != nil {
  55. log.Fatal(err)
  56. }
  57. }