Class: Deftones::Event::Loop
- Inherits:
-
Object
- Object
- Deftones::Event::Loop
- Includes:
- CallbackBehavior
- Defined in:
- lib/deftones/event/loop.rb
Instance Attribute Summary collapse
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#iterations ⇒ Object
readonly
Returns the value of attribute iterations.
Attributes included from CallbackBehavior
#humanize, #mute, #playback_rate, #probability, #state
Instance Method Summary collapse
- #cancel ⇒ Object
- #dispose ⇒ Object
-
#initialize(interval:, iterations: nil, transport: Deftones.transport, probability: 1.0, humanize: false, mute: false, playback_rate: 1.0, seed: nil, rng: nil, &callback) ⇒ Loop
constructor
A new instance of Loop.
- #start(time = 0) ⇒ Object
- #stop(_time = nil) ⇒ Object
Methods included from CallbackBehavior
#callback_interval, #callback_permitted?, #callback_time, #humanized_time, #initialize_callback_behavior, #mark_started, #mark_stopped, #mute?, #playbackRate=
Constructor Details
#initialize(interval:, iterations: nil, transport: Deftones.transport, probability: 1.0, humanize: false, mute: false, playback_rate: 1.0, seed: nil, rng: nil, &callback) ⇒ Loop
Returns a new instance of Loop.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/deftones/event/loop.rb', line 10 def initialize(interval:, iterations: nil, transport: Deftones.transport, probability: 1.0, humanize: false, mute: false, playback_rate: 1.0, seed: nil, rng: nil, &callback) raise ArgumentError, "callback is required" unless callback @interval = interval @iterations = iterations @transport = transport @callback = callback @event_id = nil initialize_callback_behavior( probability: probability, humanize: humanize, mute: mute, playback_rate: playback_rate, seed: seed, rng: rng ) end |
Instance Attribute Details
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
8 9 10 |
# File 'lib/deftones/event/loop.rb', line 8 def interval @interval end |
#iterations ⇒ Object (readonly)
Returns the value of attribute iterations.
8 9 10 |
# File 'lib/deftones/event/loop.rb', line 8 def iterations @iterations end |
Instance Method Details
#cancel ⇒ Object
46 47 48 49 50 51 |
# File 'lib/deftones/event/loop.rb', line 46 def cancel @transport.cancel(event_id: @event_id) if @event_id @event_id = nil mark_stopped self end |
#dispose ⇒ Object
53 54 55 |
# File 'lib/deftones/event/loop.rb', line 53 def dispose cancel end |
#start(time = 0) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/deftones/event/loop.rb', line 30 def start(time = 0) count = 0 scaled_interval = callback_interval(@interval) duration = @iterations ? (scaled_interval * (@iterations - 1)) : nil @event_id = @transport.schedule_repeat(scaled_interval, start_time: time, duration: duration) do |scheduled_time| @callback.call(humanized_time(scheduled_time)) if callback_permitted? count += 1 end mark_started self end |
#stop(_time = nil) ⇒ Object
42 43 44 |
# File 'lib/deftones/event/loop.rb', line 42 def stop(_time = nil) cancel end |