Skip to content

Commit

Permalink
fixed issue with showplaylist
Browse files Browse the repository at this point in the history
  • Loading branch information
ravachol committed Mar 8, 2024
1 parent 03075f8 commit cdc72bc
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/player.c
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ int printLogoAndAdjustments(SongData *songData, int termWidth, bool hideHelp, in
return aboutRows;
}

void showPlaylist(SongData *songData, PlayList *list, int chosenSong, int *chosenNodeId)
void showPlaylist(SongData *songData, PlayList *list, int *chosenSong, int *chosenNodeId)
{
int term_w, term_h;
getTermSize(&term_w, &term_h);
Expand Down Expand Up @@ -1222,7 +1222,7 @@ int printPlayer(SongData *songdata, double elapsedSeconds, AppSettings *settings
else if (appState.currentView == PLAYLIST_VIEW && refresh)
{
clearScreen();
showPlaylist(songdata, originalPlaylist, chosenRow, &chosenNodeId);
showPlaylist(songdata, originalPlaylist, &chosenRow, &chosenNodeId);
resetPlaylistDisplay = false;
refresh = false;
}
Expand Down
6 changes: 6 additions & 0 deletions src/playerops.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,12 @@ void handleRemove()
bool rebuild = false;

Node *node = findSelectedEntry(originalPlaylist, chosenRow);

if (node == NULL)
{
return;
}

Node *song = getNextSong();
int id = node->id;

Expand Down
32 changes: 16 additions & 16 deletions src/playlist_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ int displayPlaylistItems(Node *startNode, int startIter, int maxListSize, int te
return numPrintedRows;
}

int displayPlaylist(PlayList *list, int maxListSize, int indent, int chosenSong, int *chosenNodeId, bool reset)
int displayPlaylist(PlayList *list, int maxListSize, int indent, int *chosenSong, int *chosenNodeId, bool reset)
{
int termWidth, termHeight;
getTerminalSize(&termWidth, &termHeight);
Expand All @@ -124,44 +124,44 @@ int displayPlaylist(PlayList *list, int maxListSize, int indent, int chosenSong,
Node *startNode = determineStartNode(list->head, &foundAt, &startFromCurrent, list->count);

// Determine chosen song
if (chosenSong >= originalPlaylist->count)
if (*chosenSong >= list->count) // Assuming `list->count` is the correct object to use
{
chosenSong = originalPlaylist->count - 1;
*chosenSong = list->count - 1;
}

if (chosenSong < 0)
if (*chosenSong < 0)
{
chosenSong = 0;
*chosenSong = 0;
}

int startIter = 0;

// Determine where to start iterating
startIter = (startFromCurrent && (foundAt < startIter || foundAt > startIter + maxListSize)) ? foundAt : startIter;

int startIter = 0;

if (chosenSong < startIter)
if (*chosenSong < startIter)
{
startIter = chosenSong;
startIter = *chosenSong;
}

if (chosenSong > startIter + maxListSize - round(maxListSize / 2))
if (*chosenSong > startIter + maxListSize - round(maxListSize / 2))
{
startIter = chosenSong - maxListSize + round(maxListSize / 2);
startIter = *chosenSong - maxListSize + round(maxListSize / 2);
}

if (reset && !audioData.endOfListReached)
if (reset && !audioData.endOfListReached)
{
startIter = chosenSong = foundAt;
startIter = *chosenSong = foundAt;
}

// Go up
// Go up to find the starting node based on the new startIter
for (int i = foundAt; i > startIter; i--)
{
if (i > 0 && startNode->prev != NULL)
startNode = startNode->prev;
}

// Go down
// Go down to adjust the startNode based on the new startIter
if (foundAt > -1)
{
for (int i = foundAt; i < startIter; i++)
Expand All @@ -171,7 +171,7 @@ int displayPlaylist(PlayList *list, int maxListSize, int indent, int chosenSong,
}
}

int printedRows = displayPlaylistItems(startNode, startIter, maxListSize, termWidth, indent, startFromCurrent, chosenSong, chosenNodeId);
int printedRows = displayPlaylistItems(startNode, startIter, maxListSize, termWidth, indent, startFromCurrent, *chosenSong, chosenNodeId);

if (printedRows > 1)
{
Expand Down
2 changes: 1 addition & 1 deletion src/playlist_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
#include "term.h"
#include "utils.h"

int displayPlaylist(PlayList *list, int maxListSize, int indent, int chosenSong, int *chosenNodeId, bool reset);
int displayPlaylist(PlayList *list, int maxListSize, int indent, int *chosenSong, int *chosenNodeId, bool reset);

#endif

0 comments on commit cdc72bc

Please sign in to comment.