Sha256: d49e099cda4e387f12e28365b61e817adad922cb11ee20f646ab0169d3864bcf

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

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

# Ok, so a rule might be that after the first leap (after previous steps)
# one should normally move by step in the opposite direction
# unless another leap (in either direction) creates a consonant triad.
# - Brian
class HeadMusic::Style::Annotations::RecoverLargeLeaps < HeadMusic::Style::Annotation
  MESSAGE = 'Recover large leaps by step in the opposite direction.'

  def marks
    melodic_intervals.each_cons(3).map do |intervals|
      if unrecovered_leap?(intervals[0], intervals[1], intervals[2])
        HeadMusic::Style::Mark.for_all(notes_in_intervals(intervals))
      end
    end.compact
  end

  private

  def notes_in_intervals(intervals)
    (intervals[0].notes + intervals[1].notes).uniq
  end

  def unrecovered_leap?(first_interval, second_interval, third_interval)
    first_interval.large_leap? &&
      !spelling_consonant_triad?(first_interval, second_interval, third_interval) &&
      (
        !direction_changed?(first_interval, second_interval) ||
        !second_interval.step?
      )
  end

  def spelling_consonant_triad?(first_interval, second_interval, third_interval)
    first_interval.spells_consonant_triad_with?(second_interval) ||
      second_interval.spells_consonant_triad_with?(third_interval)
  end

  def direction_changed?(first_interval, second_interval)
    first_interval.ascending? && second_interval.descending? ||
      first_interval.descending? && second_interval.ascending?
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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