G-Funk Whistle Synth

Ok. I must admit, I could not stop thinking about this… mainly because I just checked my last code snippet first it does not rearly do what I want it do and secondly and quite franky: it is a mess :wink: I was lucky that it did something meaningful at all.

So here is another attempt to correct myself:

use_bpm 120
use_synth :saw

# score => [note, attack, sustain, release, amp, slide_note, slide_at (0..1)]
define :play_synth do | score |
  score.each do | n |
    
    dur = (n[1] + n[2] + n[3]) # sustain + release
    
    if n[0] != :r # if not a rest
      
      if n[5] == nil # no rest but also no slide_note
        play n[0], attack: n[1], sustain: n[2], release: n[3], amp: n[4]
        sleep dur
        
      else # slide note given
        
        slide_len = dur * n[6].round(2) # time to slide
        slide_at = dur - slide_len # time when to start sliding
        
        s = synth :saw, note: n[0], attack: n[1], sustain: n[2], release: n[3], amp: n[4]
        sleep slide_at # sleep until it's time for sliding
        control s, note: n[5], note_slide: slide_len
        sleep slide_len
      end
    else # just rest
      sleep dur
    end
  end
end

the_score = (ring
             [:c, 0.1, 2, 0.1, 1, :g, 0.5],
             [:g, 0.1, 2, 0.1, 1, nil, nil],
             [:r, 0.1, 2, 0.1],
             [:bb, 0.1, 1, 0.1, 1, :a, 0.75],
             [:a, 0.1, 0.5, 0.1, 1, :c, 0.125]
             )

live_loop :test do
  play_synth the_score
end

I admit, the data to be fed into the function is quite complex but - on the other hand - you thus have a few options to be musically expressive.