« get me outta code hell

(v), (V) - Volume controls - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/players.js
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2019-01-24 23:32:42 -0400
committerFlorrie <towerofnix@gmail.com>2019-01-24 23:32:42 -0400
commit5762a825d589704a53aaabb425d9470c726bbc0d (patch)
tree6b772bd8eccc16fd81dadca30ee65a6a56454de2 /players.js
parentb4e575f4ec8b65464f9a8f109ddf3907cf30b853 (diff)
(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).
Diffstat (limited to 'players.js')
-rw-r--r--players.js8
1 files changed, 6 insertions, 2 deletions
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() {