You must write a function called arpeggio
which adds a 5-note arpeggio
to the current track. It has two parameters: a base pitch, and a
duration. Each added note will use the provided duration, and the first
and last notes will use the provided base pitch. The second and fourth
notes will be three half-steps above the base pitch, while the third note
will be seven half-steps above the base pitch.
An example of correct behavior
Note that to set up expectations for arpeggio, you can use the
printTrack
function to print descriptions of each note in the current
track, and so you can use captureOutput
along with
expectOutputContains
to test for the presence of certain notes or note
sequences. Here is an example of this expectation
setup. Your tests do not have to specify every
note that should be present, although they may if you wish. You will need
to create at lest two expectations for track
descriptions in this manner.
Examples for arpeggio
Some examples of correct results for arpeggio
:
In []:Printsarpeggio(C4, 0.5) printTrack()
a 0.5s keyboard note at C4 (60% vol) and a 0.5s keyboard note at E4 (60% vol) and a 0.5s keyboard note at G4 (60% vol) and a 0.5s keyboard note at E4 (60% vol) and a 0.5s keyboard note at C4 (60% vol)Audio In []:Printsarpeggio(A4, 0.2) printTrack()
a 0.2s keyboard note at A4 (60% vol) and a 0.2s keyboard note at Db5 (60% vol) and a 0.2s keyboard note at E5 (60% vol) and a 0.2s keyboard note at Db5 (60% vol) and a 0.2s keyboard note at A4 (60% vol)Audio In []:Printsarpeggio(G5, 0.3) printTrack()
a 0.3s keyboard note at G5 (60% vol) and a 0.3s keyboard note at B5 (60% vol) and a 0.3s keyboard note at D6 (60% vol) and a 0.3s keyboard note at B5 (60% vol) and a 0.3s keyboard note at G5 (60% vol)Audio
How to set up expectations
Here's a example of how to set up expectations for wavesynth
notes using captureOutput
along with printTrack
.
In []:Printsfrom wavesynth import * # Here's some code that creates notes setPitch(C4) addNote(0.2) stepUp() addNote(0.3) # This isn't necessary, but we print the track first so you can see what # the expectations are dealing with printTrack() import optimism as opt # Use captureOutput to set up a test case for the printTrack output opt.captureOutput() opt.testCase(printTrack()) opt.expectOutputContains("a 0.2s keyboard note at C4") opt.expectOutputContains("and a 0.3s keyboard note at D4") # Note: our expectations don't constrain the volume level, but they could
a 0.2s keyboard note at C4 (60% vol) and a 0.3s keyboard note at D4 (60% vol)Logs✓ <soln>/arpeggio.py:18 ✓ <soln>/arpeggio.py:19Out[]:AudioTrue
arpeggio
with 2 arguments
def
to define arpeggio
with 2 argumentsaddNote
arpeggio
with 2 arguments, call addNote
in exactly 5 places.optimism
module to establish a certain number of test cases which use the following functions directly in the test case expression. (Each test case must be followed by at least one expectation):printTrack
: 2 test casesoptimism
module must be met, and it must establish at least one expectation.arpeggio
creates the correct note sequence
arpeggio
adds to the current track and compare them against the notes produced by the solution.arpeggio
adds to the end of the track
arpeggio
twice; it should create two arpeggios which happen one after the other.