Class: HeadMusic::Content::Voice::MelodicLine

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#notesObject (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_notesObject



26
27
28
# File 'lib/head_music/content/voice/melodic_line.rb', line 26

def highest_notes
  notes_at_pitch(highest_pitch)
end

#highest_pitchObject



18
19
20
# File 'lib/head_music/content/voice/melodic_line.rb', line 18

def highest_pitch
  pitches.max
end

#large_leapsObject



69
70
71
# File 'lib/head_music/content/voice/melodic_line.rb', line 69

def large_leaps
  melodic_note_pairs.select(&:large_leap?)
end

#leapsObject



65
66
67
# File 'lib/head_music/content/voice/melodic_line.rb', line 65

def leaps
  melodic_note_pairs.select(&:leap?)
end

#lowest_notesObject



30
31
32
# File 'lib/head_music/content/voice/melodic_line.rb', line 30

def lowest_notes
  notes_at_pitch(lowest_pitch)
end

#lowest_pitchObject



22
23
24
# File 'lib/head_music/content/voice/melodic_line.rb', line 22

def lowest_pitch
  pitches.min
end

#melodic_intervalsObject



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_pairsObject



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

#pitchesObject



14
15
16
# File 'lib/head_music/content/voice/melodic_line.rb', line 14

def pitches
  notes.map(&:pitch)
end

#rangeObject



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