Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSC 142 Music Player Please submit either a .zip or .jar file. You will complete this project by implementing one class. Afterwards, your program will

CSC 142 Music Player Please submit either a .zip or .jar file. You will complete this project by implementing one class. Afterwards, your program will play music from a text file. Objectives Working with lists Background This project addresses playing music. A song consists of notes, each of which has a length (duration) and pitch. The pitch of a note is described with a letter ranging from A to G. 7 notes is not enough to play very interesting music, so there are multiple octaves; after we reach note G we start over at A. Each set of 7 notes is considered one octave. Notes may also be accidentals. We normally notate this by calling them sharp, flat, or natural. Music also has silences that are called rests. For this program we will be representing notes using scientific pitch notation. This style of notation represents each note as a letter and a number specifying the octave it belongs to. For example, middle C is represented as C4. You do not need to understand any more than this about scientific pitch notation, but you can read more about it here: http://en.wikipedia.org/wiki/Scientific_pitch_notation You will write a Melody class that uses a list to represent a song comprised of a series of notes. It may have repeated sections; since we don't like redundancy, we will only store one copy of a repeated chunk of notes. Your Melody class will read files in a format described below and represent the song's notes using an ArrayList of Note objects. Starter Code Here is a link to the starter code: http://facweb.northseattle.edu/bgoldner/142/HW8-player/HW8-MusicPlayerStarter.zip There's a lot here, but only 1 file you need to edit. Once you unzip this file, you'll have a folder that contains 4 sub-folders: bin lib res src Turn the src directory into a BlueJ project. In this folder, you'll find 3 Java files: Main.java - this is the class that contains the main method to run the program. MelodyGui.java Melody.java You need to implement Melody.java. Input File Format Music is usually printed like the example sheet music at right. The notes are a series of dots. Their position in relation to the lines determines their pitch and their tops, among other things, determine their length. Since it would be difficult for us to read input in this style, we will read input from a text file in a specific format. An example input file is shown at right. The first two lines contain the song title and song artist, respectively. Each subsequent line represents a single note in the following format: duration pitch octave accidental repeat The first number on each line describes the duration of the note in seconds. The next letter describes the pitch of the note, using the standard letters A-G or R for a rest. The third token is the octave that the note is in. The fourth is the note's accidental value of sharp, flat, or natural. (For a rest, the octave and accidental are omitted.) The final token indicates whether the note is the start or stop of a repeated section: true if so, and false otherwise. In the example at right, notes 3-5 and 9-12 (lines 5-7 and 11-14) represent two repeated sections. The meaning of the data is that the song should play notes 1, 2, 3, 4, 5, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 9, 10, 11, 12, 13. Our format does not allow nested repetition, nor sections that repeat more than twice. Hot Crossed Buns Hot crOssed buns Hot crossed buns One pey, two pe y Hot crossed buis. Example file (line numbers added) 1| My Song Title 2| Felix the Cat 3| 0.2 C 4 NATURAL false 4| 0.4 F 4 NATURAL false 5| 0.2 F 4 NATURAL true 6| 0.4 G 4 NATURAL false 7| 0.2 A 4 NATURAL true 8| 0.2 A 4 NATURAL false 9| 0.4 R false 10| 0.2 B 4 NATURAL false 11| 0.2 C 4 NATURAL true 12| 0.4 D 4 NATURAL false 13| 0.2 C 5 NATURAL false 14| 0.2 A 4 NATURAL true 15| 0.4 D 4 NATURAL false Note class (provided): You are given a supplier class named Note that your Melody class will use. A Note object represents a single musical note that will form part of a melody. It keeps track of the length (duration) of the note in seconds as a double, the note's pitch (A-G, or R if the note is a rest), the octave as an int, and the accidental (sharp, natural or flat). Each Note object also uses a boolean field to keep track of whether it is the first or last note of a repeated section of the melody. The Note uses two types of enums named Pitch and Accidental. A Pitch is a constant from Pitch.A through Pitch.G or Pitch.R, meaning the frequency of the note. An Accidental indicates whether a note is sharp, flat, or neither using the constants Accidental.SHARP, Accidental.FLAT, andAccidental.NATURAL respectively. Here is a link to the JavaDocs for Note, Accidental, and Pitch. If you're interested, you can find the source files in the folder src/melody/audio. However, you are clients of these classes only. Specification You are to implement the Melody class according to the following specification: class Melody You decide on instance variables. The only requirement is to use an ArrayList to hold the series of Notes + Melody(File file) throws FileNotFoundException Load this class with the data from the file given. There is a method in each of the enum defintions to convert from a String to the correct constant. The constructor may assume that the given file is formatted correctly + void changeTempo(double ratio) Scale (multiply) the duration of each Note in this Melody by the given ratio. For example, passing a ratio of 1.0 will do nothing, while a ratio of 2.0 will make each note's duration twice as long (slow down the song), or a ratio of 0.5 will make each note half as long (speed up the song). Throw an IllegalArgumentException for <= 0. + String getArtist() Return this Melody's artist + String getTitle() Return this Melody's title + double getTotalDuration() Return this Melody's total duration (length) in seconds. In general this is equal to the sum of the durations of the song's notes, but if some sections of the song are repeated, those parts count twice toward the total. For example, a song whose notes' durations add up to 6 seconds that has a 1.5-second repeated section and a 1-second repeated section has a total duration of (6.0 + 1.5 + 1.0) = 8.5 seconds. + boolean octaveDown() Modify the state of each Note in this Melody so that they are all exactly 1 octave lower in pitch than their current state. For example, a C note in octave 4 would become a C note in octave 3. Rests are not affected by this method, and the Notes' state is otherwise unchanged other than the octaves. Octave Note.OCTAVE_MIN is the lowest possible octave allowed by our system. If any note(s) in your song are already at this octave, then the entire octaveDown call should do nothing; the call should have no effect on the state of this Melody. Return true if this method lowered the octave, and false if it was the above special case. + boolean octaveUp() Modify the state of each Note in this Melody so that they are all exactly 1 octave higher in pitch than their current state. For example, a C note in octave 4 would become a C note in octave 5. Rests are not affected by this method, and the Notes' state is otherwise unchanged other than the octaves. Note.OCTAVE_MAX is the highest possible octave allowed by our system. If any note(s) in your song are already at this octave, then the entire octaveUp call should do nothing; the call should have no effect on the state of this Melody. Return true if this method raised the octave, and false if it was the above special case. + void play() Play this Melody so that it can be heard on the computer's speakers. Essentially this consists of calling the play method on each Note. The notes should be played from the beginning of the list to the end, unless there are notes that are marked as being part of a repeated section. If a series of notes represents a repeated section, that sequence is played twice. This method should not modify the state of this Melody. Also, it should be possible to call play multiple times and get the same result each time. + void reverse() Reverse the order of the Notes in this Melody, so that future calls to play would play the notes in the opposite of the order they were in before the call. Two calls to reverse() would put the Notes back in their original order. Do not use any additional data structure; design your algorithm to work within the space of the existing list. You must write the reversal code yourself; do not use an existing Java library reversal code. + String toString() Return a String representation of this Melody. It should include the title, artist, and all the Notes, each separated by . Documentation & Style Use good documentation, style, and design techniques that we've discussed throughout the quarter. Suggestions To start, implement Melody's constructor and toString. Then you'll be able to load the file using the provided GUI and it should display the Melody content in the terminal window.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Strategic Database Technology Management For The Year 2000

Authors: Alan Simon

1st Edition

155860264X, 978-1558602649

More Books

Students also viewed these Databases questions

Question

What's the best gift you've ever received?

Answered: 1 week ago

Question

4. Choose appropriate and powerful language

Answered: 1 week ago

Question

2. Choose an appropriate organizational pattern for your speech

Answered: 1 week ago