From e22869ebdd98ecc3f870cb1d6c5c31fd1b5d61ee Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sat, 14 Jun 2008 16:08:35 +0200 Subject: Finally implemented "create station" This may be a bit buggy, because no return values are checked or returned. A big cleanup session is waiting... --- src/main.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) (limited to 'src') diff --git a/src/main.c b/src/main.c index 314748f..05d1f4e 100644 --- a/src/main.c +++ b/src/main.c @@ -232,6 +232,46 @@ PianoStation_t *selectStation (PianoHandle_t *ph) { return curStation; } +PianoSong_t *selectSong (PianoSong_t *startSong) { + PianoSong_t *tmpSong; + size_t i; + + tmpSong = startSong; + i = 0; + while (tmpSong != NULL) { + printf ("%2u) %s - %s\n", i, tmpSong->artist, tmpSong->title); + i++; + tmpSong = tmpSong->next; + } + scanf ("%i", &i); + tmpSong = startSong; + while (tmpSong != NULL && i > 0) { + tmpSong = tmpSong->next; + i--; + } + return tmpSong; +} + +PianoArtist_t *selectArtist (PianoArtist_t *startArtist) { + PianoArtist_t *tmpArtist; + size_t i; + + tmpArtist = startArtist; + i = 0; + while (tmpArtist != NULL) { + printf ("%2u) %s\n", i, tmpArtist->name); + i++; + tmpArtist = tmpArtist->next; + } + scanf ("%i", &i); + tmpArtist = startArtist; + while (tmpArtist != NULL && i > 0) { + tmpArtist = tmpArtist->next; + i--; + } + return tmpArtist; +} + int main (int argc, char **argv) { PianoHandle_t ph; struct aacPlayer player; @@ -278,6 +318,9 @@ int main (int argc, char **argv) { struct pollfd polls = {fileno (stdin), POLLIN, POLLIN}; char buf, yesnoBuf; char *lineBuf; + PianoSearchResult_t searchResult; + PianoArtist_t *tmpArtist; + PianoSong_t *tmpSong; if (poll (&polls, 1, 1000) > 0) { read (fileno (stdin), &buf, sizeof (buf)); @@ -299,6 +342,42 @@ int main (int argc, char **argv) { curSong = NULL; break; + case 'c': + lineBuf = readline ("Search for artist/title\n"); + if (lineBuf != NULL && strlen (lineBuf) > 0) { + PianoSearchMusic (&ph, lineBuf, &searchResult); + if (searchResult.songs != NULL && searchResult.artists != NULL) { + printf ("Is this an [a]rtist or [t]rack name?\n"); + read (fileno (stdin), &yesnoBuf, sizeof (yesnoBuf)); + if (yesnoBuf == 'a') { + tmpArtist = selectArtist (searchResult.artists); + PianoCreateStation (&ph, tmpArtist->musicId); + printf ("Ok.\n"); + } else if (yesnoBuf == 't') { + tmpSong = selectSong (searchResult.songs); + PianoCreateStation (&ph, tmpSong->musicId); + printf ("Ok.\n"); + } + } else if (searchResult.songs != NULL) { + printf ("Select song\n"); + tmpSong = selectSong (searchResult.songs); + PianoCreateStation (&ph, tmpSong->musicId); + printf ("Ok.\n"); + } else if (searchResult.artists != NULL) { + printf ("Select artist\n"); + tmpArtist = selectArtist (searchResult.artists); + PianoCreateStation (&ph, tmpArtist->musicId); + printf ("Ok.\n"); + } else { + printf ("Nothing found...\n"); + } + PianoDestroySearchResult (&searchResult); + } + if (lineBuf != NULL) { + free (lineBuf); + } + break; + case 'd': printf ("Really delete \"%s\"? [yn]\n", curStation->name); -- cgit v1.2.3