Sha256: 047d3e60ffd937e264a676c5ef046858adea8e4444da58463e066c476415f94b

Contents?: true

Size: 866 Bytes

Versions: 2

Compression:

Stored size: 866 Bytes

Contents

module HeadMusic::Style::Annotations
end

class HeadMusic::Style::Annotations::PrepareOctaveLeaps < HeadMusic::Style::Annotation
  MESSAGE = "Enter and exit an octave leap from within."

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

  private

  def external_entries
    melodic_intervals.map.with_index do |melodic_interval, i|
      if melodic_interval.octave? && i > 0 && !melodic_interval.spans?(notes[i-1].pitch)
        notes[[i-1, 0].max..(i+1)]
      end
    end.compact
  end

  def external_exits
    melodic_intervals.map.with_index do |melodic_interval, i|
      if melodic_interval.octave? && (i == (melodic_intervals.length - 1) || !melodic_interval.spans?(notes[i+2].pitch))
        notes[i..[i+2, notes.length - 1].min]
      end
    end.compact
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
head_music-0.17.0 lib/head_music/style/annotations/prepare_octave_leaps.rb
head_music-0.16.2 lib/head_music/style/annotations/prepare_octave_leaps.rb