Skip to content

Commit

Permalink
feat(VirtualAudioNode): the connect() method now works with VirtualAu…
Browse files Browse the repository at this point in the history
…dioParams too
  • Loading branch information
meszaros-lajos-gyorgy committed Aug 20, 2018
1 parent e32bed3 commit 0bb7c24
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
18 changes: 14 additions & 4 deletions src/VirtualAudioNode.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { EVENTS } from './constants'
import VirtualAudioParam from './VirtualAudioParam'

class VirtualAudioNode {
constructor (id, ctx) {
Expand All @@ -9,15 +10,24 @@ class VirtualAudioNode {
}

connect (destination/*, outputIndex, inputIndex */) {
// TODO: destination can be AudioNode or AudioParam
if (typeof destination === 'object' && destination._.id) {
if (destination instanceof VirtualAudioNode) {
this._.ctx._.events.add(EVENTS.CONNECT, destination._.id, this._.id, this._.ctx.currentTime)
} else if (destination instanceof VirtualAudioParam) {
this._.ctx._.events.add(EVENTS.CONNECT, destination._.nodeId, this._.id, this._.ctx.currentTime, [destination._.name])
} else if (destination === this._.ctx.destination) {
this._.ctx._.events.add(EVENTS.CONNECT, destination, this._.id, this._.ctx.currentTime)
}
}
disconnect (/* destination, output, input */) {
// TODO: destination can be AudioNode or AudioParam
disconnect (destination = null/*, output, input */) {
if (destination === null) {

} else if (destination instanceof VirtualAudioNode) {

} else if (destination instanceof VirtualAudioParam) {

} else if (destination === this._.ctx.destination) {

}
}
}

Expand Down
15 changes: 13 additions & 2 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,20 @@ const applyEventToContext = curry(({ targetId, eventName, param, time, args }, c
break
case EVENTS.CONNECT: {
const node = getNodeById(targetId, ctx)
const target = param === CTX_DESTINATION ? ctx.destination : getNodeById(param, ctx)

node.connect(target)
if (param === CTX_DESTINATION) {
node.connect(ctx.destination)
} else {
const target = getNodeById(param, ctx)

if (args.length === 0) {
node.connect(target)
} else {
const property = target[args[0]]

node.connect(property)
}
}
}
break
case EVENTS.CALL: {
Expand Down

0 comments on commit 0bb7c24

Please sign in to comment.