Class: HeadMusic::Style::Guidelines::MinimumMelodicIntervals

Inherits:
Annotation
  • Object
show all
Defined in:
lib/head_music/style/guidelines/minimum_melodic_intervals.rb

Overview

Flags a melody with fewer than the required number of moving melodic intervals. Repeated-note pairs don’t count as motion, so an all-repeated-note line gates to 0. Configure the threshold with the factory, e.g. MinimumMelodicIntervals.with(2).

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from HeadMusic::Style::Annotation

Class Method Details

.default_gate?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/head_music/style/guidelines/minimum_melodic_intervals.rb', line 12

def self.default_gate?
  true
end

.with(minimum, **options) ⇒ Object



8
9
10
# File 'lib/head_music/style/guidelines/minimum_melodic_intervals.rb', line 8

def self.with(minimum, **options)
  super(minimum: minimum, **options)
end

Instance Method Details

#deficiency_markObject (private)



50
51
52
53
54
# File 'lib/head_music/style/guidelines/minimum_melodic_intervals.rb', line 50

def deficiency_mark
  return unless moving_intervals.length < minimum

  HeadMusic::Style::Mark.for_all(placements, fitness: moving_intervals.length.to_f / minimum)
end

#marksObject



16
17
18
19
20
# File 'lib/head_music/style/guidelines/minimum_melodic_intervals.rb', line 16

def marks
  return no_motion_mark if moving_intervals.empty?

  deficiency_mark
end

#messageObject



22
23
24
# File 'lib/head_music/style/guidelines/minimum_melodic_intervals.rb', line 22

def message
  "Write at least #{minimum.humanize} melodic intervals."
end

#minimumObject (private)



28
29
30
# File 'lib/head_music/style/guidelines/minimum_melodic_intervals.rb', line 28

def minimum
  options.fetch(:minimum)
end

#moving_intervalsObject (private)



32
33
34
# File 'lib/head_music/style/guidelines/minimum_melodic_intervals.rb', line 32

def moving_intervals
  melodic_intervals.select(&:moving?)
end

#no_motion_markObject (private)



36
37
38
39
40
# File 'lib/head_music/style/guidelines/minimum_melodic_intervals.rb', line 36

def no_motion_mark
  return no_placements_mark if placements.empty?

  HeadMusic::Style::Mark.for_all(placements, fitness: 0)
end

#no_placements_markObject (private)



42
43
44
45
46
47
48
# File 'lib/head_music/style/guidelines/minimum_melodic_intervals.rb', line 42

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