Map
ping over Pitches and Beats
You've learned how to use map
to transpose (shift) all the pitch values in a song where each note plays for the same length, and you've learned how to use a table to store both pitch and beat values for the notes in a song. You can also transpose the pitch values stored in a table.
This code is a bit complicated. Notice that it plays a version of Mario Theme that has gone through the
map
block. So the question is: What does this map
block do?
Obviously, this whole page a bit of a reach, but I feel like the question will arise for some kids of how to do this, and so I want to offer something for them (even if they just read it on their own time). In the TG, this will be listed as optional. Any suggestions for improving this presentation? --MF, 2/27/22
Yeah, this is a bit of a doozy, especially because they really should have read the yellow box on the previous page to understand the ADT selectors. I definitely think it should be optional, as you say it is. Maybe you can make sure they've read that yellow box, or repeat all/parts of it here? -pf 3/6/22
I've added a first problem on this page about going back and reading that. Sufficient to close this comment, or should we discuss this further? --MF, 3/7/22
Recall that play song with pitches and beats
expects a table of song data as input, map
works through every item in a list, and every item in the table of pitches and beats is one note. So, map
applies a function to every note in the Mario Theme and outputs a table of notes (pairs of pitches and beats).
→
In order for map
to output a table of pitches and beats, it needs to apply a function that outputs pairs of pitches and beats. So the code needs a structure like this:
What function outputs pitches and beats? The block. So the code needs a structure like this:
But remember that the inputs that end up in the blank spots of the function in the map
block each time it applies the function are the items in the input list, which in this case are the notes (pitches and beats from Mario Theme (with beats)).
So, to get a beats value in the beats slot, we need to use the beats from ♪
block, which takes a note (with a pitch and a beat) and reports just the beat.
And to get a pitch value in the pitch slot, we need to use the pitches from ♪
block, and we need to add our shift value to do the transpose.
play song with pitches and beats
block work?", and read all the information included there. Before moving on, discuss any questions you have about how that block works. They don't need a hint. All they're asked to do is copy your code but with a different song substituted. For them to understand the code may be hard, but the hint doesn't help with that, and it's not required of them. Having a hint will just make them worry that they're missing something. --bh 3/3/22
I included this here so they don't have to scroll around to find it. If the are looking for a hint, it's because scrolling up didn't work somehow. Feel free to suggest a tweak, but that's the idea behind having it. --MF, 3/6/22
Your code should look like this but with your own song variable in place of Mario Theme (with beats) and a different shift value (instead of 5).
Example: Mario Theme Mapped
Tip: Try shifts like 1, 4, 7 and see which sound good to you. What about other shifts?
OK, cut for now, but left for possible discussion. I don't disagree with any of this; I was trying to get at "Why is this so complicated? Can we do this an easier way?" and empower students: "If you have an idea, try it!" But I guess it's not as empowering to say "try it" i this case... --MF, 3/6/22
map
to change the beats in some way. Try it!map
in a more complicated situation in which you want to transform only part of an item with multiple parts.