(Solved) : Standard Piano 88 Keys Repeat Pattern Notes Travel Right Notes Get Higher Get Lower Trave Q42690796 . . .

In Pyhton

A standard piano has 88 keys that just repeat this pattern of notes over and over again. As you travel to the right the notes get higher, and they get lower as your travel to the left. The notes that are in higher octaves sound higher pitched, and the lower octaves sound lower pitched. You will use a combination of the note’s letter and the octave it is played in to accurately describe an individual key on the piano. Octave 3 Octave 4 Octave 5 F# G# F# G# A# C# D# DEEGA B C D E F GLAB CDTE ETAB in a song, this would be F#3 this is A4! this would be G5 Notice how the notes themselves are repeated several times. A standard piano has 7 full octaves (1 through 7). but the first key will actually start at A0, and the last key will be C8. Octaves 0 and 8 on the piano are therefore incomplete, they will only have the notes AO, A#O, BO, and C8. By pressing any of the keys on the piano, you are causing a small hammer to hit a string that will vibrate at a particular frequency. A note is octave 5 will have twice the frequency of the same note in octave 4, which is why the octave 5 note sounds higher pitched. You can compute the frequencies for each note by implementing the following formula: Fn = F x 21/12 Fo is the frequency of base note, in other words the note that you are using to tune all of the other notes. It is standard to tune your plano so that the note A4 is exactly 440Hz, but the function you write to generate the frequencies of the notes will use any arbitrary starting frequency. n is the number of half steps you are away from the base note (A4): • n > O means you are on a note above the base note O A#4 is one half step above A4, so n=1 o B4 is two half steps above A4, so n=2 O C#5 is four half steps above A4, so n=4 O AS is twelve half steps above A4, so n=12 n<0 means you are on a note below the base note O G#4 is one half step below A4, so n = -1 o G4 is two half steps below A4, so n=-2 o A3 is twelve half steps below A4, son-12 O F3 is sixteen half steps below A4, son-16 Note Types There are few different speeds at which a note can be played in a piece of music. We generally think of this in terms of ‘beats’ rather than seconds or minutes. A song will describe its overall tempo in beats per minute (BPM), where a higher BPM means a faster song. When reading music, the notes are organized in “measures.” The composer of the song would tell you how many beats should be in one measure. We will assume that all music used in this project uses 4 beats per measure. This makes computing the speeds easier. We have five different note types in this project. The name of the note type indicates how much of one measure that note should occupy: . “Quarter” notes take up a quarter of the measure, so for us that is exactly 1 beat • “Half” notes take up half of the measure, that would mean they last for 2 beats in our songs • “Whole” notes take up the entire measure, so they require 4 beats to play correctly • “Eighth notes take up an eighth of the measure, so that would be half of one beat “Sixteenth” notes take up a sixteenth of a measure, so that would be a quarter of one beat Song Files Files that contain songs in this project are denoted by the extension “song”, and are organized like this: Song Tempo InBPM BaseNoteFrequency NoteletterAndOctave, Note Type Noteletter AndOctave, Note Type The first line of the file is the song’s tempo expressed in beats per minute. The second line of the file is frequency of the base note used to tune the rest of the notes. The rest of the lines contain the notes in the order that they should be played for a particular song. They are comma separated, where the first item is the note’s letter on the piano and octave that is should be played in. You can open up these files in any plain text editor, they use only ASCII characters. Restrictions . There is exactly one import statement allowed in this project: import random O You are not allowed to import anything else. You can only use randint() choice() and seed() from the random library • You are not allowed to use classes, exceptions, the with statement, and list/dictionary comprehensions. . From the built-in functions, you are allowed to use: O range(), len(), sorted(), int(), sum(), list(), float(), str() • From list methods, you are allowed to use: o append(), insert(), copy(), remove(), pop(), index() . From the dictionary methods, you are allowed to us: get(), values(), keys(), items(), update() • For the file/string methods, you are allowed to use: open(), strip(), split(), join() o read(), readline(), readlines().write(), writelines() • You may not make more than one pass of a file when reading it. Do not circumvent this rule by reading in the file as one entity (one string, a list, etc.), and then performing multiple passes on that. • Questions on Piazza like “Can I use [thing not listed above]?” will not be answered by an instructor. 3 Functions The following are the functions you must implement. The signature of each one is provided, do not make any changes to them otherwise the tester will not work properly. Keep in mind that you do not have to write a main body for your program in this project. There is a small starter file provided that already imports the random module for you. generate_durations (base_tempo) Description: Generates a dictionary of note durations dictated by the base tempo. This is how long each note should be played based on tempo of the song. Assume that one measure of the song is equivalent to four beats. A quarter note would then last for one beat, a half note for two beats, a whole note for four beats, an eighth note for half of a beat, and sixteenth note for a quarter of a beat. Parameters: base_tempo (positive integer), expressed in beats per minute. Return value: a dictionary of keys (strings) and values (floats) that maps note types to seconds Example: generate_durations (60) –> {‘Whole’: 4.0, ‘Half’: 2.0, ‘Quarter’: 1.0, ‘Eighth’: 0.5, ‘Sixteenth’: 0.25} Show transcribed image text A standard piano has 88 keys that just repeat this pattern of notes over and over again. As you travel to the right the notes get higher, and they get lower as your travel to the left. The notes that are in higher octaves sound higher pitched, and the lower octaves sound lower pitched. You will use a combination of the note’s letter and the octave it is played in to accurately describe an individual key on the piano. Octave 3 Octave 4 Octave 5 F# G# F# G# A# C# D# DEEGA B C D E F GLAB CDTE ETAB in a song, this would be F#3 this is A4! this would be G5 Notice how the notes themselves are repeated several times. A standard piano has 7 full octaves (1 through 7). but the first key will actually start at A0, and the last key will be C8. Octaves 0 and 8 on the piano are therefore incomplete, they will only have the notes AO, A#O, BO, and C8. By pressing any of the keys on the piano, you are causing a small hammer to hit a string that will vibrate at a particular frequency. A note is octave 5 will have twice the frequency of the same note in octave 4, which is why the octave 5 note sounds higher pitched. You can compute the frequencies for each note by implementing the following formula: Fn = F x 21/12 Fo is the frequency of base note, in other words the note that you are using to tune all of the other notes. It is standard to tune your plano so that the note A4 is exactly 440Hz, but the function you write to generate the frequencies of the notes will use any arbitrary starting frequency. n is the number of half steps you are away from the base note (A4): • n > O means you are on a note above the base note O A#4 is one half step above A4, so n=1 o B4 is two half steps above A4, so n=2 O C#5 is four half steps above A4, so n=4 O AS is twelve half steps above A4, so n=12 n {‘Whole’: 4.0, ‘Half’: 2.0, ‘Quarter’: 1.0, ‘Eighth’: 0.5, ‘Sixteenth’: 0.25}

Answer to A standard piano has 88 keys that just repeat this pattern of notes over and over again. As you travel to the right the …