addon/mixins/connectable.js:21
Connectable
A mixin that allows an object to create AudioNodes and connect them together.
Depends on audioContext
being available on the consuming object.
Property Summary
Public Properties | |
---|---|
public |
An array of Connection instances. Determines which AudioNode instances are connected to one-another and the order in which they are connected. Starts as |
Method Summary
Public Methods | |
---|---|
public |
getConnection(name): Connection
returns a connection from the connections array by it's name |
public |
getNodeFrom(name): AudioNode
returns a connection's AudioNode from the connections array by the connection's |
public |
removeConnection(name)
Find's a connection in the connections array by it's |
public |
update(key, value)
Updates an AudioNode's property in real time by setting the property on the connectable object (which affects the next play) and also sets it on it's corresponding |
Protected Methods | |
---|---|
protected |
Initializes default connections on Sound instantiation. Runs |
protected |
Gets the array of Connection instances from the connections array and returns the same array, having created any AudioNode instances that needed 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 Methods | |
---|---|
private |
_createNode(connection): Connection
Creates an AudioNode instance for a Connection instance and sets it on it's |
private |
_setAttrsOnNode(connection): Connection
Gets a Connection instance's |
private |
Observes the connections array and runs wireConnections each time it changes. |
private |
_wireConnection(connection, idx, connections): Connection
Meant to be passed to a Array.prototype.map function. Connects a Connection instance's node to the next Connection instance's node. |
Public Properties
addon/mixins/connectable.js:31
public connections: Ember.MutableArray
An array of Connection instances. Determines which AudioNode instances are
connected to one-another and the order in which they are connected. Starts
as null
but set to an array on init
via the
_initConnections method.
Public Methods
addon/mixins/connectable.js:62
public getConnection(name): Connection
returns a connection from the connections array by it's name
Parameters:
Name | Type | Attribute | Description |
---|---|---|---|
name | String |
|
The name of the AudioNode that should be returned. |
Return:
The requested Connection.
addon/mixins/connectable.js:43
public getNodeFrom(name): AudioNode
returns a connection's AudioNode from the connections array by the
connection's name
.
Parameters:
Name | Type | Attribute | Description |
---|---|---|---|
name | String |
|
The name of the AudioNode that should be returned. |
Return:
The requested AudioNode.
addon/mixins/connectable.js:76
public removeConnection(name)
Find's a connection in the connections array by it's name
and removes it.
Parameters:
Name | Type | Attribute | Description |
---|---|---|---|
name | String |
|
The name of the connection that should be removed. |
addon/mixins/connectable.js:88
public update(key, value)
Updates an AudioNode's property in real time by setting the property on the
connectable object (which affects the next play) and also sets it on it's
corresponding connection.node
(which affects the audio in real time).
If a connection is pulling a property from a connectable object via
onPlaySetAttrsOnNode[index].relativePath
, this method will update that
property directly on the Connection's node
as well as on the connectable
object.
Important to note that this only works for properties that are set directly
on a connectable object and then proxied/set on a node via
onPlaySetAttrsOnNode
.
Parameters:
Name | Type | Attribute | Description |
---|---|---|---|
key | String |
|
The name/path to a property on an Oscillator instance that should be updated. |
value | String |
|
The value that the property should be set to. |
Example:
// With set
const osc = audioService.createOscillator({ frequency: 440 });
osc.play(); // playing at 440Hz
osc.set('frequency', 1000); // still playing at 440Hz
osc.stop();
osc.play(); // now playing at 1000Hz
// With update
const osc = audioService.createOscillator({ frequency: 440 });
osc.play(); // playing at 440Hz
osc.update('frequency', 1000); // playing at 1000Hz
Protected Methods
addon/mixins/connectable.js:139
protected _initConnections( )
Initializes default connections on Sound instantiation. Runs on('init')
.
addon/mixins/connectable.js:197
protected wireConnections( ): Array | Connection
Gets the array of Connection instances from the connections array and returns the same array, having created any AudioNode instances that needed to be created, and having connected the AudioNode instances to one another in the order in which they were present in the connections array.
Return:
Array of Connection instances collected from the connections array, created, connected, and ready to play.
Private Methods
addon/mixins/connectable.js:218
private _createNode(connection): Connection
Creates an AudioNode instance for a Connection instance and sets it on it's
node
property. Unless the Connection instance's createdOnPlay
property
is true, does nothing if the AudioNode instance has already been created.
Also sets any properties from a connection's onPlaySetAttrsOnNode
array
on the node.
Parameters:
Name | Type | Attribute | Description |
---|---|---|---|
connection | Connection |
|
A Connection instance that should have it's node created (if needed). |
Return:
The input Connection instance after having it's node created.
addon/mixins/connectable.js:253
private _setAttrsOnNode(connection): Connection
Gets a Connection instance's onPlaySetAttrsOnNode
and sets them on it's
node.
Parameters:
Name | Type | Attribute | Description |
---|---|---|---|
connection | Connection |
|
The Connection instance that needs it's node's attrs set. |
Return:
The input Connection instance after having it's nodes attrs set.
addon/mixins/connectable.js:186
private _watchConnectionChanges( )
Observes the connections array and runs wireConnections each time it changes.
addon/mixins/connectable.js:300
private _wireConnection(connection, idx, connections): Connection
Meant to be passed to a Array.prototype.map function. Connects a Connection instance's node to the next Connection instance's node.
Parameters:
Name | Type | Attribute | Description |
---|---|---|---|
connection | Connection |
|
The current Connection instance in the iteration. |
idx | Number |
|
The index of the current iteration. |
connections | Array | Connection |
|
The original array of connections. |
Return:
The input Connection instance after having it's node connected to the next Connection instance's node.