Piano voice for Sonic Pi using Logic Pro samples

Elsewhere I have been asked about accessing Logic Pro samples (on a Mac) for use in Sonic Pi.
Having played with this I experimented with producing a sample voice for Sonic Pi using the Yamaha Grand Piano samples.
A first attempt at this is shown below. The relevant folder contains samples for hard, medium and soft struck piano keys together with some pad samples. Here I am utilising the Hard and Medium samples which cover the same notes. I retrieved samples, and then analaysed which ones were present pad produce an array (indexed by midi number) with values for the sample number wirthin the folder and the rpitch offset to apply.
The result is shown below.

#Sonic Pi Piano voice using Logic Pro Yamaha Piano Samples
#requires Logic Pro on a Mac

#path to sample folder
path= "/Library/Application Support/Logic/EXS Factory Samples/01 Acoustic Pianos/Yamaha Grand Piano/"
#two sample ranges for H "hard hit" or M "medium hit" samples
sph= sample_paths path,"56_H" #picks out all the Hard samples
spm=sample_paths path,"56_M" #picks out all the Medium samples

#nlookup holds a list of the sample numbers for each midi note from 0 to 108
#together with the rpitch value to use (-1,0 or 1) for each note.
#the first 20 values are blank and not playable
nlookup=[[nil,nil], [nil,nil], [nil,nil], [nil,nil], [nil,nil],
         [nil,nil], [nil,nil], [nil,nil], [nil,nil], [nil,nil],
         [nil,nil], [nil,nil], [nil,nil], [nil,nil], [nil,nil],
         [nil,nil], [nil,nil], [nil,nil], [nil,nil], [nil,nil],
         [nil,nil], [0,0], [0,1], [0,2], [1,-1], [1,0], [2,0],
         [3,0], [4,0], [5,0], [6,0], [6,1], [7,0], [8,0], [9,0],
         [9,1], [10,0], [11,0], [11,1], [12,0], [13,0], [14,0],
         [14,1], [15,0], [16,0], [16,1], [17,0], [18,0], [19,0],
         [20,0], [20,1], [21,0], [22,0], [23,0], [23,1], [24,0],
         [25,0], [26,0], [26,1], [27,0], [27,1], [28,0], [28,1],
         [29,0], [29,1], [30,-1], [30,0], [31,0], [31,1], [32,0],
         [32,1], [33,0], [33,1], [34,0], [35,0], [36,0], [37,0],
         [37,1], [38,0], [39,0], [40,0], [40,1], [41,0], [42,0],
         [43,0], [44,0], [44,1], [45,0], [46,0], [47,0], [47,1],
         [48,0], [49,0], [50,0], [51,0], [51,1], [52,0], [53,0],
         [54,0], [54,1], [55,0], [55,1], [56,0], [57,0], [58,0],
         [59,0], [60,0], [61,0], [62,0]]

#pl works out which sample to play and uses supplied values for the sustain and release
#there are two useable banks of sample H or hard and M or medium
#a third range S for soft are NOT included as the range of samples is different
define :pl do |n,s=0.1,r=0.5,v="h"|
  nv=note(n)
  if nv>20 and nv<109 #allow valid notes only
    if v=="h"
      sample sph[nlookup[nv][0]],rpitch: nlookup[nv][1],sustain: s,release: r
    else
      sample spm[nlookup[nv][0]],rpitch: nlookup[nv][1],sustain: s,release: r
    end
  end
end
#This live loop plays a 7 octave chromatic scale of the samples selected ("m" or "h")
live_loop :test do
  pl scale(:c1,:chromatic,num_octaves: 7).tick,0.4,0.5,"m"
  sleep 0.4
end
1 Like