Class: HeadMusic::Rudiment::Consonance

Inherits:
Base
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject (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)

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


48
49
50
# File 'lib/head_music/rudiment/consonance.rb', line 48

def dissonant?
  [MILD_DISSONANCE, HARSH_DISSONANCE, DISSONANCE].include?(name)
end