Which function is better + amp, release question

New to Sonic-Pi. To learn basic syntax, I’m taking a piece of piano music I know how to play and converting it to code. Say I’m writing a function that represents a bar of music. Admittedly a lot of redundancy in the function below, but this arrangement is readable (at least to me) and it allows me to style specific notes, adding amp and release in certain places, but not others.

define :intro do
  play [:d3, :a3, :f4], amp: 7
  sleep 0.2
  play [:f3, :d4], amp: 5
  sleep 0.2
  play [:a3, :f4], amp: 5
  sleep 0.2
  play [:f3, :d5], amp: 7, release: 2
  sleep 0.2
  play [:a3, :f4], amp: 5
  sleep 0.2
  play [:f3, :d4], amp: 5
  sleep 0.2
end

I could write the same basic function more concisely using variables and play_pattern_timed, as in:

define :intro do
  notes = [[:d3, :a3, :f4],[:f3, :d4],[:a3, :f4],[:f3, :d5],[:a3, :f4],[:f3, :d4]]
  duration = 0.2
  play_pattern_timed notes, duration
end

My questions: 1) is the more concise function necessarily better? and 2) if I went with the second more concise function, how I can use amp and release to style individual notes contained within the notes variable?

Thanks from a nOOb :slight_smile:

Well I can think of a bunch of ways… but to do it to individual notes,
you’d probably have to change the play_pattern_timed…

Here’s a couple of options if you decided to keep it…

Eli…

notes = [[:d3, :a3, :f4],[:f3, :d4],[:a3, :f4],[:f3, :d5],[:a3, :f4],[:f3, :d4]]
amps = [0.25, 1, 0.5,1, 0.5,0.25, 3,1, 0.25,1, 3,0.25, 0.5].ring
use_synth :hollow


comment do
  
  live_loop :intro do
    duration = 0.1
    play_pattern_timed notes, duration, release: [0.5,1,0.25].choose, amp: [0.5,1].choose
  end
  
end

uncomment do
  
  live_loop :intro1 do
    duration = 0.1
    play_pattern_timed notes, duration, release: [0.5,1,0.25].choose, amp: amps.tick
    
  end

end