There has been a long hiatus from my teaching Sonic Pi over the past few weeks. First was Thanksgiving, then Parent Teacher Conferences the following week which resulted in a half day so I did not teach my 7th graders. The following week I was ready to go but had to leave school unexpectedly for a family emergency (everything is fine with that). The week before we go on Winter Break I have to use both periods I see my 7th grade to finish a major assessment, so I will not be teaching that week either. So I was only able to get one more class in since the last time I posted. Just for clarification, I teach one period on Sonic Pi a week to 3 different sections of my 7th graders. I try to post once a week, but if I miss a class, it sets me back a whole week.
One of the things I had reflected on after finishing my form using conditional statements project was that I wanted to try and ease up on the amount of content I present to the students. I want to give them small, digestible concepts that only take 10-15 minutes to introduce and then allow them the rest of class to explore. I also want to be able to see what they have worked on during their exploration during class so I can clear up any misconceptions they might have. I do check up on kids throughout the period as they are working but I don’t always have time to see everybody, or sometimes I’ll check on someone in the beginning and leave them alone for the rest of class, only to find they made some big mistakes after I left.
I had initially wanted to talk about making scales using arrays. As 6th graders, I teach all my students how to find the notes in any major or minor scale by counting the order of half steps from the root note. However, I use numbers instead of whole and half step, so half-step = 1, whole step = 2. So the order of half steps and whole steps for a major scale would be 2 - 2 - 1 - 2 - 2 - 2 - 1. I figured this would be easy math to write out the notes of a major scale using midi notes. For example, if the root note of the scale is 60, the notes for the major scale would be [60, 62, 64, 65, 67, 69, 71, 72]. My plan was to have students find the notes in a few major scales and then enter them into arrays and discuss how to play them in order and playing random orders.
As I prepared, I began to think about the steps it would take to get to this point. First we would have to review the concept of how to find notes in a major scale, then do a few practice examples including some sort of sheet where I could assess each individual student’s understanding. From there I would need to introduce the concept of arrays and how we can take the notes from our major scales and put it into an array. From there, we would need to discuss how to iterate through the notes in an array both sequentially and randomly which would require an introduction into what random really means when using Sonic Pi.
When I saw this lesson play out in my head, I could tell that all of this was going to be too much to cram into one period if I wanted any actual time for the students to explore these topics. So I decided to break it apart and focus on just one aspect: arrays. This is a concept that is very common in CS but that also had very clear application from a musical point of view. It was a way to have students make their code more concise and efficient, while also exposing them to the possibilities of generative music via playing random sequences from their array.
When it came time to teach, I started by typing out four play commands in a row, play 60, play 64, play 67, play 72. Since we hadn’t met for a while and I was making an effort to be mindful of time, I decided to take the lead and explain that this code was going to play all 4 notes at once. I did ask how I could get them to play one at a time, which they were able to answer “with a sleep in between”. I then said there is a way I could write this same code in one line, by using something called an array.
I presented an array as a way we can store multiple values or notes in one place. In order to make an array, I need to use square brackets. Inside those square brackets, I then put the notes I want, each separated by a comma [60, 64, 67, 72]. This is an array. If I use this with a play command, it will play all four notes at once. I ran the code to show the results. Now I could add many more notes in my array to play together instead of having them in multiple lines of code.
Now let’s say that I want to play each note in my array one at a time meaning I play the first note, then the second, then third, then fourth. In order to do this, I need to put my array inside a repetition block. In this case, I have 4 notes in my array so I want to repeat 4 times. I wrote a 4.times block and inside I put my array, play [60,64,67,72]. I explained that we also would need to have a sleep in between each repetition, so I added sleep 0.5. Now lets run the code. I played it and as I expected something went wrong. I had deliberately made a mistake to demonstrate what is happening and something I anticipated student doing as well, so I wanted to put it in their heads first. What happened was that all the notes in the array played at the same time and repeated that 4 times. There is something we have to add to our array in order to make it play notes individually. At the end of the array, we need to put .tick. This command will tell Sonic Pi to “tick” through each note in the array one at a time. I ran the code and they were able to hear each note separately.
Now, what do we think would happen if I changed the number of times this repeats. I changed the 4.times to an 8.times. I got a few different answers. One student said it will go back and play the notes again. Another thought I would get an error message and the code wouldn’t run at all. I said lets find out and ran the code. They heard the four notes and then silence. I pointed out that with .tick, the program will go through the notes in the array and then continue through the array but since there is nothing there it will interpret that as a rest. I drew everyone’s attention to the console and ran the code again. They could see that the notes would print out and then the next for notes would read as rests. I took that opportunity to show that this is one way to use the console to get information about your program. We haven’t talked much about using the console, so I wanted to bring this to their attention so they can see that it can be a useful tool. The takeaway from that demonstration was that if you are going to use .tick, you can not repeat more times then you have notes in your array or nothing will happen.
Lets say that I don’t want to play them in order, but instead I want to just pick a random note out of my array. I can do this too. I just have to change the .tick to a .choose. This tells the program that each time through the repeat block, it can choose any note from the array. I changed the .tick to .choose and ran the program. I also purposefully left the repeat block as 8.times. We can hear now that we have a sequence of these notes in the array but not in order. We can also hear that it played 8 times and each time there was a note. With .choose, it doesn’t matter how many notes are in the array versus how many times you are repeating. It will always play a note.
I explained that one of the fun things we can do with computers is have it pick random combinations. But take a listen to this code again. I ran the code. Then I ran it again. Then I ran it again. And again. What do you notice? I knew I might be setting myself up here as I have spoken several times about making assumptions when presenting listening examples. But luckily a few musically inclined students pointed out that it was the same combination every time. When we talk about random with computers, it isn’t random in the same sense of a person making a random choice. It has worked out all the possible combinations and will choose one for you. Because of this, if we want to change the pattern of “random” notes, we need to add use_random_seed. I did a couple examples of this, first starting with use_random_seed 2, then 3 then 12 , then 234, then 24089740192 just to really drive the point home. Each time I had a different combination of notes. I pointed out that doing this, you can find one that you like and stay with it.
Another thing we can do with use_random_seed is to run one combination and then a different combination. I copied and pasted the code I had from the first example and changed the random seed number to something else. I also made sure to change the synth sound for the second example so it was clear when one stopped and the other started. I did not think the students would be able to figure out the change otherwise.
At that point I had shown all I wanted to and gave them the rest of the class to explore that concept. However, to keep tabs on how everyone was doing, I said I wanted them all to submit their code through Google Classroom so I could take a look at it. I just wanted to see some code that includes the concept of arrays. And for the most part, when it was over, they did submit the code. It was very helpful to be able to check on everyone’s understanding this concept immediately after the class. Most of the misunderstandings were syntax related or including use_random_seed with a .tick. I was able to leave comments in the Google doc to address the problems and then could have students go back and check on the comments in the next class.
I really felt good about the flow of this lesson. Relevant concept, short roll out, time to explore and a way to check on everyone’s progress when it was finished. I am going to try to structure more lessons like this and then every few weeks have them apply it into a bigger project.
Link to reference sheet give =n to students for this lesson: https://docs.google.com/a/thebellacademy.com/document/d/1m61Iry8N14Ox1gIe3jXgIG2dLsLHHoYd5JaO_6mMDcY/edit?usp=sharing