Sha256: 793d962106975dfa1db6afaed4cbeda9e37f22ea275e4c8668aee7db55fa69f6

Contents?: true

Size: 1.48 KB

Versions: 9

Compression:

Stored size: 1.48 KB

Contents

# Module for style guidelines.
module HeadMusic::Style::Guidelines; 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::Guidelines::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

9 entries across 9 versions & 1 rubygems

Version Path
head_music-7.0.5 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-7.0.4 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-7.0.3 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-7.0.2 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-7.0.1 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-7.0.0 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-6.0.1 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-6.0.0 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-5.0.0 lib/head_music/style/guidelines/recover_large_leaps.rb