« get me outta code hell

mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
path: root/backend.js
diff options
context:
space:
mode:
Diffstat (limited to 'backend.js')
-rw-r--r--backend.js22
1 files changed, 18 insertions, 4 deletions
diff --git a/backend.js b/backend.js
index 418c2eb..c59dfdf 100644
--- a/backend.js
+++ b/backend.js
@@ -165,6 +165,7 @@ class QueuePlayer extends EventEmitter {
     }
 
     recursivelyAddTracks(topItem)
+    this.emit('queue', topItem, afterItem, {movePlayingTrack})
     this.emitQueueUpdated()
 
     // This is the first new track, if a group was queued.
@@ -173,9 +174,12 @@ class QueuePlayer extends EventEmitter {
     return newTrack
   }
 
-  distributeQueue(grouplike, {how = 'evenly', rangeEnd = 'end-of-queue'}) {
-    if (isTrack(grouplike)) {
-      grouplike = {items: [grouplike]}
+  distributeQueue(topItem, {how = 'evenly', rangeEnd = 'end-of-queue'} = {}) {
+    let grouplike
+    if (isTrack(topItem)) {
+      grouplike = {items: [topItem]}
+    } else {
+      grouplike = topItem
     }
 
     const { items } = this.queueGrouplike
@@ -227,6 +231,7 @@ class QueuePlayer extends EventEmitter {
       }
     }
 
+    this.emit('distribute-queue', topItem, {how, rangeEnd})
     this.emitQueueUpdated()
   }
 
@@ -271,6 +276,7 @@ class QueuePlayer extends EventEmitter {
     }
 
     recursivelyUnqueueTracks(topItem)
+    this.emit('unqueue', topItem)
     this.emitQueueUpdated()
 
     return focusItem
@@ -288,6 +294,7 @@ class QueuePlayer extends EventEmitter {
       items.splice(index)
     }
 
+    this.emit('clear-queue-past', track)
     this.emitQueueUpdated()
   }
 
@@ -304,6 +311,7 @@ class QueuePlayer extends EventEmitter {
       items.splice(startIndex, endIndex - startIndex)
     }
 
+    this.emit('clear-queue-up-to', track)
     this.emitQueueUpdated()
   }
 
@@ -336,6 +344,7 @@ class QueuePlayer extends EventEmitter {
     const remainingItems = queue.items.slice(index)
     const newItems = initialItems.concat(shuffleArray(remainingItems))
     queue.items = newItems
+    this.emit('shuffle-queue')
     this.emitQueueUpdated()
   }
 
@@ -344,6 +353,7 @@ class QueuePlayer extends EventEmitter {
     // the track that's currently playing).
     this.queueGrouplike.items = this.queueGrouplike.items
       .filter(item => item === this.playingTrack)
+    this.emit('clear-queue')
     this.emitQueueUpdated()
   }
 
@@ -563,7 +573,11 @@ class QueuePlayer extends EventEmitter {
   }
 
   seekBack(seconds) {
-    this.time -= seconds
+    if (this.time < seconds) {
+      this.time = 0
+    } else {
+      this.time -= seconds
+    }
     this.player.seekBack(seconds)
     this.emit('seek-back', +seconds)
   }