From 6a9579be3afecaae2f62baacca10335de1371cf1 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Fri, 7 Aug 2009 13:20:45 +0200 Subject: New feature: Seed suggestions --- src/ui.c | 20 +++++++++++++++----- src/ui.h | 2 +- src/ui_act.c | 4 ++-- 3 files changed, 18 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/ui.c b/src/ui.c index f2630e3..c69a65c 100644 --- a/src/ui.c +++ b/src/ui.c @@ -239,9 +239,11 @@ PianoArtist_t *BarUiSelectArtist (PianoArtist_t *startArtist, FILE *curFd) { /* search music: query, search request, return music id * @param piano handle + * @param read data from fd + * @param allow seed suggestions if != NULL * @return musicId or NULL on abort/error */ -char *BarUiSelectMusicId (PianoHandle_t *ph, FILE *curFd) { +char *BarUiSelectMusicId (PianoHandle_t *ph, FILE *curFd, char *similarToId) { char *musicId = NULL; char lineBuf[100], selectBuf[2]; PianoSearchResult_t searchResult; @@ -250,10 +252,18 @@ char *BarUiSelectMusicId (PianoHandle_t *ph, FILE *curFd) { BarUiMsg (MSG_QUESTION, "Search for artist/title: "); if (BarReadlineStr (lineBuf, sizeof (lineBuf), 0, curFd) > 0) { - BarUiMsg (MSG_INFO, "Searching... "); - if (BarUiPrintPianoStatus (PianoSearchMusic (ph, lineBuf, - &searchResult)) != PIANO_RET_OK) { - return NULL; + if (strcmp ("?", lineBuf) == 0 && similarToId != NULL) { + BarUiMsg (MSG_INFO, "Receiving suggestions... "); + if (BarUiPrintPianoStatus (PianoSeedSuggestions (ph, similarToId, + 20, &searchResult)) != PIANO_RET_OK) { + return NULL; + } + } else { + BarUiMsg (MSG_INFO, "Searching... "); + if (BarUiPrintPianoStatus (PianoSearchMusic (ph, lineBuf, + &searchResult)) != PIANO_RET_OK) { + return NULL; + } } BarUiMsg (MSG_NONE, "\r"); if (searchResult.songs != NULL && searchResult.artists != NULL) { diff --git a/src/ui.h b/src/ui.h index 90b5b28..8726a13 100644 --- a/src/ui.h +++ b/src/ui.h @@ -37,7 +37,7 @@ PianoStation_t *BarUiSelectStation (PianoHandle_t *ph, const char *prompt, FILE *curFd); PianoSong_t *BarUiSelectSong (PianoSong_t *startSong, FILE *curFd); PianoArtist_t *BarUiSelectArtist (PianoArtist_t *startArtist, FILE *curFd); -char *BarUiSelectMusicId (PianoHandle_t *ph, FILE *curFd); +char *BarUiSelectMusicId (PianoHandle_t *ph, FILE *curFd, char *); void BarStationFromGenre (PianoHandle_t *ph, FILE *curFd); inline void BarUiPrintStation (PianoStation_t *); inline void BarUiPrintSong (PianoSong_t *, PianoStation_t *); diff --git a/src/ui_act.c b/src/ui_act.c index ea7a235..a3d33ed 100644 --- a/src/ui_act.c +++ b/src/ui_act.c @@ -87,7 +87,7 @@ void BarUiActAddMusic (BAR_KS_ARGS) { RETURN_IF_NO_STATION; - musicId = BarUiSelectMusicId (ph, curFd); + musicId = BarUiSelectMusicId (ph, curFd, (*curSong)->musicId); if (musicId != NULL) { if (!BarTransformIfShared (ph, *curStation)) { return; @@ -124,7 +124,7 @@ void BarUiActCreateStation (BAR_KS_ARGS) { char *musicId; PianoReturn_t pRet = PIANO_RET_ERR; - musicId = BarUiSelectMusicId (ph, curFd); + musicId = BarUiSelectMusicId (ph, curFd, NULL); if (musicId != NULL) { BarUiMsg (MSG_INFO, "Creating station... "); pRet = BarUiPrintPianoStatus (PianoCreateStation (ph, "mi", musicId)); -- cgit v1.2.3