Chord progression tool

Taking this patch for custom scales, here is the custom chord version for those who want it:

class SonicPi::Chord
  def initialize(tonic, name, num_octaves=1)
    num_octaves = 1 unless num_octaves
    
    if name.is_a?(Array)
      intervals = name
      name = :custom
    else
      name = name.to_sym
      intervals = CHORD_LOOKUP[name]
    end
    
    raise "Unknown chord name: #{name.inspect}" unless intervals
    
    tonic = Note.resolve_midi_note_without_octave(tonic)
    res = []
    
    num_octaves.times do |o|
      intervals.each do |i|
        res << tonic + i + (o * 12)
      end
    end
    
    @name = name
    @tonic = tonic
    @notes = res
    @num_octaves = num_octaves
    super(res)
  end
end
1 Like