From 3d0c59b529f8f6b23daba9d8ddb195cb81b3843a Mon Sep 17 00:00:00 2001 From: Ravachol Date: Sat, 9 Mar 2024 09:59:46 +0100 Subject: [PATCH] fixed playlist selector sometimes getting stuck --- src/playerops.c | 1 - src/playlist_ui.c | 26 ++++++++------------------ 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/playerops.c b/src/playerops.c index c035772..d8bbb28 100644 --- a/src/playerops.c +++ b/src/playerops.c @@ -362,7 +362,6 @@ void calcElapsedTime() if (currentSong != NULL && timeSinceLastUpdate >= 1.0) { updatePlaybackPosition(elapsedSeconds); - // Update the last update time to the current time lastUpdateTime = current_time; } } diff --git a/src/playlist_ui.c b/src/playlist_ui.c index c31554a..63e8bf0 100644 --- a/src/playlist_ui.c +++ b/src/playlist_ui.c @@ -95,14 +95,7 @@ int displayPlaylistItems(Node *startNode, int startIter, int maxListSize, int te if (i + 1 < 10) printf(" "); - if (startFromCurrent) - { - printf(" %d. %s \n", i + 1, buffer); - } - else - { - printf(" %d. %s \n", numPrintedRows + 1, buffer); - } + printf(" %d. %s \n", i + 1, buffer); numPrintedRows++; } @@ -124,7 +117,7 @@ int displayPlaylist(PlayList *list, int maxListSize, int indent, int *chosenSong Node *startNode = determineStartNode(list->head, &foundAt, &startFromCurrent, list->count); // Determine chosen song - if (*chosenSong >= list->count) // Assuming `list->count` is the correct object to use + if (*chosenSong >= list->count) { *chosenSong = list->count - 1; } @@ -154,22 +147,19 @@ int displayPlaylist(PlayList *list, int maxListSize, int indent, int *chosenSong startIter = *chosenSong = foundAt; } - // Go up to find the starting node based on the new startIter + // Go up to find the starting node for (int i = foundAt; i > startIter; i--) { if (i > 0 && startNode->prev != NULL) startNode = startNode->prev; } - // Go down to adjust the startNode based on the new startIter - if (foundAt > -1) + // Go down to adjust the startNode + for (int i = (foundAt == -1) ? 0 : foundAt; i < startIter; i++) { - for (int i = foundAt; i < startIter; i++) - { - if (startNode->next != NULL) - startNode = startNode->next; - } - } + if (startNode->next != NULL) + startNode = startNode->next; + } int printedRows = displayPlaylistItems(startNode, startIter, maxListSize, termWidth, indent, startFromCurrent, *chosenSong, chosenNodeId);