Sha256: bd233ed4860a8cdd97fc091b02e16dfc4fb623cb6f6368a4f72a41285310f07d

Contents?: true

Size: 727 Bytes

Versions: 2

Compression:

Stored size: 727 Bytes

Contents

# frozen_string_literal: true

# Module for Annotations.
module HeadMusic::Style::Annotations; end

# A counterpoint guideline
class HeadMusic::Style::Annotations::AtLeastEightNotes < HeadMusic::Style::Annotation
  MINIMUM_NOTES = 8

  MESSAGE = 'Write at least eight notes.'

  def marks
    placements.empty? ? no_placements_mark : deficiency_mark
  end

  private

  def no_placements_mark
    HeadMusic::Style::Mark.new(
      HeadMusic::Position.new(composition, '1:1'),
      HeadMusic::Position.new(composition, '2:1'),
      fitness: 0
    )
  end

  def deficiency_mark
    return unless notes.length < MINIMUM_NOTES
    HeadMusic::Style::Mark.for_all(placements, fitness: notes.length.to_f / MINIMUM_NOTES)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
head_music-0.19.0 lib/head_music/style/annotations/at_least_eight_notes.rb
head_music-0.18.0 lib/head_music/style/annotations/at_least_eight_notes.rb