Sha256: 2e611542504b65ec967c1080d62d97afebef8dbf310ecf71c96f546a98f094a4
Contents?: true
Size: 866 Bytes
Versions: 7
Compression:
Stored size: 866 Bytes
Contents
module HeadMusic::Style::Annotations end class HeadMusic::Style::Annotations::DirectionChanges < HeadMusic::Style::Annotation MAXIMUM_NOTES_PER_DIRECTION = 3 MESSAGE = "Balance ascending and descending motion." 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 - 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
7 entries across 7 versions & 1 rubygems