My year teaching Sonic Pi - Week 3

I started off class with a quick review of what we covered last time. I instituted a new protocol that when I was addressing the whole class with a review or presenting new concepts that everyone keep their laptop screen “at half mast” meaning halfway closed just as a sign of good faith that they were paying attention and not ignoring what I was saying. I felt like this was going to be necessary as we started learning more functions and concepts. Overall it seemed to work well. It also made it easier to zero in on the ones who clearly weren’t paying attention.

We had experimented with the play function and the different numbers that we could input. We established that certain numbers are going to inaudible because the amount of hertz that the MIDI notes correspond to fall outside of our range of hearing. We had covered the midi_to_hz command last time, but since it isn’t something we wouldn’t really be using moving forward, I didn’t bother to go over that again.

Next, I introduced the use of musical notes with the play function. I explained that each MIDI note also corresponds to a musical note. We had covered musical notes in 6th grade, so the students are all familiar with that concept. I teach notes using a concept I call the Circle of Notes (Not the same as the circle of fifths). It is basically just all the notes in a chromatic scale put in a circle. I like this method of presenting notes because the way I approach basic theory involves a lot of counting from one note to another. I also use it to learn notes on the guitar neck. You can move either way around the circle, start on any note and get a sense of the distance between notes. It also gives the idea that there isn’t necessarily a beginning and end when going from one note to another. I used to show notes in a straight line from A to A, but it became confusing if you were trying to count from something like G up to B because you would come to the end of the line and have to go back to the beginning. I’ve had a lot of success with kids using the circle to spell out scales, chords and find notes on specific frets on the guitar.

I showed the kids the basic syntax to play notes. We need a colon, then the letter of the note and a letter to indicate the octave. The octaves that we can hear fall between 0 and 10 or so, but I welcomed them to experiment. If we want to do sharps, we do not use the symbol we know for sharps, the number sign (or hashtag which the kids seem more familiar with). I realize this might have been an opportunity to explain that ‘#’ is used to include comments in your code or to comment out a line without deleting it. However, I felt like this would go off course too much. Commenting code is something I think is important and I didn’t want to gloss over it in the middle of explaining something else, so I didn’t bother mentioning it at that point. I just said we use a lowercase ‘s’ which stands for ‘sharp’, so f sharp would look like :fs4. When using a flat, we use the lowercase ‘b’ which does look like the symbol for flat that we use. I often have to remind students that a lowercase ‘b’ in music is just a symbol which stands for the term flat because they will call a note is “A B”, not “A flat” or they will write an uppercase B instead of a flat symbol.
[See the bottom of this post for an image of the circle of notes]

To show the connection between midi notes and letter notes, I wrote play :c4 and ran the code so they could hear it. Then I changed it to play 60 and ran it again so they could hear it was the same note. I made the point that either one is acceptable and deciding which one to use is your own personal preference. For students who have some musical background, using letter notes might make more sense. You could also use both within the same code. Using numbers also give the option of using decimal points for notes that are in between the letter notes that we know.

From there, I asked how many students had tried last time to put two plays one after another expecting it to play one note and then another only to find both notes played at the same time. Quite a few hands would go up. I wrote play 60 followed by play 67 and I reviewed the concept of iteration which we had covered at the end of the previous class. Since computers process code so fast, these notes are played simultaneously (at least to our ears). We need something in our code to tell the computer to wait before it plays the second note. This command is called sleep. I put a sleep 1 between the two play commands and ran it again. I explained that now the computer knows to wait before it plays the next note. I also pointed out that sleep, like play, takes a number. I changed it to sleep 2 and ran it again so they could hear the difference. I then said we can also run decimal points less than 1. I typed in sleep .5 and ran the code. I did this on purpose to show that an error message would pop up so I could reinforce the idea of syntax. In SPi, if we are going to use a decimal less than 1, we need to put a zero in front of the decimal point or else SPi won’t understand what we mean and won’t run the code. I then added the zero and ran the code. I specifically did not mention what the number after sleep stood for. I wanted to let the students play around with it and see what happens. I was also hoping that someone might ask about it later on (spoiler alert: they didn’t).

With those two commands, I allowed the class to explore and see what they could come up with. I gave them around 15 minutes to play around and then said we were going to reconvene and share what we learned. I also stressed that I wanted them to think of questions. I said to let me know if there was something they wanted to do but couldn’t figure out how to do it and I would help them out. I really believe that putting boundaries on what they are doing helps foster creativity and gets them thinking about what they could do if those boundaries weren’t in place. As they worked, I walked around the room and observed what they were doing.

