From b33d528c76b261418b79d5013b9c0fbed35f7300 Mon Sep 17 00:00:00 2001 From: Jordan Santell Date: Thu, 16 Oct 2014 09:25:24 -0700 Subject: [PATCH] Bug 1083881 - add method connectParam to AudioNodeActors, r=vp From 9677a120a84ff73e07a2dd734c8d3f3e2c9b5b9e Mon Sep 17 00:00:00 2001 --- browser/devtools/webaudioeditor/test/browser.ini | 1 + .../test/browser_audionode-actor-connectparam.js | 35 ++++++++++++++++++++++ toolkit/devtools/server/actors/webaudio.js | 30 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 browser/devtools/webaudioeditor/test/browser_audionode-actor-connectparam.js --- .../devtools/webaudioeditor/test/browser.ini | 1 + .../browser_audionode-actor-connectparam.js | 35 +++++++++++++++++++ toolkit/devtools/server/actors/webaudio.js | 30 ++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 browser/devtools/webaudioeditor/test/browser_audionode-actor-connectparam.js diff --git a/browser/devtools/webaudioeditor/test/browser.ini b/browser/devtools/webaudioeditor/test/browser.ini index 438accdc9dbe..503e6f01fb6f 100644 --- a/browser/devtools/webaudioeditor/test/browser.ini +++ b/browser/devtools/webaudioeditor/test/browser.ini @@ -23,6 +23,7 @@ support-files = [browser_audionode-actor-is-source.js] [browser_audionode-actor-bypass.js] [browser_audionode-actor-connectnode-disconnect.js] +[browser_audionode-actor-connectparam.js] [browser_webaudio-actor-simple.js] [browser_webaudio-actor-destroy-node.js] [browser_webaudio-actor-connect-param.js] diff --git a/browser/devtools/webaudioeditor/test/browser_audionode-actor-connectparam.js b/browser/devtools/webaudioeditor/test/browser_audionode-actor-connectparam.js new file mode 100644 index 000000000000..2603299d17b8 --- /dev/null +++ b/browser/devtools/webaudioeditor/test/browser_audionode-actor-connectparam.js @@ -0,0 +1,35 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Tests that AudioNodeActor#connectParam() work. + * Uses the editor front as the actors do not retain connect state. + */ + +function spawnTest() { + let { target, panel } = yield initWebAudioEditor(SIMPLE_CONTEXT_URL); + let { panelWin } = panel; + let { gFront, $, $$, EVENTS, gAudioNodes } = panelWin; + + reload(target); + + let [actors] = yield Promise.all([ + get3(gFront, "create-node"), + waitForGraphRendered(panelWin, 3, 2) + ]); + + let [dest, osc, gain] = actors; + + yield osc.disconnect(); + + osc.connectParam(gain, "gain"); + yield Promise.all([ + waitForGraphRendered(panelWin, 3, 1, 1), + once(gAudioNodes, "connect") + ]); + ok(true, "Oscillator connect to Gain's Gain AudioParam, event emitted."); + + yield teardown(panel); + finish(); +} + diff --git a/toolkit/devtools/server/actors/webaudio.js b/toolkit/devtools/server/actors/webaudio.js index b276d910edfb..09aebd6e1856 100644 --- a/toolkit/devtools/server/actors/webaudio.js +++ b/toolkit/devtools/server/actors/webaudio.js @@ -292,6 +292,36 @@ let AudioNodeActor = exports.AudioNodeActor = protocol.ActorClass({ response: { params: RetVal("json") } }), + /** + * Connects this audionode to an AudioParam via `node.connect(param)`. + */ + connectParam: method(function (destActor, paramName, output) { + let srcNode = this.node.get(); + let destNode = destActor.node.get(); + + if (srcNode === null || destNode === null) { + return CollectedAudioNodeError(); + } + + try { + // Connect via the unwrapped node, so we can call the + // patched method that fires the webaudio actor's `connect-param` event. + // Connect directly to the wrapped `destNode`, otherwise + // the patched method thinks this is a new node and won't be + // able to find it in `_nativeToActorID`. + XPCNativeWrapper.unwrap(srcNode).connect(destNode[paramName], output); + } catch (e) { + return constructError(e); + } + }, { + request: { + destActor: Arg(0, "audionode"), + paramName: Arg(1, "string"), + output: Arg(2, "nullable:number") + }, + response: { error: RetVal("nullable:json") } + }), + /** * Connects this audionode to another via `node.connect(dest)`. */