Skip to content

Commit

Permalink
fixed playlist selector sometimes getting stuck
Browse files Browse the repository at this point in the history
  • Loading branch information
ravachol committed Mar 9, 2024
1 parent cdc72bc commit 3d0c59b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
1 change: 0 additions & 1 deletion src/playerops.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
26 changes: 8 additions & 18 deletions src/playlist_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 3d0c59b

Please sign in to comment.