« get me outta code hell

Allow shift-down/n to auto-queue next track - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-09-17 10:35:58 -0300
committerFlorrie <towerofnix@gmail.com>2018-09-17 10:36:57 -0300
commit5f00f624a647fbf7838a5ff1c8d72156ae0ad38f (patch)
tree7f9daf58509c76476faca027b39c5ad9f1ad7ae8
parent586873fa41f833529ceb46b97e3f5b1cd039ccf6 (diff)
Allow shift-down/n to auto-queue next track
See #1.

Also fixed a bug where shift-up/p wouldn't queue a track at the top of the
queue when the top was selected.
-rw-r--r--ui.js55
1 files changed, 30 insertions, 25 deletions
diff --git a/ui.js b/ui.js
index b0276c6..6965331 100644
--- a/ui.js
+++ b/ui.js
@@ -342,9 +342,9 @@ class AppElement extends FocusElement {
     } else if (telc.isEscape(keyBuf)) {
       this.clearPlayingTrack()
     } else if (telc.isShiftUp(keyBuf) || telc.isCaselessLetter(keyBuf, 'p')) {
-      this.playPreviousTrack(this.playingTrack)
+      this.playPreviousTrack(this.playingTrack, true)
     } else if (telc.isShiftDown(keyBuf) || telc.isCaselessLetter(keyBuf, 'n')) {
-      this.playNextTrack(this.playingTrack)
+      this.playNextTrack(this.playingTrack, true)
     } else if (telc.isCharacter(keyBuf, '1') && this.tabber.selectable) {
       this.root.select(this.tabber)
     } else if (telc.isCharacter(keyBuf, '2') && this.queueListingElement.selectable) {
@@ -601,7 +601,7 @@ class AppElement extends FocusElement {
     }
   }
 
-  playNextTrack(track) {
+  playNextTrack(track, automaticallyQueueNextTrack = false) {
     if (!track) {
       return false
     }
@@ -614,27 +614,28 @@ class AppElement extends FocusElement {
     queueIndex++
 
     if (queueIndex >= queue.items.length) {
-      /*
-      const parent = track[parentSymbol]
-      if (!parent) {
-        return false
-      }
-      const index = parent.items.indexOf(track)
-      const nextItem = parent.items[index + 1]
-      if (!nextItem) {
+      if (automaticallyQueueNextTrack) {
+        const parent = track[parentSymbol]
+        if (!parent) {
+          return false
+        }
+        const index = parent.items.indexOf(track)
+        const nextItem = parent.items[index + 1]
+        if (!nextItem) {
+          return false
+        }
+        this.queueGrouplikeItem(nextItem, false)
+        queueIndex = queue.items.length - 1
+      } else {
         return false
       }
-      this.queueGrouplikeItem(nextItem, false)
-      queueIndex = queue.items.length - 1
-      */
-      return false
     }
 
     this.playGrouplikeItem(queue.items[queueIndex], false)
     return true
   }
 
-  playPreviousTrack(track) {
+  playPreviousTrack(track, automaticallyQueuePreviousTrack = false) {
     if (!track) {
       return false
     }
@@ -647,17 +648,21 @@ class AppElement extends FocusElement {
     queueIndex--
 
     if (queueIndex < 0) {
-      const parent = track[parentSymbol]
-      if (!parent) {
-        return false
-      }
-      const index = parent.items.indexOf(track)
-      const previousItem = parent.items[index - 1]
-      if (!previousItem) {
+      if (automaticallyQueuePreviousTrack) {
+        const parent = track[parentSymbol]
+        if (!parent) {
+          return false
+        }
+        const index = parent.items.indexOf(track)
+        const previousItem = parent.items[index - 1]
+        if (!previousItem) {
+          return false
+        }
+        this.queueGrouplikeItem(previousItem, 'FRONT')
+        queueIndex = 0
+      } else {
         return false
       }
-      this.queueGrouplikeItem(previousItem, false, 'FRONT')
-      queueIndex = 0
     }
 
     this.playGrouplikeItem(queue.items[queueIndex], false)