class HeadMusic::Circle

A Circle of Fifths or Fourths shows relationships between pitch classes

Public Class Methods

get(interval = :perfect_fifth) click to toggle source
# File lib/head_music/circle.rb, line 15
def self.get(interval = :perfect_fifth)
  @circles ||= {}
  diatonic_interval = HeadMusic::DiatonicInterval.get(interval)
  @circles[interval] ||= new(interval: diatonic_interval, starting_pitch: 'C4')
end
of_fifths() click to toggle source
# File lib/head_music/circle.rb, line 7
def self.of_fifths
  get(:perfect_fifth)
end
of_fourths() click to toggle source
# File lib/head_music/circle.rb, line 11
def self.of_fourths
  get(:perfect_fourth)
end

Public Instance Methods

index(pitch_class) click to toggle source
# File lib/head_music/circle.rb, line 21
def index(pitch_class)
  pitch_classes.index(HeadMusic::Spelling.get(pitch_class).pitch_class)
end
key_signatures_down() click to toggle source
# File lib/head_music/circle.rb, line 31
def key_signatures_down
  spellings_down.map { |spelling| HeadMusic::KeySignature.new(spelling) }
end
key_signatures_up() click to toggle source
# File lib/head_music/circle.rb, line 27
def key_signatures_up
  spellings_up.map { |spelling| HeadMusic::KeySignature.new(spelling) }
end
pitches_down() click to toggle source
# File lib/head_music/circle.rb, line 39
def pitches_down
  @pitches_down ||= begin
    [starting_pitch].tap do |list|
      loop do
        next_pitch = list.last - interval
        next_pitch += octave while starting_pitch - next_pitch > 12
        break if next_pitch.pitch_class == list.first.pitch_class

        list << next_pitch
      end
    end
  end
end
spellings_down() click to toggle source
# File lib/head_music/circle.rb, line 35
def spellings_down
  pitches_down.map(&:spelling)
end