Sha256: 96c70ea737fb69d088b39fa052b2540593afb188dcb65127892a51ed220a155a

Contents?: true

Size: 841 Bytes

Versions: 1

Compression:

Stored size: 841 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.map.with_index do |interval, i|
      HeadMusic::Style::Mark.for_all(notes[i..i + 1], fitness: HeadMusic::SMALL_PENALTY_FACTOR) unless interval.step?
    end.compact
  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.18.0 lib/head_music/style/annotations/mostly_conjunct.rb