batched actions now

This commit is contained in:
Jidong Xiao
2025-01-09 18:44:50 -05:00
parent 8351b5dcc9
commit be8564fd53

View File

@@ -35,7 +35,7 @@ The following images show the behavior of pressing "Next".
Before pressing "Next", the currently playing song is "Always Remember Us This Way":
![alt text](images/before_press_next.png "Spotify before pressing next")
Press "Next"
Press "Next":
![alt text](images/press_next.png "Spotify pressing next")
After pressing "Next", the currently playing song is now "Million Reasons":
@@ -46,7 +46,7 @@ The following images show the behavior of pressing "Previous".
Before pressing "Previous", the currently playing song is "Million Reasons":
![alt text](images/before_press_previous.png "Spotify before pressing previous")
Press "Previous"
Press "Previous":
![alt text](images/press_previous.png "Spotify pressing previous")
After pressing "Previous", the currently playing song is "Always Remember Us This Way":
@@ -54,10 +54,76 @@ After pressing "Previous", the currently playing song is "Always Remember Us Thi
## Command Line Arguments
Your program will support 5 commands.
Your program will be run like this:
### Command 1: add a music track to a playlist
The first argument is the name of an input file which contains a playlist. The second argument is the name of another input file which contains all available music tracks. The third argument is the output file. The fourth argument is the action, which in this case is "add". The fifth argument is the title of the music track.
```console
./nyplaylists.exe playlist.txt actions.txt output.txt
```
Here:
- nyplaylists.exe is the executable file name.
- playlist.txt is the name of an input file which contains a playlist - in this README, we will refer to this file as the **playlist file**.
- actions.txt is an input file which defines a sequence of actions - in this README, we will refer to this file as the **actions file**.
- output.txt where to print your output to.
## Playlist File Format and Output File Format
The playlist file and the output file have the same format. Take the playlist_tiny1.txt as an example, this file has the following 4 lines:
```console
"Perfect Duet" Ed Sheeran, Beyonce
"Always Remember Us This Way" Lady Gaga current
"Million Reasons" Lady Gaga
"I Will Never Love Again - Film Version" Lady Gaga, Bradley Cooper
```
Except the second line, each line has two fields, the music title, and the artist(s). There is one single space separating these two fields.
The second line is special, it ends with the word **current**, meaning that the song "Always Remember Us This Way" is the currently playing song. This word **current** appears in the **playlist file** once and should also appear in the output file once.
## Actions File Format
The actions file has a defines actions. Take actions1.txt as an example, this file has the following lines:
```console
add "Umbrella" Rihanna
add "We Are Young" Fun
add "You Are Still the One" Shania Twain
remove "Million Reasons" Lady Gaga
add "Viva La Vida" Coldplay
move "I Will Never Love Again - Film Version" Lady Gaga, Bradley Cooper 1
next
next
next
previous
move "You Are Still the One" Shania Twain 4
```
The **actions file** may include 5 different types of actions:
- add, which adds a song to the playlist.
- remove, which removes a song from the playlist.
- move, which moves a song to a new position - the new position is always included at the end of the line. The line *move "I Will Never Love Again - Film Version" Lady Gaga, Bradley Cooper 1*, moves the song "I Will Never Love Again - Film Version" to position 1, and the line *move "You Are Still the One" Shania Twain 4*, moves the song "You Are Still the One" to position 4. Note that, unliked array indexing in C/C++, positioning in Spotify starts at 1, as opposed to 0. This can be seen in the above Spotify screenshot: the first position is position 1.
- next, which skips the currently playing song and starts playing the song that is listed directly after it.
- previous, which skips the currently playing song and goes to the song listed directly before the currently playing song.
According to this sample **actions file**, 4 songs will be added to the playlist, 1 song will be removed, 2 songs will be moved. And the currently playing song will be a different song, instead of the song "Always Remember Us This Way".
When playlist_tiny1.txt and actions1.txt are supplied to your program as the two input files, your program should produce the following output file:
```console
"I Will Never Love Again - Film Version" Lady Gaga, Bradley Cooper
"Perfect Duet" Ed Sheeran, Beyonce
"Always Remember Us This Way" Lady Gaga
"You Are Still the One" Shania Twain
"Umbrella" Rihanna
"We Are Young" Fun current
"Viva La Vida" Coldplay
```
<!-- ### Command 1: add a music track to a playlist
The first argument is the name of an input file which contains a playlist - in this README, we will refer to this file as the **playlist file**. The second argument is the name of another input file which contains all available music tracks - in this README, we will refer to this file as the **library file**. The third argument is the output file. The fourth argument is the action, which in this case is "add". The fifth argument is the title of the music track.
```console
./nyplaylists.exe playlist.txt library.txt output.txt add title
@@ -71,7 +137,7 @@ For example, the following command will add the song Umbrella to the end of the
```
### Command 2: remove a music track from a playlist
The first argument is the name of an input file which contains a playlist. The second argument is the name of another input file which contains all available music tracks. The third argument is the output file. The fourth argument is the action, which in this case is "remove". The fifth argument is the title of the music track.
The first argument is the name of the **playlist file**. The second argument is the name of **library file**. The third argument is the output file. The fourth argument is the action, which in this case is "remove". The fifth argument is the title of the music track.
```console
./nyplaylists.exe playlist.txt library.txt output.txt remove title
@@ -83,7 +149,7 @@ For example, the following command will remove the song "Always Remember Us This
```
### Command 3: move a music track to a new position on the playlist
The first argument is the name of an input file which contains a playlist. The second argument is the output file. The third argument is the action, which in this case is "move". The fourth argument is the title of the music track. The fifth argument is the new position - where this user wants the music track to be located on the playlist. Note that, unliked array indexing in C/C++, positioning in Spotify starts at 1, as opposed to 0. This can be seen in the above Spotify screenshot: the first position is position 1.
The first argument is the name of **playlist file**. The second argument is the output file. The third argument is the action, which in this case is "move". The fourth argument is the title of the music track. The fifth argument is the new position - where this user wants the music track to be located on the playlist. Note that, unliked array indexing in C/C++, positioning in Spotify starts at 1, as opposed to 0. This can be seen in the above Spotify screenshot: the first position is position 1.
```console
./nyplaylists.exe playlist.txt output.txt move title [new_position]
@@ -95,7 +161,7 @@ For example, the following command will move the song "I Will Never Love Again -
```
### Command 4: skip to the next song in the current playlist
The first argument is the name of an input file which contains a playlist. The second argument is the output file. The third argument is the action, which in this case is "next".
The first argument is the name of **playlist file**. The second argument is the output file. The third argument is the action, which in this case is "next".
```console
./nyplaylists.exe playlist.txt output.txt next
@@ -104,26 +170,14 @@ The first argument is the name of an input file which contains a playlist. The s
This command will skip to the next song in the current playlist.
### Command 5: skip to the previous song in the current playlist
The first argument is the name of an input file which contains a playlist. The second argument is the output file. The third argument is the action, which in this case is "previous".
The first argument is the name of **playlist file**. The second argument is the output file. The third argument is the action, which in this case is "previous".
```console
./nyplaylists.exe playlist.txt output.txt previous
```
For all 5 commands, the output.txt contains the updated playlist. We have provided sample input & output files. Examples of using command line arguments can be found on the course webpage: [Programming Information](https://www.cs.rpi.edu/academics/courses/spring25/csci1200/programming_information.php).
## Input and Output File Format
All the input files and output files have the same format. Take the playlist_tiny1.txt as an example, this file has the following 4 lines:
```console
"Perfect Duet" Ed Sheeran, Beyonce
"Always Remember Us This Way" Lady Gaga
"Million Reasons" Lady Gaga
"I Will Never Love Again - Film Version" Lady Gaga, Bradley Cooper
```
Each line has two fields, the music title, and the artist(s). There is one single space separating these two fields.
-->
## Handling Music Tracks with the Same Title