The kids really seemed to be enjoying themselves and coming up with some interesting ideas. At this point, I didn’t really know where I was going to go from here. I was very interested to see what kind of things the kids would try and what type of questions would arise. Most of them seemed content just playing with the play and sleep functions. However, I was pleased this time as a few kids did have some good questions that helped shape the direction of where we wound up going. My approach to that was only to show the students who asked the question first and then when we reconvene as a class, I would share it with everyone.

A few wanted to know how to change the sound although the way there were a few different ways they phrased it. One asked how to change the beat to which I asked what do you mean by “beat”? I have learned over years of teaching music that few if any middle schoolers can accurately explain what the word “beat” means although if you ask what are some things we need in order to have music, most of them will include ‘beat’ in their answer… Most of them use it to describe other musical concepts like rhythm, tempo, arrangement and in this case, after digging deeper, this student meant the instrument sound. Once we were clear on that, I praised the question and showed him and his partner what to do. I requested that when it comes time to share out questions that he brings that up.

Another student asked how to make it go on forever, so I showed him a loop function. Another asked if there was a way to do something more than once which led to the repetition blocks use 4.times do end. I encountered two students who were making a composition where they had play :b4 and sleep 1 written at least 7 or 8 times in a row. I went over and said “I see you are doing the same thing over and over again. That seems like a lot of trouble having to keep writing the same thing that many times. Is there a question you could ask that might lead you to a way to make this easier?” They thought about it and we tried to talk it out but they didn’t quite get there. I was trying to get them to ask something along the lines of “how do I do the same thing more than once without having to write it every time?” But their brains didn’t seem to be going in the direction. So instead of telling them the answer to a question they didn’t ask, I just let them be and said “I’m going to use you as an example when we come together as a class”. I didn’t want to push them in a direction they weren’t ready to go in. I wanted students’ exploration to be natural and organic, so I avoided giving anyone information they didn’t specifically request.

After about 15 minutes, I called for laptops at half mast and opened the floor to questions. Generally, anyone who had a question had already asked it during exploration time, so I asked those students to repeat the questions they had for the class. I tried to model what I assumed was close to the student’s thought process. For example I would say “Jose kept making all these beeps and thought ‘man, I’m really getting tired of this beep sound. I wonder if there is a way to make a different sound’. So Jose asked ‘Is there a way to make a different sound?” and I said “Of course there is”. I was hoping that talking through this type of scenario would help kids arrive at some more questions in the future. I’ve found it’s not always that they don’t have a question, it’s that they don’t know how to phrase it right and rather than feel silly for asking what they think to be a ‘dumb’ question, they just won’t ask at all.

I showed the students the use_synth function and allowed them to see the drop down menu for all the different choice. I emphasized the syntax of needing to include the colon before the synth name. I showed them that if you hold shift + space bar after deleting one synth name, the menu will pop up again. I also showed that you can change snyths within your code, so I would put a few plays and sleeps with one sound and then a new use_synth with a different sound and more plays and sleeps so they could hear the difference. A lot of them seemed pretty excited at this new possibility.

I next presented the repetition commands. I referred to a student who asked “How do I make something happen more than once?” I imagine her thought process to be “I like this piece of code and want it to happen again, but is there a way I can do that without writing it all over again?” I said we could just copy and paste it, but now we are getting to have a lot of code and we really want to focus on less code to do the same thing. So this was where I could present the idea of a block of code. I know that this can be referred to as modularity, but I just wanted to give them the concept without this big word that would require some explanation as to what that means. If this were a CS class, I might feel differently, but my goal is making music so I felt ok about skipping that detail.

I presented the example of 2.times do and then typed some plays and sleeps and followed it with an end. I explained that this is a block of code which can be used again within this command. I ran the code and showed that it repeated after playing once. I then changed it to 3.times and ran it. Then 4.times. From there I typed in some code outside of the block. I asked what they thought would happen. Sure enough, they guessed that after the code ran, it would exit the block and run the rest of the code. I have made it a habit for these types of examples to change the synth sound so the change is more obvious and easy to hear. I think some students have difficulty following along when there is repetition using the same sound the whole time. It isn’t always clear when the code has moved from one part to another.

In the class which had the two students who wrote the same thing 7-8 times, I took this chance to mention what they were doing and say that this would be a good place to use this block of code. I also went over the discussion I had with them in hopes other students might start to make those connections of when they encounter something that might be able to be done an easier way.

In one of the classes, after presenting this repetition block, one student raised their hand and asked “Is there a way to make it go on forever?” “Great Question!” I exclaimed. That is just the type of question I want to hear: You see something and start thinking about what else could be done with it. The question becomes “How do I do this thing that I want to do now?” I deleted the 4.times and entered the loop function. I ran the code and they heard my example play over and over. I stressed that this code would continue until I stop the code from running. In classes where I had done the 4.times block first and had some code underneath, I asked “What happens to this code?” There was some disagreement, but we eventually established that that code will never run because we cannot exit the loop function. I did another example of putting some code before the loop so they could see the difference. In the one class where a student had asked how to do something forever, I had shown the loop function first and then typed some code underneath and asked what they think would happen.

