generate a sonic pi code for a piano chords as a melody
- User
generate a sonic pi code for a piano chords as a melody
- Assistant
Certainly! Here's an example of Sonic Pi code to generate a melody using piano chords:
rubyuse_bpm 120 # Define the chords chords = [(chord :c, :major), (chord :f, :major), (chord :g, :major), (chord :a, :minor)] # Define the rhythm rhythm = [0.5, 0.5, 1, 1] # (change the rhythm array length as per the number of chords) # Play the melody live_loop :piano_melody do index = tick % chords.length # Play the chord play_chord chords[index], sustain: rhythm[index] # Play the individual notes in the chord chords[index].each do |note| play note - 12, release: rhythm[index] # shift the notes down an octave sleep rhythm[index] end end