Class: HeadMusic::IntervalCycle

Inherits:
Object
  • Object
show all
Defined in:
lib/head_music/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.



14
15
16
17
18
19
20
# 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

Instance Attribute Details

#intervalObject (readonly)

Returns the value of attribute interval.



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

def interval
  @interval
end

#starting_pitchObject (readonly)

Returns the value of attribute starting_pitch.



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

def starting_pitch
  @starting_pitch
end

Class Method Details

.get(interval = 7) ⇒ Object



7
8
9
10
11
12
# 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

Instance Method Details

#pitch_class_setObject



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

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

#pitch_classesObject



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

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

#pitchesObject



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

def pitches
  @pitches ||= pitches_up
end

#spellingsObject



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

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