W3C home > Mailing lists > Public > public-audio@w3.org > July to September 2012

creating complex/wrapped nodes

From: Matt Diamond <mdiamond@jhu.edu>
Date: Thu, 19 Jul 2012 14:42:37 -0700
Message-ID: <CADdpXtu16ZUw2gsRgRFmD3ewr4ApZ4uZXT8j22yt-UGuFZkH+A@mail.gmail.com>
To: public-audio@w3.org
Hey all,

This might be a naive question, but is there a simple way to create
"extended" nodes with additional properties / prototype methods based on
existing nodes?

To clarify, if I wanted to build my own Envelope node, I could create an
EnvelopeNode constructor that itself instantiates an internal gain node
(e.g. this.gainNode), but an object created this way will fail to interact
normally with other native nodes... i.e. instead of
osc.connect(myEnvelopeNode) you would have to use
osc.connect(myEnvelopeNode.gainNode).

Another idea I had was simply extending EnvelopeNode with a gain node as
its prototype. However, while this will allow you to do something like
"myEnvelopeNode.connect(context.destination)", it will throw a TypeError if
you try to connect another native node to this descendant node. Native
nodes don't play well with inherited types.

The only solution I can see at this point is to simply instantiate a gain
node and then use a mixin strategy to add the requisite envelope
methods/properties to that instance of the node. However, I can't help
feeling like there's a better way.

Any suggestions?

Matt
Received on Thursday, 19 July 2012 21:43:05 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 19 July 2012 21:43:05 GMT