1
- module Browser ; module Audio ; module Node ;
1
+ module Browser ; module Audio ; module Node
2
2
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
6
8
end
7
9
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
12
34
13
35
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 } )`
17
39
else
18
40
`#@native .disconnect()`
19
41
end
20
42
end
21
43
end
22
44
23
- class Gain
24
- include Native
25
- include Pluggable
26
-
27
- alias_native :value , :gain
28
-
45
+ class Gain < Base
29
46
def initialize ( audio_context )
30
47
super `#{ audio_context . to_n } .createGain()`
31
48
end
32
49
end
33
50
34
- class Oscillator
51
+ class Oscillator < Base
35
52
TYPES = %i( sine square sawtooth triangle custom )
36
53
37
- include Native
38
- include Pluggable
39
-
40
54
alias_native :start
41
55
alias_native :stop
42
56
@@ -55,97 +69,26 @@ def type=(type)
55
69
def type
56
70
`#@native .type`
57
71
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
74
72
end
75
73
76
- class Delay
77
- include Native
78
- include Pluggable
79
-
74
+ class Delay < Base
80
75
def initialize ( audio_context , max_time = 1 )
81
76
super `#{ audio_context . to_n } .createDelay(max_time)`
82
77
end
83
-
84
- def time = ( time )
85
- `#@native .time.value = time`
86
- end
87
-
88
- def time
89
- `#@native .time.value`
90
- end
91
78
end
92
79
93
- class DynamicsCompressor
94
- include Native
95
- include Pluggable
80
+ class DynamicsCompressor < Base
96
81
97
82
alias_native :reduction
98
83
99
84
def initialize ( audio_context )
100
85
super `#{ audio_context . to_n } .createDynamicsCompressor()`
101
86
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
142
87
end
143
88
144
- class BiquadFilter
145
- TYPES = %i( lowpass highpass bandpass lowshelf highshelf peaking notch allpass )
89
+ class BiquadFilter < Base
146
90
147
- include Native
148
- include Pluggable
91
+ TYPES = %i( lowpass highpass bandpass lowshelf highshelf peaking notch allpass )
149
92
150
93
def initialize ( audio_context )
151
94
super `#{ audio_context . to_n } .createBiquadFilter()`
@@ -162,45 +105,15 @@ def type=(type)
162
105
def type
163
106
`#@native .type`
164
107
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
185
108
end
186
109
187
- class StereoPanner
188
- include Native
189
- include Pluggable
110
+ class StereoPanner < Base
190
111
191
112
alias_native :normalize
192
113
193
114
def initialize ( audio_context )
194
115
super `#{ audio_context . to_n } .createStereoPanner()`
195
116
end
196
-
197
- def pan = ( pan )
198
- `#@native .pan.value = pan`
199
- end
200
-
201
- def pan
202
- `#@native .pan.value`
203
- end
204
117
end
205
118
206
119
end ; end ; end
0 commit comments