Class: Stave::Theory::Note
Overview
rubocop:disable Metrics/ClassLength
Defined Under Namespace
Classes: PitchClass
Instance Attribute Summary
Attributes inherited from Core::Lookup
#variant
Class Method Summary
collapse
Instance Method Summary
collapse
#==, each_key, find_by, #initialize, keys, string_keys, variant, variant?, variant_lookup, variants, where, with_options
Class Method Details
.circle_of_fifths ⇒ Object
241
242
243
|
# File 'lib/stave/theory/note.rb', line 241
def self.circle_of_fifths
where(circle_of_fifths?: true)
end
|
.double_flats ⇒ Object
217
218
219
|
# File 'lib/stave/theory/note.rb', line 217
def self.double_flats
where(accidental: Accidental.double_flat)
end
|
.double_sharps ⇒ Object
233
234
235
|
# File 'lib/stave/theory/note.rb', line 233
def self.double_sharps
where(accidental: Accidental.double_sharp)
end
|
.flats ⇒ Object
221
222
223
|
# File 'lib/stave/theory/note.rb', line 221
def self.flats
where(accidental: Accidental.flat)
end
|
.naturals ⇒ Object
225
226
227
|
# File 'lib/stave/theory/note.rb', line 225
def self.naturals
where(accidental: Accidental.natural)
end
|
.sharps ⇒ Object
229
230
231
|
# File 'lib/stave/theory/note.rb', line 229
def self.sharps
where(accidental: Accidental.sharp)
end
|
.single_accidental ⇒ Object
237
238
239
|
# File 'lib/stave/theory/note.rb', line 237
def self.single_accidental
flats + naturals + sharps
end
|
Instance Method Details
#+(other) ⇒ Object
182
183
184
185
186
187
188
|
# File 'lib/stave/theory/note.rb', line 182
def +(other)
case other
when Interval then note_above(other)
when Integer then Note.find_by(to_i: (to_i + other) % 12)
else raise
end
end
|
#-(other) ⇒ Object
190
191
192
193
194
195
196
|
# File 'lib/stave/theory/note.rb', line 190
def -(other)
case other
when Interval then note_below(other)
when Integer then Note.find_by(to_i: (to_i - other) % 12)
else raise
end
end
|
#note_above(interval) ⇒ Object
206
207
208
209
210
211
|
# File 'lib/stave/theory/note.rb', line 206
def note_above(interval)
target_pitch_class = pitch_class + interval.number.offset
target_integer = (to_i + interval.to_i) % 12
Note.find_by(pitch_class: target_pitch_class, to_i: target_integer)
end
|
#note_below(interval) ⇒ Object
213
214
215
|
# File 'lib/stave/theory/note.rb', line 213
def note_below(interval)
note_above(interval.invert!)
end
|
#symbol ⇒ Object
198
199
200
|
# File 'lib/stave/theory/note.rb', line 198
def symbol
"#{pitch_class.symbol}#{accidental.symbol}"
end
|
#to_i ⇒ Object
202
203
204
|
# File 'lib/stave/theory/note.rb', line 202
def to_i
(pitch_class.to_i + accidental.transform) % 12
end
|