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

Side by Side Diff: sdk/lib/web_audio/dart2js/web_audio_dart2js.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:_js_helper' show Creates, Returns; 7 import 'dart:_js_helper' show Creates, Returns, convertDartClosureToJS;
8 import 'dart:_foreign_helper' show JS; 8 import 'dart:_foreign_helper' show JS;
9 // DO NOT EDIT - unless you are editing documentation as per: 9 // DO NOT EDIT - unless you are editing documentation as per:
10 // https://code.google.com/p/dart/wiki/ContributingHTMLDocumentation 10 // https://code.google.com/p/dart/wiki/ContributingHTMLDocumentation
11 // Auto-generated dart:audio library. 11 // Auto-generated dart:audio library.
12 12
13 13
14 14
15 15
16 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 16 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
17 // for details. All rights reserved. Use of this source code is governed by a 17 // for details. All rights reserved. Use of this source code is governed by a
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 // BSD-style license that can be found in the LICENSE file. 177 // BSD-style license that can be found in the LICENSE file.
178 178
179 179
180 @DomName('AudioContext') 180 @DomName('AudioContext')
181 class AudioContext extends EventTarget native "*AudioContext" { 181 class AudioContext extends EventTarget native "*AudioContext" {
182 182
183 @DomName('AudioContext.completeEvent') 183 @DomName('AudioContext.completeEvent')
184 @DocsEditable 184 @DocsEditable
185 static const EventStreamProvider<Event> completeEvent = const EventStreamProvi der<Event>('complete'); 185 static const EventStreamProvider<Event> completeEvent = const EventStreamProvi der<Event>('complete');
186 186
187 /// Checks if this type is supported on the current platform.
188 static bool get supported => JS('bool', '!!(window.AudioContex || window.webki tAudioContext)');
189
187 @DomName('AudioContext.activeSourceCount') 190 @DomName('AudioContext.activeSourceCount')
188 @DocsEditable 191 @DocsEditable
189 final int activeSourceCount; 192 final int activeSourceCount;
190 193
191 @DomName('AudioContext.currentTime') 194 @DomName('AudioContext.currentTime')
192 @DocsEditable 195 @DocsEditable
193 final num currentTime; 196 final num currentTime;
194 197
195 @DomName('AudioContext.destination') 198 @DomName('AudioContext.destination')
196 @DocsEditable 199 @DocsEditable
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 void setOrientation(num x, num y, num z) native; 809 void setOrientation(num x, num y, num z) native;
807 810
808 @DomName('PannerNode.setPosition') 811 @DomName('PannerNode.setPosition')
809 @DocsEditable 812 @DocsEditable
810 void setPosition(num x, num y, num z) native; 813 void setPosition(num x, num y, num z) native;
811 814
812 @DomName('PannerNode.setVelocity') 815 @DomName('PannerNode.setVelocity')
813 @DocsEditable 816 @DocsEditable
814 void setVelocity(num x, num y, num z) native; 817 void setVelocity(num x, num y, num z) native;
815 } 818 }
816 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 819 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
817 // for details. All rights reserved. Use of this source code is governed by a 820 // for details. All rights reserved. Use of this source code is governed by a
818 // BSD-style license that can be found in the LICENSE file. 821 // BSD-style license that can be found in the LICENSE file.
819 822
820 823
821 @DocsEditable
822 @DomName('ScriptProcessorNode') 824 @DomName('ScriptProcessorNode')
823 class ScriptProcessorNode extends AudioNode implements EventTarget native "*Scri ptProcessorNode" { 825 class ScriptProcessorNode extends AudioNode native "*ScriptProcessorNode" {
826 Stream<AudioProcessingEvent> _eventStream;
827
828 /**
829 * Get a Stream that fires events when AudioProcessingEvents occur.
830 * This particular stream is special in that it only allows one listener to a
831 * given stream. Subsequent calls to [listen] after the first call will throw
832 */
833 Stream<AudioProcessingEvent> get onAudioProcess {
834 if (_eventStream == null) {
835 _eventStream = new _AudioEventStream(this);
836 }
837 return _eventStream;
838 }
824 839
825 @DomName('ScriptProcessorNode.bufferSize') 840 @DomName('ScriptProcessorNode.bufferSize')
826 @DocsEditable 841 @DocsEditable
827 final int bufferSize; 842 final int bufferSize;
843
828 } 844 }
845
846 class _AudioEventStreamSubscription<AudioProcessingEvent> extends
847 StreamSubscription<AudioProcessingEvent> {
848 EventListener _callback;
849 ScriptProcessorNode _target;
850 bool _paused;
851
852 _AudioEventStreamSubscription(this._target, this._callback) {
853 _paused = false;
854 _tryResume();
855 }
856
857 void cancel() {
858 if (_callback != null) {
859 throw new StateError("Subscription has already been canceled.");
860 }
861 _unlisten();
862 }
863
864 void onData(void callback(AudioProcessingEvent)) {
865 if (_callback != null) {
866 throw new StateError("Subscription has been canceled.");
867 }
868 _setCallback(callback);
869 }
870
871 /// Has no effect.
872 void onError(void handleError(AsyncError error)) {}
873
874 /// Has no effect.
875 void onDone(void handleDone()) {}
876
877 void pause([Future resumeSignal]) {
878 if (_callback != null) {
879 throw new StateError("Subscription has been canceled.");
880 }
881 _unlisten();
882 _paused = true;
883
884 if (resumeSignal != null) {
885 resumeSignal.whenComplete(() { _paused = false; resume(); });
886 }
887 }
888
889 void resume() {
890 if (_callback != null) {
891 throw new StateError("Subscription has been canceled.");
892 }
893 if (!_paused) {
894 throw new StateError("Subscription is not paused.");
895 }
896 _tryResume();
897 }
898
899 void _tryResume() {
900 if (_callback != null) {
901 _setCallback(_callback);
902 _callback = null;
903 }
904 }
905
906 void _unlisten() {
907 if (_callback == null) {
908 var noop = (event) {};
909 _callback = JS('Function', '#.onaudioprocess', _target);
910 _setCallback(noop);
911 }
912 }
913
914 void _setCallback(callbackFunc) {
915 JS('void', '#.onaudioprocess = #', _target,
916 convertDartClosureToJS(_callback, 1));
917 }
918 }
919
920 /**
921 * Adapter for exposing DOM events as Dart streams.
922 */
923 class _AudioEventStream<AudioProcessingEvent>
924 extends Stream<AudioProcessingEvent> {
925 static Set _createdTargets = new Set();
926 ScriptProcessorNode _target;
927 StreamSubscription _streamSubscription;
928
929 _AudioEventStream(target) {
930 if (_createdTargets.contains(target)) {
931 throw new ArgumentError('This ScriptProcessorNode already has an event '
932 'stream associated with it. There can be only one listener per '
933 'ScriptProcessorNode');
934 } else {
935 _target = target;
936 _createdTargets.add(_target);
937 }
938 }
939
940 bool get isBroadcast => true;
941
942 StreamSubscription<AudioProcessingEvent> listen(
943 void onData(AudioProcessingEvent event),
944 { void onError(AsyncError error),
945 void onDone(),
946 bool unsubscribeOnError}) {
947 if (_streamSubscription != null) {
948 throw new StateError('Only one listener is allowed for this particular '
949 'stream.');
950 }
951 _streamSubscription =
952 new _AudioEventStreamSubscription<AudioProcessingEvent>(
953 this._target, onData);
954 return _streamSubscription;
955 }
956 }
957
829 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 958 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
830 // for details. All rights reserved. Use of this source code is governed by a 959 // for details. All rights reserved. Use of this source code is governed by a
831 // BSD-style license that can be found in the LICENSE file. 960 // BSD-style license that can be found in the LICENSE file.
832 961
833 962
834 @DocsEditable 963 @DocsEditable
835 @DomName('WaveShaperNode') 964 @DomName('WaveShaperNode')
836 class WaveShaperNode extends AudioNode native "*WaveShaperNode" { 965 class WaveShaperNode extends AudioNode native "*WaveShaperNode" {
837 966
838 @DomName('WaveShaperNode.curve') 967 @DomName('WaveShaperNode.curve')
839 @DocsEditable 968 @DocsEditable
840 @Returns('Float32Array') 969 @Returns('Float32Array')
841 @Creates('Float32Array') 970 @Creates('Float32Array')
842 List<double> curve; 971 List<double> curve;
843 } 972 }
844 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 973 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
845 // for details. All rights reserved. Use of this source code is governed by a 974 // for details. All rights reserved. Use of this source code is governed by a
846 // BSD-style license that can be found in the LICENSE file. 975 // BSD-style license that can be found in the LICENSE file.
847 976
848 977
849 @DocsEditable 978 @DocsEditable
850 @DomName('WaveTable') 979 @DomName('WaveTable')
851 class WaveTable native "*WaveTable" { 980 class WaveTable native "*WaveTable" {
852 } 981 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698