From 5762a825d589704a53aaabb425d9470c726bbc0d Mon Sep 17 00:00:00 2001 From: Florrie Date: Thu, 24 Jan 2019 23:32:42 -0400 Subject: (v), (V) - Volume controls "v" increases because it's lowercase and therefore more likely to be accidentally pressed, hence more likely to confuse the user when it decreases the volume (if it decreased the volume - since it increases the volume, it generally doesn't seem to have any effect until you've already discovered that v and V are used for volume controls). --- README.md | 1 + players.js | 8 ++++++-- todo.txt | 3 +++ ui.js | 15 +++++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index abd8183..5c95677 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ You're also welcome to share any ideas, suggestions, and questions through there * l - toggle track loop * Right - seek ahead * Left - seek back +* v and V - increase and decrease playback volume * Ctrl+F or / - jump to a track or group by entering (part of) its name * Ctrl+O - open a playlist from a source (like a /path/to/a/folder or a YouTube playlist URL) (you can also just pass this source to `mtui`) * t and T (shift+T) - switch between playlist tabs diff --git a/players.js b/players.js index fdcd038..e9cf76e 100644 --- a/players.js +++ b/players.js @@ -50,6 +50,7 @@ class Player extends EventEmitter { this.disablePlaybackStatus = false this.isLooping = false + this.volume = 100 } set process(newProcess) { @@ -98,6 +99,7 @@ module.exports.MPVPlayer = class extends Player { if (this.isLooping) { opts.unshift('--loop') } + opts.unshift('--volume', this.volume) return opts } @@ -174,11 +176,13 @@ module.exports.ControllableMPVPlayer = class extends module.exports.MPVPlayer { } volUp(amount) { - this.sendCommand(`add volume +${parseFloat(amount)}`) + this.volume = Math.min(100, this.volume + amount) + this.sendCommand(`set volume ${this.volume}`) } volDown(amount) { - this.sendCommand(`add volume -${parseFloat(amount)}`) + this.volume = Math.max(0, this.volume - amount) + this.sendCommand(`set volume ${this.volume}`) } togglePause() { diff --git a/todo.txt b/todo.txt index dfb14d6..13db542 100644 --- a/todo.txt +++ b/todo.txt @@ -191,3 +191,6 @@ TODO: A "play later" option for songs in the queue, identical to distributing TODO: Loop one song! (Done!) + +TODO: Volume controls! + (Done!) diff --git a/ui.js b/ui.js index 4a8f0a4..67f1bf4 100644 --- a/ui.js +++ b/ui.js @@ -409,6 +409,10 @@ class AppElement extends FocusElement { this.togglePause() } else if (telc.isCaselessLetter(keyBuf, 'l')) { this.toggleLoop() + } else if (telc.isCharacter(keyBuf, 'v')) { + this.volUp() + } else if (telc.isCharacter(keyBuf, 'V')) { + this.volDown() } else if (telc.isEscape(keyBuf)) { this.clearPlayingTrack() } else if (telc.isShiftUp(keyBuf) || telc.isCaselessLetter(keyBuf, 'p')) { @@ -503,6 +507,14 @@ class AppElement extends FocusElement { this.player.toggleLoop() } + volUp(amount = 10) { + this.player.volUp(amount) + } + + volDown(amount = 10) { + this.player.volDown(amount) + } + stopPlaying() { // We emit this so playTrack doesn't immediately start a new track. // We aren't *actually* about to play a new track. @@ -1664,6 +1676,9 @@ class PlaybackInfoElement extends DisplayElement { if (player.isLooping) { this.progressTextLabel.text += ' [Looping]' } + if (player.volume !== 100) { + this.progressTextLabel.text += ` [Volume: ${Math.round(player.volume)}%]` + } this.fixLayout() } -- cgit 1.3.0-6-gf8a5