Skip to content

Commit

Permalink
Connectable - private _wireConnections now protected wireConnections
Browse files Browse the repository at this point in the history
  • Loading branch information
sethbrasile committed Jul 29, 2016
1 parent 10e1309 commit f6e2ad4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion addon/classes/oscillator.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ const Oscillator = EmberObject.extend(Connectable, Playable, {
connections.pushObjects([ gain, panner, destination ]);

this.set('connections', connections);
this._wireConnections();
this.wireConnections();
}),

/**
Expand Down
10 changes: 5 additions & 5 deletions addon/mixins/connectable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}),

/**
Expand All @@ -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;
Expand Down
19 changes: 14 additions & 5 deletions addon/mixins/playable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
}
},

Expand All @@ -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');

Expand Down

0 comments on commit f6e2ad4

Please sign in to comment.