Class: HeadMusic::Style::Guidelines::SingableIntervals

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

Overview

A configurable guideline limiting melodic motion to singable intervals.

Options: - ascending: permitted interval shorthands for ascending motion - descending: permitted interval shorthands for descending motion - message: the annotation message (defaults to listing the permitted intervals)

Constant Summary collapse

DEFAULTS =

Traditional pedagogy permits the minor sixth ascending only.

{
  ascending: %w[P1 m2 M2 m3 M3 P4 P5 m6 P8].freeze,
  descending: %w[P1 m2 M2 m3 M3 P4 P5 P8].freeze,
  message: nil
}.freeze

Instance Method Summary collapse

Constructor Details

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

Instance Method Details

#configObject (private)



30
31
32
# File 'lib/head_music/style/guidelines/singable_intervals.rb', line 30

def config
  @config ||= DEFAULTS.merge(options)
end

#marksObject



22
23
24
25
26
# File 'lib/head_music/style/guidelines/singable_intervals.rb', line 22

def marks
  melodic_note_pairs.reject { |note_pair| permitted?(note_pair) }.map do |pair_with_unpermitted_interval|
    HeadMusic::Style::Mark.for_all(pair_with_unpermitted_interval.notes)
  end
end

#messageObject



18
19
20
# File 'lib/head_music/style/guidelines/singable_intervals.rb', line 18

def message
  config[:message] || "Use only #{permitted_descriptions.join(", ")} in the melodic line."
end

#permitted?(note_pair) ⇒ Boolean (private)

Returns:

  • (Boolean)


45
46
47
48
# File 'lib/head_music/style/guidelines/singable_intervals.rb', line 45

def permitted?(note_pair)
  melodic_interval = note_pair.melodic_interval
  whitelist_for_interval(melodic_interval).include?(melodic_interval.shorthand)
end

#permitted_descriptionsObject (private)



34
35
36
37
38
39
40
41
42
43
# File 'lib/head_music/style/guidelines/singable_intervals.rb', line 34

def permitted_descriptions
  (config[:ascending] | config[:descending]).map do |shorthand|
    if config[:ascending].include?(shorthand) && config[:descending].include?(shorthand)
      shorthand
    else
      direction = config[:ascending].include?(shorthand) ? "ascending" : "descending"
      "#{shorthand} (#{direction})"
    end
  end
end

#whitelist_for_interval(melodic_interval) ⇒ Object (private)



50
51
52
# File 'lib/head_music/style/guidelines/singable_intervals.rb', line 50

def whitelist_for_interval(melodic_interval)
  melodic_interval.ascending? ? config[:ascending] : config[:descending]
end