Class: Deftones::Music::Frequency
- Inherits:
-
Object
- Object
- Deftones::Music::Frequency
- Defined in:
- lib/deftones/music/frequency.rb
Instance Attribute Summary collapse
-
#transport ⇒ Object
readonly
Returns the value of attribute transport.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
- .ftom(value) ⇒ Object
- .mtof(value) ⇒ Object
- .parse(value) ⇒ Object
- .to_midi(value) ⇒ Object
- .to_period(value) ⇒ Object
Instance Method Summary collapse
- #dispose ⇒ Object
- #disposed? ⇒ Boolean
- #from_type(type) ⇒ Object
- #harmonize(intervals) ⇒ Object
-
#initialize(value, transport: Deftones.transport) ⇒ Frequency
constructor
A new instance of Frequency.
- #quantize(subdiv, percent = 1.0) ⇒ Object
- #to_bars_beats_sixteenths ⇒ Object
- #to_frequency ⇒ Object
- #to_hz ⇒ Object
- #to_midi ⇒ Object
- #to_milliseconds ⇒ Object
- #to_notation ⇒ Object
- #to_note ⇒ Object
- #to_s ⇒ Object (also: #toString)
- #to_samples(sample_rate = Deftones.context.sample_rate) ⇒ Object
- #to_seconds ⇒ Object
- #to_ticks ⇒ Object
- #transpose(interval) ⇒ Object
- #value_of ⇒ Object
Constructor Details
Instance Attribute Details
#transport ⇒ Object (readonly)
Returns the value of attribute transport.
6 7 8 |
# File 'lib/deftones/music/frequency.rb', line 6 def transport @transport end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/deftones/music/frequency.rb', line 6 def value @value end |
Class Method Details
.ftom(value) ⇒ Object
103 104 105 |
# File 'lib/deftones/music/frequency.rb', line 103 def ftom(value) Deftones.ftom(value) end |
.mtof(value) ⇒ Object
99 100 101 |
# File 'lib/deftones/music/frequency.rb', line 99 def mtof(value) Deftones.mtof(value) end |
.parse(value) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/deftones/music/frequency.rb', line 107 def parse(value) frequency = case value when Numeric value.to_f when /\A(-?\d+(?:\.\d+)?)hz\z/i Regexp.last_match(1).to_f else Note.to_frequency(value) end raise Deftones::InvalidFrequencyError, "Frequency must be positive" unless frequency.positive? && frequency.finite? frequency end |
.to_midi(value) ⇒ Object
127 128 129 |
# File 'lib/deftones/music/frequency.rb', line 127 def to_midi(value) Note.to_midi(Note.from_frequency(parse(value))) end |
.to_period(value) ⇒ Object
123 124 125 |
# File 'lib/deftones/music/frequency.rb', line 123 def to_period(value) 1.0 / parse(value) end |
Instance Method Details
#dispose ⇒ Object
79 80 81 82 |
# File 'lib/deftones/music/frequency.rb', line 79 def dispose @disposed = true self end |
#disposed? ⇒ Boolean
84 85 86 |
# File 'lib/deftones/music/frequency.rb', line 84 def disposed? @disposed end |
#from_type(type) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/deftones/music/frequency.rb', line 67 def from_type(type) @value = if type.respond_to?(:to_frequency) type.to_frequency elsif type.respond_to?(:value_of) type.value_of else type end self end |
#harmonize(intervals) ⇒ Object
58 59 60 |
# File 'lib/deftones/music/frequency.rb', line 58 def harmonize(intervals) Array(intervals).map { |interval| transpose(interval) } end |
#quantize(subdiv, percent = 1.0) ⇒ Object
62 63 64 65 |
# File 'lib/deftones/music/frequency.rb', line 62 def quantize(subdiv, percent = 1.0) quantized_seconds = UnitHelpers.quantize_seconds(to_seconds, subdiv, transport: transport, percent: percent) 1.0 / [quantized_seconds, 1.0e-6].max end |
#to_bars_beats_sixteenths ⇒ Object
34 35 36 |
# File 'lib/deftones/music/frequency.rb', line 34 def transport.seconds_to_position(to_seconds) end |
#to_frequency ⇒ Object
18 19 20 |
# File 'lib/deftones/music/frequency.rb', line 18 def to_frequency to_hz end |
#to_hz ⇒ Object
14 15 16 |
# File 'lib/deftones/music/frequency.rb', line 14 def to_hz self.class.parse(value) end |
#to_midi ⇒ Object
26 27 28 |
# File 'lib/deftones/music/frequency.rb', line 26 def to_midi self.class.to_midi(value) end |
#to_milliseconds ⇒ Object
38 39 40 |
# File 'lib/deftones/music/frequency.rb', line 38 def to_milliseconds to_seconds * 1000.0 end |
#to_notation ⇒ Object
46 47 48 |
# File 'lib/deftones/music/frequency.rb', line 46 def to_notation UnitHelpers.closest_notation(to_seconds, transport: transport) end |
#to_note ⇒ Object
50 51 52 |
# File 'lib/deftones/music/frequency.rb', line 50 def to_note Note.from_frequency(to_hz) end |
#to_s ⇒ Object Also known as: toString
88 89 90 |
# File 'lib/deftones/music/frequency.rb', line 88 def to_s value.to_s end |
#to_samples(sample_rate = Deftones.context.sample_rate) ⇒ Object
42 43 44 |
# File 'lib/deftones/music/frequency.rb', line 42 def to_samples(sample_rate = Deftones.context.sample_rate) UnitHelpers.samples_for_seconds(to_seconds, sample_rate) end |
#to_seconds ⇒ Object
22 23 24 |
# File 'lib/deftones/music/frequency.rb', line 22 def to_seconds self.class.to_period(value) end |
#to_ticks ⇒ Object
30 31 32 |
# File 'lib/deftones/music/frequency.rb', line 30 def to_ticks transport.seconds_to_ticks(to_seconds) end |
#transpose(interval) ⇒ Object
54 55 56 |
# File 'lib/deftones/music/frequency.rb', line 54 def transpose(interval) self.class.new(Note.from_midi(to_midi + interval.to_i), transport: transport) end |
#value_of ⇒ Object
94 95 96 |
# File 'lib/deftones/music/frequency.rb', line 94 def value_of to_hz end |