Sonic Pi Coding Class – 002

My little boy, James, has been taking piano lessons for two terms now. Last week, his teacher asked him to do an assignment on a minuet.

James knows I’ve been running a coding group at school with Sonic Pi so he asked his teacher if he could write his minuet in Sonic Pi as part of his work.  It was his first coding in a non block type language like Scratch.  I think he did a super job!  James’ version is on his own web page, here.

I thought it would be a good opportunity for me to have a go too so that I could become more familiar with what I am talking to the children about in the class.  Here’s my version which includes the student and the teachers parts played as a duet.  It took me a couple of hours to figure it all out so it was a good challenge!

Press the play button, below, to see how it turned out.

#
# Petit Minuet
#
# 170704
#
# From page 47 of Piano Adventures by Nancy and Randall Faber
# Lesson Book : Primer Level
#

# I have no idea how I originally came up with this number!
speed_multiplier = 0.5 / 8

q = 4 * speed_multiplier      # Quaver          1/8
c = 8 * speed_multiplier      # Crotchet        1/4
m = 16 * speed_multiplier     # Minim           1/2
md = 24 * speed_multiplier    # Dotted minim
s = 32 * speed_multiplier     # Semibreve       1/1

# Extend the default release time of 1 second to
# give a slightly more pleasant sound
use_synth_defaults attack: 0.0125, release: s * 8

# Student
in_thread do
  use_synth :piano
  
  play_pattern_timed [:c5, :c5, :b4], [c, c, c]
  play_pattern_timed [:c5, :d5], [m, c]
  play_pattern_timed [:e5, :e5, :d5], [c, c, c]
  play_pattern_timed [:e5, :f5], [m, c]
  play_pattern_timed [:g5, :g5, :c5], [c, c, c]
  play_pattern_timed [:b4, :c5], [m, c]
  play_pattern_timed [:f5, :e5, :d5], [c, c, c]
  play_pattern_timed [:c5], [md]
end

# Teacher right hand
in_thread do
  use_synth :piano
  
  # Bar 1
  play_pattern_timed [:e4, :e4, :d4], [c, c, c]
  
  # Bar 2
  play_pattern_timed [:e4, :d4], [m, c]
  
  # Bar 3
  2.times do
    play_chord [:c4, :a3]
    sleep c
  end
  
  play_pattern_timed [:b3], [c]
  
  # Bar 4
  play_pattern_timed [:c4, :f4, :e4, :d4], [c, q, q, c]
  
  # Bar 5
  play_pattern_timed [:e4, :e4, :e4], [c, c, c]
  
  # Bar 6
  play_pattern_timed [:d4, :e4], [m, c]
  
  # Bar 7
  play_chord [:f3, :a3]
  sleep q
  
  play :d4
  sleep q
  
  play_chord [:g3, :c4]
  sleep c
  
  play_pattern_timed [:b3], [c]
  
  # Bar 8
  play_pattern_timed [:c4], [md]
end

# Teacher left hand
in_thread do
  use_synth :piano
  
  # Bar 1
  play_pattern_timed [:c3, :c3, :g3], [c, c, c]
  
  # Bar 2
  play_pattern_timed [:c3, :d3, :e3, :f3, :g3], [q, q, q, q, c]
  
  # Bar 3
  play_pattern_timed [:r, :r, :e3], [c, c, c]
  
  # Bar 4
  play_pattern_timed [:a2, :b2], [m, c]
  
  # Bar 5
  play_pattern_timed [:c3, :r, :c3], [c, c, c]
  
  # Bar 6
  play_pattern_timed [:g2, :b2, :c3], [c, c, c]
  
  # Bar 7
  play_pattern_timed [:r, :r, :g2], [c, c, c]
  
  # Bar 8
  play_pattern_timed [:c3, :g2, :c2], [c, c, c]
end

One thought on “Sonic Pi Coding Class – 002”

Leave a Reply

Your email address will not be published. Required fields are marked *