diff options
author | Lars-Dominik Braun <PromyLOPh@lavabit.com> | 2010-07-31 13:00:36 +0200 |
---|---|---|
committer | Lars-Dominik Braun <PromyLOPh@lavabit.com> | 2010-07-31 13:59:44 +0200 |
commit | a955243adb1f484c1c4dc233d16a0afb07fe7b1e (patch) | |
tree | 349cf5b6592f0585b5b704c3e2a9e1bcd3bd5cf3 /src | |
parent | e5fb92b077c514962139abb57057041a09ca860c (diff) | |
download | pianobar-windows-a955243adb1f484c1c4dc233d16a0afb07fe7b1e.tar.gz pianobar-windows-a955243adb1f484c1c4dc233d16a0afb07fe7b1e.tar.bz2 pianobar-windows-a955243adb1f484c1c4dc233d16a0afb07fe7b1e.zip |
Replaced long argument list of ui callback functions
Structure BarApp_t contains most important data now.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 216 | ||||
-rw-r--r-- | src/main.h | 46 | ||||
-rw-r--r-- | src/settings.h | 10 | ||||
-rw-r--r-- | src/ui_act.c | 300 | ||||
-rw-r--r-- | src/ui_act.h | 50 |
5 files changed, 330 insertions, 292 deletions
@@ -44,26 +44,18 @@ THE SOFTWARE. /* pandora.com library */ #include <piano.h> -#include "player.h" -#include "settings.h" +#include "main.h" #include "terminal.h" #include "config.h" #include "ui.h" #include "ui_act.h" #include "ui_readline.h" +typedef void (*BarKeyShortcutFunc_t) (BarApp_t *app, FILE *curFd); + int main (int argc, char **argv) { - /* handles */ - PianoHandle_t ph; - WaitressHandle_t waith; - static struct audioPlayer player; - BarSettings_t settings; + static BarApp_t app; pthread_t playerThread; - /* playlist; first item is current song */ - PianoSong_t *playlist = NULL; - PianoSong_t *songHistory = NULL; - PianoStation_t *curStation = NULL; - char doQuit = 0; /* FIXME: max path length? */ char ctlPath[1024]; FILE *ctlFd = NULL; @@ -74,6 +66,8 @@ int main (int argc, char **argv) { /* terminal attributes _before_ we started messing around with ~ECHO */ struct termios termOrig; + memset (&app, 0, sizeof (app)); + /* save terminal attributes, before disabling echoing */ BarTermSave (&termOrig); @@ -81,17 +75,17 @@ int main (int argc, char **argv) { BarTermSetBuffer (0); /* init some things */ ao_initialize (); - PianoInit (&ph); + PianoInit (&app.ph); - WaitressInit (&waith); - strncpy (waith.host, PIANO_RPC_HOST, sizeof (waith.host)-1); - strncpy (waith.port, PIANO_RPC_PORT, sizeof (waith.port)-1); + WaitressInit (&app.waith); + strncpy (app.waith.host, PIANO_RPC_HOST, sizeof (app.waith.host)-1); + strncpy (app.waith.port, PIANO_RPC_PORT, sizeof (app.waith.port)-1); - BarSettingsInit (&settings); - BarSettingsRead (&settings); + BarSettingsInit (&app.settings); + BarSettingsRead (&app.settings); BarUiMsg (MSG_NONE, "Welcome to " PACKAGE "! Press %c for a list of commands.\n", - settings.keys[BAR_KS_HELP]); + app.settings.keys[BAR_KS_HELP]); /* init fds */ FD_ZERO(&readSet); @@ -110,44 +104,44 @@ int main (int argc, char **argv) { BarUiMsg (MSG_INFO, "Control fifo at %s opened\n", ctlPath); } - if (settings.username == NULL) { + if (app.settings.username == NULL) { char nameBuf[100]; BarUiMsg (MSG_QUESTION, "Username: "); BarReadlineStr (nameBuf, sizeof (nameBuf), 0, stdin); - settings.username = strdup (nameBuf); + app.settings.username = strdup (nameBuf); } - if (settings.password == NULL) { + if (app.settings.password == NULL) { char passBuf[100]; BarUiMsg (MSG_QUESTION, "Password: "); BarReadlineStr (passBuf, sizeof (passBuf), 1, stdin); - settings.password = strdup (passBuf); + app.settings.password = strdup (passBuf); } /* set up proxy (control proxy for non-us citizen or global proxy for poor * firewalled fellows) */ - if (settings.controlProxy != NULL) { + if (app.settings.controlProxy != NULL) { /* control proxy overrides global proxy */ char tmpPath[2]; - WaitressSplitUrl (settings.controlProxy, waith.proxyHost, - sizeof (waith.proxyHost), waith.proxyPort, - sizeof (waith.proxyPort), tmpPath, sizeof (tmpPath)); - } else if (settings.proxy != NULL && strlen (settings.proxy) > 0) { + WaitressSplitUrl (app.settings.controlProxy, app.waith.proxyHost, + sizeof (app.waith.proxyHost), app.waith.proxyPort, + sizeof (app.waith.proxyPort), tmpPath, sizeof (tmpPath)); + } else if (app.settings.proxy != NULL && strlen (app.settings.proxy) > 0) { char tmpPath[2]; - WaitressSplitUrl (settings.proxy, waith.proxyHost, - sizeof (waith.proxyHost), waith.proxyPort, - sizeof (waith.proxyPort), tmpPath, sizeof (tmpPath)); + WaitressSplitUrl (app.settings.proxy, app.waith.proxyHost, + sizeof (app.waith.proxyHost), app.waith.proxyPort, + sizeof (app.waith.proxyPort), tmpPath, sizeof (tmpPath)); } { PianoReturn_t pRet; WaitressReturn_t wRet; PianoRequestDataLogin_t reqData; - reqData.user = settings.username; - reqData.password = settings.password; + reqData.user = app.settings.username; + reqData.password = app.settings.password; BarUiMsg (MSG_INFO, "Login... "); - if (!BarUiPianoCall (&ph, PIANO_REQUEST_LOGIN, &waith, &reqData, &pRet, - &wRet)) { + if (!BarUiPianoCall (&app.ph, PIANO_REQUEST_LOGIN, &app.waith, + &reqData, &pRet, &wRet)) { BarTermRestore (&termOrig); return 0; } @@ -158,71 +152,71 @@ int main (int argc, char **argv) { WaitressReturn_t wRet; BarUiMsg (MSG_INFO, "Get stations... "); - if (!BarUiPianoCall (&ph, PIANO_REQUEST_GET_STATIONS, &waith, NULL, - &pRet, &wRet)) { + if (!BarUiPianoCall (&app.ph, PIANO_REQUEST_GET_STATIONS, &app.waith, + NULL, &pRet, &wRet)) { BarTermRestore (&termOrig); return 0; } } /* try to get autostart station */ - if (settings.autostartStation != NULL) { - curStation = PianoFindStationById (ph.stations, - settings.autostartStation); - if (curStation == NULL) { + if (app.settings.autostartStation != NULL) { + app.curStation = PianoFindStationById (app.ph.stations, + app.settings.autostartStation); + if (app.curStation == NULL) { BarUiMsg (MSG_ERR, "Error: Autostart station not found.\n"); } } /* no autostart? ask the user */ - if (curStation == NULL) { - curStation = BarUiSelectStation (&ph, "Select station: ", - settings.sortOrder, stdin); + if (app.curStation == NULL) { + app.curStation = BarUiSelectStation (&app.ph, "Select station: ", + app.settings.sortOrder, stdin); } - if (curStation != NULL) { - BarUiPrintStation (curStation); + if (app.curStation != NULL) { + BarUiPrintStation (app.curStation); } /* little hack, needed to signal: hey! we need a playlist, but don't * free anything (there is nothing to be freed yet) */ - memset (&player, 0, sizeof (player)); + memset (&app.player, 0, sizeof (app.player)); - while (!doQuit) { + while (!app.doQuit) { /* song finished playing, clean up things/scrobble song */ - if (player.mode == PLAYER_FINISHED_PLAYBACK) { - BarUiStartEventCmd (&settings, "songfinish", curStation, playlist, - &player, PIANO_RET_OK, WAITRESS_RET_OK); + if (app.player.mode == PLAYER_FINISHED_PLAYBACK) { + BarUiStartEventCmd (&app.settings, "songfinish", app.curStation, + app.playlist, &app.player, PIANO_RET_OK, WAITRESS_RET_OK); /* FIXME: pthread_join blocks everything if network connection * is hung up e.g. */ void *threadRet; pthread_join (playerThread, &threadRet); /* don't continue playback if thread reports error */ if (threadRet != (void *) PLAYER_RET_OK) { - curStation = NULL; + app.curStation = NULL; } - memset (&player, 0, sizeof (player)); + memset (&app.player, 0, sizeof (app.player)); } /* check whether player finished playing and start playing new * song */ - if (player.mode >= PLAYER_FINISHED_PLAYBACK || - player.mode == PLAYER_FREED) { - if (curStation != NULL) { + if (app.player.mode >= PLAYER_FINISHED_PLAYBACK || + app.player.mode == PLAYER_FREED) { + if (app.curStation != NULL) { /* what's next? */ - if (playlist != NULL) { - if (settings.history != 0) { + if (app.playlist != NULL) { + if (app.settings.history != 0) { /* prepend song to history list */ - PianoSong_t *tmpSong = songHistory; - songHistory = playlist; + PianoSong_t *tmpSong = app.songHistory; + app.songHistory = app.playlist; /* select next song */ - playlist = playlist->next; - songHistory->next = tmpSong; + app.playlist = app.playlist->next; + app.songHistory->next = tmpSong; /* limit history's length */ /* start with 1, so we're stopping at n-1 and have the * chance to set ->next = NULL */ unsigned int i = 1; - tmpSong = songHistory; - while (i < settings.history && tmpSong != NULL) { + tmpSong = app.songHistory; + while (i < app.settings.history && tmpSong != NULL) { tmpSong = tmpSong->next; ++i; } @@ -236,70 +230,71 @@ int main (int argc, char **argv) { } } else { /* don't keep history */ - playlist = playlist->next; + app.playlist = app.playlist->next; } } - if (playlist == NULL) { + if (app.playlist == NULL) { PianoReturn_t pRet; WaitressReturn_t wRet; PianoRequestDataGetPlaylist_t reqData; - reqData.station = curStation; - reqData.format = settings.audioFormat; + reqData.station = app.curStation; + reqData.format = app.settings.audioFormat; BarUiMsg (MSG_INFO, "Receiving new playlist... "); - if (!BarUiPianoCall (&ph, PIANO_REQUEST_GET_PLAYLIST, - &waith, &reqData, &pRet, &wRet)) { - curStation = NULL; + if (!BarUiPianoCall (&app.ph, PIANO_REQUEST_GET_PLAYLIST, + &app.waith, &reqData, &pRet, &wRet)) { + app.curStation = NULL; } else { - playlist = reqData.retPlaylist; - if (playlist == NULL) { + app.playlist = reqData.retPlaylist; + if (app.playlist == NULL) { BarUiMsg (MSG_INFO, "No tracks left.\n"); - curStation = NULL; + app.curStation = NULL; } } - BarUiStartEventCmd (&settings, "stationfetchplaylist", - curStation, playlist, &player, pRet, wRet); + BarUiStartEventCmd (&app.settings, "stationfetchplaylist", + app.curStation, app.playlist, &app.player, pRet, + wRet); } /* song ready to play */ - if (playlist != NULL) { - BarUiPrintSong (playlist, curStation->isQuickMix ? - PianoFindStationById (ph.stations, - playlist->stationId) : NULL); + if (app.playlist != NULL) { + BarUiPrintSong (app.playlist, app.curStation->isQuickMix ? + PianoFindStationById (app.ph.stations, + app.playlist->stationId) : NULL); - if (playlist->audioUrl == NULL) { + if (app.playlist->audioUrl == NULL) { BarUiMsg (MSG_ERR, "Invalid song url.\n"); } else { /* setup player */ - memset (&player, 0, sizeof (player)); + memset (&app.player, 0, sizeof (app.player)); - WaitressInit (&player.waith); - WaitressSetUrl (&player.waith, playlist->audioUrl); + WaitressInit (&app.player.waith); + WaitressSetUrl (&app.player.waith, app.playlist->audioUrl); /* set up global proxy, player is NULLed on songfinish */ - if (settings.proxy != NULL) { + if (app.settings.proxy != NULL) { char tmpPath[2]; - WaitressSplitUrl (settings.proxy, - player.waith.proxyHost, - sizeof (player.waith.proxyHost), - player.waith.proxyPort, - sizeof (player.waith.proxyPort), tmpPath, + WaitressSplitUrl (app.settings.proxy, + app.player.waith.proxyHost, + sizeof (app.player.waith.proxyHost), + app.player.waith.proxyPort, + sizeof (app.player.waith.proxyPort), tmpPath, sizeof (tmpPath)); } - player.gain = playlist->fileGain; - player.audioFormat = playlist->audioFormat; + app.player.gain = app.playlist->fileGain; + app.player.audioFormat = app.playlist->audioFormat; /* throw event */ - BarUiStartEventCmd (&settings, "songstart", curStation, - playlist, &player, PIANO_RET_OK, - WAITRESS_RET_OK); + BarUiStartEventCmd (&app.settings, "songstart", + app.curStation, app.playlist, &app.player, + PIANO_RET_OK, WAITRESS_RET_OK); /* prevent race condition, mode must _not_ be FREED if * thread has been started */ - player.mode = PLAYER_STARTING; + app.player.mode = PLAYER_STARTING; /* start player */ pthread_create (&playerThread, NULL, BarPlayerThread, - &player); + &app.player); } /* end if audioUrl == NULL */ } /* end if playlist != NULL */ } /* end if curStation != NULL */ @@ -323,7 +318,7 @@ int main (int argc, char **argv) { size_t i; for (i = 0; i < BAR_KS_COUNT; i++) { - if (settings.keys[i] == buf) { + if (app.settings.keys[i] == buf) { static const BarKeyShortcutFunc_t idToF[] = {BarUiActHelp, BarUiActLoveSong, BarUiActBanSong, BarUiActAddMusic, BarUiActCreateStation, @@ -335,20 +330,19 @@ int main (int argc, char **argv) { BarUiActSelectStation, BarUiActTempBanSong, BarUiActPrintUpcoming, BarUiActSelectQuickMix, BarUiActDebug, BarUiActBookmark}; - idToF[i] (&ph, &waith, &player, &settings, &playlist, - &curStation, &songHistory, &doQuit, curFd); + idToF[i] (&app, curFd); break; } } } /* show time */ - if (player.mode >= PLAYER_SAMPLESIZE_INITIALIZED && - player.mode < PLAYER_FINISHED_PLAYBACK) { + if (app.player.mode >= PLAYER_SAMPLESIZE_INITIALIZED && + app.player.mode < PLAYER_FINISHED_PLAYBACK) { /* Ugly: songDuration is unsigned _long_ int! Lets hope this won't * overflow */ - int songRemaining = (signed long int) (player.songDuration - player.songPlayed) - / BAR_PLAYER_MS_TO_S_FACTOR; + int songRemaining = (signed long int) (app.player.songDuration - + app.player.songPlayed) / BAR_PLAYER_MS_TO_S_FACTOR; char pos = 0; if (songRemaining < 0) { /* Use plus sign if song is longer than expected */ @@ -357,23 +351,23 @@ int main (int argc, char **argv) { } BarUiMsg (MSG_TIME, "%c%02i:%02i/%02i:%02i\r", (pos ? '+' : '-'), songRemaining / 60, songRemaining % 60, - player.songDuration / BAR_PLAYER_MS_TO_S_FACTOR / 60, - player.songDuration / BAR_PLAYER_MS_TO_S_FACTOR % 60); + app.player.songDuration / BAR_PLAYER_MS_TO_S_FACTOR / 60, + app.player.songDuration / BAR_PLAYER_MS_TO_S_FACTOR % 60); } } /* destroy everything (including the world...) */ - if (player.mode != PLAYER_FREED) { + if (app.player.mode != PLAYER_FREED) { pthread_join (playerThread, NULL); } if (ctlFd != NULL) { fclose (ctlFd); } - PianoDestroy (&ph); - PianoDestroyPlaylist (songHistory); - PianoDestroyPlaylist (playlist); + PianoDestroy (&app.ph); + PianoDestroyPlaylist (app.songHistory); + PianoDestroyPlaylist (app.playlist); ao_shutdown(); - BarSettingsDestroy (&settings); + BarSettingsDestroy (&app.settings); /* restore terminal attributes, zsh doesn't need this, bash does... */ BarTermRestore (&termOrig); diff --git a/src/main.h b/src/main.h new file mode 100644 index 0000000..e22e2c0 --- /dev/null +++ b/src/main.h @@ -0,0 +1,46 @@ +/* +Copyright (c) 2008-2010 + Lars-Dominik Braun <PromyLOPh@lavabit.com> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#ifndef _MAIN_H +#define _MAIN_H + +#include <piano.h> +#include <waitress.h> + +#include "player.h" +#include "settings.h" + +typedef struct { + PianoHandle_t ph; + WaitressHandle_t waith; + struct audioPlayer player; + BarSettings_t settings; + /* first item is current song */ + PianoSong_t *playlist; + PianoSong_t *songHistory; + PianoStation_t *curStation; + char doQuit; +} BarApp_t; + +#endif /* _MAIN_H */ + diff --git a/src/settings.h b/src/settings.h index 2505321..f977a47 100644 --- a/src/settings.h +++ b/src/settings.h @@ -27,14 +27,6 @@ THE SOFTWARE. #include <piano.h> #include <waitress.h> -#include "player.h" - -#define BAR_KS_ARGS PianoHandle_t *ph, WaitressHandle_t *waith, \ - struct audioPlayer *player, \ - BarSettings_t *settings, PianoSong_t **curSong, \ - PianoStation_t **curStation, PianoSong_t **songHistory, char *doQuit, \ - FILE *curFd - /* keep in mind that you have to update several arrays in main.c/ui_act.c too, * if you're adding new shortcuts */ typedef enum { @@ -87,8 +79,6 @@ typedef struct { char *eventCmd; } BarSettings_t; -typedef void (*BarKeyShortcutFunc_t) (BAR_KS_ARGS); - void BarSettingsInit (BarSettings_t *); void BarSettingsDestroy (BarSettings_t *); void BarSettingsRead (BarSettings_t *); diff --git a/src/ui_act.c b/src/ui_act.c index d907304..d411474 100644 --- a/src/ui_act.c +++ b/src/ui_act.c @@ -31,11 +31,11 @@ THE SOFTWARE. #include "ui_act.h" #include "ui_readline.h" -#define RETURN_IF_NO_STATION if (*curStation == NULL) { \ +#define RETURN_IF_NO_STATION if (app->curStation == NULL) { \ BarUiMsg (MSG_ERR, "No station selected.\n"); \ return; } -#define RETURN_IF_NO_SONG if (*curStation == NULL || *curSong == NULL) { \ +#define RETURN_IF_NO_SONG if (app->curStation == NULL || app->playlist == NULL) { \ BarUiMsg (MSG_ERR, "No song playing.\n"); \ return; } @@ -70,7 +70,7 @@ static int BarTransformIfShared (PianoHandle_t *ph, WaitressHandle_t *waith, /* print current shortcut configuration */ -void BarUiActHelp (BAR_KS_ARGS) { +BarUiActCallback(BarUiActHelp) { static const char *idToDesc[] = { NULL, "love current song", @@ -100,85 +100,86 @@ void BarUiActHelp (BAR_KS_ARGS) { BarUiMsg (MSG_NONE, "\r"); for (i = 0; i < BAR_KS_COUNT; i++) { if (idToDesc[i] != NULL) { - BarUiMsg (MSG_LIST, "%c %s\n", settings->keys[i], idToDesc[i]); + BarUiMsg (MSG_LIST, "%c %s\n", app->settings.keys[i], idToDesc[i]); } } } /* add more music to current station */ -void BarUiActAddMusic (BAR_KS_ARGS) { +BarUiActCallback(BarUiActAddMusic) { PianoReturn_t pRet; WaitressReturn_t wRet; PianoRequestDataAddSeed_t reqData; RETURN_IF_NO_STATION; - reqData.musicId = BarUiSelectMusicId (ph, waith, curFd, (*curSong)->musicId); + reqData.musicId = BarUiSelectMusicId (&app->ph, &app->waith, curFd, + app->playlist->musicId); if (reqData.musicId != NULL) { - if (!BarTransformIfShared (ph, waith, *curStation)) { + if (!BarTransformIfShared (&app->ph, &app->waith, app->curStation)) { return; } - reqData.station = *curStation; + reqData.station = app->curStation; BarUiMsg (MSG_INFO, "Adding music to station... "); - BarUiPianoCall (ph, PIANO_REQUEST_ADD_SEED, waith, &reqData, &pRet, - &wRet); + BarUiPianoCall (&app->ph, PIANO_REQUEST_ADD_SEED, &app->waith, &reqData, + &pRet, &wRet); free (reqData.musicId); - BarUiStartEventCmd (settings, "stationaddmusic", *curStation, *curSong, - player, pRet, wRet); + BarUiStartEventCmd (&app->settings, "stationaddmusic", app->curStation, + app->playlist, &app->player, pRet, wRet); } } /* ban song */ -void BarUiActBanSong (BAR_KS_ARGS) { +BarUiActCallback(BarUiActBanSong) { PianoReturn_t pRet; WaitressReturn_t wRet; RETURN_IF_NO_SONG; - if (!BarTransformIfShared (ph, waith, *curStation)) { + if (!BarTransformIfShared (&app->ph, &app->waith, app->curStation)) { return; } PianoRequestDataRateSong_t reqData; - reqData.song = *curSong; + reqData.song = app->playlist; reqData.rating = PIANO_RATE_BAN; BarUiMsg (MSG_INFO, "Banning song... "); - if (BarUiPianoCall (ph, PIANO_REQUEST_RATE_SONG, waith, &reqData, &pRet, - &wRet)) { - BarUiDoSkipSong (player); + if (BarUiPianoCall (&app->ph, PIANO_REQUEST_RATE_SONG, &app->waith, &reqData, + &pRet, &wRet)) { + BarUiDoSkipSong (&app->player); } - BarUiStartEventCmd (settings, "songban", *curStation, *curSong, player, - pRet, wRet); + BarUiStartEventCmd (&app->settings, "songban", app->curStation, + app->playlist, &app->player, pRet, wRet); } /* create new station */ -void BarUiActCreateStation (BAR_KS_ARGS) { +BarUiActCallback(BarUiActCreateStation) { PianoReturn_t pRet; WaitressReturn_t wRet; PianoRequestDataCreateStation_t reqData; - reqData.id = BarUiSelectMusicId (ph, waith, curFd, NULL); + reqData.id = BarUiSelectMusicId (&app->ph, &app->waith, curFd, NULL); if (reqData.id != NULL) { reqData.type = "mi"; BarUiMsg (MSG_INFO, "Creating station... "); - BarUiPianoCall (ph, PIANO_REQUEST_CREATE_STATION, waith, &reqData, - &pRet, &wRet); + BarUiPianoCall (&app->ph, PIANO_REQUEST_CREATE_STATION, &app->waith, + &reqData, &pRet, &wRet); free (reqData.id); - BarUiStartEventCmd (settings, "stationcreate", *curStation, *curSong, - player, pRet, wRet); + BarUiStartEventCmd (&app->settings, "stationcreate", app->curStation, + app->playlist, &app->player, pRet, wRet); } } /* add shared station by id */ -void BarUiActAddSharedStation (BAR_KS_ARGS) { +BarUiActCallback(BarUiActAddSharedStation) { PianoReturn_t pRet; WaitressReturn_t wRet; PianoRequestDataCreateStation_t reqData; @@ -190,79 +191,80 @@ void BarUiActAddSharedStation (BAR_KS_ARGS) { reqData.id = stationId; reqData.type = "sh"; BarUiMsg (MSG_INFO, "Adding shared station... "); - BarUiPianoCall (ph, PIANO_REQUEST_CREATE_STATION, waith, &reqData, - &pRet, &wRet); - BarUiStartEventCmd (settings, "stationaddshared", *curStation, - *curSong, player, pRet, wRet); + BarUiPianoCall (&app->ph, PIANO_REQUEST_CREATE_STATION, &app->waith, + &reqData, &pRet, &wRet); + BarUiStartEventCmd (&app->settings, "stationaddshared", + app->curStation, app->playlist, &app->player, pRet, wRet); } } /* delete current station */ -void BarUiActDeleteStation (BAR_KS_ARGS) { +BarUiActCallback(BarUiActDeleteStation) { PianoReturn_t pRet; WaitressReturn_t wRet; RETURN_IF_NO_STATION; BarUiMsg (MSG_QUESTION, "Really delete \"%s\"? [yN] ", - (*curStation)->name); + app->curStation->name); if (BarReadlineYesNo (0, curFd)) { BarUiMsg (MSG_INFO, "Deleting station... "); - if (BarUiPianoCall (ph, PIANO_REQUEST_DELETE_STATION, waith, - *curStation, &pRet, &wRet)) { - BarUiDoSkipSong (player); - PianoDestroyPlaylist (*curSong); - *curSong = NULL; - *curStation = NULL; + if (BarUiPianoCall (&app->ph, PIANO_REQUEST_DELETE_STATION, + &app->waith, app->curStation, &pRet, &wRet)) { + BarUiDoSkipSong (&app->player); + PianoDestroyPlaylist (app->playlist); + app->playlist = NULL; + app->curStation = NULL; } - BarUiStartEventCmd (settings, "stationdelete", *curStation, *curSong, - player, pRet, wRet); + BarUiStartEventCmd (&app->settings, "stationdelete", app->curStation, + app->playlist, &app->player, pRet, wRet); } } /* explain pandora's song choice */ -void BarUiActExplain (BAR_KS_ARGS) { +BarUiActCallback(BarUiActExplain) { PianoReturn_t pRet; WaitressReturn_t wRet; PianoRequestDataExplain_t reqData; RETURN_IF_NO_STATION; - reqData.song = *curSong; + reqData.song = app->playlist; BarUiMsg (MSG_INFO, "Receiving explanation... "); - if (BarUiPianoCall (ph, PIANO_REQUEST_EXPLAIN, waith, &reqData, &pRet, - &wRet)) { + if (BarUiPianoCall (&app->ph, PIANO_REQUEST_EXPLAIN, &app->waith, &reqData, + &pRet, &wRet)) { BarUiMsg (MSG_INFO, "%s\n", reqData.retExplain); free (reqData.retExplain); } - BarUiStartEventCmd (settings, "songexplain", *curStation, *curSong, player, - pRet, wRet); + BarUiStartEventCmd (&app->settings, "songexplain", app->curStation, + app->playlist, &app->player, pRet, wRet); } /* choose genre station and add it as shared station */ -void BarUiActStationFromGenre (BAR_KS_ARGS) { +BarUiActCallback(BarUiActStationFromGenre) { /* use genre station */ - BarStationFromGenre (ph, waith, curFd); + BarStationFromGenre (&app->ph, &app->waith, curFd); } /* print verbose song information */ -void BarUiActSongInfo (BAR_KS_ARGS) { +BarUiActCallback(BarUiActSongInfo) { RETURN_IF_NO_SONG; - BarUiPrintStation ((*curStation)); + BarUiPrintStation (app->curStation); /* print real station if quickmix */ - BarUiPrintSong ((*curSong), (*curStation)->isQuickMix ? - PianoFindStationById (ph->stations, (*curSong)->stationId) : NULL); + BarUiPrintSong (app->playlist, app->curStation->isQuickMix ? + PianoFindStationById (app->ph.stations, app->playlist->stationId) : + NULL); } /* print some debugging information */ -void BarUiActDebug (BAR_KS_ARGS) { +BarUiActCallback(BarUiActDebug) { RETURN_IF_NO_SONG; /* print debug-alike infos */ @@ -280,45 +282,47 @@ void BarUiActDebug (BAR_KS_ARGS) { "stationId:\t%s\n" "title:\t%s\n" "userSeed:\t%s\n", - (*curSong)->album, (*curSong)->artist, (*curSong)->audioFormat, - (*curSong)->audioUrl, (*curSong)->fileGain, - (*curSong)->focusTraitId, (*curSong)->identity, - (*curSong)->matchingSeed, (*curSong)->musicId, (*curSong)->rating, - (*curSong)->stationId, (*curSong)->title, (*curSong)->userSeed); + app->playlist->album, app->playlist->artist, + app->playlist->audioFormat, app->playlist->audioUrl, + app->playlist->fileGain, app->playlist->focusTraitId, + app->playlist->identity, app->playlist->matchingSeed, + app->playlist->musicId, app->playlist->rating, + app->playlist->stationId, app->playlist->title, + app->playlist->userSeed); } /* rate current song */ -void BarUiActLoveSong (BAR_KS_ARGS) { +BarUiActCallback(BarUiActLoveSong) { PianoReturn_t pRet; WaitressReturn_t wRet; RETURN_IF_NO_SONG; - if (!BarTransformIfShared (ph, waith, *curStation)) { + if (!BarTransformIfShared (&app->ph, &app->waith, app->curStation)) { return; } PianoRequestDataRateSong_t reqData; - reqData.song = *curSong; + reqData.song = app->playlist; reqData.rating = PIANO_RATE_LOVE; BarUiMsg (MSG_INFO, "Loving song... "); - BarUiPianoCall (ph, PIANO_REQUEST_RATE_SONG, waith, &reqData, &pRet, - &wRet); - BarUiStartEventCmd (settings, "songlove", *curStation, *curSong, player, - pRet, wRet); + BarUiPianoCall (&app->ph, PIANO_REQUEST_RATE_SONG, &app->waith, &reqData, + &pRet, &wRet); + BarUiStartEventCmd (&app->settings, "songlove", app->curStation, + app->playlist, &app->player, pRet, wRet); } /* skip song */ -void BarUiActSkipSong (BAR_KS_ARGS) { - BarUiDoSkipSong (player); +BarUiActCallback(BarUiActSkipSong) { + BarUiDoSkipSong (&app->player); } /* move song to different station */ -void BarUiActMoveSong (BAR_KS_ARGS) { +BarUiActCallback(BarUiActMoveSong) { PianoReturn_t pRet; WaitressReturn_t wRet; PianoRequestDataMoveSong_t reqData; @@ -327,44 +331,45 @@ void BarUiActMoveSong (BAR_KS_ARGS) { RETURN_IF_NO_SONG; - reqData.to = BarUiSelectStation (ph, "Move song to station: ", - settings->sortOrder, curFd); + reqData.to = BarUiSelectStation (&app->ph, "Move song to station: ", + app->settings.sortOrder, curFd); if (reqData.to != NULL) { /* find original station (just is case we're playing a quickmix * station) */ - reqData.from = PianoFindStationById (ph->stations, (*curSong)->stationId); + reqData.from = PianoFindStationById (app->ph.stations, + app->playlist->stationId); if (reqData.from == NULL) { BarUiMsg (MSG_ERR, "Station not found\n"); return; } - if (!BarTransformIfShared (ph, waith, reqData.from) || - !BarTransformIfShared (ph, waith, reqData.to)) { + if (!BarTransformIfShared (&app->ph, &app->waith, reqData.from) || + !BarTransformIfShared (&app->ph, &app->waith, reqData.to)) { return; } BarUiMsg (MSG_INFO, "Moving song to \"%s\"... ", reqData.to->name); - reqData.song = *curSong; - if (BarUiPianoCall (ph, PIANO_REQUEST_MOVE_SONG, waith, &reqData, - &pRet, &wRet)) { - BarUiDoSkipSong (player); + reqData.song = app->playlist; + if (BarUiPianoCall (&app->ph, PIANO_REQUEST_MOVE_SONG, &app->waith, + &reqData, &pRet, &wRet)) { + BarUiDoSkipSong (&app->player); } - BarUiStartEventCmd (settings, "songmove", *curStation, *curSong, - player, pRet, wRet); + BarUiStartEventCmd (&app->settings, "songmove", app->curStation, + app->playlist, &app->player, pRet, wRet); } } /* pause */ -void BarUiActPause (BAR_KS_ARGS) { +BarUiActCallback(BarUiActPause) { /* already locked => unlock/unpause */ - if (pthread_mutex_trylock (&player->pauseMutex) == EBUSY) { - pthread_mutex_unlock (&player->pauseMutex); + if (pthread_mutex_trylock (&app->player.pauseMutex) == EBUSY) { + pthread_mutex_unlock (&app->player.pauseMutex); } } /* rename current station */ -void BarUiActRenameStation (BAR_KS_ARGS) { +BarUiActCallback(BarUiActRenameStation) { PianoReturn_t pRet; WaitressReturn_t wRet; char lineBuf[100]; @@ -374,58 +379,58 @@ void BarUiActRenameStation (BAR_KS_ARGS) { BarUiMsg (MSG_QUESTION, "New name: "); if (BarReadlineStr (lineBuf, sizeof (lineBuf), 0, curFd) > 0) { PianoRequestDataRenameStation_t reqData; - if (!BarTransformIfShared (ph, waith, *curStation)) { + if (!BarTransformIfShared (&app->ph, &app->waith, app->curStation)) { return; } - reqData.station = *curStation; + reqData.station = app->curStation; reqData.newName = lineBuf; BarUiMsg (MSG_INFO, "Renaming station... "); - BarUiPianoCall (ph, PIANO_REQUEST_RENAME_STATION, waith, &reqData, - &pRet, &wRet); - BarUiStartEventCmd (settings, "stationrename", *curStation, *curSong, - player, pRet, wRet); + BarUiPianoCall (&app->ph, PIANO_REQUEST_RENAME_STATION, &app->waith, + &reqData, &pRet, &wRet); + BarUiStartEventCmd (&app->settings, "stationrename", app->curStation, + app->playlist, &app->player, pRet, wRet); } } /* play another station */ -void BarUiActSelectStation (BAR_KS_ARGS) { - PianoStation_t *newStation = BarUiSelectStation (ph, "Select station: ", - settings->sortOrder, curFd); +BarUiActCallback(BarUiActSelectStation) { + PianoStation_t *newStation = BarUiSelectStation (&app->ph, "Select station: ", + app->settings.sortOrder, curFd); if (newStation != NULL) { - *curStation = newStation; - BarUiPrintStation ((*curStation)); - BarUiDoSkipSong (player); - PianoDestroyPlaylist (*curSong); - *curSong = NULL; + app->curStation = newStation; + BarUiPrintStation (app->curStation); + BarUiDoSkipSong (&app->player); + PianoDestroyPlaylist (app->playlist); + app->playlist = NULL; } } /* ban song for 1 month */ -void BarUiActTempBanSong (BAR_KS_ARGS) { +BarUiActCallback(BarUiActTempBanSong) { PianoReturn_t pRet; WaitressReturn_t wRet; RETURN_IF_NO_SONG; BarUiMsg (MSG_INFO, "Putting song on shelf... "); - if (BarUiPianoCall (ph, PIANO_REQUEST_ADD_TIRED_SONG, waith, *curSong, - &pRet, &wRet)) { - BarUiDoSkipSong (player); + if (BarUiPianoCall (&app->ph, PIANO_REQUEST_ADD_TIRED_SONG, &app->waith, + app->playlist, &pRet, &wRet)) { + BarUiDoSkipSong (&app->player); } - BarUiStartEventCmd (settings, "songshelf", *curStation, *curSong, player, - pRet, wRet); + BarUiStartEventCmd (&app->settings, "songshelf", app->curStation, + app->playlist, &app->player, pRet, wRet); } /* print upcoming songs */ -void BarUiActPrintUpcoming (BAR_KS_ARGS) { +BarUiActCallback(BarUiActPrintUpcoming) { RETURN_IF_NO_SONG; - PianoSong_t *nextSong = (*curSong)->next; + PianoSong_t *nextSong = app->playlist->next; if (nextSong != NULL) { int i = 0; while (nextSong != NULL) { @@ -442,24 +447,24 @@ void BarUiActPrintUpcoming (BAR_KS_ARGS) { /* if current station is a quickmix: select stations that are played in * quickmix */ -void BarUiActSelectQuickMix (BAR_KS_ARGS) { +BarUiActCallback(BarUiActSelectQuickMix) { PianoReturn_t pRet; WaitressReturn_t wRet; RETURN_IF_NO_STATION; - if ((*curStation)->isQuickMix) { + if (app->curStation->isQuickMix) { PianoStation_t *selStation; - while ((selStation = BarUiSelectStation (ph, - "Toggle quickmix for station: ", settings->sortOrder, + while ((selStation = BarUiSelectStation (&app->ph, + "Toggle quickmix for station: ", app->settings.sortOrder, curFd)) != NULL) { selStation->useQuickMix = !selStation->useQuickMix; } BarUiMsg (MSG_INFO, "Setting quickmix stations... "); - BarUiPianoCall (ph, PIANO_REQUEST_SET_QUICKMIX, waith, NULL, &pRet, - &wRet); - BarUiStartEventCmd (settings, "stationquickmixtoggle", *curStation, - *curSong, player, pRet, wRet); + BarUiPianoCall (&app->ph, PIANO_REQUEST_SET_QUICKMIX, &app->waith, + NULL, &pRet, &wRet); + BarUiStartEventCmd (&app->settings, "stationquickmixtoggle", app->curStation, + app->playlist, &app->player, pRet, wRet); } else { BarUiMsg (MSG_ERR, "Not a QuickMix station.\n"); } @@ -467,38 +472,39 @@ void BarUiActSelectQuickMix (BAR_KS_ARGS) { /* quit */ -void BarUiActQuit (BAR_KS_ARGS) { - *doQuit = 1; - BarUiDoSkipSong (player); +BarUiActCallback(BarUiActQuit) { + app->doQuit = 1; + BarUiDoSkipSong (&app->player); } /* song history */ -void BarUiActHistory (BAR_KS_ARGS) { +BarUiActCallback(BarUiActHistory) { PianoReturn_t pRet; WaitressReturn_t wRet; char selectBuf[2], allowedBuf[3]; PianoSong_t *selectedSong; - if (*songHistory != NULL) { - selectedSong = BarUiSelectSong (*songHistory, curFd); + if (app->songHistory != NULL) { + selectedSong = BarUiSelectSong (app->songHistory, curFd); if (selectedSong != NULL) { /* use user-defined keybindings */ - allowedBuf[0] = settings->keys[BAR_KS_LOVE]; - allowedBuf[1] = settings->keys[BAR_KS_BAN]; + allowedBuf[0] = app->settings.keys[BAR_KS_LOVE]; + allowedBuf[1] = app->settings.keys[BAR_KS_BAN]; allowedBuf[2] = '\0'; BarUiMsg (MSG_QUESTION, "%s - %s: love[%c] or ban[%c]? ", selectedSong->artist, selectedSong->title, - settings->keys[BAR_KS_LOVE], settings->keys[BAR_KS_BAN]); + app->settings.keys[BAR_KS_LOVE], + app->settings.keys[BAR_KS_BAN]); BarReadline (selectBuf, sizeof (selectBuf), allowedBuf, 1, 0, curFd); - if (selectBuf[0] == settings->keys[BAR_KS_LOVE] || - selectBuf[0] == settings->keys[BAR_KS_BAN]) { + if (selectBuf[0] == app->settings.keys[BAR_KS_LOVE] || + selectBuf[0] == app->settings.keys[BAR_KS_BAN]) { /* make sure we're transforming the _original_ station (not * curStation) */ PianoStation_t *songStation = - PianoFindStationById (ph->stations, + PianoFindStationById (app->ph.stations, selectedSong->stationId); if (songStation == NULL) { @@ -506,44 +512,44 @@ void BarUiActHistory (BAR_KS_ARGS) { return; } - if (!BarTransformIfShared (ph, waith, songStation)) { + if (!BarTransformIfShared (&app->ph, &app->waith, songStation)) { return; } - if (selectBuf[0] == settings->keys[BAR_KS_LOVE]) { + if (selectBuf[0] == app->settings.keys[BAR_KS_LOVE]) { /* FIXME: copy&waste */ PianoRequestDataRateSong_t reqData; reqData.song = selectedSong; reqData.rating = PIANO_RATE_LOVE; BarUiMsg (MSG_INFO, "Loving song... "); - BarUiPianoCall (ph, PIANO_REQUEST_RATE_SONG, waith, - &reqData, &pRet, &wRet); + BarUiPianoCall (&app->ph, PIANO_REQUEST_RATE_SONG, + &app->waith, &reqData, &pRet, &wRet); - BarUiStartEventCmd (settings, "songlove", songStation, - selectedSong, player, pRet, wRet); - } else if (selectBuf[0] == settings->keys[BAR_KS_BAN]) { + BarUiStartEventCmd (&app->settings, "songlove", songStation, + selectedSong, &app->player, pRet, wRet); + } else if (selectBuf[0] == app->settings.keys[BAR_KS_BAN]) { PianoRequestDataRateSong_t reqData; reqData.song = selectedSong; reqData.rating = PIANO_RATE_BAN; BarUiMsg (MSG_INFO, "Banning song... "); - BarUiPianoCall (ph, PIANO_REQUEST_RATE_SONG, waith, - &reqData, &pRet, &wRet); - BarUiStartEventCmd (settings, "songban", songStation, - selectedSong, player, pRet, wRet); + BarUiPianoCall (&app->ph, PIANO_REQUEST_RATE_SONG, + &app->waith, &reqData, &pRet, &wRet); + BarUiStartEventCmd (&app->settings, "songban", songStation, + selectedSong, &app->player, pRet, wRet); } /* end if */ } /* end if selectBuf[0] */ } /* end if selectedSong != NULL */ } else { - BarUiMsg (MSG_INFO, (settings->history == 0) ? "History disabled.\n" : + BarUiMsg (MSG_INFO, (app->settings.history == 0) ? "History disabled.\n" : "No history yet.\n"); } } /* create song bookmark */ -void BarUiActBookmark (BAR_KS_ARGS) { +BarUiActCallback(BarUiActBookmark) { PianoReturn_t pRet; WaitressReturn_t wRet; char selectBuf[2]; @@ -554,16 +560,16 @@ void BarUiActBookmark (BAR_KS_ARGS) { BarReadline (selectBuf, sizeof (selectBuf), "sa", 1, 0, curFd); if (selectBuf[0] == 's') { BarUiMsg (MSG_INFO, "Bookmarking song... "); - BarUiPianoCall (ph, PIANO_REQUEST_BOOKMARK_SONG, waith, *curSong, - &pRet, &wRet); - BarUiStartEventCmd (settings, "songbookmark", *curStation, *curSong, - player, pRet, wRet); + BarUiPianoCall (&app->ph, PIANO_REQUEST_BOOKMARK_SONG, &app->waith, + app->playlist, &pRet, &wRet); + BarUiStartEventCmd (&app->settings, "songbookmark", app->curStation, + app->playlist, &app->player, pRet, wRet); } else if (selectBuf[0] == 'a') { BarUiMsg (MSG_INFO, "Bookmarking artist... "); - BarUiPianoCall (ph, PIANO_REQUEST_BOOKMARK_ARTIST, waith, *curSong, - &pRet, &wRet); - BarUiStartEventCmd (settings, "artistbookmark", *curStation, *curSong, - player, pRet, wRet); + BarUiPianoCall (&app->ph, PIANO_REQUEST_BOOKMARK_ARTIST, &app->waith, + app->playlist, &pRet, &wRet); + BarUiStartEventCmd (&app->settings, "artistbookmark", app->curStation, + app->playlist, &app->player, pRet, wRet); } } diff --git a/src/ui_act.h b/src/ui_act.h index 2da5883..f731f72 100644 --- a/src/ui_act.h +++ b/src/ui_act.h @@ -24,29 +24,31 @@ THE SOFTWARE. #ifndef _UI_ACT_H #define _UI_ACT_H -#include "settings.h" - -void BarUiActHelp (BAR_KS_ARGS); -void BarUiActAddMusic (BAR_KS_ARGS); -void BarUiActBanSong (BAR_KS_ARGS); -void BarUiActCreateStation (BAR_KS_ARGS); -void BarUiActAddSharedStation (BAR_KS_ARGS); -void BarUiActDeleteStation (BAR_KS_ARGS); -void BarUiActExplain (BAR_KS_ARGS); -void BarUiActStationFromGenre (BAR_KS_ARGS); -void BarUiActSongInfo (BAR_KS_ARGS); -void BarUiActLoveSong (BAR_KS_ARGS); -void BarUiActSkipSong (BAR_KS_ARGS); -void BarUiActMoveSong (BAR_KS_ARGS); -void BarUiActPause (BAR_KS_ARGS); -void BarUiActRenameStation (BAR_KS_ARGS); -void BarUiActSelectStation (BAR_KS_ARGS); -void BarUiActTempBanSong (BAR_KS_ARGS); -void BarUiActPrintUpcoming (BAR_KS_ARGS); -void BarUiActSelectQuickMix (BAR_KS_ARGS); -void BarUiActQuit (BAR_KS_ARGS); -void BarUiActDebug (BAR_KS_ARGS); -void BarUiActHistory (BAR_KS_ARGS); -void BarUiActBookmark (BAR_KS_ARGS); +#include "main.h" + +#define BarUiActCallback(name) void name (BarApp_t *app, FILE *curFd) + +BarUiActCallback(BarUiActHelp); +BarUiActCallback(BarUiActAddMusic); +BarUiActCallback(BarUiActBanSong); +BarUiActCallback(BarUiActCreateStation); +BarUiActCallback(BarUiActAddSharedStation); +BarUiActCallback(BarUiActDeleteStation); +BarUiActCallback(BarUiActExplain); +BarUiActCallback(BarUiActStationFromGenre); +BarUiActCallback(BarUiActSongInfo); +BarUiActCallback(BarUiActLoveSong); +BarUiActCallback(BarUiActSkipSong); +BarUiActCallback(BarUiActMoveSong); +BarUiActCallback(BarUiActPause); +BarUiActCallback(BarUiActRenameStation); +BarUiActCallback(BarUiActSelectStation); +BarUiActCallback(BarUiActTempBanSong); +BarUiActCallback(BarUiActPrintUpcoming); +BarUiActCallback(BarUiActSelectQuickMix); +BarUiActCallback(BarUiActQuit); +BarUiActCallback(BarUiActDebug); +BarUiActCallback(BarUiActHistory); +BarUiActCallback(BarUiActBookmark); #endif /* _UI_ACT_H */ |