1- module Browser ; module Audio ; module Node ;
1+ module Browser ; module Audio ; module Node
22
3- module Pluggable
4- def connect ( other_node )
5- `#@native .connect(#{ Native . convert ( other_node ) } )`
3+ class Base
4+ include Native
5+
6+ def initialize ( native )
7+ @native = native
68 end
79
8- def disconnect ( other_node , options = { } )
9- other_node = Native . try_convert ( other_node )
10- output = options [ :output ] || 0
11- input = options [ :input ] || 0
10+ def method_missing ( name , value = nil )
11+ if name . end_with? '='
12+ `#@native [#{ name . delete '=' } ].value = value`
13+ elsif value . nil? || value == true
14+ `#@native [#{ name } ].value`
15+ elsif value == false
16+ `#@native [#{ name } ]`
17+ else
18+ super
19+ end
20+ end
21+
22+ def respond_to_missing? ( method , include_all = false )
23+ `#@native [#{ method . delete ( '=' ) } ] != null`
24+ end
25+
26+ def connect ( destination )
27+ `#@native .connect(#{ Native . convert ( destination ) } )`
28+ end
29+
30+ def disconnect ( destination , options = { } )
31+ destination = Native . try_convert ( destination )
32+ output = options [ :output ] || 0
33+ input = options [ :input ] || 0
1234
1335 if options
14- `#@native .disconnect(#{ other_node } , #{ output } , #{ input } ) || nil`
15- elsif other_node
16- `#@native .disconnect(#{ other_node } )`
36+ `#@native .disconnect(#{ destination } , #{ output } , #{ input } ) || nil`
37+ elsif destination
38+ `#@native .disconnect(#{ destination } )`
1739 else
1840 `#@native .disconnect()`
1941 end
2042 end
2143end
2244
23- class Gain
24- include Native
25- include Pluggable
26-
27- alias_native :value , :gain
28-
45+ class Gain < Base
2946 def initialize ( audio_context )
3047 super `#{ audio_context . to_n } .createGain()`
3148 end
3249end
3350
34- class Oscillator
51+ class Oscillator < Base
3552 TYPES = %i( sine square sawtooth triangle custom )
3653
37- include Native
38- include Pluggable
39-
4054 alias_native :start
4155 alias_native :stop
4256
@@ -55,97 +69,26 @@ def type=(type)
5569 def type
5670 `#@native .type`
5771 end
58-
59- def frequency = ( frequency )
60- `#@native .frequency.value = frequency`
61- end
62-
63- def frequency
64- `#@native .frequency.value`
65- end
66-
67- def detune = ( detune )
68- `#@native .detune.value = detune`
69- end
70-
71- def detune
72- `#@native .detune.value`
73- end
7472end
7573
76- class Delay
77- include Native
78- include Pluggable
79-
74+ class Delay < Base
8075 def initialize ( audio_context , max_time = 1 )
8176 super `#{ audio_context . to_n } .createDelay(max_time)`
8277 end
83-
84- def time = ( time )
85- `#@native .time.value = time`
86- end
87-
88- def time
89- `#@native .time.value`
90- end
9178end
9279
93- class DynamicsCompressor
94- include Native
95- include Pluggable
80+ class DynamicsCompressor < Base
9681
9782 alias_native :reduction
9883
9984 def initialize ( audio_context )
10085 super `#{ audio_context . to_n } .createDynamicsCompressor()`
10186 end
102-
103- def treshold = ( treshold )
104- `#@native .treshold.value = treshold`
105- end
106-
107- def treshold
108- `#@native .treshold.value`
109- end
110-
111- def knee = ( knee )
112- `#@native .knee.value = knee`
113- end
114-
115- def knee
116- `#@native .knee.value`
117- end
118-
119- def ratio = ( ratio )
120- `#@native .ratio.value = ratio`
121- end
122-
123- def ratio
124- `#@native .ratio.value`
125- end
126-
127- def attack = ( attack )
128- `#@native .attack.value = attack`
129- end
130-
131- def attack
132- `#@native .attack.value`
133- end
134-
135- def release = ( release )
136- `#@native .release.value = release`
137- end
138-
139- def release
140- `#@native .release.value`
141- end
14287end
14388
144- class BiquadFilter
145- TYPES = %i( lowpass highpass bandpass lowshelf highshelf peaking notch allpass )
89+ class BiquadFilter < Base
14690
147- include Native
148- include Pluggable
91+ TYPES = %i( lowpass highpass bandpass lowshelf highshelf peaking notch allpass )
14992
15093 def initialize ( audio_context )
15194 super `#{ audio_context . to_n } .createBiquadFilter()`
@@ -162,45 +105,15 @@ def type=(type)
162105 def type
163106 `#@native .type`
164107 end
165-
166- def detune = ( detune )
167- `#@native .detune.value = #{ @detune = detune } `
168- end
169-
170- def q = ( q )
171- `#@native .q.value = q`
172- end
173-
174- def q
175- `#@native .q.value`
176- end
177-
178- def gain = ( gain )
179- `#@native .gain.value = gain`
180- end
181-
182- def gain
183- `#@native .gain.value`
184- end
185108end
186109
187- class StereoPanner
188- include Native
189- include Pluggable
110+ class StereoPanner < Base
190111
191112 alias_native :normalize
192113
193114 def initialize ( audio_context )
194115 super `#{ audio_context . to_n } .createStereoPanner()`
195116 end
196-
197- def pan = ( pan )
198- `#@native .pan.value = pan`
199- end
200-
201- def pan
202- `#@native .pan.value`
203- end
204117end
205118
206119end ; end ; end
0 commit comments