@extends('template') @section('title') Lab 2: Extra motifs @stop @section('content') # Lab 2: Extra motifs These extra exercises build on the [motifs functions](motifs); if you haven't finished that part you should do that first. ## Create a user-specified motif
Depending on what you type it, this will sound different every time. Here is an example of what this would sound like if the user enters 3 for the duration, -2 for the first gap, and 4 for the second gap:
The printed output (including the prompts and inputs provided) should look like this:
What should the duration be? 3
How far between notes 1 and 2? -2
How far between notes 2 and 3? 4
a 0.333s keyboard note at C4 (60% vol)
and a 0.333s keyboard note at A3 (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 C4 (60% vol)
and a 0.333s keyboard note at G4 (60% vol)
and a 0.333s keyboard note at G4 (60% vol)
and a 0.333s keyboard note at E4 (60% vol)
and a 0.333s keyboard note at B4 (60% vol)
Hints:
1. You'll have to enable the test for `customNotes` in `test_motifs.py`,
and you should disable the other tests for clarity.
2. You will need to convert the duration to a number, and then calculate
the per-motif duration from that. You should probably convert it to a
floating-point number in case someone types in a fractional number of
seconds.
3. When you run `test_motifs.py`, nothing will happen until you finish
entering the inputs it requests.
4. You should call `motif` rather than copying and pasting code to create
the notes.
## Challenge: Add some random beats to your motifs
Write a function called `randomBeatsNotes` which adds the same notes as `climbingNotes` does (it should in fact call `climbingNotes` to achieve that) but which also adds three beats at random points while the notes are playing, one during each copy of the motif.
Here is what the result might sound like, although it will sound different every time. How can we pick something randomly? Python has a built-in `random` module for that. You'll need to import it, just like you've been importing other modules like `turtle`. One of the functions it provides is called [`random`](/reference/quickref#random) which picks a random number between 0 and 1, that we can multiply by a number of seconds to pick a delay value up to a specific maximum delay. [Our quick-reference page](/reference/quickref#seed) has documentation on a few other functions in the `random` module as well. Hints: 1. `randomBeatsNotes` will have 1 parameter: the total duration (just like `climbingNotes` does). 2. The duration of each beat is 1/2 the duration of the notes (so 1/6 the duration of each motif). Their volume has been set 4 steps [`quieter`](/reference/quickref#quieter) than the base volume. 2. Writing a separate function to place one random beat within a specific time interval is a good approach 4. Ideally, the beats should end before the end of their assocaited motifs, but its okay if yours have a chance of lasting beyond the end of their motif. You use the prepared line of code in `test_motifs.py` to test your function. @include('/labs/lab02/_toc') @stop