diff --git a/addon/classes/oscillator.js b/addon/classes/oscillator.js index e6811fd..18bcd07 100644 --- a/addon/classes/oscillator.js +++ b/addon/classes/oscillator.js @@ -165,7 +165,7 @@ const Oscillator = EmberObject.extend(Connectable, Playable, { connections.pushObjects([ gain, panner, destination ]); this.set('connections', connections); - this._wireConnections(); + this.wireConnections(); }), /** diff --git a/addon/mixins/connectable.js b/addon/mixins/connectable.js index c722aba..8dfb6ec 100644 --- a/addon/mixins/connectable.js +++ b/addon/mixins/connectable.js @@ -184,14 +184,14 @@ export default Mixin.create({ */ /** - * Observes the connections array and runs _wireConnections each time it + * Observes the connections array and runs wireConnections each time it * changes. * * @private * @method _watchConnectionChanges */ _watchConnectionChanges: observer('connections.[]', function() { - this._wireConnections(); + this.wireConnections(); }), /** @@ -200,13 +200,13 @@ export default Mixin.create({ * to be created, and having connected the AudioNode instances to one another * in the order in which they were present in the connections array. * - * @private - * @method _wireConnections + * @protected + * @method wireConnections * * @return {array|Connection} Array of Connection instances collected from the * connections array, created, connected, and ready to play. */ - _wireConnections() { + wireConnections() { const createNode = this._createNode.bind(this); const setAttrsOnNode = this._setAttrsOnNode.bind(this); const wireConnection = this._wireConnection; diff --git a/addon/mixins/playable.js b/addon/mixins/playable.js index 684e2df..a83c68f 100644 --- a/addon/mixins/playable.js +++ b/addon/mixins/playable.js @@ -18,6 +18,10 @@ const { * the future, as well as track whether the audio source is currently playing or * not. * + * Consuming object must implement `wireConnections` and `getNodeFrom` methods. + * These methods are included in the {{#crossLink "Connectable"}}{{/crossLink}} + * mixin. + * * @public * @class Playable */ @@ -153,17 +157,22 @@ export default Mixin.create({ * @private * @method _stop * - * @param {number} time The moment in time (in seconds, relative to the + * @param {number} stopAt The moment in time (in seconds, relative to the * {{#crossLink "AudioContext"}}AudioContext's{{/crossLink}} "beginning of * time") when the audio source should be stopped. */ - _stop(time) { + _stop(stopAt) { const node = this.getNodeFrom('audioSource'); const currentTime = this.get('audioContext.currentTime'); if (node) { - node.stop(time); - later(() => this.set('isPlaying', false), (time - currentTime) * 1000); + node.stop(stopAt); + } + + if (stopAt === currentTime) { + this.set('isPlaying', false); + } else { + later(() => this.set('isPlaying', false), (stopAt - currentTime) * 1000); } }, @@ -183,7 +192,7 @@ export default Mixin.create({ _play(playAt) { const currentTime = this.get('audioContext.currentTime'); - this._wireConnections(); + this.wireConnections(); const node = this.getNodeFrom('audioSource');