# Lesson 14 # Scales Lesson. In this lesson, # you will use programming features # to create and manipulate major and # minor scales. # General Instructions: # # This lesson contains two examples and # two exercises (A, B). # # To listen to an example, change "comment" # to "uncomment" on the "comment do" line, # then click the "Run" menu command at the # top of the Sonic Pi editor window. # When you are done with the example, turn # it off by changing "uncomment" back to # "comment," and move on to the next section # of the lesson. # # Normally, Sonic Pi runs lines and blocks of # code one after the other in sequence. # However, in music we often want to play # several different things at the same time. # Threads allow us to do this. Creating a # thread allows the code within the thread to # start at exactly the same time as any code # follows. # Example 1: Major scales using threads. comment do use_bpm 100 use_synth :piano # C Major Scale scale_ring = (ring :C4, :D4, :E4, :F4, :G4, :A4, :B4, :C5) index = 0 #create a metronome in 4/4 in_thread do loop do 2.times do sample :drum_heavy_kick sleep 1 sample :perc_snap sleep 1 end end end in_thread do loop do note = scale_ring[index] play note sleep 0.5 index += 1 end end use_synth :dsaw new_index = 7 loop do note = scale_ring[new_index] play note sleep 0.5 new_index -= 1 end end # Exercise A # 1) Change the C Major scale in scale_ring # (Example 1) to: # a) G major # b) D major # c) A major # d) E major # e) F major # f) Bb major # g) Eb major # h) Ab major # 2) Change the second scale-playing loop # (after the second thread) to: # a) play the same scale in the same direction # as in the seconds thread, but a 3rd higher. # b) play the same scale in the same direction # as in the second thread, but a 6th lower. # Example 2: Minor scales using threads. comment do use_bpm 100 use_synth :piano # C natural minor scale scale_ring = (ring :C4, :D4, :Eb4, :F4, :G4, :Ab4, :Bb4, :C5) index = 0 #create a metronome in 4/4 in_thread do loop do 2.times do sample :drum_heavy_kick sleep 1 sample :perc_snap sleep 1 end end end loop do note = scale_ring[index] play note sleep 0.5 index += 1 end end # Exercise B # 1) Change the minor scale form in the # loop that plays after the first thread # (Example 2) in the following way: # a) Create harmonic minor ascending by # using an if conditional on the index # of the note to be played, and change the # note accordingly. # TIP: evaluate the index by using the # the modulo operator % # (index-target) % length = 0 # where index is the current index, # target is the index of the note to # change, and length is the total # number of notes in the ring. # The modulo operator gives the # remainder of the division of # the first term by the second term. # Examples of % operator: # 3 % 2 = 1 # 3 % 3 = 0 # 5 % 3 = 2 # 6 % 3 = 0 # Examples of (index-target) % length = 0 # length = 8 # target = 4 # index = 4, (4 - 4) % 8 = 0 # index = 12, (12 - 4) % 8 = 0 # index = 20, (20 - 4) % 8 = 0 # Note that index = 4 will not give you the # harmonic minor scale! You will need to use # the correct index.