Class: Coltrane::Theory::Note
Overview
Notes are different ways of calling pitch classes. In the context of equal tempered scales, they’re more like a conceptual subject for matters of convention than an actual thing.
Take for example A# and Bb. Those are different notes. Nevertheless, in the context of equal tempered scales they represent pretty much the same frequency.
The theory of notes have changed too much in the course of time, which lead us with a lot of conventions and strategies when dealing with music. That’s what this class is for.
Constant Summary
collapse
- ALTERATIONS =
{
'b' => -1,
'#' => +1
}.freeze
Constants inherited
from PitchClass
PitchClass::NOTATION
Instance Attribute Summary collapse
Attributes inherited from PitchClass
#integer
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from PitchClass
#<=>, #==, #accidental?, all, all_letters, #ascending_interval_to, #descending_interval_to, #enharmonic?, #fundamental_frequency, #letter, #pretty_name, size, #size, #true_notation
Constructor Details
#initialize(arg) ⇒ Note
Returns a new instance of Note.
Instance Attribute Details
#alteration ⇒ Object
Returns the value of attribute alteration.
17
18
19
|
# File 'lib/coltrane/theory/note.rb', line 17
def alteration
@alteration
end
|
Class Method Details
.[](arg) ⇒ Object
42
43
44
|
# File 'lib/coltrane/theory/note.rb', line 42
def self.[](arg)
new(arg)
end
|
Instance Method Details
#+(other) ⇒ Object
94
95
96
|
# File 'lib/coltrane/theory/note.rb', line 94
def +(other)
super(other).yield_self { |r| r.is_a?(Note) ? r.alter(alteration) : r }
end
|
#-(other) ⇒ Object
90
91
92
|
# File 'lib/coltrane/theory/note.rb', line 90
def -(other)
super(other).yield_self { |r| r.is_a?(Note) ? r.alter(alteration) : r }
end
|
#accidents ⇒ Object
86
87
88
|
# File 'lib/coltrane/theory/note.rb', line 86
def accidents
(@alteration > 0 ? '#' : 'b') * alteration.abs
end
|
#alter(x) ⇒ Object
62
63
64
|
# File 'lib/coltrane/theory/note.rb', line 62
def alter(x)
Note.new(name).tap { |n| n.alteration = x }
end
|
#as(letter) ⇒ Object
98
99
100
101
|
# File 'lib/coltrane/theory/note.rb', line 98
def as(letter)
a = (Note[letter] - self)
alter([a.semitones, -(-a).semitones].min_by(&:abs))
end
|
#base_pitch_class ⇒ Object
50
51
52
|
# File 'lib/coltrane/theory/note.rb', line 50
def base_pitch_class
PitchClass[integer - alteration]
end
|
#double_flat? ⇒ Boolean
78
79
80
|
# File 'lib/coltrane/theory/note.rb', line 78
def double_flat?
alteration == -2
end
|
#double_sharp? ⇒ Boolean
70
71
72
|
# File 'lib/coltrane/theory/note.rb', line 70
def double_sharp?
alteration == 2
end
|
#flat? ⇒ Boolean
74
75
76
|
# File 'lib/coltrane/theory/note.rb', line 74
def flat?
alteration == -1
end
|
#name ⇒ Object
46
47
48
|
# File 'lib/coltrane/theory/note.rb', line 46
def name
"#{base_pitch_class}#{accidents}".gsub(/#b|b#/, '')
end
|
#natural? ⇒ Boolean
82
83
84
|
# File 'lib/coltrane/theory/note.rb', line 82
def natural?
alteration == 0
end
|
#pitch_class ⇒ Object
54
55
56
|
# File 'lib/coltrane/theory/note.rb', line 54
def pitch_class
PitchClass.new(self)
end
|
#sharp? ⇒ Boolean
66
67
68
|
# File 'lib/coltrane/theory/note.rb', line 66
def sharp?
alteration == 1
end
|