Class: Deftones::Source::OmniOscillator
Constant Summary
collapse
- SNAPSHOT_OPTION_KEYS =
%i[
count
detune
frequency
harmonicity
modulation_depth
modulation_frequency
modulation_index
phase
spread
type
width
].freeze
- TYPE_MAP =
{
sine: Oscillator,
square: Oscillator,
triangle: Oscillator,
sawtooth: Oscillator,
pulse: PulseOscillator,
pwm: PWMOscillator,
fm: FMOscillator,
am: AMOscillator,
fat: FatOscillator
}.freeze
Instance Attribute Summary collapse
Attributes inherited from Core::Source
#mute, #volume
Instance Method Summary
collapse
-
#apply_snapshot(source, snapshot) ⇒ Object
private
-
#build_source_options(source_class, snapshot_options) ⇒ Object
private
-
#cancel_stop ⇒ Object
(also: #cancelStop)
-
#frequency ⇒ Object
-
#initialize(type: :sine, context: Deftones.context, **options) ⇒ OmniOscillator
constructor
A new instance of OmniOscillator.
-
#method_missing(method_name, *arguments, &block) ⇒ Object
-
#onstop ⇒ Object
-
#onstop=(callback) ⇒ Object
-
#process(_input_buffer, num_frames, start_frame, cache) ⇒ Object
-
#rebuild_source ⇒ Object
private
-
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
-
#restart(time = nil) ⇒ Object
-
#snapshot_source(source) ⇒ Object
private
-
#snapshot_source_options(source) ⇒ Object
private
-
#start(time = nil) ⇒ Object
-
#state(time = context.current_time) ⇒ Object
-
#stop(time = nil) ⇒ Object
-
#sync ⇒ Object
-
#synced? ⇒ Boolean
-
#unsync ⇒ Object
#active_at?, #apply_volume!, #clear_transport_event, #dispose, #mute?, #notify_stop_in_window, #number_of_inputs, #render, #render_block, #resolve_time, #resolve_transport_time, #schedule_transport_event, #source_type, #uses_legacy_render_for_block?
Constructor Details
#initialize(type: :sine, context: Deftones.context, **options) ⇒ OmniOscillator
Returns a new instance of OmniOscillator.
34
35
36
37
38
39
|
# File 'lib/deftones/source/omni_oscillator.rb', line 34
def initialize(type: :sine, context: Deftones.context, **options)
super(context: context)
@type = type.to_sym
@options = options
rebuild_source
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
102
103
104
105
106
|
# File 'lib/deftones/source/omni_oscillator.rb', line 102
def method_missing(method_name, *arguments, &block)
return super unless @source.respond_to?(method_name)
@source.public_send(method_name, *arguments, &block)
end
|
Instance Attribute Details
#source ⇒ Object
Returns the value of attribute source.
32
33
34
|
# File 'lib/deftones/source/omni_oscillator.rb', line 32
def source
@source
end
|
#type ⇒ Object
Returns the value of attribute type.
32
33
34
|
# File 'lib/deftones/source/omni_oscillator.rb', line 32
def type
@type
end
|
Instance Method Details
#apply_snapshot(source, snapshot) ⇒ Object
160
161
162
163
164
165
166
167
168
169
170
171
|
# File 'lib/deftones/source/omni_oscillator.rb', line 160
def apply_snapshot(source, snapshot)
return source if snapshot.empty?
source.volume.value = snapshot[:volume] if source.respond_to?(:volume) && snapshot.key?(:volume)
source.mute = snapshot[:mute] if source.respond_to?(:mute=) && snapshot.key?(:mute)
source.onstop = snapshot[:onstop] if source.respond_to?(:onstop=) && snapshot.key?(:onstop)
source.instance_variable_set(:@start_time, snapshot[:start_time]) if snapshot.key?(:start_time)
source.instance_variable_set(:@stop_time, snapshot[:stop_time]) if snapshot.key?(:stop_time)
source.instance_variable_set(:@stop_notified, snapshot[:stop_notified]) if snapshot.key?(:stop_notified)
source.sync if snapshot[:synced] && source.respond_to?(:sync)
source
end
|
#build_source_options(source_class, snapshot_options) ⇒ Object
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/deftones/source/omni_oscillator.rb', line 122
def build_source_options(source_class, snapshot_options)
allowed_keys = source_class.instance_method(:initialize).parameters.filter_map do |kind, name|
name if %i[key keyreq].include?(kind)
end
@options
.merge(snapshot_options)
.merge(context: context)
.then do |options|
options[:type] = @type if source_class == Oscillator
options.select { |key, _value| allowed_keys.include?(key) }
end
end
|
#cancel_stop ⇒ Object
Also known as:
cancelStop
65
66
67
68
|
# File 'lib/deftones/source/omni_oscillator.rb', line 65
def cancel_stop
@source.cancel_stop
self
end
|
#frequency ⇒ Object
46
47
48
|
# File 'lib/deftones/source/omni_oscillator.rb', line 46
def frequency
@source.frequency if @source.respond_to?(:frequency)
end
|
#onstop ⇒ Object
88
89
90
|
# File 'lib/deftones/source/omni_oscillator.rb', line 88
def onstop
@source.onstop
end
|
#onstop=(callback) ⇒ Object
92
93
94
|
# File 'lib/deftones/source/omni_oscillator.rb', line 92
def onstop=(callback)
@source.onstop = callback
end
|
#process(_input_buffer, num_frames, start_frame, cache) ⇒ Object
96
97
98
|
# File 'lib/deftones/source/omni_oscillator.rb', line 96
def process(_input_buffer, num_frames, start_frame, cache)
@source.render(num_frames, start_frame, cache)
end
|
#rebuild_source ⇒ Object
114
115
116
117
118
119
120
|
# File 'lib/deftones/source/omni_oscillator.rb', line 114
def rebuild_source
source_class = TYPE_MAP.fetch(@type) { Oscillator }
snapshot = snapshot_source(@source)
source_options = build_source_options(source_class, snapshot.fetch(:options, {}))
@source = source_class.new(**source_options)
apply_snapshot(@source, snapshot)
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
108
109
110
|
# File 'lib/deftones/source/omni_oscillator.rb', line 108
def respond_to_missing?(method_name, include_private = false)
@source.respond_to?(method_name, include_private) || super
end
|
#restart(time = nil) ⇒ Object
60
61
62
63
|
# File 'lib/deftones/source/omni_oscillator.rb', line 60
def restart(time = nil)
@source.restart(time)
self
end
|
#snapshot_source(source) ⇒ Object
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/deftones/source/omni_oscillator.rb', line 136
def snapshot_source(source)
return { options: {} } unless source
{
options: snapshot_source_options(source),
mute: source.respond_to?(:mute?) ? source.mute? : false,
onstop: source.respond_to?(:onstop) ? source.onstop : nil,
start_time: source.instance_variable_get(:@start_time),
stop_notified: source.instance_variable_get(:@stop_notified),
stop_time: source.instance_variable_get(:@stop_time),
synced: source.respond_to?(:synced?) ? source.synced? : false,
volume: source.respond_to?(:volume) ? source.volume.value : 0.0
}
end
|
#snapshot_source_options(source) ⇒ Object
151
152
153
154
155
156
157
158
|
# File 'lib/deftones/source/omni_oscillator.rb', line 151
def snapshot_source_options(source)
SNAPSHOT_OPTION_KEYS.each_with_object({}) do |key, options|
next unless source.respond_to?(key)
value = source.public_send(key)
options[key] = value.respond_to?(:value) ? value.value : value
end
end
|
#start(time = nil) ⇒ Object
50
51
52
53
|
# File 'lib/deftones/source/omni_oscillator.rb', line 50
def start(time = nil)
@source.start(time)
self
end
|
#state(time = context.current_time) ⇒ Object
84
85
86
|
# File 'lib/deftones/source/omni_oscillator.rb', line 84
def state(time = context.current_time)
@source.state(time)
end
|
#stop(time = nil) ⇒ Object
55
56
57
58
|
# File 'lib/deftones/source/omni_oscillator.rb', line 55
def stop(time = nil)
@source.stop(time)
self
end
|
#sync ⇒ Object
70
71
72
73
|
# File 'lib/deftones/source/omni_oscillator.rb', line 70
def sync
@source.sync
self
end
|
#synced? ⇒ Boolean
80
81
82
|
# File 'lib/deftones/source/omni_oscillator.rb', line 80
def synced?
@source.synced?
end
|
#unsync ⇒ Object
75
76
77
78
|
# File 'lib/deftones/source/omni_oscillator.rb', line 75
def unsync
@source.unsync
self
end
|