@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`
Partner A
`motif` accepts the following parameters: 1. `duration` - The total duration for the motif 1. `climb1` - How far up the scale to climb between the 1st and 2nd notes. 1. `climb2` - How far up the scale to climb between the 2nd and 3rd notes. The function will create three notes of equal duration (whose duration adds up to the specified total duration) and in between each pair of notes it will use `climbUp` to change the pitch. Write your code for `motif`, and then test your work by **running the provided `test_motifs.py` file**, which imports your file and then makes the following function calls: ```py # Import of the functions we'll be testing import motifs # 1-second duration, moving one note down and then one note back up motifs.motif(1, -1, 1) # Another motif, this time moving up and then down motifs.motif(1, 3, -1) ```

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`
Partner B
Now that you have a `motif` function, why not repeat a motif?

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