class HeadMusic::Voice
A Voice
is a stream of music with some indepedence that is conceptually one part or for one performer. The melodic lines in counterpoint are each a voice.
Attributes
composition[R]
placements[R]
role[R]
Public Class Methods
new(composition: nil, role: nil)
click to toggle source
# File lib/head_music/content/voice.rb, line 12 def initialize(composition: nil, role: nil) @composition = composition || HeadMusic::Composition.new @role = role @placements = [] end
Public Instance Methods
cantus_firmus?()
click to toggle source
# File lib/head_music/content/voice.rb, line 74 def cantus_firmus? role.to_s =~ /cantus.?firmus/i end
earliest_bar_number()
click to toggle source
# File lib/head_music/content/voice.rb, line 94 def earliest_bar_number return 1 if notes.empty? placements.first.position.bar_number end
highest_notes()
click to toggle source
# File lib/head_music/content/voice.rb, line 49 def highest_notes notes.select { |note| note.pitch == highest_pitch } end
highest_pitch()
click to toggle source
# File lib/head_music/content/voice.rb, line 41 def highest_pitch pitches.max end
large_leaps()
click to toggle source
# File lib/head_music/content/voice.rb, line 70 def large_leaps melodic_intervals.select(&:large_leap?) end
latest_bar_number()
click to toggle source
# File lib/head_music/content/voice.rb, line 100 def latest_bar_number return 1 if notes.empty? placements.last.position.bar_number end
leaps()
click to toggle source
# File lib/head_music/content/voice.rb, line 66 def leaps melodic_intervals.select(&:leap?) end
lowest_notes()
click to toggle source
# File lib/head_music/content/voice.rb, line 53 def lowest_notes notes.select { |note| note.pitch == lowest_pitch } end
lowest_pitch()
click to toggle source
# File lib/head_music/content/voice.rb, line 45 def lowest_pitch pitches.min end
melodic_intervals()
click to toggle source
# File lib/head_music/content/voice.rb, line 61 def melodic_intervals @melodic_intervals ||= notes.each_cons(2).map { |note_pair| HeadMusic::MelodicInterval.new(*note_pair) } end
note_at(position)
click to toggle source
# File lib/head_music/content/voice.rb, line 78 def note_at(position) notes.detect { |note| position.within_placement?(note) } end
note_following(position)
click to toggle source
# File lib/head_music/content/voice.rb, line 90 def note_following(position) notes.detect { |note| note.position > position } end
note_preceding(position)
click to toggle source
# File lib/head_music/content/voice.rb, line 86 def note_preceding(position) notes.select { |note| note.position < position }.last end
notes()
click to toggle source
# File lib/head_music/content/voice.rb, line 24 def notes @placements.select(&:note?) end
notes_during(placement)
click to toggle source
# File lib/head_music/content/voice.rb, line 82 def notes_during(placement) notes.select { |note| note.during?(placement) } end
notes_not_in_key()
click to toggle source
# File lib/head_music/content/voice.rb, line 28 def notes_not_in_key key_spellings = key_signature.pitches.map(&:spelling).uniq notes.reject { |note| key_spellings.include? note.pitch.spelling } end
pitches()
click to toggle source
# File lib/head_music/content/voice.rb, line 33 def pitches notes.map(&:pitch) end
place(position, rhythmic_value, pitch = nil)
click to toggle source
# File lib/head_music/content/voice.rb, line 18 def place(position, rhythmic_value, pitch = nil) HeadMusic::Placement.new(self, position, rhythmic_value, pitch).tap do |placement| insert_into_placements(placement) end end
range()
click to toggle source
# File lib/head_music/content/voice.rb, line 57 def range HeadMusic::DiatonicInterval.new(lowest_pitch, highest_pitch) end
rests()
click to toggle source
# File lib/head_music/content/voice.rb, line 37 def rests @placements.select(&:rest?) end
to_s()
click to toggle source
# File lib/head_music/content/voice.rb, line 106 def to_s "#{role}: #{pitches.first(10).map(&:to_s)}" end
Private Instance Methods
insert_into_placements(placement)
click to toggle source
# File lib/head_music/content/voice.rb, line 112 def insert_into_placements(placement) @placements << placement @placements = @placements.sort end