Map
permap
block to transpose (shift) all the pitches in your song.Pamela, I debated whether to teach the ADT first so they can traverse a 2D list or to show them how to use MAP to transpose first. I went with MAP first and letting 2D lists/ADTs be a later optional page (perhaps not even to be written now or perhaps just a "Take It Further" on the last page) since the goal of the course is functional, and MAP would align with that. There is no real need to teach ADTs although the context does naturally inspire it. --MF, 2/12/22
When transposing a song, it's especially important not to call MIDI note numbers "pitch." The actual pitches are in a geometric progression, not a linear one, and when you transpose by n steps you're actually multiplying the pitches by (\sqrt[12]{2})^n. --bh 3/3/22
I agree to rename the variable for next year. --MF, 3/6/22
Another advantage of using a list to store your notes is that you can use higher order functions to process your list. You can use map
to play a song higher or lower than the original pitches.
If you store the list of pitches in a variable, you can use play song
together with map
to play the same song several times in different ways.
map
example. Click each block to: set the variable, play the song, and then play the transposed (shifted) song.
+
function in the map
block) from 3 to some other integer. (You can make it any integer—positive or negative—but if it's too high or low, you won't be able to hear the song).The map
block takes two inputs: a function (in this case ) and a list, applies the function to each item in the list, and reports a new list of the results.
Recall, a function that takes a function as input (like map
) is called a higher order function.
map
example, and play the song.play song
blocks, changing the shift values in the map
blocks, or changing the pitches in the song.map
and play song
together with one of the variables that you used to store your pitches to make your song more complex.
Better? --MF, 3/7/22
map
block out of the play song with pitches and beats
block temporarily and then click it to see what values it reports.map
to transpose lists of pitches stored in variables and create more complex music.
See 1.4.4. --MF, 3/6/22