Lab 15
This lab is due on Monday.
Develop the "note" data definition, for data that can be either (that is, mixed data) silence or a note at a given midi note number. In both cases, you’ll need to represent the duration of the note. To get you ready for the next year at Cal Poly, each of these choices should be represented as a structure. Provide at least three examples of notes.
Develop the notes->sound function, that accepts a list of notes (using the data definition you created) and returns a sound, containing all of the notes in the list, played simultaneously. Use one of the single-cycle sounds to make it sound somewhat interesting.
Develop the sounds-nice-with-60? function, that accepts a note and returns true if it is not 1, 2, or 6 half-steps away from midi note number 60. Silence always sounds nice.
Develop the sounds-nice/2? function, that accepts two notes and returns true if either one (or both) is silence, or if the two notes are not separated by 1, 2, or 6 half-steps.
Develop the sounds-nice/3? function, that accepts three notes and returns true if no pair of the three notes is separated by 1, 2, or 6 half-steps.
Develop the random-note function, that randomly produces either silence or a note in the range [60-72] (inclusive). Silence should occur 30% of the time. The remainder of the notes should occur with equal likelihood. The duration of the note should be between 1/2 a second and two seconds. No test cases are required for this, but make sure that your function does sometimes produce silence.
Develop the chord data definition, containing exactly three notes. Note that this is quite a bit different from the chord data definition of the prior lab.
Develop the random-chord function, that produces a chord containing three notes using random-note. No test cases are required. It’s fine if some of the "notes" in the chord are actually silence. Use play and notes->sound to try playing these chords.
If you have time, try one or more of the following:
Develop the only-nice-chords function that accepts a list of chords and returns only those that sound nice according to sounds-nice/3?
Generate 1000 chords and see how many are ’nice’, to estimate the probability that a randomly chosen chord is ’nice’.
(substantially harder: ) generalize the sounds-nice/3? function to a sounds-nice? function, that accepts a list of any number of notes and determines whether all pairs of notes in the chord sound nice together.
A chord-pair, representing two tones played together, has two midi note numbers and a duration in frames
A chord, representing a set of tones played together, has a list of midi note numbers and a duration in frames
A key-signature, representing a key signature, has a set of seven strings, indicating whether the given note in the scale is "sharp", "natural", or "flat".
A chord-sequence, representing a sequence of chords, contains a list of chords and a volume.