summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2016-04-14 16:21:34 +0200
committerLars-Dominik Braun <lars@6xq.net>2016-04-14 16:25:13 +0200
commit0ec2df77a72edde7b65a4ac8e7ffff4470120a51 (patch)
treef42ccee095dead476f58700991de24ba00e07177 /src
parent8c06a59a34b5d9bba277a50198fe2dd50d832da3 (diff)
downloadpianobar-0ec2df77a72edde7b65a4ac8e7ffff4470120a51.tar.gz
pianobar-0ec2df77a72edde7b65a4ac8e7ffff4470120a51.tar.bz2
pianobar-0ec2df77a72edde7b65a4ac8e7ffff4470120a51.zip
Fix songfinish event when changing stations
The event did not contain any song data (title, artist, …), because the playlist was destroyed by the ui command. Now the actual station switch is deferred by introducing nextStation and letting the main loop handle it. Fixes issue #584.
Diffstat (limited to 'src')
-rw-r--r--src/main.c30
-rw-r--r--src/main.h4
-rw-r--r--src/ui.c3
-rw-r--r--src/ui_act.c18
4 files changed, 30 insertions, 25 deletions
diff --git a/src/main.c b/src/main.c
index c0388e2..a85949a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -177,21 +177,18 @@ static bool BarMainGetStations (BarApp_t *app) {
static void BarMainGetInitialStation (BarApp_t *app) {
/* try to get autostart station */
if (app->settings.autostartStation != NULL) {
- app->curStation = PianoFindStationById (app->ph.stations,
+ app->nextStation = PianoFindStationById (app->ph.stations,
app->settings.autostartStation);
- if (app->curStation == NULL) {
+ if (app->nextStation == NULL) {
BarUiMsg (&app->settings, MSG_ERR,
"Error: Autostart station not found.\n");
}
}
/* no autostart? ask the user */
- if (app->curStation == NULL) {
- app->curStation = BarUiSelectStation (app, app->ph.stations,
+ if (app->nextStation == NULL) {
+ app->nextStation = BarUiSelectStation (app, app->ph.stations,
"Select station: ", NULL, app->settings.autoselect);
}
- if (app->curStation != NULL) {
- BarUiPrintStation (&app->settings, app->curStation);
- }
}
/* wait for user input
@@ -211,20 +208,21 @@ static void BarMainGetPlaylist (BarApp_t *app) {
PianoReturn_t pRet;
CURLcode wRet;
PianoRequestDataGetPlaylist_t reqData;
- reqData.station = app->curStation;
+ reqData.station = app->nextStation;
reqData.quality = app->settings.audioQuality;
BarUiMsg (&app->settings, MSG_INFO, "Receiving new playlist... ");
if (!BarUiPianoCall (app, PIANO_REQUEST_GET_PLAYLIST,
&reqData, &pRet, &wRet)) {
- app->curStation = NULL;
+ app->nextStation = NULL;
} else {
app->playlist = reqData.retPlaylist;
if (app->playlist == NULL) {
BarUiMsg (&app->settings, MSG_INFO, "No tracks left.\n");
- app->curStation = NULL;
+ app->nextStation = NULL;
}
}
+ app->curStation = app->nextStation;
BarUiStartEventCmd (&app->settings, "stationfetchplaylist",
app->curStation, app->playlist, &app->player, app->ph.stations,
pRet, wRet);
@@ -297,10 +295,10 @@ static void BarMainPlayerCleanup (BarApp_t *app, pthread_t *playerThread) {
++app->playerErrors;
if (app->playerErrors >= app->settings.maxPlayerErrors) {
/* don't continue playback if thread reports too many error */
- app->curStation = NULL;
+ app->nextStation = NULL;
}
} else {
- app->curStation = NULL;
+ app->nextStation = NULL;
}
memset (&app->player, 0, sizeof (app->player));
@@ -363,8 +361,7 @@ static void BarMainLoop (BarApp_t *app) {
/* check whether player finished playing and start playing new
* song */
- if (app->player.mode == PLAYER_DEAD && app->curStation != NULL &&
- !app->doQuit) {
+ if (app->player.mode == PLAYER_DEAD) {
/* what's next? */
if (app->playlist != NULL) {
PianoSong_t *histsong = app->playlist;
@@ -372,7 +369,10 @@ static void BarMainLoop (BarApp_t *app) {
histsong->head.next = NULL;
BarUiHistoryPrepend (app, histsong);
}
- if (app->playlist == NULL) {
+ if (app->playlist == NULL && app->nextStation != NULL && !app->doQuit) {
+ if (app->nextStation != app->curStation) {
+ BarUiPrintStation (&app->settings, app->nextStation);
+ }
BarMainGetPlaylist (app);
}
/* song ready to play */
diff --git a/src/main.h b/src/main.h
index 0dd2647..7dc0ac8 100644
--- a/src/main.h
+++ b/src/main.h
@@ -39,7 +39,9 @@ typedef struct {
/* first item is current song */
PianoSong_t *playlist;
PianoSong_t *songHistory;
- PianoStation_t *curStation;
+ /* station of current song and station used to fetch songs from if playlist
+ * is empty */
+ PianoStation_t *curStation, *nextStation;
sig_atomic_t doQuit;
BarReadlineFds_t input;
unsigned int playerErrors;
diff --git a/src/ui.c b/src/ui.c
index c2a55df..5350dea 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -802,7 +802,8 @@ void BarUiStartEventCmd (const BarSettings_t *settings, const char *type,
pipeWriteFd = fdopen (pipeFd[1], "w");
- if (curSong != NULL && stations != NULL && curStation->isQuickMix) {
+ if (curSong != NULL && stations != NULL && curStation != NULL &&
+ curStation->isQuickMix) {
songStation = PianoFindStationById (stations, curSong->stationId);
}
diff --git a/src/ui_act.c b/src/ui_act.c
index e8452e6..e1dbfc0 100644
--- a/src/ui_act.c
+++ b/src/ui_act.c
@@ -236,10 +236,14 @@ BarUiActCallback(BarUiActDeleteStation) {
if (BarUiActDefaultPianoCall (PIANO_REQUEST_DELETE_STATION,
selStation) && selStation == app->curStation) {
BarUiDoSkipSong (&app->player);
- PianoDestroyPlaylist (PianoListNextP (app->playlist));
- app->playlist->head.next = NULL;
- BarUiHistoryPrepend (app, app->playlist);
- app->playlist = NULL;
+ if (app->playlist != NULL) {
+ /* drain playlist */
+ PianoDestroyPlaylist (PianoListNextP (app->playlist));
+ app->playlist->head.next = NULL;
+ }
+ app->nextStation = NULL;
+ /* XXX: usually we shoudn’t touch cur*, but DELETE_STATION destroys
+ * station struct */
app->curStation = NULL;
}
BarUiActDefaultEventcmd ("stationdelete");
@@ -468,14 +472,12 @@ BarUiActCallback(BarUiActSelectStation) {
PianoStation_t *newStation = BarUiSelectStation (app, app->ph.stations,
"Select station: ", NULL, app->settings.autoselect);
if (newStation != NULL) {
- app->curStation = newStation;
- BarUiPrintStation (&app->settings, app->curStation);
+ app->nextStation = newStation;
BarUiDoSkipSong (&app->player);
if (app->playlist != NULL) {
+ /* drain playlist */
PianoDestroyPlaylist (PianoListNextP (app->playlist));
app->playlist->head.next = NULL;
- BarUiHistoryPrepend (app, app->playlist);
- app->playlist = NULL;
}
}
}