Sha256: b64d8e834b0342d8a74993232b3cba2d57583765021c847c8e43730aff012fb1

Contents?: true

Size: 813 Bytes

Versions: 1

Compression:

Stored size: 813 Bytes

Contents

# frozen_string_literal: true

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

# A counterpoint guideline
class HeadMusic::Style::Annotations::MostlyConjunct < HeadMusic::Style::Annotation
  MESSAGE = 'Use mostly conjunct motion.'

  MINIMUM_CONJUNCT_PORTION = HeadMusic::GOLDEN_RATIO_INVERSE**2
  # ~38%
  # Fux is 5/13 for lydian cantus firmus

  def marks
    marks_for_skips_and_leaps if conjunct_ratio < MINIMUM_CONJUNCT_PORTION
  end

  private

  def marks_for_skips_and_leaps
    melodic_intervals.
      reject(&:step?).
      map { |interval| HeadMusic::Style::Mark.for_all(interval.notes, fitness: HeadMusic::SMALL_PENALTY_FACTOR) }
  end

  def conjunct_ratio
    return 1 if melodic_intervals.empty?
    melodic_intervals.count(&:step?).to_f / melodic_intervals.length
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
head_music-0.19.0 lib/head_music/style/annotations/mostly_conjunct.rb