« get me outta code hell

'Clear past / up to this track' queue menu options - 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:
authorFlorrie <towerofnix@gmail.com>2019-09-10 12:23:41 -0300
committerFlorrie <towerofnix@gmail.com>2019-09-10 12:23:41 -0300
commit47bd859d1a02683395bbf941d7dc0375d7ef8334 (patch)
tree484c6fdc82af9b14a2ff1e6894d2ad3b060aa3c6 /backend.js
parent366b6e90f1d237a8e1e0d92224f65990157d0cd6 (diff)
'Clear past / up to this track' queue menu options
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',