summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c100
1 files changed, 46 insertions, 54 deletions
diff --git a/src/main.c b/src/main.c
index eca4705..6e99ada 100644
--- a/src/main.c
+++ b/src/main.c
@@ -158,29 +158,21 @@ static bool BarMainGetStations(BarApp_t *app)
/* get initial station from autostart setting or user rl
*/
-static void BarMainGetInitialStation(BarApp_t *app)
-{
- /* try to get autostart station */
- if (app->settings.autostartStation != NULL)
- {
- app->curStation = PianoFindStationById(app->ph.stations,
- app->settings.autostartStation);
- if (app->curStation == 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,
- "Select station: ", NULL, app->settings.autoselect);
- }
- if (app->curStation != NULL)
- {
- BarUiPrintStation(&app->settings, app->curStation);
- }
+static void BarMainGetInitialStation (BarApp_t *app) {
+ /* try to get autostart station */
+ if (app->settings.autostartStation != NULL) {
+ app->nextStation = PianoFindStationById (app->ph.stations,
+ app->settings.autostartStation);
+ if (app->nextStation == NULL) {
+ BarUiMsg (&app->settings, MSG_ERR,
+ "Error: Autostart station not found.\n");
+ }
+ }
+ /* no autostart? ask the user */
+ if (app->nextStation == NULL) {
+ app->nextStation = BarUiSelectStation (app, app->ph.stations,
+ "Select station: ", NULL, app->settings.autoselect);
+ }
}
/* wait for user rl
@@ -198,31 +190,27 @@ static void BarMainHandleUserInput(BarApp_t *app)
/* fetch new playlist
*/
-static void BarMainGetPlaylist(BarApp_t *app)
-{
- PianoReturn_t pRet;
- PianoRequestDataGetPlaylist_t reqData;
- reqData.station = app->curStation;
- reqData.quality = app->settings.audioQuality;
-
- BarUiMsg(&app->settings, MSG_INFO, "Receiving new playlist... ");
- if (!BarUiPianoCall(app, PIANO_REQUEST_GET_PLAYLIST,
- &reqData, &pRet))
- {
- app->curStation = NULL;
- }
- else
- {
- app->playlist = reqData.retPlaylist;
- if (app->playlist == NULL)
- {
- BarUiMsg(&app->settings, MSG_INFO, "No tracks left.\n");
- app->curStation = NULL;
- }
- }
- BarUiStartEventCmd(&app->settings, "stationfetchplaylist",
- app->curStation, app->playlist, &app->player, app->ph.stations,
- pRet);
+static void BarMainGetPlaylist (BarApp_t *app) {
+ PianoReturn_t pRet;
+ PianoRequestDataGetPlaylist_t reqData;
+ 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)) {
+ app->nextStation = NULL;
+ } else {
+ app->playlist = reqData.retPlaylist;
+ if (app->playlist == NULL) {
+ BarUiMsg (&app->settings, MSG_INFO, "No tracks left.\n");
+ app->nextStation = NULL;
+ }
+ }
+ app->curStation = app->nextStation;
+ BarUiStartEventCmd (&app->settings, "stationfetchplaylist",
+ app->curStation, app->playlist, &app->player, app->ph.stations,
+ pRet);
}
/* start new player thread
@@ -276,7 +264,7 @@ static void BarMainPlayerCleanup(BarApp_t *app)
if (app->playerErrors >= app->settings.maxPlayerErrors)
{
/* don't continue playback if thread reports too many error */
- app->curStation = NULL;
+ app->nextStation = NULL;
app->playerErrors = 0;
}
}
@@ -338,7 +326,7 @@ static void BarMainLoop(BarApp_t *app)
/* check whether player finished playing and start playing new
* song */
- if (BarPlayer2IsFinished(app->player) && app->curStation != NULL)
+ if (BarPlayer2IsFinished(app->player) && app->nextStation != NULL)
{
/* what's next? */
if (app->playlist != NULL)
@@ -348,10 +336,14 @@ static void BarMainLoop(BarApp_t *app)
histsong->head.next = NULL;
BarUiHistoryPrepend(app, histsong);
}
- if (app->playlist == NULL)
- {
- BarMainGetPlaylist(app);
- }
+ 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 */
if (app->playlist != NULL)
{