main.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. //log.Println("Parsed string:", arg)
  32. } else if arg == "-s" {
  33. have_string = true
  34. } else if have_blob {
  35. content, err := os.ReadFile(arg)
  36. if err != nil {
  37. log.Print(err)
  38. }
  39. msg.Append(content)
  40. have_blob = false
  41. //log.Println("Parsed blob...")
  42. } else if arg == "-b" {
  43. have_blob = true
  44. } else if arg == "true" {
  45. msg.Append(true)
  46. //log.Println("Parsed bool:", true)
  47. } else if arg == "false" {
  48. msg.Append(false)
  49. //log.Println("Parsed bool:", false)
  50. } else if i, err := strconv.Atoi(arg); err == nil {
  51. msg.Append(int32(i))
  52. //log.Println("Parsed int:", i)
  53. } else if f, err := strconv.ParseFloat(arg, 64); err == nil {
  54. msg.Append(float32(f))
  55. //log.Println("Parsed float:", f)
  56. } else {
  57. msg.Append(arg)
  58. //log.Println("Parsed string:", arg)
  59. }
  60. }
  61. if err := client.Send(msg); err != nil {
  62. log.Fatal(err)
  63. }
  64. }