Scales and Intervals


This project is featured in chapter 3 of Coding and the Arts.

Starter Project

As long as students know how to define and modify variables in Ruby or Sonic Pi there’s no need for a starter project here. The following starter is a useful demonstration of variable definition, modification, and the first few steps of a scale.

use_bpm 120
current_note = 60
play(current_note)
sleep(1)
current_note = current_note + 2
play(current_note)
sleep(1)
current_note = current_note + 2
play(current_note)
sleep(1)
current_note = current_note + 1
play(current_note)
sleep(1)
# Continue the pattern to finish a C Major scale

Open in Github

Exemplar Project

This exemplar shows two different ways to apply intervals to create a scale. The first simply finishes the sequence in the starter code, but the second is a more elegant and concise solution that places the intervals in a list and then iterates over it with a loop. These are but two of many ways that your students might use intervals to play a scale.

use_bpm 120
current_note = 60
play(current_note)
sleep(1)
# C Major scale using single variable
current_note = current_note + 2
play(current_note)
sleep(1)
current_note = current_note + 2
play(current_note)
sleep(1)
current_note = current_note + 1
play(current_note)
sleep(1)
current_note = current_note + 2
play(current_note)
sleep(1)
current_note = current_note + 2
play(current_note)
sleep(1)
current_note = current_note + 2
play(current_note)
sleep(1)
current_note = current_note + 1
play(current_note)
sleep(1)
# Minor scale using a list of intervals and a loop
intervals = [0, 2, 1, 2, 2, 1, 2, 2]
8.times do |index|
current_note = current_note + intervals[index]
play(current_note)
sleep(1)
end

Open in Github

See Also