« 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.js31
1 files changed, 31 insertions, 0 deletions
diff --git a/backend.js b/backend.js
index 0ddd15b..57910e9 100644
--- a/backend.js
+++ b/backend.js
@@ -316,6 +316,37 @@ class Backend extends EventEmitter {
     return focusItem
   }
 
+  clearQueuePast(track) {
+    const { items } = this.queueGrouplike
+    const index = items.indexOf(track) + 1
+
+    if (index < 0) {
+      return
+    } else if (index < items.indexOf(this.playingTrack)) {
+      items.splice(index, items.length - index, this.playingTrack)
+    } else {
+      items.splice(index)
+    }
+
+    this.emitQueueUpdated()
+  }
+
+  clearQueueUpTo(track) {
+    const { items } = this.queueGrouplike
+    const endIndex = items.indexOf(track)
+    const startIndex = (this.playingTrack ? items.indexOf(this.playingTrack) + 1 : 0)
+
+    if (endIndex < 0) {
+      return
+    } else if (endIndex < startIndex) {
+      return
+    } else {
+      items.splice(startIndex, endIndex - startIndex)
+    }
+
+    this.emitQueueUpdated()
+  }
+
   playSooner(item) {
     this.distributeQueue(item, {
       how: 'randomly',