Ways to play a chord progression, some ideas?

Hi again :

One of the nasty things of not being a programmer,

is that everything seems right,but usually doesn’t work,

and we don’t know why.

I was trying to pass a simple chord progression through

Sonic Pi. Seems that would work perfectly well, but… it didn’t.

Here is the code that i was trying to run :

# Playing a Chord Progression

# Note Durations

w = 4
h = 2
q = 1
e = 0.5
s = 0.25
r = 0.25

use_synth :tri
use_synth_defaults attack: 0.05, sustain: 0.5, release: 0.75,
  cutoff: 80,amp: 0.5
use_octave 1

chords = [
  (chord_degree :i,:A3,:minor,3),(chord_invert (:G3,:major),1),
  (chord_degree :iv,:D4,:minor,4],(chord_degree :i,:A3,:minor),
   ]
   
   dur =   (knit w,4)
   
   live_loop :chords do
     use_bpm 100
     chords.each do |c|
       play c.tick(:cho)
       sleep dur.tick(:dur)
     end
   end

Where is the mistake ?

Also,if there’s better or simplest ways to do it,

please,let me know.

Thank you in advance !!

Hi @GWB70.

It was pretty close. You’ll notice there’s a square bracket that should be a round bracket in the chords array.
Also, the parameters for the chord_invert fn were not quite right. Lastly, if your intention is to play the chords as actual chords instead of each individual note, the tick(:cho) was unnecessary - the .each already steps through the list of chords.

As for optimisation, others may have different ideas, but here’s my two cents:
I have used chords.tick(:cho) instead of chords.each since this is more idiomatic Sonic Pi syntax (though by no means is it absolutely necessary). However, in order to make chords.tick(:cho) work properly, we then need to make chords a ring, instead of an array, as ticking past the end of an array will return nil, whereas ticking past the end of a ring will loop back to its beginning (assuming that’s what we want).

# Playing a Chord Progression

# Note Durations

w = 4
h = 2
q = 1
e = 0.5
s = 0.25
r = 0.25

use_synth :tri
use_synth_defaults attack: 0.05, sustain: 0.5, release: 0.75,
  cutoff: 80,amp: 0.5
use_octave 1

chords = (ring
          (chord_degree :i,:A3,:minor,3),(chord_invert (chord :G3,:major),1),
          (chord_degree :iv,:D4,:minor,4),(chord_degree :i,:A3,:minor),
          )

dur =   (knit w,4)

live_loop :chords do
  use_bpm 100
  play chords.tick(:cho)
  sleep dur.tick(:dur)
end
1 Like

Hi GWB,

EDIT: Scratch my answer. Ethan got there first :slight_smile:

The problem was with line 18, the chord = line…

I’m afraid I’m no expert on playing chords… someone
else will have to point out better methods.

Eli…

chords = [
  (chord_degree :i,:A3,:minor,3),
  (chord_invert (chord :G3,:major),1),
  (chord_degree :iv,:D4,:minor,4),
  (chord_degree :i,:A3,:minor)
]

Hi Ethan :

Thank you for clarify things to me,

especially your technical explanation is quite valuable to me.

Thanks to the help of this forum, i started almost from zero,

and now am close to achieve something, that is :

Use Sonic Pi as compositional aid tool.

All the best !:slightly_smiling_face:

Hi Eli :

All help is always valuable,we can learn

the same thing in several ways.

Yours also played,but needs to be passed through a ring,

as explained above.Thank you for your help,again.

Have a nice week.:slightly_smiling_face:

My answers often get delayed, because I can’t resist
playing around with the code people ask questions about…

Eli…