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

PERFECT_CONSONANCE =
:perfect_consonance
IMPERFECT_CONSONANCE =
:imperfect_consonance
CONTEXTUAL =
:contextual
MILD_DISSONANCE =
:mild_dissonance
HARSH_DISSONANCE =
:harsh_dissonance
DISSONANCE =
:dissonance
LEVELS =
[
  PERFECT_CONSONANCE,
  IMPERFECT_CONSONANCE,
  CONTEXTUAL,
  MILD_DISSONANCE,
  HARSH_DISSONANCE,
  DISSONANCE
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Consonance

Returns a new instance of Consonance.



35
36
37
# File 'lib/head_music/rudiment/consonance.rb', line 35

def initialize(name)
  @name = name.to_s.to_sym
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



31
32
33
# File 'lib/head_music/rudiment/consonance.rb', line 31

def name
  @name
end

Class Method Details

.get(name) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/head_music/rudiment/consonance.rb', line 22

def self.get(name)
  return name if name.is_a?(self)
  return nil if name.nil?

  @consonances ||= {}
  name_sym = name.to_sym
  @consonances[name_sym] ||= new(name) if LEVELS.include?(name_sym)
end

Instance Method Details

#==(other) ⇒ Object



39
40
41
# File 'lib/head_music/rudiment/consonance.rb', line 39

def ==(other)
  to_s == other.to_s
end

#consonant?Boolean

Check if this represents a consonance (perfect or imperfect)

Returns:

  • (Boolean)


44
45
46
# File 'lib/head_music/rudiment/consonance.rb', line 44

def consonant?
  [PERFECT_CONSONANCE, IMPERFECT_CONSONANCE].include?(name)
end

#contextual?Boolean

Contextual is special - neither strictly consonant nor dissonant

Returns:

  • (Boolean)


54
55
56
# File 'lib/head_music/rudiment/consonance.rb', line 54

def contextual?
  name == CONTEXTUAL
end

#dissonant?Boolean

Check if this represents any form of dissonance

Returns:

  • (Boolean)


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

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