Class: HeadMusic::IntervalCycle
- Inherits:
-
Object
- Object
- HeadMusic::IntervalCycle
- 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
Instance Attribute Summary collapse
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#starting_pitch ⇒ Object
readonly
Returns the value of attribute starting_pitch.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(interval:, starting_pitch: "C4") ⇒ IntervalCycle
constructor
A new instance of IntervalCycle.
- #pitch_class_set ⇒ Object
- #pitch_classes ⇒ Object
- #pitches ⇒ Object
- #spellings ⇒ Object
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
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
3 4 5 |
# File 'lib/head_music/interval_cycle.rb', line 3 def interval @interval end |
#starting_pitch ⇒ Object (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_set ⇒ Object
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_classes ⇒ Object
24 25 26 |
# File 'lib/head_music/interval_cycle.rb', line 24 def pitch_classes @pitch_classes ||= pitches.map(&:pitch_class) end |
#pitches ⇒ Object
20 21 22 |
# File 'lib/head_music/interval_cycle.rb', line 20 def pitches @pitches ||= pitches_up end |
#spellings ⇒ Object
32 33 34 |
# File 'lib/head_music/interval_cycle.rb', line 32 def spellings @spellings ||= pitches.map(&:spelling) end |