Is there a way to calculate logarithms in Sonic Pi? I want to write music in just intonation and I’d rather not have to manually perform the calculations myself each time I enter a note.
try this Ruby function Math.log(n)
EDIT th above gives log base e If you want a differnt base use
Math.log(n,base)
live_loop :test_log_in_ruby do
tick
puts "x=", look, "log(x)=", Math.log(look)
sleep 1
end
Thanks everyone! And I just realised that there’s another way to write just intonation music - play hz_to_midi
.
# c scale ..... a = 440
# 24,27,30,32,36,40,45,48
midinumber=[:r]
for justnumber in 1..96
midinumber[justnumber] = hz_to_midi(justnumber*11)
end
puts midinumber[40]