Sha256: 484f7f1375a53929f76ceb0e3710010ae3abec7e764693af52649048dba9382f

Contents?: true

Size: 704 Bytes

Versions: 1

Compression:

Stored size: 704 Bytes

Contents

# frozen_string_literal: true

module Coltrane
  class DiatonicScale < Scale
    def initialize(tone, major: true)
      @major = major
      tone   = Note[tone]
      notes  = CircleOfFifths.new(tone - (major? ? 0 : 9), 7).notes.sort
      super notes: notes.rotate(notes.index(tone))
    end

    def name
      major? ? 'Major' : 'Natural Minor'
    end

    def relative_minor
      minor? ? self : self.class.new(@tone + 9, major: false)
    end

    def relative_major
      major? ? self : self.class.new(@tone - 9, major: true)
    end

    def relative
      major? ? relative_minor : relative_major
    end

    def major?
      !!@major
    end

    def minor?
      !@major
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
coltrane-2.2.1 lib/coltrane/diatonic_scale.rb