Class: Coltrane::Theory::Frequency
- Inherits:
-
Object
- Object
- Coltrane::Theory::Frequency
show all
- Defined in:
- lib/coltrane/theory/frequency.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(frequency) ⇒ Frequency
Returns a new instance of Frequency.
8
9
10
|
# File 'lib/coltrane/theory/frequency.rb', line 8
def initialize(frequency)
@frequency = frequency.to_f
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
47
48
49
|
# File 'lib/coltrane/theory/frequency.rb', line 47
def method_missing(method, *args)
Frequency[frequency.send(method, args[0].to_f)]
end
|
Instance Attribute Details
#frequency ⇒ Object
Returns the value of attribute frequency.
6
7
8
|
# File 'lib/coltrane/theory/frequency.rb', line 6
def frequency
@frequency
end
|
Instance Method Details
#/(other) ⇒ Object
40
41
42
43
44
45
|
# File 'lib/coltrane/theory/frequency.rb', line 40
def /(other)
case other
when Frequency then FrequencyInterval[1200 * Math.log2(other.frequency / frequency)]
when Numeric then Frequency[frequency / other]
end
end
|
#==(other) ⇒ Object
28
29
30
|
# File 'lib/coltrane/theory/frequency.rb', line 28
def ==(other)
frequency == (other.is_a?(Frequency) ? other.frequency : other)
end
|
#octave(n) ⇒ Object
24
25
26
|
# File 'lib/coltrane/theory/frequency.rb', line 24
def octave(n)
Frequency[frequency * 2**n]
end
|
#octave_down(n = 1) ⇒ Object
36
37
38
|
# File 'lib/coltrane/theory/frequency.rb', line 36
def octave_down(n = 1)
octave(-n)
end
|
#octave_up(n = 1) ⇒ Object
32
33
34
|
# File 'lib/coltrane/theory/frequency.rb', line 32
def octave_up(n = 1)
octave(n)
end
|
#to_f ⇒ Object
20
21
22
|
# File 'lib/coltrane/theory/frequency.rb', line 20
def to_f
frequency
end
|
#to_s ⇒ Object
16
17
18
|
# File 'lib/coltrane/theory/frequency.rb', line 16
def to_s
"#{frequency}hz"
end
|