Class: Xi::Stream
Direct Known Subclasses
Constant Summary collapse
Instance Attribute Summary collapse
-
#clock ⇒ Object
Returns the value of attribute clock.
-
#delta ⇒ Object
Returns the value of attribute delta.
-
#gate ⇒ Object
Returns the value of attribute gate.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
-
#initialize(name, clock, **opts) ⇒ Stream
constructor
A new instance of Stream.
- #inspect ⇒ Object
- #notify(now, cps) ⇒ Object
- #play ⇒ Object (also: #start, #pause)
- #playing? ⇒ Boolean
- #set(delta: nil, gate: nil, **source) ⇒ Object (also: #call)
- #stop ⇒ Object
- #stopped? ⇒ Boolean
Constructor Details
#initialize(name, clock, **opts) ⇒ Stream
Returns a new instance of Stream.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/xi/stream.rb', line 16 def initialize(name, clock, **opts) Array(opts.delete(:include)).each { |m| include_mixin(m) } @name = name.to_sym @opts = opts @mutex = Mutex.new @playing = false @last_sound_object_id = 0 @state = {} @changed_params = [].to_set @playing_sound_objects = {} @prev_ts = {} @prev_delta = {} self.clock = clock end |
Instance Attribute Details
#clock ⇒ Object
Returns the value of attribute clock.
6 7 8 |
# File 'lib/xi/stream.rb', line 6 def clock @clock end |
#delta ⇒ Object
Returns the value of attribute delta.
6 7 8 |
# File 'lib/xi/stream.rb', line 6 def delta @delta end |
#gate ⇒ Object
Returns the value of attribute gate.
6 7 8 |
# File 'lib/xi/stream.rb', line 6 def gate @gate end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
6 7 8 |
# File 'lib/xi/stream.rb', line 6 def opts @opts end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
6 7 8 |
# File 'lib/xi/stream.rb', line 6 def source @source end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
6 7 8 |
# File 'lib/xi/stream.rb', line 6 def state @state end |
Instance Method Details
#inspect ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/xi/stream.rb', line 97 def inspect "#<#{self.class.name} :#{@name} " \ "#{ ? :playing : :stopped} at #{@clock.cps}cps" \ "#{" #{@opts}" if @opts.any?}>" rescue => err error(err) end |
#notify(now, cps) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/xi/stream.rb', line 105 def notify(now, cps) return unless && @source @mutex.synchronize do @changed_params.clear update_all_state if @reset gate_off = gate_off_old_sound_objects(now) gate_on = play_enums(now, cps) # Call hooks do_gate_off_change(gate_off) unless gate_off.empty? do_state_change if state_changed? do_gate_on_change(gate_on) unless gate_on.empty? end end |
#play ⇒ Object Also known as: start, pause
76 77 78 79 80 81 82 |
# File 'lib/xi/stream.rb', line 76 def play @mutex.synchronize do @playing = true @clock.subscribe(self) end self end |
#playing? ⇒ Boolean
68 69 70 |
# File 'lib/xi/stream.rb', line 68 def @mutex.synchronize { @playing } end |
#set(delta: nil, gate: nil, **source) ⇒ Object Also known as: call
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/xi/stream.rb', line 34 def set(delta: nil, gate: nil, **source) @mutex.synchronize do remove_parameters_from_prev_source(source) @source = source @gate = gate || parameter_with_smallest_delta(source) @delta = delta if delta @reset = true unless @playing update_internal_structures end play self end |
#stop ⇒ Object
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/xi/stream.rb', line 85 def stop @mutex.synchronize do @playing = false @state.clear @prev_ts.clear @prev_delta.clear @clock.unsubscribe(self) end self end |
#stopped? ⇒ Boolean
72 73 74 |
# File 'lib/xi/stream.rb', line 72 def stopped? ! end |