Sha256: bb98187b2414f8b0dca59928051651aa168a30ce3f458f08cc0390f17975f6bd
Contents?: true
Size: 897 Bytes
Versions: 1
Compression:
Stored size: 897 Bytes
Contents
# frozen_string_literal: true # Module for Annotations. module HeadMusic::Style::Annotations; end # A melodic line should have direction changes. class HeadMusic::Style::Annotations::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.drop(1).select.with_index do |interval, i| previous_direction = melodic_intervals[i].direction interval.direction != previous_direction end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
head_music-0.18.0 | lib/head_music/style/annotations/direction_changes.rb |