Class: HeadMusic::Rudiment::Consonance
- Defined in:
- lib/head_music/rudiment/consonance.rb
Overview
Consonance describes a category or degree of harmonic pleasantness
Constant Summary collapse
- LEVELS =
Detailed categories aligned with music theory
%w[ perfect_consonance imperfect_consonance contextual mild_dissonance harsh_dissonance dissonance ].freeze
- PERFECT_CONSONANCE =
Constants for each consonance level
:perfect_consonance- IMPERFECT_CONSONANCE =
:imperfect_consonance- CONTEXTUAL =
:contextual- MILD_DISSONANCE =
:mild_dissonance- HARSH_DISSONANCE =
:harsh_dissonance- DISSONANCE =
:dissonance
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#consonant? ⇒ Boolean
Check if this represents a consonance (perfect or imperfect).
-
#contextual? ⇒ Boolean
Contextual is special - neither strictly consonant nor dissonant.
-
#dissonant? ⇒ Boolean
Check if this represents any form of dissonance.
-
#initialize(name) ⇒ Consonance
constructor
A new instance of Consonance.
Constructor Details
#initialize(name) ⇒ Consonance
Returns a new instance of Consonance.
34 35 36 |
# File 'lib/head_music/rudiment/consonance.rb', line 34 def initialize(name) @name = name.to_s.to_sym end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
30 31 32 |
# File 'lib/head_music/rudiment/consonance.rb', line 30 def name @name end |
Class Method Details
.get(name) ⇒ Object
24 25 26 27 28 |
# File 'lib/head_music/rudiment/consonance.rb', line 24 def self.get(name) @consonances ||= {} name_sym = name.to_sym @consonances[name_sym] ||= new(name) if LEVELS.include?(name.to_s) end |
Instance Method Details
#==(other) ⇒ Object
38 39 40 |
# File 'lib/head_music/rudiment/consonance.rb', line 38 def ==(other) to_s == other.to_s end |
#consonant? ⇒ Boolean
Check if this represents a consonance (perfect or imperfect)
43 44 45 |
# File 'lib/head_music/rudiment/consonance.rb', line 43 def consonant? [PERFECT_CONSONANCE, IMPERFECT_CONSONANCE].include?(name) end |
#contextual? ⇒ Boolean
Contextual is special - neither strictly consonant nor dissonant
53 54 55 |
# File 'lib/head_music/rudiment/consonance.rb', line 53 def contextual? name == CONTEXTUAL end |
#dissonant? ⇒ Boolean
Check if this represents any form of dissonance
48 49 50 |
# File 'lib/head_music/rudiment/consonance.rb', line 48 def dissonant? [MILD_DISSONANCE, HARSH_DISSONANCE, DISSONANCE].include?(name) end |