« get me outta code hell

auto expand/collapse timestamps (for SQP) - mtui - Music Text User Interface - user-friendly command line music player
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <towerofnix@gmail.com>2021-07-17 21:43:22 -0300
committer(quasar) nebula <towerofnix@gmail.com>2021-07-17 21:43:22 -0300
commitc30367f90211e6cfa61482bb68f829ee210e5cb6 (patch)
treea969bf45b36f442d4a2d6e96c1ed89542c312020
parent8f0ccabc8b12465771f770508fd0786baf49a518 (diff)
auto expand/collapse timestamps (for SQP)
-rw-r--r--todo.txt4
-rw-r--r--ui.js21
2 files changed, 22 insertions, 3 deletions
diff --git a/todo.txt b/todo.txt
index dadbca7..f8202c2 100644
--- a/todo.txt
+++ b/todo.txt
@@ -598,8 +598,12 @@ TODO: Some kind of timestamp indicator in the progress bar area??? E.g, name
 TODO: Timestamp editing within mtui itself?????????
 
 TODO: Automatically expand/collapse timestamp lists in the queue sidebar!
+      (Done!)
 
 TODO: Apparently, seeking to a timestamp under a previous track in the queue
       doesn't respect the current queue order (i.e. it sticks the track after
       the current track). Definitely a bug!
       (Done - fixed!)
+
+TODO: Next/previous buttons should seek between timestamps if there are more
+      within the same track.
diff --git a/ui.js b/ui.js
index c62f93a..b67fc8d 100644
--- a/ui.js
+++ b/ui.js
@@ -549,6 +549,18 @@ class AppElement extends FocusElement {
       }
     }
 
+    // Unfortunately, there isn't really any reliable way to make these work if
+    // the containing queue isn't of the selected queue player.
+    const timestampData = track && this.getTimestampData(track)
+    if (timestampData && queuePlayer === this.SQP) {
+      this.queueListingElement.expandTimestamps(track)
+    }
+
+    const oldTimestampData = oldTrack && this.getTimestampData(oldTrack)
+    if (oldTimestampData && queuePlayer === this.SQP) {
+      this.queueListingElement.collapseTimestamps(oldTrack)
+    }
+
     if (track && this.enableAutoDJ) {
       queuePlayer.setVolumeMultiplier(0.5);
       const message = 'now playing: ' + getNameWithoutTrackNumber(track);
@@ -1943,7 +1955,7 @@ class AppElement extends FocusElement {
       if (isTimestamp && selectedIndex === playingIndex) {
         const selectedTimestampIndex = timestampData.indexOf(selectedInput.data)
 
-        const found = timestampData.findIndex(ts => ts.timestamp > timeData.curSecTotal)
+        const found = timestampData.findIndex(ts => ts.timestamp > trackPassedSec)
         const playingTimestampIndex = (found >= 0 ? found - 1 : 0)
         const distance = Math.abs(selectedTimestampIndex - playingTimestampIndex)
 
@@ -2232,8 +2244,11 @@ class GrouplikeListingElement extends Form {
 
   expandTimestamps(item) {
     if (this.grouplike && this.grouplike.items.includes(item)) {
-      this.expandedTimestamps.push(item)
-      this.buildTimestampItems()
+      const ET = this.expandedTimestamps
+      if (!ET.includes(item)) {
+        this.expandedTimestamps.push(item)
+        this.buildTimestampItems()
+      }
     }
   }