Just to tell that the / operator can lead to confusion with kids
We have to convert before as a float.
Yes it’s correct as sonic pi uses ruby language but for kids it can be a bit tricky to explain.
use_midi_defaults port: "microsoft_gs_wavetable_synth_0"
use_bpm 60
# boucles
puts 1/2 # gives 0
puts 1.to_f / 2 # gives 0.5
4.times do
midi :c2,channel: 10
midi :fs2,channel: 10
sleep 0.5
midi :fs2,channel: 10
sleep (1 / 2) # hum 1 divided by 2 equals 0.5 no ? No it returns 0 as an integer
sleep (1.to_f / 2) #
midi :d2,channel: 10
midi :fs2,channel: 10
sleep 0.5
midi :fs2,channel: 10
sleep 0.5
end
midi :cs3,channel: 10
Agreed that it’s confusing. Unfortunately there’s nothing we can do about it unless we create our own fork of Ruby and start making changes. This isn’t something I’m prepared to do.
Very surprised you did no want to fork the ruby language
By the way; it’s a good occasion to explain that in code there are different types of variables right ?