Class: AudioStream::AudioObservableFxBus
Instance Method Summary
collapse
#fx, #mono, #notify_complete, #notify_next, #send_to, #stereo, #subscribe, #subscribe_on_next
Constructor Details
Returns a new instance of AudioObservableFxBus.
6
7
8
9
10
11
|
# File 'lib/audio_stream/audio_observable_fx_bus.rb', line 6
def initialize(effector)
@effector = effector
@mutex = Mutex.new
@observable_keys = {}
@notifications = {}
end
|
Instance Method Details
#connect_observable(key, observable) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/audio_stream/audio_observable_fx_bus.rb', line 13
def connect_observable(key, observable)
@mutex.synchronize {
if !@effector.audio_input_keys.include?(key)
raise Error.new("audio input key is not registed: %s => %s", @effector.class.name, key)
end
@observable_keys.select {|obs, key1|
key1==key
}.each {|obs, key1|
obs.delete_observer(self)
@observable_keys.delete(obs)
}
@observable_keys[observable] = key
observable.add_observer(self)
}
end
|
#on_complete ⇒ Object
72
73
74
|
# File 'lib/audio_stream/audio_observable_fx_bus.rb', line 72
def on_complete
notify_complete
end
|
#on_next(inputs) ⇒ Object
67
68
69
70
|
# File 'lib/audio_stream/audio_observable_fx_bus.rb', line 67
def on_next(inputs)
output = @effector.process(inputs)
notify_next(output)
end
|
#update(notification) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/audio_stream/audio_observable_fx_bus.rb', line 33
def update(notification)
do_notify = false
is_completed = false
next_inputs = nil
@mutex.synchronize {
@notifications[notification.caller_obj] = notification
if @notifications.length==@observable_keys.length
next_inputs = {}
@notifications.each {|caller_obj, notification|
key = @observable_keys[notification.caller_obj]
case notification.stat
when AudioNotification::STAT_NEXT
next_inputs[key] = notification.input
when AudioNotification::STAT_COMPLETE
is_completed = true
end
}
do_notify = true
@notifications.clear
end
}
if do_notify
if !is_completed
on_next(next_inputs)
else
on_complete
end
end
end
|