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

Inherits:
HeadMusic::Style::Guideline 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 - violation_key: names an alternative violation template

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
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Class Method Details

.describe(shorthand, settings) ⇒ Object



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

def self.describe(shorthand, settings)
  both = settings[:ascending].include?(shorthand) && settings[:descending].include?(shorthand)
  return shorthand if both

  direction = settings[:ascending].include?(shorthand) ? :ascending : :descending
  HeadMusic::Style::Template.render("interval_directions.#{direction}", interval: shorthand)
end

.template_values(config) ⇒ Object

Derivable from configuration alone, so an item can preview it without a voice.



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

def self.template_values(config)
  return {} if config[:violation_key]

  settings = DEFAULTS.merge(config)
  shorthands = settings[:ascending] | settings[:descending]
  {intervals: shorthands.map { |shorthand| describe(shorthand, settings) }.join(", ")}
end

.violation_key(config = {}) ⇒ Object



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

def self.violation_key(config = {})
  config[:violation_key] || super()
end

Instance Method Details

#ascending_shorthandsObject (private)



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

def ascending_shorthands
  config[:ascending]
end

#configObject (private)



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

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

#descending_shorthandsObject (private)



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

def descending_shorthands
  config[:descending]
end

#marksObject



38
39
40
41
42
# File 'lib/head_music/style/guidelines/singable_intervals.rb', line 38

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

#permitted?(note_pair) ⇒ Boolean (private)

Returns:

  • (Boolean)


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

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

#whitelist_for_interval(melodic_interval) ⇒ Object (private)



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

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