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.



12
13
14
15
16
17
18
# File 'lib/head_music/interval_cycle.rb', line 12

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.



3
4
5
# File 'lib/head_music/interval_cycle.rb', line 3

def interval
  @interval
end

#starting_pitchObject (readonly)

Returns the value of attribute starting_pitch.



3
4
5
# File 'lib/head_music/interval_cycle.rb', line 3

def starting_pitch
  @starting_pitch
end

Class Method Details

.get(interval = 7) ⇒ Object



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

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



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

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

#pitch_classesObject



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

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

#pitchesObject



20
21
22
# File 'lib/head_music/interval_cycle.rb', line 20

def pitches
  @pitches ||= pitches_up
end

#spellingsObject



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

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