Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: sdk/lib/web_audio/dartium/web_audio_dartium.dart

Issue 11510013: Making ScriptProcessorNode not an EventTarget. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 library dart.dom.web_audio; 1 library dart.dom.web_audio;
2 2
3 import 'dart:async'; 3 import 'dart:async';
4 import 'dart:collection'; 4 import 'dart:collection';
5 import 'dart:html'; 5 import 'dart:html';
6 import 'dart:html_common'; 6 import 'dart:html_common';
7 import 'dart:nativewrappers'; 7 import 'dart:nativewrappers';
8 import 'dart:typeddata' as _typeddata; 8 import 'dart:typeddata' as _typeddata;
9 // DO NOT EDIT 9 // DO NOT EDIT
10 // Auto-generated dart:audio library. 10 // Auto-generated dart:audio library.
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 AudioContext.internal() : super.internal(); 229 AudioContext.internal() : super.internal();
230 230
231 @DomName('AudioContext.completeEvent') 231 @DomName('AudioContext.completeEvent')
232 @DocsEditable 232 @DocsEditable
233 static const EventStreamProvider<Event> completeEvent = const EventStreamProvi der<Event>('complete'); 233 static const EventStreamProvider<Event> completeEvent = const EventStreamProvi der<Event>('complete');
234 factory AudioContext() => _create(); 234 factory AudioContext() => _create();
235 235
236 @DocsEditable 236 @DocsEditable
237 static AudioContext _create() native "AudioContext_constructorCallback"; 237 static AudioContext _create() native "AudioContext_constructorCallback";
238 238
239 /// Checks if this type is supported on the current platform.
240 static bool get supported => true;
241
239 @DomName('AudioContext.activeSourceCount') 242 @DomName('AudioContext.activeSourceCount')
240 @DocsEditable 243 @DocsEditable
241 int get activeSourceCount native "AudioContext_activeSourceCount_Getter"; 244 int get activeSourceCount native "AudioContext_activeSourceCount_Getter";
242 245
243 @DomName('AudioContext.currentTime') 246 @DomName('AudioContext.currentTime')
244 @DocsEditable 247 @DocsEditable
245 num get currentTime native "AudioContext_currentTime_Getter"; 248 num get currentTime native "AudioContext_currentTime_Getter";
246 249
247 @DomName('AudioContext.destination') 250 @DomName('AudioContext.destination')
248 @DocsEditable 251 @DocsEditable
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 1082
1080 @DomName('PannerNode.setPosition') 1083 @DomName('PannerNode.setPosition')
1081 @DocsEditable 1084 @DocsEditable
1082 void setPosition(num x, num y, num z) native "PannerNode_setPosition_Callback" ; 1085 void setPosition(num x, num y, num z) native "PannerNode_setPosition_Callback" ;
1083 1086
1084 @DomName('PannerNode.setVelocity') 1087 @DomName('PannerNode.setVelocity')
1085 @DocsEditable 1088 @DocsEditable
1086 void setVelocity(num x, num y, num z) native "PannerNode_setVelocity_Callback" ; 1089 void setVelocity(num x, num y, num z) native "PannerNode_setVelocity_Callback" ;
1087 1090
1088 } 1091 }
1089 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1092 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
1090 // for details. All rights reserved. Use of this source code is governed by a 1093 // for details. All rights reserved. Use of this source code is governed by a
1091 // BSD-style license that can be found in the LICENSE file. 1094 // BSD-style license that can be found in the LICENSE file.
1092 1095
1093 // WARNING: Do not edit - generated code.
1094 1096
1097 @DomName('ScriptProcessorNode')
1098 class ScriptProcessorNode extends AudioNode {
1099 Stream<AudioProcessingEvent> _eventStream;
1095 1100
1096 @DocsEditable 1101 /**
1097 @DomName('ScriptProcessorNode') 1102 * Get a Stream that fires events when AudioProcessingEvents occur.
1098 class ScriptProcessorNode extends AudioNode implements EventTarget { 1103 * This particular stream is special in that it only allows one listener to a
1104 * given stream. Subsequent calls to [listen] after the first call will throw
1105 */
1106 Stream<AudioProcessingEvent> get onAudioProcess {
1107 if (_eventStream == null) {
1108 _eventStream = new _AudioEventStream(this);
1109 }
1110 return _eventStream;
1111 }
1099 ScriptProcessorNode.internal() : super.internal(); 1112 ScriptProcessorNode.internal() : super.internal();
1100 1113
1101 @DomName('ScriptProcessorNode.bufferSize') 1114 @DomName('ScriptProcessorNode.bufferSize')
1102 @DocsEditable 1115 @DocsEditable
1103 int get bufferSize native "ScriptProcessorNode_bufferSize_Getter"; 1116 int get bufferSize native "ScriptProcessorNode_bufferSize_Getter";
1104 1117
1105 } 1118 }
1119
1120 class _AudioEventStreamSubscription<AudioProcessingEvent> extends
1121 StreamSubscription<AudioProcessingEvent> {
1122 EventListener _callback;
1123 ScriptProcessorNode _target;
1124 bool _paused;
1125
1126 _AudioEventStreamSubscription(this._target, this._callback) {
1127 _paused = false;
1128 _tryResume();
1129 }
1130
1131 void cancel() {
1132 if (_callback != null) {
1133 throw new StateError("Subscription has already been canceled.");
1134 }
1135 _unlisten();
1136 }
1137
1138 void onData(void callback(AudioProcessingEvent)) {
1139 if (_callback != null) {
1140 throw new StateError("Subscription has been canceled.");
1141 }
1142 _setCallback(callback);
1143 }
1144
1145 /// Has no effect.
1146 void onError(void handleError(AsyncError error)) {}
1147
1148 /// Has no effect.
1149 void onDone(void handleDone()) {}
1150
1151 void pause([Future resumeSignal]) {
1152 if (_callback != null) {
1153 throw new StateError("Subscription has been canceled.");
1154 }
1155 _unlisten();
1156 _paused = true;
1157
1158 if (resumeSignal != null) {
1159 resumeSignal.whenComplete(() { _paused = false; resume(); });
1160 }
1161 }
1162
1163 void resume() {
1164 if (_callback != null) {
1165 throw new StateError("Subscription has been canceled.");
1166 }
1167 if (!_paused) {
1168 throw new StateError("Subscription is not paused.");
1169 }
1170 _tryResume();
1171 }
1172
1173 void _tryResume() {
1174 if (_callback != null) {
1175 _setCallback(_callback);
1176 _callback = null;
1177 }
1178 }
1179
1180 void _unlisten() {
1181 if (_callback == null) {
1182 var noop = (event) {};
1183 // TODO(podivilov): Implement on Dartium.
1184 _setCallback(noop);
1185 }
1186 }
1187
1188 void _setCallback(callbackFunc) {
1189 // TODO(podivilov): Implement on Dartium.
1190 }
1191 }
1192
1193 /**
1194 * Adapter for exposing DOM events as Dart streams.
1195 */
1196 class _AudioEventStream<AudioProcessingEvent>
1197 extends Stream<AudioProcessingEvent> {
1198 static Set _createdTargets = new Set();
1199 ScriptProcessorNode _target;
1200 StreamSubscription _streamSubscription;
1201
1202 _AudioEventStream(target) {
1203 if (_createdTargets.contains(target)) {
1204 throw new ArgumentError('This ScriptProcessorNode already has an event '
1205 'stream associated with it. There can be only one listener per '
1206 'ScriptProcessorNode');
1207 } else {
1208 _target = target;
1209 _createdTargets.add(_target);
1210 }
1211 }
1212
1213 bool get isBroadcast => true;
1214
1215 StreamSubscription<AudioProcessingEvent> listen(
1216 void onData(AudioProcessingEvent event),
1217 { void onError(AsyncError error),
1218 void onDone(),
1219 bool unsubscribeOnError}) {
1220 if (_streamSubscription != null) {
1221 throw new StateError('Only one listener is allowed for this particular '
1222 'stream.');
1223 }
1224 _streamSubscription =
1225 new _AudioEventStreamSubscription<AudioProcessingEvent>(
1226 this._target, onData);
1227 return _streamSubscription;
1228 }
1229 }
1230
1106 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1231 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
1107 // for details. All rights reserved. Use of this source code is governed by a 1232 // for details. All rights reserved. Use of this source code is governed by a
1108 // BSD-style license that can be found in the LICENSE file. 1233 // BSD-style license that can be found in the LICENSE file.
1109 1234
1110 // WARNING: Do not edit - generated code. 1235 // WARNING: Do not edit - generated code.
1111 1236
1112 1237
1113 @DocsEditable 1238 @DocsEditable
1114 @DomName('WaveShaperNode') 1239 @DomName('WaveShaperNode')
1115 class WaveShaperNode extends AudioNode { 1240 class WaveShaperNode extends AudioNode {
(...skipping 14 matching lines...) Expand all
1130 1255
1131 // WARNING: Do not edit - generated code. 1256 // WARNING: Do not edit - generated code.
1132 1257
1133 1258
1134 @DocsEditable 1259 @DocsEditable
1135 @DomName('WaveTable') 1260 @DomName('WaveTable')
1136 class WaveTable extends NativeFieldWrapperClass1 { 1261 class WaveTable extends NativeFieldWrapperClass1 {
1137 WaveTable.internal(); 1262 WaveTable.internal();
1138 1263
1139 } 1264 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698