Sha256: 2fec1916cf5aa1a7337ef9e0045884b3fa35d81ed0385004f9aefd249c2f1a23

Contents?: true

Size: 1012 Bytes

Versions: 2

Compression:

Stored size: 1012 Bytes

Contents

# frozen_string_literal: true

# Module for Annotations.
module HeadMusic::Style::Annotations; end

# A counterpoint guideline
class HeadMusic::Style::Annotations::PrepareOctaveLeaps < HeadMusic::Style::Annotation
  MESSAGE = 'Enter and exit an octave leap from within.'

  def marks
    (external_entries + external_exits + octave_ending).map do |trouble_spot|
      HeadMusic::Style::Mark.for_all(trouble_spot)
    end
  end

  private

  def external_entries
    melodic_intervals.each_cons(2).map do |pair|
      first, second = *pair
      pair.map(&:notes).uniq if second.octave? && !second.spans?(first.first_note.pitch)
    end.compact
  end

  def external_exits
    melodic_intervals.each_cons(2).map do |pair|
      first, second = *pair
      pair.map(&:notes).uniq if first.octave? && !first.spans?(second.second_note.pitch)
    end.compact
  end

  def octave_ending
    octave_ending? ? [melodic_intervals.last.notes] : []
  end

  def octave_ending?
    melodic_intervals.last&.octave?
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
head_music-0.19.0 lib/head_music/style/annotations/prepare_octave_leaps.rb
head_music-0.18.0 lib/head_music/style/annotations/prepare_octave_leaps.rb