Thank you for the assistance, d0lfyn. I was able to accomplish what I wanted.
I was using play_pattern_timed to play the song, so after connecting to Sforzando as you described, I created a custom method.
define :play_pattern_timed_midi do |notes, times, **args|
if is_list_like?(times)
t = times.ring
notes.each_with_index do |note, idx|
kwargs = if args.last.is_a?(Hash) then args.last else {} end
duration = t[idx]
kwargs[:duration] = duration
midi(note, *[kwargs])
#play(note, *[kwargs])
sleep(duration)
end
else
play_pattern_timed_midi(notes, [times], *args)
end
I encountered an error though: undefined method `last’ for {}:Hash
I’m not sure why I got this error. Maybe the version of Sonic Pi I’m using?
In any case, I replaced that line with
kwargs = if args.values.last.is_a?(Hash) then args.values.last else {} end
After that, the song played, but it didn’t sound good. I realized that when the duration is passed into play, the sustain is affected. This, however, does not happen when duration is passed into midi.
So I replaced the midi line with
midi note, sustain: duration
The song still didn’t sound quite right though. Next, I learned that for play the sustain and release of a note are affected by the bpm. This might have been obvious to most, but as I said, I’m new to music. For that, I added the following
multiplier = 60 / current_bpm
midi note, sustain: duration * multiplier
I’m not sure if the release is being altered as well, but now the song sounds like it should.