lib/head_music/circle.rb in head_music-0.23.1 vs lib/head_music/circle.rb in head_music-0.23.2
- old
+ new
@@ -1,11 +1,11 @@
# frozen_string_literal: true
+require 'head_music/interval_cycle'
+
# A Circle of Fifths or Fourths shows relationships between pitch classes
-# TODO: Replace or empower with IntervalCycle (?)
-# https://en.wikipedia.org/wiki/Interval_cycle
-class HeadMusic::Circle
+class HeadMusic::Circle < HeadMusic::IntervalCycle
def self.of_fifths
get(7)
end
def self.of_fourths
@@ -17,10 +17,11 @@
@circles[interval.to_i] ||= new(interval)
end
attr_reader :interval, :pitch_classes
+ # Accepts an interval (as an integer number of semitones)
def initialize(interval)
@interval = interval.to_i
@pitch_classes = pitch_classes_by_interval
end
@@ -30,16 +31,13 @@
private_class_method :new
private
- def pitch_classes_by_interval
- [HeadMusic::PitchClass.get(0)].tap do |list|
- loop do
- next_pitch_class = list.last + interval
- break if next_pitch_class == list.first
+ def interval_cycle
+ @interval_cycle ||= HeadMusic::IntervalCycle.get(interval)
+ end
- list << next_pitch_class
- end
- end
+ def pitch_classes_by_interval
+ interval_cycle.send(:pitch_classes_by_interval)
end
end