Sha256: 3e5331c98b8ced8558969f282cdd61475d3c96f74cf8cbdb904489713eb1cdd2

Contents?: true

Size: 856 Bytes

Versions: 27

Compression:

Stored size: 856 Bytes

Contents

# frozen_string_literal: true

# Module for style guidelines.
module HeadMusic::Style::Guidelines; end

# A melodic line should have direction changes.
class HeadMusic::Style::Guidelines::DirectionChanges < HeadMusic::Style::Annotation
  def marks
    return unless overage.positive?

    penalty_exponent = overage**0.5
    HeadMusic::Style::Mark.for_all(notes, fitness: HeadMusic::PENALTY_FACTOR**penalty_exponent)
  end

  private

  def overage
    return 0 if notes.length < 2

    [notes_per_direction - self.class.maximum_notes_per_direction, 0].max
  end

  def notes_per_direction
    notes.length.to_f / (melodic_intervals_changing_direction.length + 1)
  end

  def melodic_intervals_changing_direction
    melodic_intervals.each_cons(2).reject do |interval_pair|
      interval_pair[0].direction == interval_pair[1].direction
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
head_music-4.0.1 lib/head_music/style/guidelines/direction_changes.rb
head_music-4.0.0 lib/head_music/style/guidelines/direction_changes.rb
head_music-3.0.1 lib/head_music/style/guidelines/direction_changes.rb
head_music-3.0.0 lib/head_music/style/guidelines/direction_changes.rb
head_music-2.0.1 lib/head_music/style/guidelines/direction_changes.rb
head_music-2.0.0 lib/head_music/style/guidelines/direction_changes.rb
head_music-1.0.0 lib/head_music/style/guidelines/direction_changes.rb
head_music-0.29.0 lib/head_music/style/guidelines/direction_changes.rb
head_music-0.28.0 lib/head_music/style/guidelines/direction_changes.rb
head_music-0.27.0 lib/head_music/style/guidelines/direction_changes.rb
head_music-0.26.3 lib/head_music/style/guidelines/direction_changes.rb
head_music-0.26.2 lib/head_music/style/guidelines/direction_changes.rb
head_music-0.26.1 lib/head_music/style/guidelines/direction_changes.rb
head_music-0.26.0 lib/head_music/style/guidelines/direction_changes.rb
head_music-0.25.0 lib/head_music/style/guidelines/direction_changes.rb
head_music-0.24.5 lib/head_music/style/guidelines/direction_changes.rb
head_music-0.24.4 lib/head_music/style/guidelines/direction_changes.rb
head_music-0.24.3 lib/head_music/style/guidelines/direction_changes.rb
head_music-0.24.2 lib/head_music/style/guidelines/direction_changes.rb
head_music-0.24.1 lib/head_music/style/guidelines/direction_changes.rb