Help with melodic basslines?

Hi! I’m new to this, I’m starting to program music with Sonic Pi, and I’m having a lot of fun! I have a few questions, if anyone here knows the software, I need some help with something.

I’m trying to create a bassline that follows the note of the chord that’s currently playing. I’d like to do this without having to write each note individually. I know there has to be a much simpler way.

I’ve attached a screenshot so you can see how the code is written for now.

I initially thought I could do it with “if” statements, but I couldn’t find a way to program it correctly. Any ideas? Thanks!

Hi

Welcome to Sonic Pi! Because a chord is a ring array, we can target individual chord tones by index (to derive a bassline from a given chord); 0 = root, 1 = 3rd, 2 = 5th etc:

live_loop :tonic do
  play chord(:e, :minor)[0], release: 0.1
  sleep 0.5
end

HTH

PD-Pi

For example

triads = [":e3"]

use_synth :fm
live_loop :chord do
  tick
  play chord(triads[0], :minor)+12
  sleep 2
end


use_synth :bass_foundation
live_loop :root do
  tick
    play chord(triads[0], :minor)[[0,1,2].look], release: 0.1
  sleep 0.5
end