/* search music: query, search request, return music id * @param app handle * @param seed suggestion station * @param seed suggestion musicid * @param prompt string * @return musicId or NULL on abort/error */ char *BarUiSelectMusicId (BarApp_t *app, PianoStation_t *station, const char *msg) { char *musicId = NULL; char lineBuf[100], selectBuf[2]; PianoSearchResult_t searchResult; PianoArtist_t *tmpArtist; PianoSong_t *tmpSong; BarUiMsg (&app->settings, MSG_QUESTION, msg); if (BarReadlineStr (lineBuf, sizeof (lineBuf), &app->input, BAR_RL_DEFAULT) > 0) { PianoReturn_t pRet; WaitressReturn_t wRet; PianoRequestDataSearch_t reqData; reqData.searchStr = lineBuf; BarUiMsg (&app->settings, MSG_INFO, "Searching... "); if (!BarUiPianoCall (app, PIANO_REQUEST_SEARCH, &reqData, &pRet, &wRet)) { return NULL; } memcpy (&searchResult, &reqData.searchResult, sizeof (searchResult)); BarUiMsg (&app->settings, MSG_NONE, "\r"); if (searchResult.songs != NULL && searchResult.artists != NULL) { /* songs and artists found */ BarUiMsg (&app->settings, MSG_QUESTION, "Is this an [a]rtist or [t]rack name? "); BarReadline (selectBuf, sizeof (selectBuf), "at", &app->input, BAR_RL_FULLRETURN, -1); if (*selectBuf == 'a') { tmpArtist = BarUiSelectArtist (app, searchResult.artists); if (tmpArtist != NULL) { musicId = strdup (tmpArtist->musicId); } } else if (*selectBuf == 't') { tmpSong = BarUiSelectSong (&app->settings, searchResult.songs, &app->input); if (tmpSong != NULL) { musicId = strdup (tmpSong->musicId); } } } else if (searchResult.songs != NULL) { /* songs found */ tmpSong = BarUiSelectSong (&app->settings, searchResult.songs, &app->input); if (tmpSong != NULL) { musicId = strdup (tmpSong->musicId); } } else if (searchResult.artists != NULL) { /* artists found */ tmpArtist = BarUiSelectArtist (app, searchResult.artists); if (tmpArtist != NULL) { musicId = strdup (tmpArtist->musicId); } } else { BarUiMsg (&app->settings, MSG_INFO, "Nothing found...\n"); } PianoDestroySearchResult (&searchResult); } return musicId; }
/* 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, WaitressHandle_t *waith, FILE *curFd, char *similarToId) { char *musicId = NULL; char lineBuf[100], selectBuf[2]; PianoSearchResult_t searchResult; PianoArtist_t *tmpArtist; PianoSong_t *tmpSong; BarUiMsg (MSG_QUESTION, "Search for artist/title: "); if (BarReadlineStr (lineBuf, sizeof (lineBuf), 0, curFd) > 0) { if (strcmp ("?", lineBuf) == 0 && similarToId != NULL) { PianoReturn_t pRet; WaitressReturn_t wRet; PianoRequestDataGetSeedSuggestions_t reqData; reqData.musicId = similarToId; reqData.max = 20; BarUiMsg (MSG_INFO, "Receiving suggestions... "); if (!BarUiPianoCall (ph, PIANO_REQUEST_GET_SEED_SUGGESTIONS, waith, &reqData, &pRet, &wRet)) { return NULL; } memcpy (&searchResult, &reqData.searchResult, sizeof (searchResult)); } else { PianoReturn_t pRet; WaitressReturn_t wRet; PianoRequestDataSearch_t reqData; reqData.searchStr = lineBuf; BarUiMsg (MSG_INFO, "Searching... "); if (!BarUiPianoCall (ph, PIANO_REQUEST_SEARCH, waith, &reqData, &pRet, &wRet)) { return NULL; } memcpy (&searchResult, &reqData.searchResult, sizeof (searchResult)); } BarUiMsg (MSG_NONE, "\r"); if (searchResult.songs != NULL && searchResult.artists != NULL) { /* songs and artists found */ BarUiMsg (MSG_QUESTION, "Is this an [a]rtist or [t]rack name? "); BarReadline (selectBuf, sizeof (selectBuf), "at", 1, 0, curFd); if (*selectBuf == 'a') { tmpArtist = BarUiSelectArtist (searchResult.artists, curFd); if (tmpArtist != NULL) { musicId = strdup (tmpArtist->musicId); } } else if (*selectBuf == 't') { tmpSong = BarUiSelectSong (searchResult.songs, curFd); if (tmpSong != NULL) { musicId = strdup (tmpSong->musicId); } } } else if (searchResult.songs != NULL) { /* songs found */ tmpSong = BarUiSelectSong (searchResult.songs, curFd); if (tmpSong != NULL) { musicId = strdup (tmpSong->musicId); } } else if (searchResult.artists != NULL) { /* artists found */ tmpArtist = BarUiSelectArtist (searchResult.artists, curFd); if (tmpArtist != NULL) { musicId = strdup (tmpArtist->musicId); } } else { BarUiMsg (MSG_INFO, "Nothing found...\n"); } PianoDestroySearchResult (&searchResult); } return musicId; }