Class: Coltrane::Theory::Voicing

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*pitch_strings, pitches: nil) ⇒ Voicing

Returns a new instance of Voicing.



10
11
12
13
14
15
16
17
18
# File 'lib/coltrane/theory/voicing.rb', line 10

def initialize(*pitch_strings, pitches: nil)
  @pitches = if pitch_strings.any?
               pitch_strings.map { |s| Pitch[s] }
             elsif pitches
               pitches
             else
               raise WrongArgumentsError
             end
end

Instance Attribute Details

#pitchesObject (readonly)

Returns the value of attribute pitches.



8
9
10
# File 'lib/coltrane/theory/voicing.rb', line 8

def pitches
  @pitches
end

Class Method Details

.[](*args) ⇒ Object



20
21
22
# File 'lib/coltrane/theory/voicing.rb', line 20

def self.[](*args)
  new(*args)
end

Instance Method Details

#chordObject



30
31
32
33
34
# File 'lib/coltrane/theory/voicing.rb', line 30

def chord
  @chord ||= Chord.new(notes: notes)
rescue ChordNotFoundError
  return false
end

#frequenciesObject



36
37
38
# File 'lib/coltrane/theory/voicing.rb', line 36

def frequencies
  pitches.map(&:frequency)
end

#pitch_classesObject Also known as: notes



24
25
26
# File 'lib/coltrane/theory/voicing.rb', line 24

def pitch_classes
  NoteSet[*pitches.map(&:pitch_class).uniq]
end