|
@@ -0,0 +1,126 @@
|
|
|
|
+package main
|
|
|
|
+
|
|
|
|
+import "fmt"
|
|
|
|
+import "log"
|
|
|
|
+import "time"
|
|
|
|
+import "os/exec"
|
|
|
|
+import "github.com/hypebeast/go-osc/osc"
|
|
|
|
+
|
|
|
|
+// 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)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func main() {
|
|
|
|
+ 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)
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ d.AddMsgHandler("/8bus/ovly/video/play", play)
|
|
|
|
+
|
|
|
|
+ // Main loop
|
|
|
|
+ //done := make(chan bool)
|
|
|
|
+ go func() {
|
|
|
|
+ for {
|
|
|
|
+ select {
|
|
|
|
+ //case <-done:
|
|
|
|
+ // return
|
|
|
|
+ case <-ticker.C:
|
|
|
|
+ ovly.t += 1
|
|
|
|
+ update_title(ovly.title, ovly.t)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+
|
|
|
|
+ // 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()
|
|
|
|
+
|
|
|
|
+ // Enable cursor
|
|
|
|
+ fmt.Print("[?25h")
|
|
|
|
+}
|
|
|
|
+
|