Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment you will compose a unique piece of music by playing a sequence of ( given ) sound files stored on your computer.

In this assignment you will "compose" a unique piece of music by playing a sequence of (given) sound files stored on your computer. The objective of this assignment is to give you practice structuring a program using multiple functions. The fun of this assignment is that you will get to play music. However, given the range of hardware devices that you all are working on, playing music may not, in fact, work for you. If you cannot get the music to play on your device, it is fine (although not quite as much fun)you will not lose marks for this, and you can most certainly do the assignment just the same. A Musikalisches Wrfelspiel is a process for generating music by concatenating a random sequence of pre-composed musical fragments. In this exercise, you will compose a Viennese waltz in the style of Mozart by playing a sequence of 32 WAV files (sound files) that are chosen at random according to the results of throwing dice, as described below. The waltz is composed of two partsthe minuet, followed by the trio. Minuet. The minuet consists of a sequence of N musical phrases (numbered 0 to N). For the purposes of this assignment, a musical phrase is short musical fragment, approximately two seconds in length. Each minuet phrase is stored in a file on your computer (see the attached MusicFiles zip file) and is called "minueti-s.wav" where i is a number between 0 and 15 and s is a number between 2 and 12. A file name which represents the phrase to play will be generated at random and that phrase will be played. To determine which WAV file to play for phrase i, roll two dice. If the sum is s, then play minueti-s.wav. For example, if you roll an 8 for phrase 0, then play minuet0-8.wav. Note that each roll has 11 possible outcomes (2 through 12), but some outcomes (such as 7) are much more likely than others (such as 2 or 12). Trio. The trio consists of a sequence of M phrases (numbered 0 to M), each chosen at random. Trio files are each stored in a file on your computer (see the MusicFiles zip file) and are called "trioi-s.wav" where i is a number from 0 to 15 and s is a number from 1 to 6. To determine which WAV file to play for phrase i, roll one die. If the result is s, then play trioi-s.wav. For example, if you roll a 6 for phrase 15, then play trio15-6.wav. Setup Data files The WAV files are available for download in the MusicFiles zip file in the Quick Links. Save this zip file to a folder (directory) and unzip it to the same folder that your python program is (or will be) in. It is suggested that you call your python program aMusicPlayer (or something else that starts with "a") so that the python file will appear at the top of the list of the many .wav files. It will be easier to find that way. Playing a WAV file Windows: To play a WAV file, use the following: import winsound #play a wav file winsound.PlaySound('minuet0-2.wav', winsound.SND_FILENAME) You can test this by putting the lines above in a new Python file and try it out. You must have the file called minuet0-2.wav in the same directory as your test python file. Macs: Install playsound by opening a terminal window and typing: pip3 install playsound Play the file using: from playsound import playsound #play a wav file playsound('minuet0-2.wav') You can test this by putting the lines above in a new Python file and try it out. You must have the file minuet0-2.wav in the same directory as your test python file. If the sound doesn't work for you or you are working on replit.com or another online platform: You can still write the program even if you cannot get the sound to workjust print out the file names that would be played instead of playing them. Add a comment where you would play the file if you were on a different computer. It would be a good idea to have a friend test out your program for you if possible. There will be no points deduction for the sound not playing but you must print the file names if you do not play the sounds. Function Documentation Now that you are writing functions, we expect to see function header comments in addition to the program header. We would like you to follow the convention below for writing your function headers (called "docstrings"). Please note that this is different than what the book shows. Our method follows the suggested styling found in the pep 8 Python style guide for docstring conventions. A docstring, short for documentation string is a string literal that serves as documentation of the program. Every function should have a docstring that describes what the function's purpose is, anything

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

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions