Playing piano on the pi


Hi there,

I’m currently programming piano sheet music in sonic pi. I need to overcome 2 problems with that.

The first problem is that i need to work 2 lines of music at the same time. one for the left hand and one for the right.

The second problem i have is that i need to play 2 noted in the same time.

Has anyone a idea how to solve the problem?


Here is one solution which I have uswed in the past.
Play each part in a thread and they play together. Chords can be played by sending two notes (or mote) at a time to the play function as a list eg [:g2,:g3]
Each part has a list of notes and correspending durations sent to a play command in a for loop. Normally I use separate sustain and release settings, but in this case, using a percussive synth like :piano, it is best to leave the default release time.

#Bach Chorale Piano
with_fx :reverb,room: 0.5 do
  use_synth :piano
  use_bpm 80
  in_thread do
    for j in 0..a1.length-1
      play a1[j],sustain: b1[j]#,release: b1[j]*0.1
      sleep b1[j]
  in_thread do
    for j in 0..a2.length-1
      play a2[j],sustain: b2[j]*0.9#,release: b2[j]*0.1
      sleep b2[j]


is there another solution? i programmed it in Play_pattern_timed compartmentalised it in rows of 10 (4 nodes in a block). it giving me trouble converting. with 3 pages of music it will be a really long line


Well you have to get the note information typed in somehow. If you have midi parts avialable I have used a script to convert these to Sonic Pi format. There are some constraints, and you may have to split some parts into two using MuseScore2 but I have done some extensive pieces using it see