Playing piano on the pi


#1

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?


#2

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
  
  a1=[]
  b1=[]
  a1=[[:Bf3,:D4],[:C4,:G4],[:C4,:A4],[:D4,:Bf4],[:Ef4,:C5],[:D4,:A4],[:D4,:Fs4],[:C4,:Fs4],[:Bf3,:G4],[:D4,:G4],[:Ef4,:A4],[:D4,:A4],[:Bf3,:D4],[:Ef4,:D5],[:A4,:C5],[:D4,:Bf4],[:Ef4,:Bf4],[:C4,:A4],[:D4,:Bf4],[:D4,:A4],[:D4,:Bf4],[:F4,:C5],[:Bf4,:D5],[:Bf4,:D5],[:F4,:C5],[:F4,:A4],[:Ef4,:A4],[:D4,:A4,:Bf4],[:C4,:Ef4,:A4],[:D4,:G4],[:Ef4,:G4],[:Ef4,:A4],[:D4,:F4],[:Ef4,:G4],[:F4,:A4],[:D4,:G4],[:D4,:F4],[:Ef4,:G4],[:C4,:Ef4],[:Bf3,:D4],[:C4,:Ef4],[:D4,:F4],[:Ef4,:G4],[:Ef4,:G4],[:D4,:G4],[:D4,:Fs4],[:D4,:G4]]
  b1=[1.0,1.0,1.0,1.0,1.0,2.0,1.0,1.0,1.0,1.0,1.0,1.0,3.0,1.0,1.0,1.0,1.0,1.0,3.0,1.0,1.0,1.0,1.0,1.0,2.0,1.0,1.0,1.0,1.0,1.0,0.25,0.25,0.25,0.25,1.0,1.0,0.5,0.5,1.0,0.25,0.25,0.25,0.25,1.0,1.0,1.0,4.0]
  
  in_thread do
    for j in 0..a1.length-1
      play a1[j],sustain: b1[j]#,release: b1[j]*0.1
      sleep b1[j]
    end
  end
  
 a2=[[:G2,:G3],[:Ef2,:G3],[:D2,:Fs3],[:G2,:G3],[:C3,:G3],[:D3,:Fs3],[:D3,:A3],[:Gf3,:A3],[:Ef3,:Bf3],[:Ef2,:Bf3],[:A2,:C4],[:D3,:C4],[:G2,:G3],[:Bf2,:F3],[:A2,:Ef3],[:G2,:G3],[:Ef2,:G3],[:F2,:F3],[:G2,:D3],[:Fs2,:D3],[:Ef2,:G3],[:F2,:A3],[:F2,:Bf3],[:Bf2,:Bf3],[:F2,:A3],[:F2,:C4],[:A2,:C4],[:Bf2,:F3],[:G2,:G3],[:A2,:A3],[:G2,:Bf3],[:Ef3,:Bf3,:C4],[:F2,:F3,:C4],[:G2,:Bf2,:C4],[:F2,:Bf3],[:Ef2,:A3],[:F2,:A3],[:G2,:G3],[:C3,:G3],[:G2,:A3],[:G2,:Bf3],[:D3,:A3],[:G2,:Bf3]]
  b2=[1.0,1.0,1.0,1.0,1.0,2.0,1.0,1.0,1.0,1.0,1.0,1.0,3.0,1.0,1.0,1.0,1.0,1.0,3.0,1.0,1.0,1.0,1.0,1.0,2.0,1.0,1.0,0.5,0.5,1.0,1.0,1.0,1.0,0.5,0.5,1.0,1.0,1.0,0.5,0.5,1.0,1.0,4.0]
  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]
    end
  end
  
end


#3

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


#4

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