Class: HeadMusic::Motion
- Inherits:
-
Object
- Object
- HeadMusic::Motion
- Defined in:
- lib/head_music/motion.rb
Overview
Motion defines the relative pitch direction of the upper and lower voices of subsequence intervals.
Instance Attribute Summary collapse
-
#first_harmonic_interval ⇒ Object
readonly
Returns the value of attribute first_harmonic_interval.
-
#second_harmonic_interval ⇒ Object
readonly
Returns the value of attribute second_harmonic_interval.
Instance Method Summary collapse
- #contrapuntal_motion ⇒ Object
- #contrary? ⇒ Boolean
- #direct? ⇒ Boolean
-
#initialize(first_harmonic_interval, second_harmonic_interval) ⇒ Motion
constructor
A new instance of Motion.
- #notes ⇒ Object
- #oblique? ⇒ Boolean
- #parallel? ⇒ Boolean
- #repetition? ⇒ Boolean
- #similar? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(first_harmonic_interval, second_harmonic_interval) ⇒ Motion
Returns a new instance of Motion.
7 8 9 10 |
# File 'lib/head_music/motion.rb', line 7 def initialize(first_harmonic_interval, second_harmonic_interval) @first_harmonic_interval = first_harmonic_interval @second_harmonic_interval = second_harmonic_interval end |
Instance Attribute Details
#first_harmonic_interval ⇒ Object (readonly)
Returns the value of attribute first_harmonic_interval.
5 6 7 |
# File 'lib/head_music/motion.rb', line 5 def first_harmonic_interval @first_harmonic_interval end |
#second_harmonic_interval ⇒ Object (readonly)
Returns the value of attribute second_harmonic_interval.
5 6 7 |
# File 'lib/head_music/motion.rb', line 5 def second_harmonic_interval @second_harmonic_interval end |
Instance Method Details
#contrapuntal_motion ⇒ Object
46 47 48 49 50 |
# File 'lib/head_music/motion.rb', line 46 def contrapuntal_motion %i[parallel similar oblique contrary repetition].detect do |motion_type| send("#{motion_type}?") end end |
#contrary? ⇒ Boolean
36 37 38 39 40 |
# File 'lib/head_music/motion.rb', line 36 def contrary? upper_melodic_interval.moving? && lower_melodic_interval.moving? && upper_melodic_interval.direction != lower_melodic_interval.direction end |
#direct? ⇒ Boolean
21 22 23 |
# File 'lib/head_music/motion.rb', line 21 def direct? parallel? || similar? end |
#notes ⇒ Object
42 43 44 |
# File 'lib/head_music/motion.rb', line 42 def notes upper_notes + lower_notes end |
#oblique? ⇒ Boolean
16 17 18 19 |
# File 'lib/head_music/motion.rb', line 16 def oblique? upper_melodic_interval.repetition? && lower_melodic_interval.moving? || lower_melodic_interval.repetition? && upper_melodic_interval.moving? end |
#parallel? ⇒ Boolean
25 26 27 28 29 |
# File 'lib/head_music/motion.rb', line 25 def parallel? upper_melodic_interval.moving? && upper_melodic_interval.direction == lower_melodic_interval.direction && upper_melodic_interval.steps == lower_melodic_interval.steps end |
#repetition? ⇒ Boolean
12 13 14 |
# File 'lib/head_music/motion.rb', line 12 def repetition? upper_melodic_interval.repetition? && lower_melodic_interval.repetition? end |
#similar? ⇒ Boolean
31 32 33 34 |
# File 'lib/head_music/motion.rb', line 31 def similar? upper_melodic_interval.direction == lower_melodic_interval.direction && upper_melodic_interval.steps != lower_melodic_interval.steps end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/head_music/motion.rb', line 52 def to_s "#{contrapuntal_motion} motion from #{first_harmonic_interval} to #{second_harmonic_interval}" end |