|
|
|
@ -5,6 +5,7 @@ import (
@@ -5,6 +5,7 @@ import (
|
|
|
|
|
"fmt" |
|
|
|
|
"log" |
|
|
|
|
"net" |
|
|
|
|
"path" |
|
|
|
|
"strings" |
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
@ -16,8 +17,11 @@ import (
@@ -16,8 +17,11 @@ import (
|
|
|
|
|
var ( |
|
|
|
|
app *cview.Application |
|
|
|
|
|
|
|
|
|
editorPaused bool |
|
|
|
|
statusBuffer *cview.TextView |
|
|
|
|
editorPaused bool |
|
|
|
|
statusBuffer *cview.TextView |
|
|
|
|
lengthBuffer *cview.TextView |
|
|
|
|
slider *cview.Slider |
|
|
|
|
castInfoBuffer *cview.TextView |
|
|
|
|
|
|
|
|
|
editorCursor time.Duration |
|
|
|
|
editorCursorTime time.Time |
|
|
|
@ -57,14 +61,28 @@ func updateStatus() {
@@ -57,14 +61,28 @@ func updateStatus() {
|
|
|
|
|
if !editorPaused && editorStatus == "playing" { |
|
|
|
|
cursor += time.Since(editorCursorTime) |
|
|
|
|
} |
|
|
|
|
statusBuffer.SetText(fmt.Sprintf("%d:%02d", int(cursor.Minutes())%60, int(cursor.Seconds())%60)) |
|
|
|
|
ms := ((cursor.Nanoseconds() / int64(time.Millisecond)) % 1000) / 100 |
|
|
|
|
statusBuffer.SetText(fmt.Sprintf("%d:%02d.%d", int(cursor.Minutes()), int(cursor.Seconds())%60, ms)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func updateSlider() { |
|
|
|
|
lengthBuffer.SetText(fmt.Sprintf("%d:%02d", int(loadedCastLength.Minutes()), int(loadedCastLength.Seconds())%60)) |
|
|
|
|
slider.SetProgress(int(float64(editorCursor) / float64(loadedCastLength) * 100)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func handleUpdateUI() { |
|
|
|
|
t := time.NewTicker(time.Second) |
|
|
|
|
t := time.NewTicker(100 * time.Millisecond) |
|
|
|
|
i := 0 |
|
|
|
|
for range t.C { |
|
|
|
|
updateStatus() |
|
|
|
|
if i == 0 { |
|
|
|
|
updateSlider() |
|
|
|
|
} |
|
|
|
|
app.Draw() |
|
|
|
|
i++ |
|
|
|
|
if i > 9 { |
|
|
|
|
i = 0 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -103,7 +121,31 @@ func runEditor(controlAddress string, force bool) {
@@ -103,7 +121,31 @@ func runEditor(controlAddress string, force bool) {
|
|
|
|
|
|
|
|
|
|
statusBuffer = cview.NewTextView() |
|
|
|
|
|
|
|
|
|
app.SetRoot(statusBuffer, true) |
|
|
|
|
lengthBuffer = cview.NewTextView() |
|
|
|
|
lengthBuffer.SetTextAlign(cview.AlignRight) |
|
|
|
|
lengthBuffer.SetText("0:00") |
|
|
|
|
|
|
|
|
|
sliderChanged := func(value int) { |
|
|
|
|
c := time.Duration(float64(loadedCastLength) * (float64(value) / 100)) |
|
|
|
|
sendCommand(&command{commandPlay, c, ""}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
slider = cview.NewSlider() |
|
|
|
|
slider.SetChangedFunc(sliderChanged) |
|
|
|
|
|
|
|
|
|
castInfoBuffer = cview.NewTextView() |
|
|
|
|
castInfoBuffer.SetTextAlign(cview.AlignCenter) |
|
|
|
|
|
|
|
|
|
grid := cview.NewGrid() |
|
|
|
|
grid.SetRows(-1, 1, 3, -1) |
|
|
|
|
grid.AddItem(cview.NewTextView(), 0, 0, 1, 2, 0, 0, true) |
|
|
|
|
grid.AddItem(statusBuffer, 1, 0, 1, 1, 0, 0, false) |
|
|
|
|
grid.AddItem(lengthBuffer, 1, 1, 1, 1, 0, 0, false) |
|
|
|
|
grid.AddItem(slider, 2, 0, 1, 2, 0, 0, true) |
|
|
|
|
grid.AddItem(castInfoBuffer, 3, 0, 1, 2, 0, 0, true) |
|
|
|
|
grid.AddItem(cview.NewTextView(), 4, 0, 1, 2, 0, 0, true) |
|
|
|
|
|
|
|
|
|
app.SetRoot(grid, true) |
|
|
|
|
|
|
|
|
|
quit := func(ev *tcell.EventKey) *tcell.EventKey { |
|
|
|
|
app.Stop() |
|
|
|
@ -136,7 +178,6 @@ func runEditor(controlAddress string, force bool) {
@@ -136,7 +178,6 @@ func runEditor(controlAddress string, force bool) {
|
|
|
|
|
c := editorCursor + 5*time.Second |
|
|
|
|
editorCursor = c |
|
|
|
|
sendCommand(&command{commandPlay, c, ""}) |
|
|
|
|
updateStatus() |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -147,7 +188,6 @@ func runEditor(controlAddress string, force bool) {
@@ -147,7 +188,6 @@ func runEditor(controlAddress string, force bool) {
|
|
|
|
|
} |
|
|
|
|
editorCursor = c |
|
|
|
|
sendCommand(&command{commandPlay, c, ""}) |
|
|
|
|
updateStatus() |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -164,6 +204,13 @@ func runEditor(controlAddress string, force bool) {
@@ -164,6 +204,13 @@ func runEditor(controlAddress string, force bool) {
|
|
|
|
|
|
|
|
|
|
go handleUpdateUI() |
|
|
|
|
|
|
|
|
|
err = loadCast(filePath) |
|
|
|
|
if err != nil { |
|
|
|
|
log.Fatalf("failed to load cast at %s: %s", filePath, err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
castInfoBuffer.SetText(path.Base(filePath)) |
|
|
|
|
|
|
|
|
|
castCommand <- &command{commandLoad, 0, filePath} |
|
|
|
|
castCommand <- &command{commandPlay, 0, ""} |
|
|
|
|
|
|
|
|
|