Class: Coltrane::Theory::Pitch
- Inherits:
-
Object
- Object
- Coltrane::Theory::Pitch
- 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 (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.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/coltrane/theory/pitch.rb', line 9 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.
7 8 9 |
# File 'lib/coltrane/theory/pitch.rb', line 7 def integer @integer end |
Class Method Details
.[](*args) ⇒ Object
28 29 30 |
# File 'lib/coltrane/theory/pitch.rb', line 28 def self.[](*args) new *args end |
Instance Method Details
#+(other) ⇒ Object
62 63 64 65 66 |
# File 'lib/coltrane/theory/pitch.rb', line 62 def +(other) case other when Integer then Pitch[integer + other] end end |
#-(other) ⇒ Object
68 69 70 71 72 |
# File 'lib/coltrane/theory/pitch.rb', line 68 def -(other) case other when Integer then Pitch[integer - other] end end |
#==(other) ⇒ Object Also known as: eql?, eq
51 52 53 |
# File 'lib/coltrane/theory/pitch.rb', line 51 def ==(other) integer == other.integer end |
#frequency ⇒ Object
55 56 57 |
# File 'lib/coltrane/theory/pitch.rb', line 55 def frequency pitch_class.frequency.octave(octave) end |
#octave ⇒ Object
40 41 42 |
# File 'lib/coltrane/theory/pitch.rb', line 40 def octave (integer / 12) - 1 end |
#pitch_class ⇒ Object
36 37 38 |
# File 'lib/coltrane/theory/pitch.rb', line 36 def pitch_class PitchClass[integer] end |
#scientific_notation ⇒ Object Also known as: notation, name, to_s
32 33 34 |
# File 'lib/coltrane/theory/pitch.rb', line 32 def scientific_notation "#{pitch_class}#{octave}" end |