Skip to content

Instantly share code, notes, and snippets.

@mrjoshida
Created January 3, 2021 21:20
Show Gist options
  • Save mrjoshida/72fbc7c039da3fc91b7bca42fa398e71 to your computer and use it in GitHub Desktop.
Save mrjoshida/72fbc7c039da3fc91b7bca42fa398e71 to your computer and use it in GitHub Desktop.
Exemplar code for the Chapter 3 project Scales and Intervals in the book Coding and the Arts (creativecodingbook.com). Paste into Sonic Pi to run.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment