Ver código fonte

initial simple primary prototype

blackwine 6 meses atrás
commit
17ff780e2b
5 arquivos alterados com 175 adições e 0 exclusões
  1. 13 0
      Makefile
  2. 27 0
      README.md
  3. 7 0
      go.mod
  4. 2 0
      go.sum
  5. 126 0
      ovly.go

+ 13 - 0
Makefile

@@ -0,0 +1,13 @@
+dir_guard=@mkdir -p $(@D)
+
+all: ovly
+
+ovly: ovly.go
+	go build $^
+
+put: build/ovly.linux_amd64
+
+build/ovly.linux_amd64: ovly.go
+	$(dir_guard)
+	GOOS=linux GOARCH=amd64 go build -o build/ovly.linux_amd64 ovly.go
+	scp $@ xuj.local:/usr/local/bin/ovly

+ 27 - 0
README.md

@@ -0,0 +1,27 @@
+API
+===
+
+OSC API 
+
+overlay
+---------
+
+    /8bus/ovly/title           - sets title bar (string)
+    /8bus/ovly/timer/reset     - reset timer (void)
+
+player
+------
+
+    /8bus/entry/1/play         - 
+    /8bus/entry/2/stop         - 
+    /8bus/entry/3/set_path     - 
+    /8bus/entry/next           - 
+    /8bus/entry/prev           - 
+    /8bus/entry/set            - 
+    /8bus/compo/set            - 
+
+future enhancements
+-------------------
+
+    /8bus/ovly/timer/format    - "s": seconds, "m": minutes:seconds
+

+ 7 - 0
go.mod

@@ -0,0 +1,7 @@
+module 8bus
+
+go 1.22.4
+
+require (
+	github.com/hypebeast/go-osc v0.0.0-20220308234300-cec5a8a1e5f5 // indirect
+)

+ 2 - 0
go.sum

@@ -0,0 +1,2 @@
+github.com/hypebeast/go-osc v0.0.0-20220308234300-cec5a8a1e5f5 h1:fqwINudmUrvGCuw+e3tedZ2UJ0hklSw6t8UPomctKyQ=
+github.com/hypebeast/go-osc v0.0.0-20220308234300-cec5a8a1e5f5/go.mod h1:lqMjoCs0y0GoRRujSPZRBaGb4c5ER6TfkFKSClxkMbY=

+ 126 - 0
ovly.go

@@ -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("")
+//	fmt.Printf("      %-160s %6d  ", title, t)
+//}
+
+// Updates title of bar in Overlay object
+func update_title(title string, t int) {
+	fmt.Print("")
+	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")
+
+	// Set up and start OSC server
+	server := &osc.Server{
+		Addr:       addr,
+		Dispatcher: d,
+	}
+	server.ListenAndServe()
+
+	// Enable cursor
+	fmt.Print("[?25h")
+}
+