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 the sequence of consecutive pairs, the interval spanned by each pair, and the leaps among them. 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.



9
10
11
# File 'lib/head_music/content/voice/melodic_line.rb', line 9

def initialize(notes)
  @notes = notes
end

Instance Attribute Details

#notesObject (readonly)

Returns the value of attribute notes.



7
8
9
# File 'lib/head_music/content/voice/melodic_line.rb', line 7

def notes
  @notes
end

Instance Method Details

#large_leapsObject



28
29
30
# File 'lib/head_music/content/voice/melodic_line.rb', line 28

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

#leapsObject



24
25
26
# File 'lib/head_music/content/voice/melodic_line.rb', line 24

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

#melodic_intervalsObject



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

def melodic_intervals
  @melodic_intervals ||=
    melodic_note_pairs.map { |note_pair| HeadMusic::Analysis::MelodicInterval.new(*note_pair.notes) }
end

#melodic_note_pairsObject



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

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