To do for next year. --MF, 3/6/22
For Each
to Traverse a ListThe paragraph below is well-intentioned, but it doesn't belong here. Maybe after your sample song that uses REPEAT?
Where do you mean, exactly? --MF, 3/6/22
Using the repeat
block strategically can make your code shorter and easier to read. It's generally a good idea to write shorter code that is easier to read because when something isn't working right, it's easier to find and fix the problem, or when you want to change it later or have someone else read it, that's easier too.
One way to simplify writing a song is to use a list to store the pitches and then play each pitch in the list. You can use
for each
to run a command (or group of commands) for each item in a list. For example:
A list is an ordered sequence of items. You've been using lists throughout this course: to store words for a story, to manipulate the letters of a secret message, and even to store lists such as each individual's responses to the question in a survey.
It doesn't mean that the items have to appear in alphabetical or numeric order. It just means that these are different lists:
This might be a risky move. I was hoping to give the kids a chance to start from scratch if they had a cluttered project, but it does mean that from this page on, some students will have only one project for the lab while others will have two. It also means that I can't refer to their project by name on the subsequent pages, so if they name it awkwardly and forget the name, they won't be able to find it. Thoughts? --MF, 2/23/22
The further along I get in writing this lab, the more I regret this choice because I have no way of telling them what project I want them to open other than "your last one". I'm now thinking they should start from a new starter XML here without any option. Thoughts? --MF, 2/27/22
I agree, pick one. I first thought they should start with the example project, but then they don't get the practice in exercise 2. Maybe have them start with the sample (which should be called the starter instead of sample) but still make them make their own FOR EACH block? -bh 3/3/22
How about they start with starter project and you can remind them they can open up song player in another tab to remember the pitches that they used? -pf 3/3/22
To resolve next time around. --MF, 3/6/22
for each
example project and save it to your Snap! account.for each
. If you opened the example project, edit the pitches in the list to create your song. If you opened your own "Song Player" project...
for each
block into the scripting area, and drag a play ♪
block inside it.play ♪
block. Dragging will make a copy of pitch, so you should see pitch in both places.play ♪
block. (For example, if you want half notes, type the number "0.5".)list
block into the list input slot of the for each
block, add some notes, and click the script to test out your song as you build it.list
block:
For Each
to Play Any List of Pitches
You can create a play song
block that will apply this script to any input song.
How much experience have they had before this of generalizing a script by turning it into a procedure with an input? They should have done that several times by now, no? So that experience should be called out here. "Remember how you generalized your blah blah by making it a procedure with an input? You can do the same thing with this script that plays the notes in a list." --bh 3/3/22
To revisit... --MF, 3/6/22
play song
that takes a list of notes as input and plays each note in the list using for each
.
play song
block should be pink! --MF, 2/21/22
play song
that takes one input called song, which will be a list of pitches. (To add an input, you have the hover over the tiny space to the right of the block name to get the plus sign (+) to show up and then click it.)for each pitch, play ♪
code by right-clicking the for each
block and selecting "duplicate," and then attach the copied code to the play song
hat block in the block editor.for each
block where song had been, and click, "OK."Sorry, this is another Snap bug report, but when I ran play-song, the song suddenly sounded horrifying. I even added an explicit set-instrument to 1 but it still sounds really sharp/grating. It did that for the first 3 times I played it. After writing this comment, it seems to be okay. Not sure what triggers it. I still am getting the issue where switching tabs while playing a song prolongs the current note, that seems very repeatable. -pf 3/3/22
This needs to go on GH not in the curriculum. https://github.com/jmoenig/Snap/issues :) --MF, 3/6/22
play song
block with at least two different lists of pitches, and fix any issues with the block.play song
block by attaching a comment to the hat block. The help text should describe what the block takes as input and what effect the block produces.
Does my play song
block have to play every note for the same length of time?
No. On a later page, you can learn a way to store and play songs with both pitch and beat information about each note.
for each
to play each pitch in a list and created a play song
block that will work with any list of pitches.This is a more general problem, but it looks particularly bad here: When a <code> text embedded in a line includes spaces, the spaces are way too big compared to all the other spaces on the line. Ideally you'd say <code>for</code> <code>each</code>
but that's too horrible to contemplate, so somehow it should be fixed in the Javascript. --bh 3/3/22
Go for it! :) --MF, 3/6/22
The orange color of item is inaccessible per https://webaim.org/resources/contrastchecker/ It would need to be a significantly darker orange to meet a11y contrast standards. -pf 3/3/22
Thanks. Let's address this at a meeting. --MF, 3/6/22