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.



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



22
23
24
25
26
27
28
# 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?

  name_sym = name.to_sym
  fetch_or_register(name_sym, name) if LEVELS.include?(name_sym)
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