« get me outta code hell

order: alphabetize order of groups - 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-08-06 15:42:38 -0300
committer(quasar) nebula <towerofnix@gmail.com>2021-08-06 15:42:38 -0300
commit4e0cb3a38deb8600cbcacb3f87b9e6dba8930aa1 (patch)
tree8ea3c32c0acd0e4a63fc7013105e9c88f704aac8
parentdf99d463242a30e863a3c84253549a18e2170d45 (diff)
order: alphabetize order of groups
-rw-r--r--todo.txt13
-rw-r--r--ui.js65
2 files changed, 54 insertions, 24 deletions
diff --git a/todo.txt b/todo.txt
index fa437df..7e5fa1c 100644
--- a/todo.txt
+++ b/todo.txt
@@ -613,3 +613,16 @@ TODO: Should skipping back to a previous track with timestamps automatically
       seek to the final timestamp within that track? I'm undecided, but at the
       moment leaning *slightly* towards "no". I may be biased due to it is
       harder to code that behavior though! :P
+
+TODO: The timestamp comment regex should probably skip dashes and other common
+      punctuation between the timestamp itself and the comment!
+
+TODO: Pressing ^L to locate the currently playing track (in the queue listing)
+      should focus the current timestamp, if there is one.
+
+TODO: I don't think "jump to" (/) works with timestamp items, lol.
+
+TODO: "Alphabetize order of groups" order option. Listen to the releases of
+      an artist, or your whole library, alphabetically - or prefix group names
+      with the date of release and play works chronologically! Or do whatever
+      other shenanigansy inline metadata you like.
diff --git a/ui.js b/ui.js
index a5481c8..b586335 100644
--- a/ui.js
+++ b/ui.js
@@ -16,6 +16,7 @@ const {
 
 const {
   cloneGrouplike,
+  collapseGrouplike,
   countTotalTracks,
   flattenGrouplike,
   getCorrespondingFileForItem,
@@ -326,6 +327,7 @@ class AppElement extends FocusElement {
       {value: 'reverse', label: 'Reverse all'},
       {value: 'reverse-groups', label: 'Reverse order of groups'},
       {value: 'alphabetic', label: 'Alphabetically'},
+      {value: 'alphabetic-groups', label: 'Alphabetize order of groups'},
       {value: 'normal', label: 'In order'}
     ], this.showContextMenu)
 
@@ -1815,30 +1817,45 @@ class AppElement extends FocusElement {
 
     const oldName = item.name
     if (isGroup(item)) {
-      if (order === 'shuffle') {
-        item = {
-          name: `${oldName} (shuffled)`,
-          items: shuffleArray(flattenGrouplike(item).items)
-        }
-      } else if (order === 'shuffle-groups') {
-        item = shuffleOrderOfGroups(item)
-        item.name = `${oldName} (group order shuffled)`
-      } else if (order === 'reverse') {
-        item = {
-          name: `${oldName} (reversed)`,
-          items: flattenGrouplike(item).items.reverse()
-        }
-      } else if (order === 'reverse-groups') {
-        item = reverseOrderOfGroups(item)
-        item.name = `${oldName} (group order reversed)`
-      } else if (order === 'alphabetic') {
-        item = {
-          name: `${oldName} (alphabetic)`,
-          items: orderBy(
-            flattenGrouplike(item).items,
-            t => getNameWithoutTrackNumber(t).replace(/[^a-zA-Z0-9]/g, '')
-          )
-        }
+      switch (order) {
+        case 'shuffle':
+          item = {
+            name: `${oldName} (shuffled)`,
+            items: shuffleArray(flattenGrouplike(item).items)
+          }
+          break
+        case 'shuffle-groups':
+          item = shuffleOrderOfGroups(item)
+          item.name = `${oldName} (group order shuffled)`
+          break
+        case 'reverse':
+          item = {
+            name: `${oldName} (reversed)`,
+            items: flattenGrouplike(item).items.reverse()
+          }
+          break
+        case 'reverse-groups':
+          item = reverseOrderOfGroups(item)
+          item.name = `${oldName} (group order reversed)`
+          break
+        case 'alphabetic':
+          item = {
+            name: `${oldName} (alphabetic)`,
+            items: orderBy(
+              flattenGrouplike(item).items,
+              t => getNameWithoutTrackNumber(t).replace(/[^a-zA-Z0-9]/g, '')
+            )
+          }
+          break
+        case 'alphabetic-groups':
+          item = {
+            name: `${oldName} (group order alphabetic)`,
+            items: orderBy(
+              collapseGrouplike(item).items,
+              t => t.name.replace(/[^a-zA-Z0-9]/g, '')
+            )
+          }
+          break
       }
     } else {
       // Make it into a grouplike that just contains itself.