Sha256: dc9b28275f3577d6a43fe34b6e6ca4cde0a3c6fa920557ce12b6084dc9f97a93

Contents?: true

Size: 1.51 KB

Versions: 21

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

# 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

21 entries across 21 versions & 1 rubygems

Version Path
head_music-0.27.0 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-0.26.3 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-0.26.2 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-0.26.1 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-0.26.0 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-0.25.0 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-0.24.5 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-0.24.4 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-0.24.3 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-0.24.2 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-0.24.1 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-0.24.0 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-0.23.4 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-0.23.3 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-0.23.2 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-0.23.1 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-0.23.0 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-0.22.0 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-0.20.0 lib/head_music/style/guidelines/recover_large_leaps.rb
head_music-0.19.2 lib/head_music/style/guidelines/recover_large_leaps.rb