@extends('template') @section('title') Lab 2: Musical Motifs @stop @section('head') @stop @section('content') # Lab 2: Musical Motifs
Our goal in this part of today's lab is to create melodies out of repeating motifs like the following:
To accomplish this task, we'll create a function that will create a three-note pattern, called `motif`: **Open the provided file** `lab02/motifs.py` to get started... ## Function 1: `motif`What you hear should be six notes, moving first down once and back up, then repeating a note and then up thrice and finally down once. It should sound like this:
The printed output should look like this: ```txt a 0.333s keyboard note at C4 (60% vol) and a 0.333s keyboard note at B3 (60% vol) and a 0.333s keyboard note at C4 (60% vol) and a 0.333s keyboard note at C4 (60% vol) and a 0.333s keyboard note at F4 (60% vol) and a 0.333s keyboard note at E4 (60% vol) ``` ## Function 2: `climbingNotes`Write a function called `climbingNotes` which repeats the same motif three times: a base note, a note two rungs higher on the scale, and then a note one rung back down, between the first two. If we repeat this motif, since it leaves the pitch one rung higher than where it started, the pitch will gradually increase.
`climbingNotes` should have only one parameter, which determines the total duration of all three motifs it creates. You can uncomment the relevant line in `test_motifs.py` in order to test it, and if you also comment out the tests for `motif`, it should sound like this: The printed output should look like this: ```txt a 0.333s keyboard note at C4 (60% vol) and a 0.333s keyboard note at E4 (60% vol) and a 0.333s keyboard note at D4 (60% vol) and a 0.333s keyboard note at D4 (60% vol) and a 0.333s keyboard note at F4 (60% vol) and a 0.333s keyboard note at E4 (60% vol) and a 0.333s keyboard note at E4 (60% vol) and a 0.333s keyboard note at G4 (60% vol) and a 0.333s keyboard note at F4 (60% vol) ``` Hints: 1. `climbingNotes` does not need to call `addNote` itself: it should call your `motif` function! 1. You'll need to compute the duration of each motif by dividing the total duration by 3. ## That's it! Congratulations, you made it to the end of the lab! If you still have time left, there are some optional exercises you could work on: - [The bagels exercises](bagels) will show you how to use functions with `turtle` graphics. - If you prefer, there are [extra motifs exercises](extra_motifs) that will build on the code you just wrote. @include('/labs/lab02/_toc') @stop