Class: Deftones::Music::Ticks
- Inherits:
-
Object
- Object
- Deftones::Music::Ticks
- Defined in:
- lib/deftones/music/ticks.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
Instance Method Summary collapse
- #dispose ⇒ Object
- #disposed? ⇒ Boolean
- #from_type(type) ⇒ Object
-
#initialize(value, transport: Deftones.transport) ⇒ Ticks
constructor
A new instance of Ticks.
- #quantize(subdiv, percent = 1.0) ⇒ Object
- #to_bars_beats_sixteenths ⇒ Object
- #to_frequency ⇒ Object
- #to_i ⇒ Object
- #to_midi ⇒ Object
- #to_milliseconds ⇒ Object
- #to_notation ⇒ Object
- #to_s ⇒ Object (also: #toString)
- #to_samples(sample_rate = Deftones.context.sample_rate) ⇒ Object
- #to_seconds ⇒ Object
- #to_ticks ⇒ 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/ticks.rb', line 6 def transport @transport end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
6 7 8 |
# File 'lib/deftones/music/ticks.rb', line 6 def value @value end |
Class Method Details
.parse(value, bpm: Deftones.transport.bpm, time_signature: Deftones.transport.time_signature, ppq: Deftones.transport.ppq) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/deftones/music/ticks.rb', line 92 def parse(value, bpm: Deftones.transport.bpm, time_signature: Deftones.transport.time_signature, ppq: Deftones.transport.ppq) return value.to_f if value.is_a?(Numeric) string_value = value.to_s direct_ticks = string_value.match(/\A(-?\d+(?:\.\d+)?)i\z/i) return direct_ticks[1].to_f if direct_ticks seconds = Time.parse(value, bpm: bpm, time_signature: time_signature, ppq: ppq) (seconds / (60.0 / bpm.to_f)) * ppq.to_f end |
Instance Method Details
#dispose ⇒ Object
72 73 74 75 |
# File 'lib/deftones/music/ticks.rb', line 72 def dispose @disposed = true self end |
#disposed? ⇒ Boolean
77 78 79 |
# File 'lib/deftones/music/ticks.rb', line 77 def disposed? @disposed end |
#from_type(type) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/deftones/music/ticks.rb', line 60 def from_type(type) @value = if type.respond_to?(:to_ticks) type.to_ticks elsif type.respond_to?(:value_of) type.value_of else type end self end |
#quantize(subdiv, percent = 1.0) ⇒ Object
55 56 57 58 |
# File 'lib/deftones/music/ticks.rb', line 55 def quantize(subdiv, percent = 1.0) quantized_seconds = UnitHelpers.quantize_seconds(to_seconds, subdiv, transport: transport, percent: percent) transport.seconds_to_ticks(quantized_seconds).round end |
#to_bars_beats_sixteenths ⇒ Object
31 32 33 |
# File 'lib/deftones/music/ticks.rb', line 31 def transport.seconds_to_position(to_seconds) end |
#to_frequency ⇒ Object
35 36 37 |
# File 'lib/deftones/music/ticks.rb', line 35 def to_frequency 1.0 / [to_seconds, 1.0e-6].max end |
#to_i ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/deftones/music/ticks.rb', line 14 def to_i self.class.parse( value, bpm: transport.bpm, time_signature: transport.time_signature, ppq: transport.ppq ).round end |
#to_midi ⇒ Object
39 40 41 |
# File 'lib/deftones/music/ticks.rb', line 39 def to_midi Note.to_midi(Note.from_frequency(to_frequency)) end |
#to_milliseconds ⇒ Object
43 44 45 |
# File 'lib/deftones/music/ticks.rb', line 43 def to_milliseconds to_seconds * 1000.0 end |
#to_notation ⇒ Object
51 52 53 |
# File 'lib/deftones/music/ticks.rb', line 51 def to_notation UnitHelpers.closest_notation(to_seconds, transport: transport) end |
#to_s ⇒ Object Also known as: toString
81 82 83 |
# File 'lib/deftones/music/ticks.rb', line 81 def to_s value.to_s end |
#to_samples(sample_rate = Deftones.context.sample_rate) ⇒ Object
47 48 49 |
# File 'lib/deftones/music/ticks.rb', line 47 def to_samples(sample_rate = Deftones.context.sample_rate) UnitHelpers.samples_for_seconds(to_seconds, sample_rate) end |
#to_seconds ⇒ Object
23 24 25 |
# File 'lib/deftones/music/ticks.rb', line 23 def to_seconds transport.ticks_to_seconds(to_i) end |
#to_ticks ⇒ Object
27 28 29 |
# File 'lib/deftones/music/ticks.rb', line 27 def to_ticks to_i end |
#value_of ⇒ Object
87 88 89 |
# File 'lib/deftones/music/ticks.rb', line 87 def value_of to_i end |