| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of web_audio; | 5 part of web_audio; |
| 6 | 6 |
| 7 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS
{ | 7 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS
{ |
| 8 $!MEMBERS | 8 $!MEMBERS |
| 9 $if DART2JS | |
| 10 factory AudioContext() => JS('AudioContext', | 9 factory AudioContext() => JS('AudioContext', |
| 11 'new (window.AudioContext || window.webkitAudioContext)()'); | 10 'new (window.AudioContext || window.webkitAudioContext)()'); |
| 12 | 11 |
| 13 GainNode createGain() { | 12 GainNode createGain() { |
| 14 if (JS('bool', '#.createGain !== undefined', this)) { | 13 if (JS('bool', '#.createGain !== undefined', this)) { |
| 15 return JS('GainNode', '#.createGain()', this); | 14 return JS('GainNode', '#.createGain()', this); |
| 16 } else { | 15 } else { |
| 17 return JS('GainNode', '#.createGainNode()', this); | 16 return JS('GainNode', '#.createGainNode()', this); |
| 18 } | 17 } |
| 19 } | 18 } |
| 20 | 19 |
| 21 ScriptProcessorNode createScriptProcessor(int bufferSize, | 20 ScriptProcessorNode createScriptProcessor(int bufferSize, |
| 22 [int numberOfInputChannels, int numberOfOutputChannels]) { | 21 [int numberOfInputChannels, int numberOfOutputChannels]) { |
| 23 var function = JS('=Object', '#.createScriptProcessor || ' | 22 var function = JS('=Object', '#.createScriptProcessor || ' |
| 24 '#.createJavaScriptNode', this, this); | 23 '#.createJavaScriptNode', this, this); |
| 25 if (numberOfOutputChannels != null) { | 24 if (numberOfOutputChannels != null) { |
| 26 return JS('ScriptProcessorNode', '#.call(#, #, #, #)', function, this, | 25 return JS('ScriptProcessorNode', '#.call(#, #, #, #)', function, this, |
| 27 bufferSize, numberOfInputChannels, numberOfOutputChannels); | 26 bufferSize, numberOfInputChannels, numberOfOutputChannels); |
| 28 } else if (numberOfInputChannels != null) { | 27 } else if (numberOfInputChannels != null) { |
| 29 return JS('ScriptProcessorNode', '#.call(#, #, #)', function, this, | 28 return JS('ScriptProcessorNode', '#.call(#, #, #)', function, this, |
| 30 bufferSize, numberOfInputChannels); | 29 bufferSize, numberOfInputChannels); |
| 31 } else { | 30 } else { |
| 32 return JS('ScriptProcessorNode', '#.call(#, #)', function, this, | 31 return JS('ScriptProcessorNode', '#.call(#, #)', function, this, |
| 33 bufferSize); | 32 bufferSize); |
| 34 } | 33 } |
| 35 } | 34 } |
| 36 $endif | |
| 37 | 35 |
| 38 $if DART2JS | |
| 39 @JSName('decodeAudioData') | 36 @JSName('decodeAudioData') |
| 40 @DomName('AudioContext.decodeAudioData') | 37 @DomName('AudioContext.decodeAudioData') |
| 41 @DocsEditable() | 38 @DocsEditable() |
| 42 Future _decodeAudioData(ByteBuffer audioData, | 39 Future _decodeAudioData(ByteBuffer audioData, |
| 43 [AudioBufferCallback successCallback, | 40 [AudioBufferCallback successCallback, |
| 44 AudioBufferCallback errorCallback]) native; | 41 AudioBufferCallback errorCallback]) native; |
| 45 | 42 |
| 46 @DomName('AudioContext.decodeAudioData') | 43 @DomName('AudioContext.decodeAudioData') |
| 47 Future<AudioBuffer> decodeAudioData(ByteBuffer audioData) { | 44 Future<AudioBuffer> decodeAudioData(ByteBuffer audioData) { |
| 48 var completer = new Completer<AudioBuffer>(); | 45 var completer = new Completer<AudioBuffer>(); |
| 49 _decodeAudioData(audioData, | 46 _decodeAudioData(audioData, |
| 50 (value) { completer.complete(value); }, | 47 (value) { completer.complete(value); }, |
| 51 (error) { | 48 (error) { |
| 52 if (error == null) { | 49 if (error == null) { |
| 53 completer.completeError(''); | 50 completer.completeError(''); |
| 54 } else { | 51 } else { |
| 55 completer.completeError(error); | 52 completer.completeError(error); |
| 56 } | 53 } |
| 57 }); | 54 }); |
| 58 return completer.future; | 55 return completer.future; |
| 59 } | 56 } |
| 60 $else | |
| 61 @DomName('AudioContext.decodeAudioData') | |
| 62 Future<AudioBuffer> decodeAudioData(ByteBuffer audioData, | |
| 63 [AudioBufferCallback successCallback, | |
| 64 AudioBufferCallback errorCallback]) { | |
| 65 if (errorCallback != null) { | |
| 66 return convertNativePromiseToDartFuture(_blink.BlinkAudioContext.instance.
decodeAudioData_Callback_3_( | |
| 67 this, audioData, successCallback, errorCallback)); | |
| 68 } | |
| 69 if (successCallback != null) { | |
| 70 return convertNativePromiseToDartFuture(_blink.BlinkAudioContext.instance | |
| 71 .decodeAudioData_Callback_2_(this, audioData, successCallback)); | |
| 72 } | |
| 73 return convertNativePromiseToDartFuture(_blink.BlinkAudioContext.instance | |
| 74 .decodeAudioData_Callback_1_(this, audioData)); | |
| 75 } | |
| 76 $endif | |
| 77 } | 57 } |
| OLD | NEW |