-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TAG issue: Subclassing / Node composition #251
Comments
with sublassing capabilities writing custom nodes will be way easier and there won't be a fight of |
For example, I have a multi channel analyzer node. If I were to expose a currently ideomatic webaudio api, it would be sourceOne.connect(analyzer.node);
sourceTwo.connect(analyzer.node);
analyzer.on('data', function(data) {
console.log(data); // [[ 0, 1, ... ], [ 1, 1, ... ]]
}); Having unnamed parameters sucks, and especially when you disconnect one node it becomes super confusing. So the api I have now is like this: analyzer
.add('one', sourceOne)
.add('two', sourceTwo)
.on('data', function(data) {
console.log(data); // { one: [ 0, 1, ... ], two: [ 1, 1, ... ] }
}); This works but isn't ideomatic webaudio style, i.e. it's not using sourceOne.connect(analyzer.input('one'));
sourceTwo.connect(analyzer.input('two'));
analyzer.on('data', function(data) {
console.log(data); // { one: [ 0, 1, ... ], two: [ 1, 1, ... ] }
}); So I'd have be able to create custom audionodes. |
This is likely a meta-issue: make sure we can compose nodes somehow. |
Would it be useful to a factory method for creating custom nodes? Maybe something like this:
It would be nice if we could do write
In the case of a custom node possessing multiple input nodes which have multiple inputs themselves a user would have to specify which of the inputs in the following way: |
Even having a custom "compositorNode" that could have a graph internally would be a fix for this. It really, really sucks to not be able to properly do this, since it means you can't create (e.g.) a "ChorusEffectNode" that can be both connected to and connected. |
I would really love to see this happen. I've already gone extra miles to have something like this in my WAAX library. Having this feature on API level would be much more useful then JS polyfills and prototype override/inheritance. If this happens, I can see my plug-ins can be ported with very little effort. Also another useful thing to have is a collective AudioParam. Some parameters can be abstracted on top of a set of AudioParams. Redirection/collective control on them makes much more sense inside of CompositorNode. @chris Do you have any idea/proposal for this? |
I'm not sure this should be v.next. |
TPAC: @cwilso to verify that de facto subclassing/extension of native nodes can be done, then close. |
I believe that there's no reason this would not be addressed by the existence of regular constructors as per #250, and the ability to delegate from a subclass to the prototype via |
@domenic I think the working group has reached the agreement. Could you take a look at the comments above and let us know TAG's decision? |
I'm having a hard time understanding what the concrete proposal is for changing the spec based on the above comments. Would you be able to summarize? |
@domenic Sorry about the confusion. Here is the summary:
class CustomGainNode extends GainNode {
// Override an existing method.
connect () {
console.log(' connected!');
super.connect.apply(this, arguments);
}
// Adding a new method.
mute () {
this.gain.setValueAtTime(0, 0);
}
}
Hope this helps and let me know if you need more clarification. |
That plans sounds pretty good! A way to improve https://github.com/GoogleChrome/web-audio-samples/wiki/CompositeAudioNode to avoid having to override connect would be to add an overload to connect() that accepted something like a dictionary whose single member is (Alternately you could pick a name that is more specific to this adapter purpose like |
@domenic Thanks for the idea. I will certainly make some improvements! |
@joeberkovitz @mdjp What would be the next step here? |
Seems to me we can just proceed on cleaning up the constructor definitions I don't think we need to do anything special to address the ...Joe . . . . . ...Joe Joe Berkovitz +1 978 314 6271 49R Day Street "Bring music to life" On Fri, May 20, 2016 at 10:49 AM, Hongchan Choi notifications@github.com
|
Then perhaps we can move this issue to the ready-for-editing status. |
done! |
Now we have constructors, this isn't an issue any more. |
Is there an info was the extending implemented by any browser? Chrome 91 doesn't seem to allow that. |
Can you elaborate what you tried and what did not work? |
@hoch I mean your example: class CustomGainNode extends GainNode {
mute () {
this.gain.setValueAtTime(0, 0);
}
}
let ctx = new AudioContext
let g = new CustomGainNode(ctx)
g.mute()
// VM207:1 Uncaught TypeError: g.mute is not a function
// at <anonymous>:1:3 Can that be considered a chromium bug? Is that expected to be implemented? |
I responded on the bug, but it seems working correctly for me. We can continue the discussion on the bug, not here. |
The following issue was raised by the W3C TAG as part of their review of the Web Audio API
ISSUE: Subclassing
Related to a lack of constructors, but worth calling out independently, it's not currently possible to meaningfully compose node types, either through mixins or through subclassing. In JS, this sort of "is a" relationship is usually set up through the subclassing pattern:
There doesn't seem to be any way in the current design to enable this sort of composition. This is deeply unfortunate.
The text was updated successfully, but these errors were encountered: