Class: HeadMusic::Content::Voice::MelodicLine
- Inherits:
-
Object
- Object
- HeadMusic::Content::Voice::MelodicLine
- Defined in:
- lib/head_music/content/voice/melodic_line.rb
Overview
The melodic view of a voice: its notes read as a sequence — the pitches they sound, the span between the extremes, the note at or around a position, and the consecutive pairs with their intervals and leaps. Built from an ordered list of notes and memoizes the pairs, so callers sharing a MelodicLine see the same pair objects.
Instance Attribute Summary collapse
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
Instance Method Summary collapse
-
#highest_notes ⇒ Object
-
#highest_pitch ⇒ Object
-
#initialize(notes) ⇒ MelodicLine
constructor
A new instance of MelodicLine.
-
#large_leaps ⇒ Object
-
#leaps ⇒ Object
-
#lowest_notes ⇒ Object
-
#lowest_pitch ⇒ Object
-
#melodic_intervals ⇒ Object
-
#melodic_note_pairs ⇒ Object
-
#note_at(position) ⇒ Object
-
#note_following(position) ⇒ Object
-
#note_preceding(position) ⇒ Object
-
#notes_at_pitch(pitch) ⇒ Object
private
-
#notes_during(placement) ⇒ Object
-
#pitches ⇒ Object
-
#range ⇒ Object
Constructor Details
#initialize(notes) ⇒ MelodicLine
Returns a new instance of MelodicLine.
10 11 12 |
# File 'lib/head_music/content/voice/melodic_line.rb', line 10 def initialize(notes) @notes = notes end |
Instance Attribute Details
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
8 9 10 |
# File 'lib/head_music/content/voice/melodic_line.rb', line 8 def notes @notes end |
Instance Method Details
#highest_notes ⇒ Object
26 27 28 |
# File 'lib/head_music/content/voice/melodic_line.rb', line 26 def highest_notes notes_at_pitch(highest_pitch) end |
#highest_pitch ⇒ Object
18 19 20 |
# File 'lib/head_music/content/voice/melodic_line.rb', line 18 def highest_pitch pitches.max end |
#large_leaps ⇒ Object
69 70 71 |
# File 'lib/head_music/content/voice/melodic_line.rb', line 69 def large_leaps melodic_note_pairs.select(&:large_leap?) end |
#leaps ⇒ Object
65 66 67 |
# File 'lib/head_music/content/voice/melodic_line.rb', line 65 def leaps melodic_note_pairs.select(&:leap?) end |
#lowest_notes ⇒ Object
30 31 32 |
# File 'lib/head_music/content/voice/melodic_line.rb', line 30 def lowest_notes notes_at_pitch(lowest_pitch) end |
#lowest_pitch ⇒ Object
22 23 24 |
# File 'lib/head_music/content/voice/melodic_line.rb', line 22 def lowest_pitch pitches.min end |
#melodic_intervals ⇒ Object
60 61 62 63 |
# File 'lib/head_music/content/voice/melodic_line.rb', line 60 def melodic_intervals @melodic_intervals ||= melodic_note_pairs.map { |note_pair| HeadMusic::Analysis::MelodicInterval.new(*note_pair.notes) } end |
#melodic_note_pairs ⇒ Object
54 55 56 57 58 |
# File 'lib/head_music/content/voice/melodic_line.rb', line 54 def melodic_note_pairs @melodic_note_pairs ||= notes.each_cons(2).map do |first_note, second_note| MelodicNotePair.new(first_note, second_note) end end |
#note_at(position) ⇒ Object
38 39 40 |
# File 'lib/head_music/content/voice/melodic_line.rb', line 38 def note_at(position) notes.detect { |note| position.within_placement?(note) } end |
#note_following(position) ⇒ Object
50 51 52 |
# File 'lib/head_music/content/voice/melodic_line.rb', line 50 def note_following(position) notes.detect { |note| note.position > position } end |
#note_preceding(position) ⇒ Object
46 47 48 |
# File 'lib/head_music/content/voice/melodic_line.rb', line 46 def note_preceding(position) notes.reverse.find { |note| note.position < position } end |
#notes_at_pitch(pitch) ⇒ Object (private)
75 76 77 |
# File 'lib/head_music/content/voice/melodic_line.rb', line 75 def notes_at_pitch(pitch) notes.select { |note| note.pitch == pitch } end |
#notes_during(placement) ⇒ Object
42 43 44 |
# File 'lib/head_music/content/voice/melodic_line.rb', line 42 def notes_during(placement) notes.select { |note| note.during?(placement) } end |
#pitches ⇒ Object
14 15 16 |
# File 'lib/head_music/content/voice/melodic_line.rb', line 14 def pitches notes.map(&:pitch) end |
#range ⇒ Object
34 35 36 |
# File 'lib/head_music/content/voice/melodic_line.rb', line 34 def range HeadMusic::Analysis::DiatonicInterval.new(lowest_pitch, highest_pitch) end |