ovly.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package main
  2. import (
  3. "fmt"
  4. "log"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "github.com/hypebeast/go-osc/osc"
  9. )
  10. func main() {
  11. // Setup and spawn the OSC server
  12. addr := "0.0.0.0:9137"
  13. d := osc.NewStandardDispatcher()
  14. // Screen bar handlers
  15. bar := NewScreenBar("DECRUNCH... Screen")
  16. d.AddMsgHandler("/party/bar/title/set", bar.setTitle)
  17. d.AddMsgHandler("/party/bar/t/reset", bar.reset)
  18. // Media player handlers
  19. player := NewMPV()
  20. d.AddMsgHandler("/party/media/play", player.play)
  21. d.AddMsgHandler("/party/media/stop", player.stop)
  22. d.AddMsgHandler("/party/media/volume", player.volume)
  23. // ATARI 800 XL emulator player handlers
  24. xl_emu := NewXLEmulator()
  25. d.AddMsgHandler("/party/emu/xl/play", xl_emu.play)
  26. d.AddMsgHandler("/party/emu/xl/stop", xl_emu.stop)
  27. d.AddMsgHandler("/party/emu/xl/volume", xl_emu.volume)
  28. // C64 handler
  29. c64 := C64{u1541_host: "http://192.168.7.64"}
  30. d.AddMsgHandler("/party/c64/reset", c64.reset)
  31. d.AddMsgHandler("/party/c64/reboot", c64.reboot)
  32. d.AddMsgHandler("/party/c64/run/sid", c64.sidplay)
  33. d.AddMsgHandler("/party/c64/run/prg", c64.runPRG)
  34. d.AddMsgHandler("/party/c64/drive/a/insert", c64.insertDisk)
  35. d.AddMsgHandler("/party/c64/send/keys", c64.sendKeys)
  36. // AMIGA 600 handler
  37. a600 := Amiga{host: "b600.local"}
  38. d.AddMsgHandler("/party/amiga/reset", a600.reset)
  39. d.AddMsgHandler("/party/amiga/drive/0/insert", a600.insertDisk)
  40. // AMIGA 1200/030 handler
  41. a1230 := Amiga{host: "b1200.local"}
  42. d.AddMsgHandler("/party/amiga/reset", a1230.reset)
  43. d.AddMsgHandler("/party/amiga/drive/0/insert", a1230.insertDisk)
  44. // Disable cursor, move it home and clear the terminal
  45. fmt.Print("[?25l")
  46. // Set up and start OSC server
  47. go func() {
  48. server := &osc.Server{Addr: addr, Dispatcher: d}
  49. if err := server.ListenAndServe(); err != nil {
  50. log.Fatal("error: ", err.Error())
  51. }
  52. }()
  53. // Wait for signal
  54. ch := make(chan os.Signal, 1)
  55. signal.Notify(
  56. ch, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT,
  57. )
  58. d.AddMsgHandler("/party/halt", func(msg *osc.Message) {
  59. ch <- syscall.SIGINT
  60. })
  61. <-ch
  62. // Defered enable cursor (futile)
  63. fmt.Println("[?25h")
  64. }