Project 2: MyTunes

Due 08/08/05

FAQ

You are going to write a program MyTunes to manage your music library. Your music collection is a set of albums. Each album has several songs. A playlist is a set of songs--perhaps from multiple albums. You will keep track of songs and playlists.

Remember good coding practices: use of well-written comments, good variable and function names, constants, functions, etc. (See the web pages and your lecture notes for more information about good style.) There are several parts to the project. Build up the project from the different parts. Test each implemented part separately.

Part 0: Reading in your music collection

Your system may have a file called "mytunes.collection", which contains your songs. The format of the file is
number_of_songs
artist1_name; album1_name; song1_name; song1_length (minutes:seconds)
artist2_name; album2_name; song2_name; song2_length (minutes:seconds)
...

If there is no file called "mytunes.collection", you have no music in your collection. Example collection files can be found in mytunes. Feel free to share your collection files with the class.

You should use a Song struct to maintain information about the song, such as the album, artist, name, and length of the song.

You will not have more than 50000 songs in your collection.

Add a function that will print out the music collection, nicely formatted.

Change your program so that it will allow the user to enter the name of the collection file as a command-line argument. The program will attempt to read that file to initialize the music collection. If you do not give a command-line argument, the program will attempt to read the default "mytunes.collection".

Part 1: Adding albums to your music collection

Initially, your music is stored in separate files for each album. The format of the file is
artist_name
album_name
number_of_songs
song1_length (minutes:seconds) song1_name
song2_length (minutes:seconds) song2_name
...
The directory albums contains some example album files. Feel free to submit your own albums to share with the class.

Write a function to read in one album. Store the songs in the music collection. Print out the total length of the album as well.

Example Run:

Enter your option: m
Enter the name of the album: albums/bte.txt

Number                                  Name                          Album                         Artist  Length

   0                                  Burned              Before the Robots               Better Than Ezra   03:41
   1                                Daylight              Before the Robots               Better Than Ezra   03:54
   2                                Lifetime              Before the Robots               Better Than Ezra   03:27
   3                       It's Only Natural              Before the Robots               Better Than Ezra   04:16
   4                                Overcome              Before the Robots               Better Than Ezra   05:22
   5                                 Special              Before the Robots               Better Than Ezra   04:03
   6                          American Dream              Before the Robots               Better Than Ezra   03:40
   7                          Our Last Night              Before the Robots               Better Than Ezra   04:12
   8                          Southern Thing              Before the Robots               Better Than Ezra   04:02
   9                                   Juicy              Before the Robots               Better Than Ezra   03:53
  10                                  Hollow              Before the Robots               Better Than Ezra   03:30
  11                         Our Finest Year              Before the Robots               Better Than Ezra   04:22
Total time: 00:48:22

Part 2: Sorting the collection

Add additional options to the print function you wrote in Part 0 that allow the user to sort the albums, either by artist name, album title, song title, or song length. For 5 points extra credit, you can implement merge sort to sort your array. Then, print out the music collection nicely.

Part 3: Searching for Songs

Allow the user to search for songs by name or artist name. You must implement binary search. If the song is not in the collection, print an appropriate message.

Part 4: Creating and Displaying a Playlist

Allow the user to create an empty playlist and then add songs to the playlist using an id. You will need to create an appropriate data structure to maintain the songs in the playlist. You can find example playlist files in playlists.

Display the playlist in a nice format that includes the total length of the playlist.

Part 5: Importing/Exporting a Playlist

Allow the user to import a playlist or export the playlist to a file. The format of the playlist file is

playlist_name
number_of_songs
artist1_name; album1_name; song1_name; song1_length (minutes:seconds)
artist2_name; album2_name; song2_name; song2_length (minutes:seconds)
...

You can assume that an artist's name, an album name, the song name and length do not include the delimiter character ';'. You should, however, make your program flexible so that you can easily change the delimiter character.

When creating the exported playlist file, add a ".play" extension to the playlist's name to create the file name. If the playlist's name contains spaces, you should remove spaces from the name before creating the filename.

Part 6: Saving the Collection

Before the user exits, you should save the current collection in mytunes.collection. Use the file format described in Part 0.

Part 7: The User Menu

Your user menu should allow the user to execute each option

Allow the user to enter either a lower case or capital letter for each option. If you implement the user menu with integers, you'll lose 5 points.

Extra Credit: Dynamic Memory Allocation (10 points)

To reduce the size of datastructures, use dynamic memory allocation to allocate memory to your data structures to ensure that you are not using extra space for strings.

Demonstrating and testing your program

Refer to the top sheet for the required test cases that you must demonstrate.

Test plan (20 points)

Good programmers write a test plan before writing their code. They use the test plan to verify that the program operates as expected and to meet a customer's requirements.

Write your test plan in a separate file. (You can write the test plan in a format other than a plain text file in Emacs, if you would like.) Your test plan should include the program's input and its expected output. (How do you know the expected output?) Write a test plan for each of your programs. Follow the test plan in your script (after you've executed the required test cases).

Hints

Submission

The project is due at the beginning of class on August 8. Staple the top sheet to the top of your paper submission.

Submit the electronic copy via email to Gang before 6 p.m. on August 8 and the paper copy to Sara before class.

Sign up for a demo with either Sara or Gang on CPM during the week of August 8.

Grading

There are two components to your project grade: correctness and style.
Thanks to Francis Zappaterrini for his help in creating and designing the MyTunes project.