From f721509d54832f02aa6cd7f7f8a0782dd551b79a Mon Sep 17 00:00:00 2001 From: Florrie Date: Thu, 31 May 2018 14:58:28 -0300 Subject: Playback indicator --- index.js | 2 +- players.js | 4 ++-- tui-lib | 2 +- ui.js | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 63 insertions(+), 14 deletions(-) diff --git a/index.js b/index.js index 6a3c8f8..5546f6d 100644 --- a/index.js +++ b/index.js @@ -55,7 +55,7 @@ async function main() { ] } - // let grouplike = require('./flat.json') + // grouplike = require('./flat.json') grouplike = updatePlaylistFormat(grouplike) diff --git a/players.js b/players.js index d1d0186..be5205f 100644 --- a/players.js +++ b/players.js @@ -41,7 +41,7 @@ function getTimeStrings({curHour, curMin, curSec, lenHour, lenMin, lenSec}) { duration = `${lenMin}:${lenSec}` } - return {percentDone, timeDone, timeLeft, duration} + return {percentDone, timeDone, timeLeft, duration, curSecTotal, lenSecTotal} } class Player extends EventEmitter { @@ -92,7 +92,7 @@ class Player extends EventEmitter { module.exports.MPVPlayer = class extends Player { getMPVOptions(file) { - return ['--no-audio-display', file] + return ['--no-video', file] } playFile(file) { diff --git a/tui-lib b/tui-lib index f267629..b7e7223 160000 --- a/tui-lib +++ b/tui-lib @@ -1 +1 @@ -Subproject commit f2676294c95695e2de3a7fb88eafae76d6827618 +Subproject commit b7e7223670328b4cba1c1454dd25057d24025b2b diff --git a/ui.js b/ui.js index 68c6d73..29a2e27 100644 --- a/ui.js +++ b/ui.js @@ -3,8 +3,10 @@ const { getPlayer } = require('./players') const { parentSymbol } = require('./playlist-utils') const ansi = require('./tui-lib/util/ansi') const Button = require('./tui-lib/ui/form/Button') +const DisplayElement = require('./tui-lib/ui/DisplayElement') const FocusElement = require('./tui-lib/ui/form/FocusElement') const Form = require('./tui-lib/ui/form/Form') +const Label = require('./tui-lib/ui/Label') const ListScrollForm = require('./tui-lib/ui/form/ListScrollForm') const Pane = require('./tui-lib/ui/Pane') const RecordStore = require('./record-store') @@ -41,10 +43,19 @@ class AppElement extends FocusElement { this.form.addInput(this.queueListingElement, false) this.queueListingElement.on('select', item => this.playGrouplikeItem(item)) + + this.playbackPane = new Pane() + this.addChild(this.playbackPane) + + this.playbackInfoElement = new PlaybackInfoElement() + this.playbackPane.addChild(this.playbackInfoElement) } async setup() { this.player = await getPlayer() + this.player.on('printStatusLine', data => { + this.playbackInfoElement.updateProgress(data) + }) } async shutdown() { @@ -57,16 +68,17 @@ class AppElement extends FocusElement { this.h = this.parent.contentH this.paneLeft.w = Math.max(Math.floor(0.8 * this.contentW), this.contentW - 80) - this.paneLeft.h = this.contentH + this.paneLeft.h = this.contentH - 4 this.paneRight.x = this.paneLeft.right this.paneRight.w = this.contentW - this.paneLeft.right - this.paneRight.h = this.contentH - - this.grouplikeListingElement.w = this.paneLeft.contentW - this.grouplikeListingElement.h = this.paneLeft.contentH - - this.queueListingElement.w = this.paneRight.contentW - this.queueListingElement.h = this.paneRight.contentH + this.paneRight.h = this.paneLeft.h + this.playbackPane.y = this.paneLeft.bottom + this.playbackPane.w = this.contentW + this.playbackPane.h = this.contentH - this.playbackPane.y + + this.grouplikeListingElement.fillParent() + this.queueListingElement.fillParent() + this.playbackInfoElement.fillParent() } keyPressed(keyBuf) { @@ -149,6 +161,7 @@ class AppElement extends FocusElement { await this.player.kill() this.recordStore.getRecord(item).playing = true this.playingTrack = item + this.playbackInfoElement.updateTrack(item) try { await this.player.playFile(downloadFile) } finally { @@ -255,9 +268,9 @@ class GrouplikeItemElement extends Button { writable.write(ansi.moveCursor(this.absTop, this.absLeft)) this.drawX = this.x this.writeStatus(writable) + writable.write(this.item.name.slice(0, this.w - this.drawX)) this.drawX += this.item.name.length - writable.write(this.item.name) - writable.write(' '.repeat(this.w - this.drawX)) + writable.write(' '.repeat(Math.max(0, this.w - this.drawX))) writable.write(ansi.resetAttributes()) } @@ -293,4 +306,40 @@ class GrouplikeItemElement extends Button { } } +class PlaybackInfoElement extends DisplayElement { + constructor() { + super() + + this.progressBarLabel = new Label('') + this.addChild(this.progressBarLabel) + + this.progressTextLabel = new Label('') + this.addChild(this.progressTextLabel) + + this.trackNameLabel = new Label('') + this.addChild(this.trackNameLabel) + } + + fixLayout() { + const centerX = el => el.x = Math.round((this.w - el.w) / 2) + centerX(this.progressTextLabel) + centerX(this.trackNameLabel) + + this.trackNameLabel.y = 0 + this.progressBarLabel.y = 1 + this.progressTextLabel.y = this.progressBarLabel.y + } + + updateProgress({timeDone, timeLeft, duration, lenSecTotal, curSecTotal}) { + this.progressBarLabel.text = '-'.repeat(Math.floor(this.w / lenSecTotal * curSecTotal)) + this.progressTextLabel.text = timeDone + ' / ' + duration + this.fixLayout() + } + + updateTrack(track) { + this.trackNameLabel.text = track.name + this.fixLayout() + } +} + module.exports.AppElement = AppElement -- cgit 1.3.0-6-gf8a5