Permalink
Browse files

Add feature: Create new station from selected song

New keybinding ‘v’, new setting act_createstationfromsong.
  • Loading branch information...
PromyLOPh committed Jul 5, 2012
1 parent bf13c96 commit 24ed240c865837b8c9d7c9240f6ef3ba9065b162
Showing with 89 additions and 13 deletions.
  1. +4 −0 contrib/pianobar.1
  2. +9 −0 src/libpiano/piano.h
  3. +26 −5 src/libpiano/request.c
  4. +2 −1 src/settings.h
  5. +4 −1 src/ui.c
  6. +41 −6 src/ui_act.c
  7. +1 −0 src/ui_act.h
  8. +2 −0 src/ui_dispatch.h
View
@@ -139,6 +139,10 @@ Ban song for one month.
.B act_upcoming = u
Show next songs in playlist.
+.TP
+.B act_stationcreatefromsong = v
+Create new station from the current song or artist.
+
.TP
.B act_stationselectquickmix = x
Select quickmix stations. You can toggle the selection with 't', select all
View
@@ -207,6 +207,15 @@ typedef struct {
PianoSearchResult_t searchResult;
} PianoRequestDataSearch_t;
+typedef struct {
+ char *token;
+ enum {
+ PIANO_MUSICTYPE_INVALID = 0,
+ PIANO_MUSICTYPE_SONG,
+ PIANO_MUSICTYPE_ARTIST,
+ } type;
+} PianoRequestDataCreateStation_t;
+
typedef struct {
PianoStation_t *station;
char *musicId;
View
@@ -204,12 +204,33 @@ PianoReturn_t PianoRequest (PianoHandle_t *ph, PianoRequest_t *req,
case PIANO_REQUEST_CREATE_STATION: {
/* create new station from specified musicToken or station number */
- char *token = req->data;
+ PianoRequestDataCreateStation_t *reqData = req->data;
- assert (token != NULL);
-
- json_object_object_add (j, "musicToken",
- json_object_new_string (token));
+ assert (reqData != NULL);
+ assert (reqData->token != NULL);
+
+ if (reqData->type == PIANO_MUSICTYPE_INVALID) {
+ json_object_object_add (j, "musicToken",
+ json_object_new_string (reqData->token));
+ } else {
+ json_object_object_add (j, "trackToken",
+ json_object_new_string (reqData->token));
+ switch (reqData->type) {
+ case PIANO_MUSICTYPE_SONG:
+ json_object_object_add (j, "musicType",
+ json_object_new_string ("song"));
+ break;
+
+ case PIANO_MUSICTYPE_ARTIST:
+ json_object_object_add (j, "musicType",
+ json_object_new_string ("artist"));
+ break;
+
+ default:
+ assert (0);
+ break;
+ }
+ }
method = "station.createStation";
break;
View
@@ -56,8 +56,9 @@ typedef enum {
BAR_KS_VOLUP = 22,
BAR_KS_MANAGESTATION = 23,
BAR_KS_PLAYPAUSE2 = 24,
+ BAR_KS_CREATESTATIONFROMSONG = 25,
/* insert new shortcuts _before_ this element and increase its value */
- BAR_KS_COUNT = 25,
+ BAR_KS_COUNT = 26,
} BarKeyShortcutId_t;
#define BAR_KS_DISABLED '\x00'
View
@@ -611,8 +611,11 @@ void BarStationFromGenre (BarApp_t *app) {
} while (curGenre == NULL);
/* create station */
+ PianoRequestDataCreateStation_t reqData;
+ reqData.token = curGenre->musicId;
+ reqData.type = PIANO_MUSICTYPE_INVALID;
BarUiMsg (&app->settings, MSG_INFO, "Adding shared station \"%s\"... ", curGenre->name);
- BarUiPianoCall (app, PIANO_REQUEST_CREATE_STATION, curGenre->musicId, &pRet, &wRet);
+ BarUiPianoCall (app, PIANO_REQUEST_CREATE_STATION, &reqData, &pRet, &wRet);
}
/* replaces format characters (%x) in format string with custom strings
View
@@ -147,14 +147,45 @@ BarUiActCallback(BarUiActBanSong) {
BarUiActCallback(BarUiActCreateStation) {
PianoReturn_t pRet;
WaitressReturn_t wRet;
- char *id = NULL;
+ PianoRequestDataCreateStation_t reqData;
- id = BarUiSelectMusicId (app, NULL,
+ reqData.type = PIANO_MUSICTYPE_INVALID;
+ reqData.token = BarUiSelectMusicId (app, NULL,
"Create station from artist or title: ");
- if (id != NULL) {
+ if (reqData.token != NULL) {
BarUiMsg (&app->settings, MSG_INFO, "Creating station... ");
- BarUiActDefaultPianoCall (PIANO_REQUEST_CREATE_STATION, id);
- free (id);
+ BarUiActDefaultPianoCall (PIANO_REQUEST_CREATE_STATION, &reqData);
+ free (reqData.token);
+ BarUiActDefaultEventcmd ("stationcreate");
+ }
+}
+
+/* create new station
+ */
+BarUiActCallback(BarUiActCreateStationFromSong) {
+ PianoReturn_t pRet;
+ WaitressReturn_t wRet;
+ PianoRequestDataCreateStation_t reqData;
+ char selectBuf[2];
+
+ reqData.token = selSong->trackToken;
+ reqData.type = PIANO_MUSICTYPE_INVALID;
+
+ BarUiMsg (&app->settings, MSG_QUESTION, "Create station from [s]ong or [a]rtist? ");
+ BarReadline (selectBuf, sizeof (selectBuf), "sa", &app->input,
+ BAR_RL_FULLRETURN, -1);
+ switch (selectBuf[0]) {
+ case 's':
+ reqData.type = PIANO_MUSICTYPE_SONG;
+ break;
+
+ case 'a':
+ reqData.type = PIANO_MUSICTYPE_ARTIST;
+ break;
+ }
+ if (reqData.type != PIANO_MUSICTYPE_INVALID) {
+ BarUiMsg (&app->settings, MSG_INFO, "Creating station... ");
+ BarUiActDefaultPianoCall (PIANO_REQUEST_CREATE_STATION, &reqData);
BarUiActDefaultEventcmd ("stationcreate");
}
}
@@ -165,12 +196,16 @@ BarUiActCallback(BarUiActAddSharedStation) {
PianoReturn_t pRet;
WaitressReturn_t wRet;
char stationId[50];
+ PianoRequestDataCreateStation_t reqData;
+
+ reqData.token = stationId;
+ reqData.type = PIANO_MUSICTYPE_INVALID;
BarUiMsg (&app->settings, MSG_QUESTION, "Station id: ");
if (BarReadline (stationId, sizeof (stationId), "0123456789", &app->input,
BAR_RL_DEFAULT, -1) > 0) {
BarUiMsg (&app->settings, MSG_INFO, "Adding shared station... ");
- BarUiActDefaultPianoCall (PIANO_REQUEST_CREATE_STATION, stationId);
+ BarUiActDefaultPianoCall (PIANO_REQUEST_CREATE_STATION, &reqData);
BarUiActDefaultEventcmd ("stationaddshared");
}
}
View
@@ -37,6 +37,7 @@ BarUiActCallback(BarUiActHelp);
BarUiActCallback(BarUiActAddMusic);
BarUiActCallback(BarUiActBanSong);
BarUiActCallback(BarUiActCreateStation);
+BarUiActCallback(BarUiActCreateStationFromSong);
BarUiActCallback(BarUiActAddSharedStation);
BarUiActCallback(BarUiActDeleteStation);
BarUiActCallback(BarUiActExplain);
View
@@ -95,6 +95,8 @@ static const BarUiDispatchAction_t dispatchActions[BAR_KS_COUNT] = {
"act_managestation"},
{' ', BAR_DC_GLOBAL | BAR_DC_STATION, BarUiActPause, NULL,
"act_songpause2"},
+ {'v', BAR_DC_SONG, BarUiActCreateStationFromSong,
+ "create new station from song or artist", "act_stationcreatefromsong"},
};
#include <piano.h>

0 comments on commit 24ed240

Please sign in to comment.