Class: Coltrane::Theory::Pitch
- Inherits:
-
Object
- Object
- Coltrane::Theory::Pitch
- Includes:
- Comparable
- Defined in:
- lib/coltrane/theory/pitch.rb
Overview
It describes a pitch, like E4 or Bb5. It’s like a note, but it has an octave
Instance Attribute Summary collapse
-
#integer ⇒ Object
(also: #hash, #midi)
readonly
Returns the value of attribute integer.
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?, #eq)
- #frequency ⇒ Object
-
#initialize(notation_arg = nil, note: nil, octave: nil, notation: nil, frequency: nil) ⇒ Pitch
constructor
A new instance of Pitch.
- #octave ⇒ Object
- #pitch_class ⇒ Object
- #scientific_notation ⇒ Object (also: #notation, #name, #to_s)
Constructor Details
#initialize(notation_arg = nil, note: nil, octave: nil, notation: nil, frequency: nil) ⇒ Pitch
Returns a new instance of Pitch.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/coltrane/theory/pitch.rb', line 10 def initialize(notation_arg = nil, note: nil, octave: nil, notation: nil, frequency: nil) @integer = begin if (n = notation_arg || notation) n.is_a?(Integer) ? n : integer_from_notation(n) elsif note && octave integer_from_note_and_octave(Note[note], octave) elsif frequency integer_from_frequency(frequency) else raise(InvalidArgumentsError) end end end |
Instance Attribute Details
#integer ⇒ Object (readonly) Also known as: hash, midi
Returns the value of attribute integer.
8 9 10 |
# File 'lib/coltrane/theory/pitch.rb', line 8 def integer @integer end |
Class Method Details
.[](*args) ⇒ Object
29 30 31 |
# File 'lib/coltrane/theory/pitch.rb', line 29 def self.[](*args) new *args end |
Instance Method Details
#+(other) ⇒ Object
67 68 69 70 71 |
# File 'lib/coltrane/theory/pitch.rb', line 67 def +(other) case other when Integer then Pitch[integer + other] end end |
#-(other) ⇒ Object
73 74 75 76 77 |
# File 'lib/coltrane/theory/pitch.rb', line 73 def -(other) case other when Integer then Pitch[integer - other] end end |
#<=>(other) ⇒ Object
33 34 35 |
# File 'lib/coltrane/theory/pitch.rb', line 33 def <=>(other) integer <=> other.integer end |
#==(other) ⇒ Object Also known as: eql?, eq
56 57 58 |
# File 'lib/coltrane/theory/pitch.rb', line 56 def ==(other) integer == other.integer end |
#frequency ⇒ Object
60 61 62 |
# File 'lib/coltrane/theory/pitch.rb', line 60 def frequency pitch_class.frequency.octave(octave) end |
#octave ⇒ Object
45 46 47 |
# File 'lib/coltrane/theory/pitch.rb', line 45 def octave (integer / 12) - 1 end |
#pitch_class ⇒ Object
41 42 43 |
# File 'lib/coltrane/theory/pitch.rb', line 41 def pitch_class PitchClass[integer] end |
#scientific_notation ⇒ Object Also known as: notation, name, to_s
37 38 39 |
# File 'lib/coltrane/theory/pitch.rb', line 37 def scientific_notation "#{pitch_class}#{octave}" end |