void MainWindow::addToPlaylist() //POST: Opens a file dialog. Adds the returned file (of type either .wav, .mp3, .m4a, or .m3u) to the playlist. numTracks is // updated to the final number of tracks. If no song is currently playing, we start playing the first song on our playlist. { QFileDialog dialog(this); //Dialog for opening a file dialog.setFileMode(QFileDialog::ExistingFiles); //Handle multiple files (existing) QStringList qfileNames; //Files being added QString qfileName; //Current files being added string fileName; //convert the QString to a string string extension; //get the file's extension ifstream inFile; //if the file is a playlist (m3u), we need to read it if(dialog.exec()) qfileNames = dialog.selectedFiles(); //Get first file user selected if(qfileNames.isEmpty()) //Don't proceed if user didn't select a filename return; for (int i=0; i < qfileNames.size(); i++) //Loop through each file to add { qfileName = qfileNames[i]; //get the ith song of our list fileName = qfileName.toStdString(); //convert it to a string extension = fileName.substr(fileName.length()-3, 3); //and get the extension if (extension != "wav" && extension != "m3u" && extension != "mp3" && extension != "m4a") //If invalid file extension, { QMessageBox msgBox(QMessageBox::Warning, "Invalid File", //display warning message "Selected file is not of type .wav, .mp3, .m4a, or .m3u"); msgBox.exec(); } else { if (extension != "m3u") //if file is not a playlist, addSong(fileName); //add the file to our playlist else //otherwise, { inFile.open(fileName.c_str()); //open the playlist file, while(getline(inFile, fileName)) //loop through every line, addSong(fileName); //and add to our playlist every song in the file. inFile.close(); } } } if (curTrack == -1) //if we're not playing anything, gotoNextSong(); //start playing the first song of our playlist. }
void Gui::addSongs(const std::vector<std::string>& names) { for(const auto& song_name : names) { addSong(song_name); } }
void CollectionDialog::addSong() { KURL::List urls = KFileDialog::getOpenURLs(":MidiFiles", "*.kar *.mid *.kar.gz *.mid.gz\n*.kar *.kar.gz\n*.mid *.mid.gz\n*",this); KURL::List::Iterator it; for( it = urls.begin(); it != urls.end(); ++it ) addSong(*it); }
void SongQueue::addSong(const QString &singer, const QString &file) { Song song; song.file = file; song.songid = 0; song.singer = singer; addSong( song ); }
bool Radio::runCommand(std::string input){ std::string command = ""; unsigned int i = 0; for(i = 0; i < input.length() && input[i] != ' '; ++ i){ command = command + input[i]; } ++ i; std::string restStr = ""; if(i < input.length()){ restStr = input.substr(i); } if(command == "QUIT"){ return false; } if(command == "INIT"){ init(restStr); return true; } if(command == "ADD"){ addSong(restStr); return true; } if(command == "RUN"){ int result = 0; result = runFile(restStr); if(result == 0){ return false; }else{ return true; } } if(command == "REST"){ rest(restStr); return true; } if(command == "PLAY"){ play(restStr); return true; } if(command == "LIKE"){ like(restStr); return true; } if(command == "DISLIKE"){ dislike(restStr); return true; } return false; }
void SongLibrary::resortSong(Song *song) { if (_lib == song) _lib = song->_next; else { Song *seeker = _lib; while (seeker->_next && (seeker->_next != song)) seeker = seeker->_next; if (seeker->_next) seeker->_next = seeker->_next->_next; } addSong(song); }
void SongQueue::addSong( const QString &singer, int id ) { SongDatabaseInfo info; if ( !pSongDatabase->songById( id, info ) ) return; Song song; song.artist = info.artist; song.file = info.filePath; song.songid = id; song.singer = singer; song.title = info.title; addSong( song ); }
void menuSong(struct playLists arrPlaylist[20], int someAlbum, int numSong){ int red = FOREGROUND_RED | FOREGROUND_INTENSITY; int aqua = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY; const int num = 7; char forChoice[7][20] = {"Listen", "Rename", "Delete", "Cancel", "Copy", "Insert", "Create a new song"}; int lll = 0, pointCommand = 0; format(65, 0, aqua); printf("What to do?"); outCommand(0, num, forChoice, 61); struct playLists * tmp = malloc(sizeof(struct playLists)); format(50, 0, 7); printf("%s", tmp->someSong[0].name); while(lll == 0){ switch(getch()){ case 72: pointCommand--; break; case 80: pointCommand++; break; case 13: lll = 1; break; case 27: return 1; } outCommand(pointCommand, num, forChoice, 61); } switch(pointCommand%num){ case 0: playSongs(arrPlaylist[someAlbum].someSong[numSong].nots); break; case 1: renameSong(arrPlaylist, someAlbum, numSong); break; case 2: delSong(arrPlaylist, someAlbum, numSong); break; case 3: choiceSong(arrPlaylist, someAlbum); break; case 4: copySong(arrPlaylist, someAlbum, tmp, numSong); break; case 5: insertSong(arrPlaylist, someAlbum, tmp, numSong); break; case 6: addSong(arrPlaylist, someAlbum); break; } }
void choiceSong(struct playLists arrPlaylist[20], int someAlbum){ system("cls"); int red = FOREGROUND_RED | FOREGROUND_INTENSITY; int aqua = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY; int i, numberSong = 0, points = 0, lll = 0; format(2, 0, aqua); printf("%s", arrPlaylist[someAlbum].namelist); for(i = 0; i < 100; i++){ if(strcmp(arrPlaylist[someAlbum].someSong[i].name, "\0") != 0){ numberSong++; if(i == 0) format(0, 2*i+2, red); else format(0, 2*i+2, 7); printf("%s", arrPlaylist[someAlbum].someSong[i].name); } } if(numberSong == 0){ format(0, 2, 7); printf("This album is empty"); format(0, 4, aqua); printf("You want to add songs here?"); if(getch() == 13) addSong(arrPlaylist, someAlbum, 0); else choicePlaylists(arrPlaylist); } while(lll == 0){ switch(getch()){ case 72: points--; break; case 80: points++; break; case 13: lll = 1; break; case 8: return choicePlaylists(arrPlaylist); } outSongs(numberSong, arrPlaylist[someAlbum] , points); } menuSong(arrPlaylist, someAlbum, points%numberSong); }
CollectionDialog::CollectionDialog(SLManager *slm,int selC,QWidget *parent,const char *name) : QDialog(parent,name,TRUE) { setCaption(i18n("Collections Manager")); ok=new KPushButton(KStdGuiItem::ok(),this); ok->setGeometry(140,200,100,30); connect(ok,SIGNAL(clicked()),SLOT(accept()) ); cancel=new KPushButton(KStdGuiItem::cancel(),this); cancel->setGeometry(250,200,100,30); connect(cancel,SIGNAL(clicked()),SLOT(reject()) ); label=new QLabel(i18n("Available collections:"),this); label->adjustSize(); label->move(10,10); collections=new QListBox(this,"collectionlist"); collections->setGeometry(10,20+label->height(),340,90); connect(collections,SIGNAL(highlighted(int)),SLOT(collectionselected(int))); connect(collections,SIGNAL(selected(int)),SLOT(changeCollectionName(int))); slman=slm; for (int i=0;i<=slman->numberOfCollections();i++) { collections->insertItem(i18n( slman->getCollectionName(i) ),i); #ifdef COLLECTDLGDEBUG printf("Name : %s\n",slman->getCollectionName(i)); #endif }; selectedC=selC; #ifdef COLLECTDLGDEBUG printf("selectedC : %d\n",selectedC); #endif label2=new QLabel(i18n("Songs in selected collection:"),this); label2->adjustSize(); label2->move(10,collections->y()+collections->height()+10); songs=new QListBox(this,"songlist"); songs->setGeometry(10,label2->y()+label2->height()+10,340,120); connect(songs,SIGNAL(highlighted(int)),SLOT(songselected(int))); currentsl=slman->getCollection(selectedC); if (slman->numberOfCollections()>0) { collections->setCurrentItem(selectedC); collections->centerCurrentItem(); }; //fillInSongList(); newC=new QPushButton(i18n("&New..."),this); newC->adjustSize(); newC->move(360,collections->y()+5); connect(newC,SIGNAL(clicked()),SLOT(newCollection()) ); copyC=new QPushButton(i18n("&Copy..."),this); copyC->adjustSize(); copyC->move(360,newC->y()+newC->height()+5); connect(copyC,SIGNAL(clicked()),SLOT(copyCollection()) ); deleteC=new QPushButton(i18n("Delete"),this); deleteC->adjustSize(); deleteC->move(360,copyC->y()+copyC->height()+5); connect(deleteC,SIGNAL(clicked()),SLOT(deleteCollection()) ); addS=new QPushButton(i18n("&Add..."),this); addS->adjustSize(); addS->move(360,songs->y()+5); connect(addS,SIGNAL(clicked()),SLOT(addSong()) ); delS=new QPushButton(i18n("&Remove"),this); delS->adjustSize(); delS->move(360,addS->y()+addS->height()+5); connect(delS,SIGNAL(clicked()),SLOT(removeSong()) ); ok->move(ok->x(),songs->y()+songs->height()+10); cancel->move(ok->x()+ok->width()+5,ok->y()); setMinimumSize(400,ok->y()+ok->height()+5); //setMaximumSize(360,240); }
int main( int argc, char* argv[ ] ) { Playlist *myList = NULL; int minutes, seconds; char *name, *title, *artist; Option opt; printf("\n\nWelcome to project 5 - music playlists\n\n"); opt = getAction(); while (opt != QUIT) { switch (opt) { case ADD_LIST: printf("Adding a new playlist to start of library\n"); name = getString("Enter the name of the new playlist"); printf("\nAdding the playlist '%s' to your library (at front of library) \n", name); myList = add(myList, name); break; case ADD_SONG: printf("Add a song to an existing playlist\n"); name = getString("Enter the name of the playlist"); title = getString("Enter the title of the song to add"); artist = getString("Enter the name of the artist"); getTime(&minutes, &seconds); printf("\nAdding the song below to the playlist '%s' (at end of playlist)\n", name); printf("\tTitle : %s\n", title); printf("\tArtist: %s\n", artist); printf("\tLength: %d:%d\n", minutes, seconds); addSong(myList, name, title, artist, minutes, seconds); break; case PRINT_LIST: printf("Print the songs in a playlist\n"); name = getString("Enter the name of the playlist"); printf("\nPrinting the names of all songs in the playlist '%s'\n", name); printSongs(myList, name); break; case LIST_SIZE: printf("Print the size of a playlist\n"); name = getString("Enter the name of the playlist"); printf("\nThe playlist '%s' contains N songs and has NN:NN minutes of music\n", name); printSize(myList, name); break; case STATS: printf("Print statistics on all your playslists\n"); printStats(myList); break; case ADD_LIST_ORDERED: printf("Adding a new playlist to library (ordered)\n"); name = getString("Enter the name of the new playlist"); printf("\nAdding the playlist '%s' to your library (in alphabetical order)\n", name); myList = addOrdered(myList, name); break; case ADD_SONG_ORDERED: printf("Add a song to an existing playlist (ordered)\n"); name = getString("Enter the name of the playlist"); title = getString("Enter the title of the song to add"); artist = getString("Enter the name of the artist"); getTime(&minutes, &seconds); printf("\nAdding the song below to the playlist '%s' (in alphabetical order)\n", name); printf("\tTitle : %s\n", title); printf("\tArtist: %s\n", artist); printf("\tLength: %d:%d\n", minutes, seconds); addSongOrdered(myList, name, title, artist, minutes, seconds); break; case REMOVE_SONG: printf("Removing a song from an existing playlist\n"); name = getString("Enter the name of the playlist"); title = getString("Enter the title of the song to remove"); artist = getString("Enter the artist of the song to remove"); printf("\nRemoving the song '%s' by '%s' from the playlist %s\n", title, artist, name); removeSong(myList, name, title, artist); break; case REMOVE_LIST: printf("Removing a playlist\n"); name = getString("Enter the name of the playlist to remove"); printf("\nRemoving the the playlist %s from your library\n", name); myList = removeList(myList, name); break; case HELP: optionDetails(); break; default: break; } opt = getAction(); } return 0; }
/************************************************************* * Function: main () * Created: January 27th, 2012 * Last Revised: February 2nd, 2012 * Description: This function controls the program * Input parameters: None * Returns: None * Preconditions: the program needs to be run * Postconditions: the program has been run *************************************************************/ int main (void) { // variables char programTitle[] = "Digital Music Manager"; Node *pSongs = NULL; int prog_state = 0, sub_state = 0, option = 0; Bool success = false; FILE *ioFile = NULL; while (prog_state >= 0) { //// LOADING //// if (prog_state == 0) { // open the music file ioFile = fopen ("music.dmm", "r+"); prog_state = 1; } //// MAIN MENU //// else if (prog_state == 1) { // display menu and get selected option option = display_menu (2, 2, ':', 1, 9, ";", programTitle, "Main Menu", "Display Songs;Rate Songs;Sort Songs;Add Song;Edit Song;Delete Song;Load Songs;Store Songs;Exit Digital Music Manager"); // Display Songs if (option == 1) { displaySongs (pSongs); } // Rate Songs else if (option == 2) { editSong (1, &pSongs); } // Sort Songs else if (option == 3) { sortSongs (&pSongs, display_menu (2, 2, ':', 1, 3, ";", programTitle, "Choose an Insert Order...", "Insert by Song Title;Insert by Genre;Insert by Rating")); } // Add Song else if (option == 4) { success = addSong (&pSongs); if (!success) { printf ("Failed to create song!\n"); } else { sortSongs (&pSongs, display_menu (2, 2, ':', 1, 3, ";", programTitle, "Choose an Insert Order...", "Insert by Song Title;Insert by Genre;Insert by Rating")); } } // Edit Song else if (option == 5) { editSong (0, &pSongs); } // Delete Song else if (option == 6) { deleteSong (&pSongs); } // Load Songs else if (option == 7) { loadSongs (&pSongs, ioFile); } // Store Songs else if (option == 8) { storeSongs (pSongs, ioFile); } // Exit program else if (option == 9) { fclose (ioFile); prog_state = -1; } } } return 0; }