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.
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
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
5 6 7 |
# File 'lib/head_music/interval_cycle.rb', line 5 def interval @interval end |
#starting_pitch ⇒ Object (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_set ⇒ Object
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_classes ⇒ Object
26 27 28 |
# File 'lib/head_music/interval_cycle.rb', line 26 def pitch_classes @pitch_classes ||= pitches.map(&:pitch_class) end |
#pitches ⇒ Object
22 23 24 |
# File 'lib/head_music/interval_cycle.rb', line 22 def pitches @pitches ||= pitches_up end |
#spellings ⇒ Object
34 35 36 |
# File 'lib/head_music/interval_cycle.rb', line 34 def spellings @spellings ||= pitches.map(&:spelling) end |