class HeadMusic::IntervalCycle
An Interval Cycle is a collection of pitch classes created from a sequence of the same interval class.
Attributes
interval[R]
starting_pitch[R]
Public Class Methods
get(interval = 7)
click to toggle source
# File lib/head_music/interval_cycle.rb, line 7 def self.get(interval = 7) @interval_cycles ||= {} interval = interval.to_s.gsub(/^C/i, '').to_i interval = HeadMusic::ChromaticInterval.get(interval) @interval_cycles[interval.to_i] ||= new(interval: interval, starting_pitch: 'C4') end
new(interval:, starting_pitch: 'C4')
click to toggle source
# File lib/head_music/interval_cycle.rb, line 14 def initialize(interval:, starting_pitch: 'C4') @interval = interval if interval.is_a?(HeadMusic::DiatonicInterval) @interval ||= interval if interval.is_a?(HeadMusic::ChromaticInterval) @interval ||= HeadMusic::ChromaticInterval.get(interval) if interval.to_s.match?(/\d/) @interval ||= HeadMusic::DiatonicInterval.get(interval) @starting_pitch = HeadMusic::Pitch.get(starting_pitch) end
Public Instance Methods
pitch_class_set()
click to toggle source
# File lib/head_music/interval_cycle.rb, line 30 def pitch_class_set @pitch_class_set ||= HeadMusic::PitchClassSet.new(pitches) end
pitch_classes()
click to toggle source
# File lib/head_music/interval_cycle.rb, line 26 def pitch_classes @pitch_classes ||= pitches.map(&:pitch_class) end
pitches()
click to toggle source
# File lib/head_music/interval_cycle.rb, line 22 def pitches @pitches ||= pitches_up end
spellings()
click to toggle source
# File lib/head_music/interval_cycle.rb, line 34 def spellings @spellings ||= pitches.map(&:spelling) end
Protected Instance Methods
octave()
click to toggle source
# File lib/head_music/interval_cycle.rb, line 54 def octave @octave ||= HeadMusic::DiatonicInterval.get(:perfect_octave) end
pitches_up()
click to toggle source
# File lib/head_music/interval_cycle.rb, line 40 def pitches_up @pitches_up ||= begin [starting_pitch].tap do |list| loop do next_pitch = list.last + interval next_pitch -= octave while next_pitch - starting_pitch > 12 break if next_pitch.pitch_class == list.first.pitch_class list << next_pitch end end end end