Class: HeadMusic::Style::Guidelines::WeakBeatDissonanceTreatment

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

Overview

A counterpoint guideline

Constant Summary collapse

MESSAGE =
"Use only passing tones for dissonances on the weak beat."

Instance Method Summary collapse

Constructor Details

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

Instance Method Details

#cantus_firmus_positionsObject (private)



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

def cantus_firmus_positions
  @cantus_firmus_positions ||= Set.new(cantus_firmus.notes.map { |n| n.position.to_s })
end

#dissonant_weak_beat_notesObject (private)



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

def dissonant_weak_beat_notes
  weak_beat_notes.select { |note| dissonant_with_cantus?(note) }
end

#dissonant_with_cantus?(note) ⇒ Boolean (private)

Returns:

  • (Boolean)


34
35
36
37
# File 'lib/head_music/style/guidelines/weak_beat_dissonance_treatment.rb', line 34

def dissonant_with_cantus?(note)
  interval = HeadMusic::Analysis::HarmonicInterval.new(cantus_firmus, voice, note.position)
  interval.notes.length == 2 && interval.dissonance?(:two_part_harmony)
end

#downbeat_position?(position) ⇒ Boolean (private)

Returns:

  • (Boolean)


26
27
28
# File 'lib/head_music/style/guidelines/weak_beat_dissonance_treatment.rb', line 26

def downbeat_position?(position)
  cantus_firmus_positions.include?(position.to_s)
end

#following_note(note) ⇒ Object (private)



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

def following_note(note)
  index = notes.index(note)
  notes[index + 1] if index && index < notes.length - 1
end

#marksObject



8
9
10
11
12
13
14
# File 'lib/head_music/style/guidelines/weak_beat_dissonance_treatment.rb', line 8

def marks
  return [] unless cantus_firmus&.notes&.any?

  dissonant_weak_beat_notes.reject { |note| passing_tone?(note) }.map do |note|
    HeadMusic::Style::Mark.for(note)
  end
end

#passing_tone?(note) ⇒ Boolean (private)

Returns:

  • (Boolean)


39
40
41
42
43
44
45
46
47
48
# File 'lib/head_music/style/guidelines/weak_beat_dissonance_treatment.rb', line 39

def passing_tone?(note)
  prev = preceding_note(note)
  foll = following_note(note)
  return false unless prev && foll

  approach = HeadMusic::Analysis::MelodicInterval.new(prev, note)
  departure = HeadMusic::Analysis::MelodicInterval.new(note, foll)

  approach.step? && departure.step? && approach.direction == departure.direction
end

#preceding_note(note) ⇒ Object (private)



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

def preceding_note(note)
  index = notes.index(note)
  notes[index - 1] if index && index > 0
end

#weak_beat_notesObject (private)



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

def weak_beat_notes
  notes.reject { |note| downbeat_position?(note.position) }
end