Finally, I went back to sleep and asked “Did anyone wonder about the meaning of the number we put after sleep? What does this 1 mean? 1 what?” No one really seemed to have given it much thought. Some of them shouted out “it’s one second” or “it’s one beat”. One student said “it’s one amount of time, whatever that amount might be” which I kind of liked. I suggested an increment or duration of time. So with all those responses I was able to say “You are all correct” Right now it is 1 second. It is also one beat. But there is something we can do to change the length so that it is still one beat or one increment of time, but no longer 1 second. This brought us to the concept of BPM which (few students were aware of) means Beats Per Minute. This means how many beats go by in a minute. It is basically a way to measure the speed or tempo of a song. If I have 60 BPM, I have one beat every second. This is the default BPM of Sonic Pi. What if I had 120 BPM, how many beats would I have every second? Remember this means every minute there are 120 beats going by where as 60 bpm is 60 beats in a minute. They thought and eventually one brave soul called out “one beat every half a second”. Right. What about 30 BPM? “One beat every 2 seconds” I went on that 90 beats would be a beat every .75 seconds (although I’m not even sure if that is right) But the point is not how many seconds, the point is that if you change the bpm, that sleep 1 will last longer or shorter depending on what you do which is why I liked the student’s response about one “amount of time”. I showed them the use_bpm function and wrote a few plays with sleep 1 in between. I started with 65 bpm, then changed to 90, then 130, then 40, just to drive the point home that higher numbers mean the code will go faster.

At this point, we were right about at pack up time which I (and the students) were not happy about. I really had wanted to give them time to play around with these new functions and I could tell they felt the same. I feel like retention is lost since we only do this once a week for roughly 40 minutes. I suppose I could have given a little less time during the first exploration but I don’t think that would have made too much of a difference on the back end. I also worry that letting them start up again with only 5 minutes or so becomes harder to tear them away and then the pack up routine gets thrown off and we are rushed which results in stuff not getting put away properly and that is not something I want them to get in the habit of. I told them we would go over these commands again next time and they would have a lot more time to experiment with them.

Some after thoughts from this lesson…….

1.) I find myself referring to things like play, use_bpm and the rest as “commands” and not “functions” which I believe is more accurate from a computer science perspective. As I was saying earlier about modularity, I am hesitant to use words that I don’t feel the students have any connection to. When we first discussed coding, we established that it was a way of giving “commands” to a computer to make it do something. That was the kids’ word, so I have kind of stuck with it. I don’t feel that “function” would have the same impact. I also think part of it is still my uncomfortableness with CS in general and working through my Imposter Syndrome. Maybe when I teach them how to make a function, I can tie it back and start using the proper vocabulary.

2.) I felt like the bpm discussion could have been an opportunity to involve some actual math where I give them some bpm numbers and they figure out how many beats per second to get a better grasp of the subject. I even thought after the lesson about putting together some sort of quick worksheet or as we say in the education biz, an “exit slip” which is a way to assess understanding of a certain concept at the end of a lesson. Checking for understanding is something administrators are REALLY big on especially during performance evaluations. However, the last thing I want to do is take away coding time to do yuck paperwork. But at the same time, I am really trying to look for ways to check for understanding, not just how to check for understanding but WHAT am I really checking for. Again, not a CS class so seeing if they understand the concept of bpms in relation to tempo is more of a musical concept that is worth knowing. I’m sure I will be musing about this idea of assessment a lot.

3.) With the questions that came up, I wished this time I had the Google Doc open for the class to share. This would give a chance for me to tell kids with a good question to share it in the doc so others could see it and maybe get a better sense of what type of questions they should be asking. I really want to stress the idea of asking questions and also asking the type of questions that can lead you somewhere new and interesting. I also like the idea of having some type of documentation of student thoughts and questions and being able to provide instant feedback, so I still need to play around the best way to do that. I know this might not sound idyllic, but having this type of instant feedback is another thing that administrators love to see. Ideally, I wish I could just shut my door and play with code however I want, but this is a reality that teachers have to operate in. Finding ways to show the type of best practices that a principal wants to see also helps to legitimize teaching Sonic Pi in the classroom. So while I will tailor this to my style of teaching music, I am going to remain cognizant of how this can be adapted to fit the “model” methods of pedagogy that we are all held accountable to as professional educators.

Next week, I’m going to have the kids take all the commands we have learned so far and make their first compositions.

Circle of Notes