|
@@ -1,126 +1,77 @@
|
|
|
package main
|
|
|
|
|
|
-import "fmt"
|
|
|
-import "log"
|
|
|
-import "time"
|
|
|
-import "os/exec"
|
|
|
-import "github.com/hypebeast/go-osc/osc"
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "log"
|
|
|
+ "os"
|
|
|
+ "os/signal"
|
|
|
+ "syscall"
|
|
|
|
|
|
-// Overlay object
|
|
|
-type Overlay struct {
|
|
|
- title string
|
|
|
- t int
|
|
|
- show_t bool
|
|
|
-}
|
|
|
-
|
|
|
-//type Title struct {
|
|
|
-// title string
|
|
|
-//}
|
|
|
-//
|
|
|
-//type Timer struct {
|
|
|
-// t int
|
|
|
-// visible bool
|
|
|
-//}
|
|
|
-
|
|
|
-//type MediaPlayer interface {
|
|
|
-// set() string
|
|
|
-//}
|
|
|
-
|
|
|
-//type Titler interface {
|
|
|
-// set() string
|
|
|
-//}
|
|
|
-//
|
|
|
-//func (tit *Title)set(title string) {
|
|
|
-// fmt.Print("[H[2J[3J")
|
|
|
-// fmt.Printf(" %-160s %6d ", title, t)
|
|
|
-//}
|
|
|
-
|
|
|
-// Updates title of bar in Overlay object
|
|
|
-func update_title(title string, t int) {
|
|
|
- fmt.Print("[H[2J[3J")
|
|
|
- fmt.Printf(" %-160s %6d ", title, t)
|
|
|
-}
|
|
|
-
|
|
|
-// Run executable
|
|
|
-func run(output chan string, cmd string, args ...string) {
|
|
|
- // Find executable
|
|
|
- path, err := exec.LookPath(cmd)
|
|
|
- if err != nil {
|
|
|
- fmt.Printf("can't find '%s'\n", cmd)
|
|
|
- } else {
|
|
|
- fmt.Printf("'%s' executable is in '%s'\n", cmd, path)
|
|
|
- }
|
|
|
-
|
|
|
- out, err := exec.Command(path, args...).Output()
|
|
|
- if err != nil {
|
|
|
- log.Print(err)
|
|
|
- }
|
|
|
- log.Printf("%s\n", out)
|
|
|
- output <- string(out)
|
|
|
-}
|
|
|
-
|
|
|
-// Play media file via mpv, osc message sets the file path
|
|
|
-func play(msg *osc.Message) {
|
|
|
- var uri string;
|
|
|
- ch := make(chan string)
|
|
|
- for _, arg := range msg.Arguments {
|
|
|
- switch arg.(type) {
|
|
|
- case string:
|
|
|
- uri = arg.(string)
|
|
|
- }
|
|
|
- }
|
|
|
- run(ch, "mpv", "-fs", "--audio-device=alsa/hdmi", uri)
|
|
|
-}
|
|
|
+ "github.com/hypebeast/go-osc/osc"
|
|
|
+)
|
|
|
|
|
|
func main() {
|
|
|
+ // Setup and spawn the OSC server
|
|
|
addr := "0.0.0.0:9137"
|
|
|
d := osc.NewStandardDispatcher()
|
|
|
- ovly := Overlay{"DECRUNCH Screen...", 0, true}
|
|
|
|
|
|
- d.AddMsgHandler("/8bus/ovly/title", func(msg *osc.Message) {
|
|
|
- for _, arg := range msg.Arguments {
|
|
|
- switch arg.(type) {
|
|
|
- case string:
|
|
|
- ovly.title = arg.(string)
|
|
|
- }
|
|
|
- }
|
|
|
- update_title(ovly.title, 0)
|
|
|
- })
|
|
|
-
|
|
|
- ticker := time.NewTicker(time.Second)
|
|
|
- d.AddMsgHandler("/8bus/ovly/timer/reset", func (msg *osc.Message) {
|
|
|
- ovly.t = 0
|
|
|
- ticker.Reset(time.Second)
|
|
|
- update_title(ovly.title, 0)
|
|
|
- })
|
|
|
+ // Screen bar handlers
|
|
|
+ bar := NewScreenBar("DECRUNCH... Screen")
|
|
|
+ d.AddMsgHandler("/party/bar/title/set", bar.setTitle)
|
|
|
+ d.AddMsgHandler("/party/bar/t/reset", bar.reset)
|
|
|
+
|
|
|
+ // Media player handlers
|
|
|
+ player := NewMPV()
|
|
|
+ d.AddMsgHandler("/party/media/play", player.play)
|
|
|
+ d.AddMsgHandler("/party/media/stop", player.stop)
|
|
|
+ d.AddMsgHandler("/party/media/volume", player.volume)
|
|
|
+
|
|
|
+ // ATARI 800 XL emulator player handlers
|
|
|
+ xl_emu := NewXLEmulator()
|
|
|
+ d.AddMsgHandler("/party/emu/xl/play", xl_emu.play)
|
|
|
+ d.AddMsgHandler("/party/emu/xl/stop", xl_emu.stop)
|
|
|
+ d.AddMsgHandler("/party/emu/xl/volume", xl_emu.volume)
|
|
|
+
|
|
|
+ // C64 handler
|
|
|
+ c64 := C64{u1541_host: "http://192.168.7.64"}
|
|
|
+ d.AddMsgHandler("/party/c64/reset", c64.reset)
|
|
|
+ d.AddMsgHandler("/party/c64/reboot", c64.reboot)
|
|
|
+ d.AddMsgHandler("/party/c64/run/sid", c64.sidplay)
|
|
|
+ d.AddMsgHandler("/party/c64/run/prg", c64.runPRG)
|
|
|
+ d.AddMsgHandler("/party/c64/drive/a/insert", c64.insertDisk)
|
|
|
+ d.AddMsgHandler("/party/c64/send/keys", c64.sendKeys)
|
|
|
+
|
|
|
+ // AMIGA 600 handler
|
|
|
+ a600 := Amiga{host: "b600.local"}
|
|
|
+ d.AddMsgHandler("/party/amiga/reset", a600.reset)
|
|
|
+ d.AddMsgHandler("/party/amiga/drive/0/insert", a600.insertDisk)
|
|
|
+
|
|
|
+ // AMIGA 1200/030 handler
|
|
|
+ a1230 := Amiga{host: "b1200.local"}
|
|
|
+ d.AddMsgHandler("/party/amiga/reset", a1230.reset)
|
|
|
+ d.AddMsgHandler("/party/amiga/drive/0/insert", a1230.insertDisk)
|
|
|
|
|
|
- d.AddMsgHandler("/8bus/ovly/video/play", play)
|
|
|
+ // Disable cursor, move it home and clear the terminal
|
|
|
+ fmt.Print("[?25l[H[2J[3J")
|
|
|
|
|
|
- // Main loop
|
|
|
- //done := make(chan bool)
|
|
|
+ // Set up and start OSC server
|
|
|
go func() {
|
|
|
- for {
|
|
|
- select {
|
|
|
- //case <-done:
|
|
|
- // return
|
|
|
- case <-ticker.C:
|
|
|
- ovly.t += 1
|
|
|
- update_title(ovly.title, ovly.t)
|
|
|
- }
|
|
|
+ server := &osc.Server{Addr: addr, Dispatcher: d}
|
|
|
+ if err := server.ListenAndServe(); err != nil {
|
|
|
+ log.Fatal("error: ", err.Error())
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
- // Disable cursor, move it home and clear the terminal
|
|
|
- fmt.Print("[?25l[H[2J[3J")
|
|
|
-
|
|
|
- // Set up and start OSC server
|
|
|
- server := &osc.Server{
|
|
|
- Addr: addr,
|
|
|
- Dispatcher: d,
|
|
|
- }
|
|
|
- server.ListenAndServe()
|
|
|
+ // Wait for signal
|
|
|
+ ch := make(chan os.Signal, 1)
|
|
|
+ signal.Notify(
|
|
|
+ ch, syscall.SIGHUP, syscall.SIGINT, syscall.SIGQUIT,
|
|
|
+ )
|
|
|
+ d.AddMsgHandler("/party/halt", func(msg *osc.Message) {
|
|
|
+ ch <- syscall.SIGINT
|
|
|
+ })
|
|
|
+ <-ch
|
|
|
|
|
|
- // Enable cursor
|
|
|
- fmt.Print("[?25h")
|
|
|
+ // Defered enable cursor (futile)
|
|
|
+ fmt.Println("[?25h")
|
|
|
}
|
|
|
-
|