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

#ascending_shorthandsObject (private)



60
61
62
# File 'lib/head_music/style/guidelines/singable_intervals.rb', line 60

def ascending_shorthands
  config[:ascending]
end

#both_directions?(shorthand) ⇒ Boolean (private)

Returns:

  • (Boolean)


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

def both_directions?(shorthand)
  ascending_shorthands.include?(shorthand) && descending_shorthands.include?(shorthand)
end

#configObject (private)



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

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

#descending_shorthandsObject (private)



64
65
66
# File 'lib/head_music/style/guidelines/singable_intervals.rb', line 64

def descending_shorthands
  config[:descending]
end

#describe_shorthand(shorthand) ⇒ Object (private)



40
41
42
43
44
45
# File 'lib/head_music/style/guidelines/singable_intervals.rb', line 40

def describe_shorthand(shorthand)
  return shorthand if both_directions?(shorthand)

  direction = ascending_shorthands.include?(shorthand) ? "ascending" : "descending"
  "#{shorthand} (#{direction})"
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)


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

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
# File 'lib/head_music/style/guidelines/singable_intervals.rb', line 34

def permitted_descriptions
  (ascending_shorthands | descending_shorthands).map do |shorthand|
    describe_shorthand(shorthand)
  end
end

#whitelist_for_interval(melodic_interval) ⇒ Object (private)



56
57
58
# File 'lib/head_music/style/guidelines/singable_intervals.rb', line 56

def whitelist_for_interval(melodic_interval)
  melodic_interval.ascending? ? ascending_shorthands : descending_shorthands
end