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)



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

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

#dissonant_weak_beat_notesObject (private)



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

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

#dissonant_with_cantus?(note) ⇒ Boolean (private)

Returns:

  • (Boolean)


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

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)


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

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

#following_note(note) ⇒ Object (private)



71
72
73
74
# File 'lib/head_music/style/guidelines/weak_beat_dissonance_treatment.rb', line 71

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| recognized_figure?(note) }.map do |note|
    HeadMusic::Style::Mark.for(note)
  end
end

#melodic_interval_between(first_note, second_note) ⇒ Object (private)



62
63
64
# File 'lib/head_music/style/guidelines/weak_beat_dissonance_treatment.rb', line 62

def melodic_interval_between(first_note, second_note)
  HeadMusic::Analysis::MelodicInterval.new(first_note, second_note)
end

#passing_tone?(note) ⇒ Boolean (private)

Returns:

  • (Boolean)


43
44
45
# File 'lib/head_music/style/guidelines/weak_beat_dissonance_treatment.rb', line 43

def passing_tone?(note)
  stepwise_figure?(note, same_direction: true)
end

#preceding_note(note) ⇒ Object (private)



66
67
68
69
# File 'lib/head_music/style/guidelines/weak_beat_dissonance_treatment.rb', line 66

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

#recognized_figure?(note) ⇒ Boolean (private)

Returns:

  • (Boolean)


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

def recognized_figure?(note)
  passing_tone?(note)
end

#stepwise_figure?(note, same_direction:) ⇒ Boolean (private)

Returns:

  • (Boolean)


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

def stepwise_figure?(note, same_direction:)
  surrounding = surrounding_notes(note)
  return false unless surrounding

  approach = melodic_interval_between(surrounding.first, note)
  departure = melodic_interval_between(note, surrounding.last)
  approach.step? && departure.step? && (approach.direction == departure.direction) == same_direction
end

#surrounding_notes(note) ⇒ Object (private)



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

def surrounding_notes(note)
  prev = preceding_note(note)
  foll = following_note(note)
  [prev, foll] if prev && foll
end

#weak_beat_notesObject (private)



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

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