Sha256: 263a73e5a4103bd4550894e2a4cf7414392e20cfdfcc394b66a3d68fda967928

Contents?: true

Size: 786 Bytes

Versions: 3

Compression:

Stored size: 786 Bytes

Contents

module HeadMusic::Style::Annotations
end

class HeadMusic::Style::Annotations::DirectionChanges < HeadMusic::Style::Annotation
  def marks
    if overage > 0
      penalty_exponent = overage**0.5
      HeadMusic::Style::Mark.for_all(notes, fitness: HeadMusic::PENALTY_FACTOR**penalty_exponent)
    end
  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.drop(1).select.with_index do |interval, i|
      previous_direction = melodic_intervals[i].direction
      interval.direction != previous_direction
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
head_music-0.17.0 lib/head_music/style/annotations/direction_changes.rb
head_music-0.16.2 lib/head_music/style/annotations/direction_changes.rb
head_music-0.16.0 lib/head_music/style/annotations/direction_changes.rb