Class: Coltrane::Theory::Voicing
- Inherits:
-
Object
- Object
- Coltrane::Theory::Voicing
- Defined in:
- lib/coltrane/theory/voicing.rb
Overview
This class describes an actual implementation of a Chord, being aware of exact octaves of each pitch and even repeating pitches across octaves.
Instance Attribute Summary collapse
-
#pitches ⇒ Object
readonly
Returns the value of attribute pitches.
Class Method Summary collapse
Instance Method Summary collapse
- #chord ⇒ Object
- #discontinuity ⇒ Object
- #frequencies ⇒ Object
-
#initialize(*pitch_strings, pitches: nil) ⇒ Voicing
constructor
A new instance of Voicing.
- #pitch_classes ⇒ Object (also: #notes)
Constructor Details
#initialize(*pitch_strings, pitches: nil) ⇒ Voicing
Returns a new instance of Voicing.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/coltrane/theory/voicing.rb', line 11 def initialize(*pitch_strings, pitches: nil) @pitches = begin if pitch_strings.any? pitch_strings.map { |s| Pitch[s] } elsif pitches pitches else raise WrongArgumentsError end end.sort end |
Instance Attribute Details
#pitches ⇒ Object (readonly)
Returns the value of attribute pitches.
9 10 11 |
# File 'lib/coltrane/theory/voicing.rb', line 9 def pitches @pitches end |
Class Method Details
.[](*args) ⇒ Object
23 24 25 |
# File 'lib/coltrane/theory/voicing.rb', line 23 def self.[](*args) new(*args) end |
Instance Method Details
#chord ⇒ Object
33 34 35 36 37 |
# File 'lib/coltrane/theory/voicing.rb', line 33 def chord @chord ||= Chord.new(notes: notes) rescue ChordNotFoundError return false end |
#discontinuity ⇒ Object
43 44 45 46 47 48 |
# File 'lib/coltrane/theory/voicing.rb', line 43 def discontinuity frequencies.each_with_index.reduce(0) do |max_dist, (freq, index)| next 0 if index.zero? [max_dist, freq.to_f - frequencies[index - 1].to_f].max end end |
#frequencies ⇒ Object
39 40 41 |
# File 'lib/coltrane/theory/voicing.rb', line 39 def frequencies @frequencies ||= pitches.map(&:frequency) end |
#pitch_classes ⇒ Object Also known as: notes
27 28 29 |
# File 'lib/coltrane/theory/voicing.rb', line 27 def pitch_classes NoteSet[*pitches.map(&:pitch_class).uniq] end |