Class: Coltrane::Interval
- Inherits:
-
Object
- Object
- Coltrane::Interval
- Defined in:
- lib/coltrane/interval.rb
Overview
Interval describe the logarithmic distance between 2 frequencies. It’s measured in cents.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cents ⇒ Object
(also: #hash)
readonly
Returns the value of attribute cents.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #ascending? ⇒ Boolean
- #descending? ⇒ Boolean
-
#initialize(cents) ⇒ Interval
constructor
A new instance of Interval.
- #semitones ⇒ Object
Constructor Details
#initialize(cents) ⇒ Interval
Returns a new instance of Interval.
13 14 15 |
# File 'lib/coltrane/interval.rb', line 13 def initialize(cents) @cents = cents.round end |
Instance Attribute Details
#cents ⇒ Object (readonly) Also known as: hash
Returns the value of attribute cents.
7 8 9 |
# File 'lib/coltrane/interval.rb', line 7 def cents @cents end |
Instance Method Details
#+(other) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/coltrane/interval.rb', line 36 def +(other) case other when Numeric then Interval[cents + other] when Interval then Interval[cents + other.cents] end end |
#-(other) ⇒ Object
43 44 45 46 47 48 |
# File 'lib/coltrane/interval.rb', line 43 def -(other) case other when Numeric then Interval[cents - other] when Interval then Interval[cents - other.cents] end end |
#==(other) ⇒ Object Also known as: eql?
29 30 31 |
# File 'lib/coltrane/interval.rb', line 29 def ==(other) cents == other.cents end |
#ascending? ⇒ Boolean
21 22 23 |
# File 'lib/coltrane/interval.rb', line 21 def ascending? cents < 0 end |
#descending? ⇒ Boolean
25 26 27 |
# File 'lib/coltrane/interval.rb', line 25 def descending? cents > 0 end |
#semitones ⇒ Object
17 18 19 |
# File 'lib/coltrane/interval.rb', line 17 def semitones (cents.to_f / 100).round end |