Class: HeadMusic::Analysis::Motion
- Inherits:
-
Object
- Object
- HeadMusic::Analysis::Motion
- Defined in:
- lib/head_music/analysis/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.
- #lower_melodic_interval ⇒ Object private
- #lower_notes ⇒ Object private
- #notes ⇒ Object
- #oblique? ⇒ Boolean
- #parallel? ⇒ Boolean
- #repetition? ⇒ Boolean
- #similar? ⇒ Boolean
- #to_s ⇒ Object
- #upper_melodic_interval ⇒ Object private
- #upper_notes ⇒ Object private
Constructor Details
#initialize(first_harmonic_interval, second_harmonic_interval) ⇒ Motion
Returns a new instance of Motion.
8 9 10 11 |
# File 'lib/head_music/analysis/motion.rb', line 8 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.
6 7 8 |
# File 'lib/head_music/analysis/motion.rb', line 6 def first_harmonic_interval @first_harmonic_interval end |
#second_harmonic_interval ⇒ Object (readonly)
Returns the value of attribute second_harmonic_interval.
6 7 8 |
# File 'lib/head_music/analysis/motion.rb', line 6 def second_harmonic_interval @second_harmonic_interval end |
Instance Method Details
#contrapuntal_motion ⇒ Object
47 48 49 50 51 |
# File 'lib/head_music/analysis/motion.rb', line 47 def contrapuntal_motion i[parallel similar oblique contrary repetition].detect do |motion_type| send("#{motion_type}?") end end |
#contrary? ⇒ Boolean
37 38 39 40 41 |
# File 'lib/head_music/analysis/motion.rb', line 37 def contrary? upper_melodic_interval.moving? && lower_melodic_interval.moving? && upper_melodic_interval.direction != lower_melodic_interval.direction end |
#direct? ⇒ Boolean
22 23 24 |
# File 'lib/head_music/analysis/motion.rb', line 22 def direct? parallel? || similar? end |
#lower_melodic_interval ⇒ Object (private)
65 66 67 |
# File 'lib/head_music/analysis/motion.rb', line 65 def lower_melodic_interval HeadMusic::Analysis::MelodicInterval.new(lower_notes.first, lower_notes.last) end |
#lower_notes ⇒ Object (private)
73 74 75 |
# File 'lib/head_music/analysis/motion.rb', line 73 def lower_notes [first_harmonic_interval, second_harmonic_interval].map(&:lower_note) end |
#notes ⇒ Object
43 44 45 |
# File 'lib/head_music/analysis/motion.rb', line 43 def notes upper_notes + lower_notes end |
#oblique? ⇒ Boolean
17 18 19 20 |
# File 'lib/head_music/analysis/motion.rb', line 17 def oblique? upper_melodic_interval.repetition? && lower_melodic_interval.moving? || lower_melodic_interval.repetition? && upper_melodic_interval.moving? end |
#parallel? ⇒ Boolean
26 27 28 29 30 |
# File 'lib/head_music/analysis/motion.rb', line 26 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
13 14 15 |
# File 'lib/head_music/analysis/motion.rb', line 13 def repetition? upper_melodic_interval.repetition? && lower_melodic_interval.repetition? end |
#similar? ⇒ Boolean
32 33 34 35 |
# File 'lib/head_music/analysis/motion.rb', line 32 def similar? upper_melodic_interval.direction == lower_melodic_interval.direction && upper_melodic_interval.steps != lower_melodic_interval.steps end |
#to_s ⇒ Object
53 54 55 56 57 |
# File 'lib/head_music/analysis/motion.rb', line 53 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 |
#upper_melodic_interval ⇒ Object (private)
61 62 63 |
# File 'lib/head_music/analysis/motion.rb', line 61 def upper_melodic_interval HeadMusic::Analysis::MelodicInterval.new(upper_notes.first, upper_notes.last) end |
#upper_notes ⇒ Object (private)
69 70 71 |
# File 'lib/head_music/analysis/motion.rb', line 69 def upper_notes [first_harmonic_interval, second_harmonic_interval].map(&:upper_note) end |