Module: Deftones::Event::CallbackBehavior
- Defined in:
- lib/deftones/event/callback_behavior.rb
Instance Attribute Summary collapse
-
#humanize ⇒ Object
Returns the value of attribute humanize.
-
#mute ⇒ Object
Returns the value of attribute mute.
-
#playback_rate ⇒ Object
(also: #playbackRate)
Returns the value of attribute playback_rate.
-
#probability ⇒ Object
Returns the value of attribute probability.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #callback_interval(value) ⇒ Object private
- #callback_permitted? ⇒ Boolean private
- #callback_time(value) ⇒ Object private
- #humanized_time(time) ⇒ Object private
- #initialize_callback_behavior(probability: 1.0, humanize: false, mute: false, playback_rate: 1.0, seed: nil, rng: nil) ⇒ Object private
- #mark_started ⇒ Object private
- #mark_stopped ⇒ Object private
- #mute? ⇒ Boolean
- #playbackRate=(value) ⇒ Object
Instance Attribute Details
#humanize ⇒ Object
Returns the value of attribute humanize.
6 7 8 |
# File 'lib/deftones/event/callback_behavior.rb', line 6 def humanize @humanize end |
#mute ⇒ Object
Returns the value of attribute mute.
6 7 8 |
# File 'lib/deftones/event/callback_behavior.rb', line 6 def mute @mute end |
#playback_rate ⇒ Object Also known as: playbackRate
Returns the value of attribute playback_rate.
6 7 8 |
# File 'lib/deftones/event/callback_behavior.rb', line 6 def playback_rate @playback_rate end |
#probability ⇒ Object
Returns the value of attribute probability.
6 7 8 |
# File 'lib/deftones/event/callback_behavior.rb', line 6 def probability @probability end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
7 8 9 |
# File 'lib/deftones/event/callback_behavior.rb', line 7 def state @state end |
Instance Method Details
#callback_interval(value) ⇒ Object (private)
39 40 41 42 43 |
# File 'lib/deftones/event/callback_behavior.rb', line 39 def callback_interval(value) base = Deftones::Music::Time.parse(value) rate = @playback_rate.zero? ? 1.0 : @playback_rate.abs base / rate end |
#callback_permitted? ⇒ Boolean (private)
49 50 51 52 53 54 55 |
# File 'lib/deftones/event/callback_behavior.rb', line 49 def callback_permitted? return false if @mute return true if @probability >= 1.0 return false if @probability <= 0.0 @rng.rand <= @probability end |
#callback_time(value) ⇒ Object (private)
45 46 47 |
# File 'lib/deftones/event/callback_behavior.rb', line 45 def callback_time(value) Deftones::Music::Time.parse(value) end |
#humanized_time(time) ⇒ Object (private)
57 58 59 60 61 62 |
# File 'lib/deftones/event/callback_behavior.rb', line 57 def humanized_time(time) return time unless @humanize amount = @humanize == true ? 0.01 : Deftones::Music::Time.parse(@humanize) time + (((@rng.rand * 2.0) - 1.0) * amount) end |
#initialize_callback_behavior(probability: 1.0, humanize: false, mute: false, playback_rate: 1.0, seed: nil, rng: nil) ⇒ Object (private)
21 22 23 24 25 26 27 28 29 |
# File 'lib/deftones/event/callback_behavior.rb', line 21 def initialize_callback_behavior(probability: 1.0, humanize: false, mute: false, playback_rate: 1.0, seed: nil, rng: nil) @probability = probability.to_f @humanize = humanize @mute = !!mute @playback_rate = playback_rate.to_f @rng = rng || (seed.nil? ? Random : Random.new(seed)) @state = :stopped end |
#mark_started ⇒ Object (private)
31 32 33 |
# File 'lib/deftones/event/callback_behavior.rb', line 31 def mark_started @state = :started end |
#mark_stopped ⇒ Object (private)
35 36 37 |
# File 'lib/deftones/event/callback_behavior.rb', line 35 def mark_stopped @state = :stopped end |
#mute? ⇒ Boolean
9 10 11 |
# File 'lib/deftones/event/callback_behavior.rb', line 9 def mute? @mute end |
#playbackRate=(value) ⇒ Object
15 16 17 |
# File 'lib/deftones/event/callback_behavior.rb', line 15 def playbackRate=(value) self.playback_rate = value end |