Play piano whit sonic pi. Thanks

hello I´m Víctor. I want to play whit Sonic pi songs like piano. two notes same time (left hand and rigth hand), please see this video.

how I can do that?

Hi Victor
This is possible in Sonic Pi, but it would take you some time to complete. First you ought to consider copyright. The music for this song is for sale (I think the link in below the youtube video takes you to a site where it is for sale for $4.99). If you purchase and transfer the song to Sonic Pi then strictly it should not be made publically available.

In principle to play music such as this on Sonic Pi the key is to have several lists of notes and their durations, which can then be played at the same time, by playing each one in a separate thread. If I were you and you have never done this before I would start with a simpler song, with a simpler rhythm. It is possible for a single part to contain chords, provided that each note in the chord lasts for the same time. So in this case the first two bars could be played with two parallel lists of notes, one for the right hand and the other for the left.
I assume you can read music, because otherwise you will find it very difficult to do.

the notes for the right hand would be:

[ [:d4,:f4,:a4], [:c4,:f4,:a4],:e4,:d4,[:a4,:cs4] ]
You can see there are 4 sections. The initial chord of three notes, which lasts for 1.5 crotchet beats, then a second tied chord of three notes which lasts for 2.5 crotchet beats, then a single ‘e’ which lasts for 0.75 crotchets follewed by a single tied ‘d’ which lasts for 0.75 crotchets and finally a two note chord which lasts for 2.5 crotchets
The corresponding duration iist is therefore:

In the left hand we just have single notes and the list is:
The corresponding durations are:

The other thing we need to know are the tempo, ie how many crotchets/minute are to be played. It sounds on the video to be about 80 crotchets a minute which we set with use_bpm 80. We also specify the instrument, and will use the piano synth.
Putting this all together we get this (I’ve also added the notes for bars 3 and 4 from the video:

#beginning of Buena Vista Social Club - Chan Chan on Sonic Pi
use_bpm 80 #the tempo in beats (crotchets)/minute
use_synth :piano
rh_notes=[ [:d4,:f4,:a4], [:c4,:f4,:a4],:e4,:d4,[:a4,:cs4] ]
rh_notes += [:d4,[:a3,:c4,:f4],:a4,:f4,:c4,:d4,:e4,:d4,[:a4,:cs4]] #I've added bars 2 and 3 notes
rh_durations= [1.5,2.5,0.75,0.75,2.5] #durations in crotchet lengths
rh_durations+=[1.5,1.5,0.25,0.25,0.25,0.25,0.75,0.75,1.5] #I've added bars 2 and 3 durations
lh_notes = [:d2,:f2,:d3,:d3,:g2,:a2,:a1,:a1]
lh_notes+=[:d2,:f2,:d3,:d3,:g2,:a2,:a2,:g2,:f2,:e2] #bars 2 and 3
lh_durations = [1.5,1.5,0.5,0.5,1.5,1.5,0.5,0.5] #durations in crotchet lengths
lh_durations += [1.5,1.5,0.5,0.5,1.5,1.5,0.25,0.25,0.25,0.25] #bars 2 and 3

#to play the notes we set up two threads, and use the tick function
#because the piano is a percussive instrument we don't need to apply any release: values

with_fx :reverb do #apply some reverb to make it sound more interesting
  in_thread do #play right hand
    #look at the length (ie number of notes in rh) and loop that number of times
    rh_notes.length.times do
      #use tick to select the next note each time we go through the loop
      play rh_notes.tick,sustain: rh_durations.look
      sleep rh_durations.look #look has same value as tick and so selects the corresponding duration
  in_thread do #play left hand
    lh_notes.length.times do
      play lh_notes.tick,sustain: lh_durations.look
      sleep lh_durations.look

This sounds reasonably like the piano in the video.

I have done a lot of transcriptions like this for Sonic Pi, although I usually stick to early Classical Music which is out of copyright! Sometimes, as here, I do it by hand, but if a midi file is available I often put this into muse score (on a Mac or Windows PI), and convert the parts to single notes at a time for each part (by creating extra parts). I then use a processing script to convert the midi to Sonic Pi notation as per three articles I wrote on the subject,
I hope you manage to get things going. Let us know how you get on. have fun working out the triplet note lengths in bar 5!


Hello, Thanks… thanks a lof … frieds