From 5ccf456d9ba332d587c97e8724a5b767e96a5802 Mon Sep 17 00:00:00 2001 From: Florrie Date: Sun, 29 Oct 2017 15:55:47 -0300 Subject: Add track number to status line and make status line more consistent This does two big things - there's a few changes in pickers.js to support track numbers (and a new supporting function in playlist-utils.js), and some changes in loop-play.js to make the status line formatting consistent regardless of the active player. --- src/playlist-utils.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/playlist-utils.js') diff --git a/src/playlist-utils.js b/src/playlist-utils.js index 013f56a..c2f6aae 100644 --- a/src/playlist-utils.js +++ b/src/playlist-utils.js @@ -453,6 +453,30 @@ function isSameTrack(track1, track2) { return false } +function getTrackIndexInParent(track) { + if (parentSymbol in track === false) { + throw new Error( + 'getTrackIndexInParent called with a track that has no parent!' + ) + } + + const parent = track[parentSymbol] + + let i = 0, foundTrack = false; + for (; i < parent.items.length; i++) { + if (isSameTrack(track, parent.items[i])) { + foundTrack = true + break + } + } + + if (foundTrack === false) { + return [-1, parent.items.length] + } else { + return [i, parent.items.length] + } +} + function isGroup(obj) { return !!(obj && obj.items) @@ -501,7 +525,7 @@ async function safeUnlink(file, playlist) { } module.exports = { - parentSymbol, + parentSymbol, oldSymbol, updatePlaylistFormat, updateTrackFormat, flattenGrouplike, partiallyFlattenGrouplike, collapseGrouplike, @@ -512,6 +536,7 @@ module.exports = { getItemPathString, parsePathString, isSameTrack, + getTrackIndexInParent, isGroup, isTrack, safeUnlink } -- cgit 1.3.0-6-gf8a5