Class: HeadMusic::Analysis::IntervalCycle

Inherits:
Object
  • Object
show all
Defined in:
lib/head_music/analysis/interval_cycle.rb

Overview

An Interval Cycle is a collection of pitch classes created from a sequence of the same interval class.

Direct Known Subclasses

Circle

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interval:, starting_pitch: "C4") ⇒ IntervalCycle

Returns a new instance of IntervalCycle.



15
16
17
18
19
20
21
# File 'lib/head_music/analysis/interval_cycle.rb', line 15

def initialize(interval:, starting_pitch: "C4")
  @interval = interval if interval.is_a?(HeadMusic::Analysis::DiatonicInterval)
  @interval ||= interval if interval.is_a?(HeadMusic::Rudiment::ChromaticInterval)
  @interval ||= HeadMusic::Rudiment::ChromaticInterval.get(interval) if interval.to_s.match?(/\d/)
  @interval ||= HeadMusic::Analysis::DiatonicInterval.get(interval)
  @starting_pitch = HeadMusic::Rudiment::Pitch.get(starting_pitch)
end

Instance Attribute Details

#intervalObject (readonly)

Returns the value of attribute interval.



6
7
8
# File 'lib/head_music/analysis/interval_cycle.rb', line 6

def interval
  @interval
end

#starting_pitchObject (readonly)

Returns the value of attribute starting_pitch.



6
7
8
# File 'lib/head_music/analysis/interval_cycle.rb', line 6

def starting_pitch
  @starting_pitch
end

Class Method Details

.get(interval = 7) ⇒ Object



8
9
10
11
12
13
# File 'lib/head_music/analysis/interval_cycle.rb', line 8

def self.get(interval = 7)
  @interval_cycles ||= {}
  interval = interval.to_s.gsub(/^C/i, "").to_i
  interval = HeadMusic::Rudiment::ChromaticInterval.get(interval)
  @interval_cycles[interval.to_i] ||= new(interval: interval, starting_pitch: "C4")
end

Instance Method Details

#octaveObject (protected)



53
54
55
# File 'lib/head_music/analysis/interval_cycle.rb', line 53

def octave
  @octave ||= HeadMusic::Analysis::DiatonicInterval.get(:perfect_octave)
end

#pitch_class_setObject



31
32
33
# File 'lib/head_music/analysis/interval_cycle.rb', line 31

def pitch_class_set
  @pitch_class_set ||= HeadMusic::Analysis::PitchClassSet.new(pitches)
end

#pitch_classesObject



27
28
29
# File 'lib/head_music/analysis/interval_cycle.rb', line 27

def pitch_classes
  @pitch_classes ||= pitches.map(&:pitch_class)
end

#pitchesObject



23
24
25
# File 'lib/head_music/analysis/interval_cycle.rb', line 23

def pitches
  @pitches ||= pitches_up
end

#pitches_upObject (protected)



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/head_music/analysis/interval_cycle.rb', line 41

def pitches_up
  @pitches_up ||= [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

#spellingsObject



35
36
37
# File 'lib/head_music/analysis/interval_cycle.rb', line 35

def spellings
  @spellings ||= pitches.map(&:spelling)
end