Sha256: 63b1d989d25ec64f7e9e1936f092f4f7fc543147c5b9241128eb4d2ac9ebf575

Contents?: true

Size: 801 Bytes

Versions: 20

Compression:

Stored size: 801 Bytes

Contents

class HeadMusic::Circle
  def self.of_fifths
    get(7)
  end

  def self.of_fourths
    get(5)
  end

  def self.get(interval = 7)
    @circles ||= {}
    @circles[interval.to_i] ||= new(interval)
  end

  attr_reader :interval, :pitch_classes

  def initialize(interval)
    @interval = HeadMusic::Interval.get(interval.to_i)
    @pitch_classes = pitch_classes_by_interval(interval)
  end

  def index(pitch_class)
    @pitch_classes.index(HeadMusic::Spelling.get(pitch_class).pitch_class)
  end

  private_class_method :new

  private

  def pitch_classes_by_interval(interval)
    [HeadMusic::PitchClass.get(0)].tap do |list|
      loop do
        next_pitch_class = list.last + interval
        break if next_pitch_class == list.first
        list << next_pitch_class
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
head_music-0.17.0 lib/head_music/circle.rb
head_music-0.16.2 lib/head_music/circle.rb
head_music-0.16.0 lib/head_music/circle.rb
head_music-0.14.8 lib/head_music/circle.rb
head_music-0.14.7 lib/head_music/circle.rb
head_music-0.14.5 lib/head_music/circle.rb
head_music-0.14.4 lib/head_music/circle.rb
head_music-0.14.2 lib/head_music/circle.rb
head_music-0.14.1 lib/head_music/circle.rb
head_music-0.13.2 lib/head_music/circle.rb
head_music-0.11.9 lib/head_music/circle.rb
head_music-0.11.8 lib/head_music/circle.rb
head_music-0.11.7 lib/head_music/circle.rb
head_music-0.11.6 lib/head_music/circle.rb
head_music-0.11.5 lib/head_music/circle.rb
head_music-0.11.4 lib/head_music/circle.rb
head_music-0.11.3 lib/head_music/circle.rb
head_music-0.11.2 lib/head_music/circle.rb
head_music-0.11.1 lib/head_music/circle.rb
head_music-0.10.0 lib/head_music/circle.rb