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.
5 6 7 8 |
# File 'lib/head_music/motion.rb', line 5 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.
3 4 5 |
# File 'lib/head_music/motion.rb', line 3 def first_harmonic_interval @first_harmonic_interval end |
#second_harmonic_interval ⇒ Object (readonly)
Returns the value of attribute second_harmonic_interval.
3 4 5 |
# File 'lib/head_music/motion.rb', line 3 def second_harmonic_interval @second_harmonic_interval end |
Instance Method Details
#contrapuntal_motion ⇒ Object
44 45 46 47 48 |
# File 'lib/head_music/motion.rb', line 44 def contrapuntal_motion %i[parallel similar oblique contrary repetition].detect do |motion_type| send("#{motion_type}?") end end |
#contrary? ⇒ Boolean
34 35 36 37 38 |
# File 'lib/head_music/motion.rb', line 34 def contrary? upper_melodic_interval.moving? && lower_melodic_interval.moving? && upper_melodic_interval.direction != lower_melodic_interval.direction end |
#direct? ⇒ Boolean
19 20 21 |
# File 'lib/head_music/motion.rb', line 19 def direct? parallel? || similar? end |
#notes ⇒ Object
40 41 42 |
# File 'lib/head_music/motion.rb', line 40 def notes upper_notes + lower_notes end |
#oblique? ⇒ Boolean
14 15 16 17 |
# File 'lib/head_music/motion.rb', line 14 def oblique? upper_melodic_interval.repetition? && lower_melodic_interval.moving? || lower_melodic_interval.repetition? && upper_melodic_interval.moving? end |
#parallel? ⇒ Boolean
23 24 25 26 27 |
# File 'lib/head_music/motion.rb', line 23 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
10 11 12 |
# File 'lib/head_music/motion.rb', line 10 def repetition? upper_melodic_interval.repetition? && lower_melodic_interval.repetition? end |
#similar? ⇒ Boolean
29 30 31 32 |
# File 'lib/head_music/motion.rb', line 29 def similar? upper_melodic_interval.direction == lower_melodic_interval.direction && upper_melodic_interval.steps != lower_melodic_interval.steps end |
#to_s ⇒ Object
50 51 52 53 54 |
# File 'lib/head_music/motion.rb', line 50 def to_s return "repetition of a #{second_harmonic_interval}" unless contrapuntal_motion != :repetition "#{contrapuntal_motion} motion from a #{first_harmonic_interval} to a #{second_harmonic_interval}" end |