commit a850277f59e2e0ebae6d90aaad092337a84445f9
parent 68a345c3fe9e7519014590caf4e4fadbeb8d54fd
Author: Louis Burda <quent.burda@gmail.com>
Date: Mon, 28 Feb 2022 11:42:46 +0100
Try to preserving playing track when reindexing / moving
Diffstat:
M | src/cmd.c | | | 40 | +++++++++++++++++++++++++++++++++++++--- |
M | src/tui.c | | | 42 | +++++++++++++++++++++++++++++++----------- |
2 files changed, 68 insertions(+), 14 deletions(-)
diff --git a/src/cmd.c b/src/cmd.c
@@ -72,6 +72,9 @@ cmd_move(const char *name)
ERROR("Failed to move track");
}
+ if (player.track == track)
+ player.track = new;
+
if (!track_rm(track, true))
ERROR("Failed to move track");
@@ -113,11 +116,18 @@ cmd_copy(const char *name)
bool
cmd_reindex(const char *name)
{
+ struct track *track;
struct link *link;
struct tag *tag;
struct ref *ref;
struct list matches;
+ struct tag *playing_tag;
+ char *playing_name;
+ bool status;
+ status = false;
+ playing_tag = NULL;
+ playing_name = NULL;
list_init(&matches);
if (!*name) {
@@ -143,17 +153,41 @@ cmd_reindex(const char *name)
}
}
- if (list_empty(&matches)) return false;
+ if (list_empty(&matches))
+ return false;
+
+ /* save old playing track */
+ if (player.track) {
+ playing_tag = player.track->tag;
+ playing_name = strdup(player.track->name);
+ OOM_CHECK(playing_name);
+ }
+ /* update each tag specified */
for (LIST_ITER(&matches, link)) {
ref = UPCAST(link, struct ref, link);
if (!tracks_update(ref->data))
- return false;
+ goto cleanup;
+ }
+
+ /* try to find old playing track among reindexed tracks */
+ if (playing_tag) {
+ for (LIST_ITER(&playing_tag->tracks, link)) {
+ track = UPCAST(link, struct track, link_tt);
+ if (!strcmp(track->name, playing_name)) {
+ player.track = track;
+ break;
+ }
+ }
}
+ status = true;
+
+cleanup:
refs_free(&matches);
+ free(playing_name);
- return true;
+ return status;
}
bool
diff --git a/src/tui.c b/src/tui.c
@@ -312,16 +312,16 @@ tag_pane_input(wint_t c)
case KEY_NPAGE: /* seek half a page down */
listnav_update_sel(&tag_nav, tag_nav.sel + tag_nav.wlen / 2);
break;
- case 'g': /* seek start of list */
+ case L'g': /* seek start of list */
listnav_update_sel(&tag_nav, 0);
break;
- case 'G': /* seek end of list */
+ case L'G': /* seek end of list */
listnav_update_sel(&tag_nav, tag_nav.max - 1);
break;
- case 'n': /* nav through selected tags */
+ case L'n': /* nav through selected tags */
seek_next_selected_tag();
break;
- case 'D': /* delete tag */
+ case L'D': /* delete tag */
delete_selected_tag();
playlist_update(false);
break;
@@ -389,6 +389,20 @@ play_selected_track(void)
}
void
+seek_playing_track_tag(void)
+{
+ int index;
+
+ if (!player.track)
+ return;
+
+ index = list_index(&tags, &player.track->tag->link);
+ if (index < 0) return;
+
+ listnav_update_sel(&tag_nav, index);
+}
+
+void
seek_playing_track(void)
{
struct link *link;
@@ -439,16 +453,16 @@ track_pane_input(wint_t c)
listnav_update_sel(&track_nav,
track_nav.sel + track_nav.wlen / 2);
break;
- case 'g': /* seek start of list */
+ case L'g': /* seek start of list */
listnav_update_sel(&track_nav, 0);
break;
- case 'G': /* seek end of list */
+ case L'G': /* seek end of list */
listnav_update_sel(&track_nav, track_nav.max - 1);
break;
- case 'n': /* seek playing */
+ case L'n': /* seek playing */
seek_playing_track();
break;
- case 'D': /* delete track */
+ case L'D': /* delete track */
delete_selected_track();
break;
default:
@@ -877,7 +891,7 @@ main_input(wint_t c)
case L'/':
cmd_input_mode = IMODE_TRACK_SELECT;
pane_after_cmd = pane_sel;
- pane_sel = &pane_bot;
+ pane_sel = cmd_pane;
completion_reset = 1;
history = &track_select_history;
completion = track_name_gen;
@@ -885,7 +899,7 @@ main_input(wint_t c)
case L'!':
cmd_input_mode = IMODE_TRACK_PLAY;
pane_after_cmd = pane_sel;
- pane_sel = &pane_bot;
+ pane_sel = cmd_pane;
completion_reset = 1;
history = &track_play_history;
completion = track_name_gen;
@@ -893,7 +907,7 @@ main_input(wint_t c)
case L'?':
cmd_input_mode = IMODE_TAG_SELECT;
pane_after_cmd = pane_sel;
- pane_sel = &pane_bot;
+ pane_sel = cmd_pane;
completion_reset = 1;
history = &tag_select_history;
completion = tag_name_gen;
@@ -907,6 +921,12 @@ main_input(wint_t c)
case L'q':
quit = 1;
break;
+ case L'N':
+ seek_playing_track_tag();
+ update_tracks_vis();
+ seek_playing_track();
+ pane_sel = track_pane;
+ break;
}
}