Sha256: 1f1e86cfb725116e4f931c18d5c62ad32974601b43cc7796b42b63b74643a346

Contents?: true

Size: 968 Bytes

Versions: 1

Compression:

Stored size: 968 Bytes

Contents

module HeadMusic::Style::Annotations
end

class HeadMusic::Style::Annotations::NoUnisonsInMiddle < HeadMusic::Style::Annotation
  MESSAGE = "Unisons may only be used in the first and last note."

  def marks
    unison_pairs.map do |notes|
      HeadMusic::Style::Mark.for_all(notes)
    end.flatten
  end

  private

  def unison_pairs
    middle_unisons.map(&:notes).reject(&:nil?)
  end

  def middle_unisons
    middle_intervals.select { |interval| interval.perfect_consonance? && interval.unison? }
  end

  def middle_intervals
    [harmonic_intervals[1..-2]].flatten.reject(&:nil?)
  end

  def harmonic_intervals
    cantus_firmus.notes.map do |cantus_firmus_note|
      counterpoint_notes = voice.notes_during(cantus_firmus_note)
      counterpoint_notes.map { |note|
        HarmonicInterval.new(cantus_firmus_note.voice, voice, note.position)
      }
    end.flatten
  end

  def positions
    voices.map(:notes).flatten.map(&:position).sort.uniq
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
head_music-0.13.2 lib/head_music/style/annotations/no_unisons_in_middle.rb