-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1025864-observe-audioparams.patch
1124 lines (1055 loc) · 38.2 KB
/
1025864-observe-audioparams.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From e4dbb7bc50ddedfa9ecda6b7aebbe216e9271072 Mon Sep 17 00:00:00 2001
From: Jordan Santell <[email protected]>
Date: Mon, 4 Aug 2014 17:51:16 -0700
Subject: Bug 1025864 - Add observer updates when AudioParams change in the Web Audio Editor r=vp
---
browser/devtools/shared/frame-script-utils.js | 10 +
browser/devtools/webaudioeditor/test/browser.ini | 7 +-
.../browser_wa_properties-view-change-params.js | 46 ++++
.../browser_webaudio-actor-change-params-01.js | 46 ++++
.../browser_webaudio-actor-change-params-02.js | 36 +++
.../browser_webaudio-actor-change-params-03.js | 32 +++
.../webaudioeditor/test/doc_change-param.html | 25 ++
browser/devtools/webaudioeditor/test/head.js | 16 +-
.../webaudioeditor/webaudioeditor-controller.js | 33 ++-
.../devtools/webaudioeditor/webaudioeditor-view.js | 20 +-
toolkit/devtools/server/actors/webaudio.js | 254 +++++++++++++++++----
11 files changed, 471 insertions(+), 54 deletions(-)
create mode 100644 browser/devtools/webaudioeditor/test/browser_wa_properties-view-change-params.js
create mode 100644 browser/devtools/webaudioeditor/test/browser_webaudio-actor-change-params-01.js
create mode 100644 browser/devtools/webaudioeditor/test/browser_webaudio-actor-change-params-02.js
create mode 100644 browser/devtools/webaudioeditor/test/browser_webaudio-actor-change-params-03.js
create mode 100644 browser/devtools/webaudioeditor/test/doc_change-param.html
diff --git a/browser/devtools/shared/frame-script-utils.js b/browser/devtools/shared/frame-script-utils.js
index 51068b8..aee6bd1 100644
--- a/browser/devtools/shared/frame-script-utils.js
+++ b/browser/devtools/shared/frame-script-utils.js
@@ -1,18 +1,28 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
+let { utils: Cu, interfaces: Ci } = Components;
+
addMessageListener("devtools:test:history", function ({ data }) {
content.history[data.direction]();
});
addMessageListener("devtools:test:navigate", function ({ data }) {
content.location = data.location;
});
addMessageListener("devtools:test:reload", function ({ data }) {
data = data || {};
content.location.reload(data.forceget);
});
+
+addMessageListener("devtools:test:forceCC", function () {
+ let DOMWindowUtils = content.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindowUtils)
+ DOMWindowUtils.cycleCollect();
+ DOMWindowUtils.garbageCollect();
+ DOMWindowUtils.garbageCollect();
+});
diff --git a/browser/devtools/webaudioeditor/test/browser.ini b/browser/devtools/webaudioeditor/test/browser.ini
index 84dca5d..d56008c 100644
--- a/browser/devtools/webaudioeditor/test/browser.ini
+++ b/browser/devtools/webaudioeditor/test/browser.ini
@@ -4,28 +4,32 @@ support-files =
doc_simple-context.html
doc_complex-context.html
doc_simple-node-creation.html
doc_buffer-and-array.html
doc_media-node-creation.html
doc_destroy-nodes.html
doc_connect-toggle.html
doc_connect-param.html
+ doc_change-param.html
440hz_sine.ogg
head.js
[browser_audionode-actor-get-set-param.js]
[browser_audionode-actor-get-type.js]
+[browser_audionode-actor-get-param-flags.js]
[browser_audionode-actor-get-params-01.js]
[browser_audionode-actor-get-params-02.js]
-[browser_audionode-actor-get-param-flags.js]
[browser_audionode-actor-is-source.js]
[browser_webaudio-actor-simple.js]
[browser_webaudio-actor-destroy-node.js]
[browser_webaudio-actor-connect-param.js]
+[browser_webaudio-actor-change-params-01.js]
+[browser_webaudio-actor-change-params-02.js]
+[browser_webaudio-actor-change-params-03.js]
[browser_wa_destroy-node-01.js]
[browser_wa_first-run.js]
[browser_wa_reset-01.js]
[browser_wa_reset-02.js]
[browser_wa_reset-03.js]
@@ -41,9 +45,10 @@ support-files =
[browser_wa_inspector-toggle.js]
[browser_wa_properties-view.js]
[browser_wa_properties-view-media-nodes.js]
# [browser_wa_properties-view-edit-01.js]
# [browser_wa_properties-view-edit-02.js]
# Disabled for too many intermittents bug 1010423
[browser_wa_properties-view-params.js]
+[browser_wa_properties-view-change-params.js]
[browser_wa_properties-view-params-objects.js]
diff --git a/browser/devtools/webaudioeditor/test/browser_wa_properties-view-change-params.js b/browser/devtools/webaudioeditor/test/browser_wa_properties-view-change-params.js
new file mode 100644
index 0000000..080f6a9
--- /dev/null
+++ b/browser/devtools/webaudioeditor/test/browser_wa_properties-view-change-params.js
@@ -0,0 +1,46 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Tests that params view correctly updates changed parameters
+ * when source code updates them, as well as CHANGE_PARAM events.
+ */
+
+function spawnTest() {
+ let [target, debuggee, panel] = yield initWebAudioEditor(CHANGE_PARAM_URL);
+ let { panelWin } = panel;
+ let { gFront, $, $$, EVENTS, WebAudioInspectorView } = panelWin;
+ let gVars = WebAudioInspectorView._propsView;
+
+ // Set parameter polling to 20ms for tests
+ panelWin.PARAM_POLLING_FREQUENCY = 20;
+
+ let started = once(gFront, "start-context");
+
+ reload(target);
+
+ let [actors] = yield Promise.all([
+ getN(gFront, "create-node", 3),
+ waitForGraphRendered(panelWin, 3, 0)
+ ]);
+
+ let oscId = actors[1].actorID;
+
+ click(panelWin, findGraphNode(panelWin, oscId));
+ yield once(panelWin, EVENTS.UI_INSPECTOR_NODE_SET);
+
+ // Yield twice so we get a diff
+ yield once(panelWin, EVENTS.CHANGE_PARAM);
+ let [[_, args]] = yield getSpread(panelWin, EVENTS.CHANGE_PARAM);
+ is(args.actorID, oscId, "EVENTS.CHANGE_PARAM has correct `actorID`");
+ ok(args.oldValue < args.newValue, "EVENTS.CHANGE_PARAM has correct `newValue` and `oldValue`");
+ is(args.param, "detune", "EVENTS.CHANGE_PARAM has correct `param`");
+
+ let [[_, args]] = yield getSpread(panelWin, EVENTS.CHANGE_PARAM);
+ checkVariableView(gVars, 0, { "detune": args.newValue }, "`detune` parameter updated.");
+ let [[_, args]] = yield getSpread(panelWin, EVENTS.CHANGE_PARAM);
+ checkVariableView(gVars, 0, { "detune": args.newValue }, "`detune` parameter updated.");
+
+ yield teardown(panel);
+ finish();
+}
diff --git a/browser/devtools/webaudioeditor/test/browser_webaudio-actor-change-params-01.js b/browser/devtools/webaudioeditor/test/browser_webaudio-actor-change-params-01.js
new file mode 100644
index 0000000..072a17d
--- /dev/null
+++ b/browser/devtools/webaudioeditor/test/browser_webaudio-actor-change-params-01.js
@@ -0,0 +1,46 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Test WebAudioActor `change-param` events and front.[en|dis]ableChangeParamEvents
+ */
+
+function spawnTest () {
+ let [target, debuggee, front] = yield initBackend(CHANGE_PARAM_URL);
+ let [_, nodes] = yield Promise.all([
+ front.setup({ reload: true }),
+ getN(front, "create-node", 3)
+ ]);
+
+ let osc = nodes[1];
+ let eventCount = 0;
+
+ yield front.enableChangeParamEvents(osc, 20);
+
+ front.on("change-param", onChangeParam);
+
+ yield getN(front, "change-param", 3);
+ yield front.disableChangeParamEvents();
+
+ let currEventCount = eventCount;
+
+ // Be flexible here incase we get an extra counter before the listener is turned off
+ ok(eventCount >= 3, "Calling `enableChangeParamEvents` should allow front to emit `change-param`.");
+
+ yield wait(100);
+
+ ok((eventCount - currEventCount) <= 2, "Calling `disableChangeParamEvents` should turn off the listener.");
+
+ front.off("change-param", onChangeParam);
+
+ yield removeTab(target.tab);
+ finish();
+
+ function onChangeParam ({ newValue, oldValue, param, actorID }) {
+ is(actorID, osc.actorID, "correct `actorID` in `change-param`.");
+ is(param, "detune", "correct `param` property in `change-param`.");
+ ok(newValue > oldValue,
+ "correct `newValue` (" + newValue + ") and `oldValue` (" + oldValue + ") in `change-param`");
+ eventCount++;
+ }
+}
diff --git a/browser/devtools/webaudioeditor/test/browser_webaudio-actor-change-params-02.js b/browser/devtools/webaudioeditor/test/browser_webaudio-actor-change-params-02.js
new file mode 100644
index 0000000..b650e5e
--- /dev/null
+++ b/browser/devtools/webaudioeditor/test/browser_webaudio-actor-change-params-02.js
@@ -0,0 +1,36 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Test that listening to param change polling does not break when the AudioNode is collected.
+ */
+
+function spawnTest () {
+ let [target, debuggee, front] = yield initBackend(DESTROY_NODES_URL);
+ let waitUntilDestroyed = getN(front, "destroy-node", 10);
+ let [_, nodes] = yield Promise.all([
+ front.setup({ reload: true }),
+ getN(front, "create-node", 13)
+ ]);
+
+ let bufferNode = nodes[6];
+
+ yield front.enableChangeParamEvents(bufferNode, 20);
+
+ front.on("change-param", onChangeParam);
+
+ forceCC();
+
+ yield waitUntilDestroyed;
+ yield wait(50);
+
+ front.off("change-param", onChangeParam);
+
+ ok(true, "listening to `change-param` on a dead node doesn't throw.");
+ yield removeTab(target.tab);
+ finish();
+
+ function onChangeParam (args) {
+ ok(false, "`change-param` should not be emitted on a node that hasn't changed params or is dead.");
+ }
+}
diff --git a/browser/devtools/webaudioeditor/test/browser_webaudio-actor-change-params-03.js b/browser/devtools/webaudioeditor/test/browser_webaudio-actor-change-params-03.js
new file mode 100644
index 0000000..43715cb
--- /dev/null
+++ b/browser/devtools/webaudioeditor/test/browser_webaudio-actor-change-params-03.js
@@ -0,0 +1,32 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Test WebAudioActor `change-param` events on special types.
+ */
+
+function spawnTest () {
+ let [target, debuggee, front] = yield initBackend(CHANGE_PARAM_URL);
+ let [_, nodes] = yield Promise.all([
+ front.setup({ reload: true }),
+ getN(front, "create-node", 3)
+ ]);
+
+ let shaper = nodes[2];
+ let eventCount = 0;
+
+ yield front.enableChangeParamEvents(shaper, 20);
+
+ let onChange = once(front, "change-param");
+
+ shaper.setParam("curve", null);
+
+ let { newValue, oldValue } = yield onChange;
+
+ is(oldValue.type, "object", "`oldValue` should be an object.");
+ is(oldValue.class, "Float32Array", "`oldValue` should be of class Float32Array.");
+ is(newValue.type, "null", "`newValue` should be null.");
+
+ yield removeTab(target.tab);
+ finish();
+}
diff --git a/browser/devtools/webaudioeditor/test/doc_change-param.html b/browser/devtools/webaudioeditor/test/doc_change-param.html
new file mode 100644
index 0000000..c8925d9
--- /dev/null
+++ b/browser/devtools/webaudioeditor/test/doc_change-param.html
@@ -0,0 +1,25 @@
+<!-- Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ -->
+<!doctype html>
+
+<html>
+ <head>
+ <meta charset="utf-8"/>
+ <title>Web Audio Editor test page</title>
+ </head>
+
+ <body>
+
+ <script type="text/javascript;version=1.8">
+ "use strict";
+
+ let ctx = new AudioContext();
+ let osc = ctx.createOscillator();
+ let shaperNode = ctx.createWaveShaper();
+ let detuneVal = 0;
+ shaperNode.curve = new Float32Array(65536);
+ setInterval(() => osc.detune.value = ++detuneVal, 10);
+ </script>
+ </body>
+
+</html>
diff --git a/browser/devtools/webaudioeditor/test/head.js b/browser/devtools/webaudioeditor/test/head.js
index ec4aa4a..c97ea3a 100644
--- a/browser/devtools/webaudioeditor/test/head.js
+++ b/browser/devtools/webaudioeditor/test/head.js
@@ -14,26 +14,29 @@ Services.prefs.setBoolPref("devtools.debugger.log", true);
let { Task } = Cu.import("resource://gre/modules/Task.jsm", {});
let { Promise } = Cu.import("resource://gre/modules/Promise.jsm", {});
let { gDevTools } = Cu.import("resource:///modules/devtools/gDevTools.jsm", {});
let { devtools } = Cu.import("resource://gre/modules/devtools/Loader.jsm", {});
let { DebuggerServer } = Cu.import("resource://gre/modules/devtools/dbg-server.jsm", {});
let { WebAudioFront } = devtools.require("devtools/server/actors/webaudio");
let TargetFactory = devtools.TargetFactory;
+let mm = null;
+const FRAME_SCRIPT_UTILS_URL = "chrome://browser/content/devtools/frame-script-utils.js";
const EXAMPLE_URL = "http://example.com/browser/browser/devtools/webaudioeditor/test/";
const SIMPLE_CONTEXT_URL = EXAMPLE_URL + "doc_simple-context.html";
const COMPLEX_CONTEXT_URL = EXAMPLE_URL + "doc_complex-context.html";
const SIMPLE_NODES_URL = EXAMPLE_URL + "doc_simple-node-creation.html";
const MEDIA_NODES_URL = EXAMPLE_URL + "doc_media-node-creation.html";
const BUFFER_AND_ARRAY_URL = EXAMPLE_URL + "doc_buffer-and-array.html";
const DESTROY_NODES_URL = EXAMPLE_URL + "doc_destroy-nodes.html";
const CONNECT_TOGGLE_URL = EXAMPLE_URL + "doc_connect-toggle.html";
const CONNECT_PARAM_URL = EXAMPLE_URL + "doc_connect-param.html";
+const CHANGE_PARAM_URL = EXAMPLE_URL + "doc_change-param.html";
// All tests are asynchronous.
waitForExplicitFinish();
let gToolEnabled = Services.prefs.getBoolPref("devtools.webaudioeditor.enabled");
registerCleanupFunction(() => {
info("finish() was called, cleaning up...");
@@ -127,16 +130,18 @@ function initBackend(aUrl) {
return Task.spawn(function*() {
let tab = yield addTab(aUrl);
let target = TargetFactory.forTab(tab);
let debuggee = target.window.wrappedJSObject;
yield target.makeRemote();
let front = new WebAudioFront(target.client, target.form);
+
+ loadFrameScripts();
return [target, debuggee, front];
});
}
function initWebAudioEditor(aUrl) {
info("Initializing a web audio editor pane.");
return Task.spawn(function*() {
@@ -144,16 +149,18 @@ function initWebAudioEditor(aUrl) {
let target = TargetFactory.forTab(tab);
let debuggee = target.window.wrappedJSObject;
yield target.makeRemote();
Services.prefs.setBoolPref("devtools.webaudioeditor.enabled", true);
let toolbox = yield gDevTools.showToolbox(target, "webaudioeditor");
let panel = toolbox.getCurrentPanel();
+
+ loadFrameScripts();
return [target, debuggee, panel];
});
}
function teardown(aPanel) {
info("Destroying the web audio editor.");
return Promise.all([
@@ -374,19 +381,22 @@ function countGraphObjects (win) {
edges: win.document.querySelectorAll(".edgePaths > .edgePath").length
}
}
/**
* Forces cycle collection and GC, used in AudioNode destruction tests.
*/
function forceCC () {
- SpecialPowers.DOMWindowUtils.cycleCollect();
- SpecialPowers.DOMWindowUtils.garbageCollect();
- SpecialPowers.DOMWindowUtils.garbageCollect();
+ mm.sendAsyncMessage("devtools:test:forceCC");
+}
+
+function loadFrameScripts () {
+ mm = gBrowser.selectedBrowser.messageManager;
+ mm.loadFrameScript(FRAME_SCRIPT_UTILS_URL, false);
}
/**
* List of audio node properties to test against expectations of the AudioNode actor
*/
const NODE_DEFAULT_VALUES = {
"AudioDestinationNode": {},
diff --git a/browser/devtools/webaudioeditor/webaudioeditor-controller.js b/browser/devtools/webaudioeditor/webaudioeditor-controller.js
index b8a801f9..cc865a6 100644
--- a/browser/devtools/webaudioeditor/webaudioeditor-controller.js
+++ b/browser/devtools/webaudioeditor/webaudioeditor-controller.js
@@ -15,19 +15,20 @@ const { defer, all } = Cu.import("resource://gre/modules/Promise.jsm", {}).Promi
const { Task } = Cu.import("resource://gre/modules/Task.jsm", {});
const require = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools.require;
const EventEmitter = require("devtools/toolkit/event-emitter");
const STRINGS_URI = "chrome://browser/locale/devtools/webaudioeditor.properties"
const L10N = new ViewHelpers.L10N(STRINGS_URI);
const Telemetry = require("devtools/shared/telemetry");
const telemetry = new Telemetry();
-
let { console } = Cu.import("resource://gre/modules/devtools/Console.jsm", {});
+let PARAM_POLLING_FREQUENCY = 1000;
+
// The panel's window global is an EventEmitter firing the following events:
const EVENTS = {
// Fired when the first AudioNode has been created, signifying
// that the AudioContext is being used and should be tracked via the editor.
START_CONTEXT: "WebAudioEditor:StartContext",
// On node creation, connect and disconnect.
CREATE_NODE: "WebAudioEditor:CreateNode",
@@ -149,16 +150,18 @@ function shutdownWebAudioEditor() {
let WebAudioEditorController = {
/**
* Listen for events emitted by the current tab target.
*/
initialize: function() {
telemetry.toolOpened("webaudioeditor");
this._onTabNavigated = this._onTabNavigated.bind(this);
this._onThemeChange = this._onThemeChange.bind(this);
+ this._onSelectNode = this._onSelectNode.bind(this);
+ this._onChangeParam = this._onChangeParam.bind(this);
gTarget.on("will-navigate", this._onTabNavigated);
gTarget.on("navigate", this._onTabNavigated);
gFront.on("start-context", this._onStartContext);
gFront.on("create-node", this._onCreateNode);
gFront.on("connect-node", this._onConnectNode);
gFront.on("disconnect-node", this._onDisconnectNode);
gFront.on("change-param", this._onChangeParam);
gFront.on("destroy-node", this._onDestroyNode);
@@ -168,37 +171,43 @@ let WebAudioEditorController = {
// with CSS
gDevTools.on("pref-changed", this._onThemeChange);
// Set up events to refresh the Graph view
window.on(EVENTS.CREATE_NODE, this._onUpdatedContext);
window.on(EVENTS.CONNECT_NODE, this._onUpdatedContext);
window.on(EVENTS.DISCONNECT_NODE, this._onUpdatedContext);
window.on(EVENTS.DESTROY_NODE, this._onUpdatedContext);
+
+ // Set up a controller for managing parameter changes per audio node
+ window.on(EVENTS.UI_SELECT_NODE, this._onSelectNode);
},
/**
* Remove events emitted by the current tab target.
*/
- destroy: function() {
+ destroy: Task.async(function* () {
telemetry.toolClosed("webaudioeditor");
gTarget.off("will-navigate", this._onTabNavigated);
gTarget.off("navigate", this._onTabNavigated);
gFront.off("start-context", this._onStartContext);
gFront.off("create-node", this._onCreateNode);
gFront.off("connect-node", this._onConnectNode);
gFront.off("disconnect-node", this._onDisconnectNode);
gFront.off("change-param", this._onChangeParam);
gFront.off("destroy-node", this._onDestroyNode);
window.off(EVENTS.CREATE_NODE, this._onUpdatedContext);
window.off(EVENTS.CONNECT_NODE, this._onUpdatedContext);
window.off(EVENTS.DISCONNECT_NODE, this._onUpdatedContext);
window.off(EVENTS.DESTROY_NODE, this._onUpdatedContext);
+ window.off(EVENTS.UI_SELECT_NODE, this._onSelectNode);
gDevTools.off("pref-changed", this._onThemeChange);
- },
+
+ yield gFront.disableChangeParamEvents();
+ }),
/**
* Called when page is reloaded to show the reload notice and waiting
* for an audio context notice.
*/
reset: function () {
$("#reload-notice").hidden = true;
$("#waiting-notice").hidden = false;
@@ -333,19 +342,31 @@ let WebAudioEditorController = {
let node = getViewNodeByActor(nodeActor);
node.disconnect();
window.emit(EVENTS.DISCONNECT_NODE, node.id);
},
/**
* Called when a node param is changed.
*/
- _onChangeParam: function({ actor, param, value }) {
- window.emit(EVENTS.CHANGE_PARAM, getViewNodeByActor(actor), param, value);
- }
+ _onChangeParam: function (args) {
+ window.emit(EVENTS.CHANGE_PARAM, args);
+ },
+
+ /**
+ * Called on UI_SELECT_NODE, used to manage
+ * `change-param` events on that node.
+ */
+ _onSelectNode: function (_, id) {
+ let node = getViewNodeById(id);
+
+ if (node && node.actor) {
+ gFront.enableChangeParamEvents(node.actor, PARAM_POLLING_FREQUENCY);
+ }
+ },
};
/**
* Convenient way of emitting events from the panel window.
*/
EventEmitter.decorate(this);
/**
diff --git a/browser/devtools/webaudioeditor/webaudioeditor-view.js b/browser/devtools/webaudioeditor/webaudioeditor-view.js
index 8b69fc4..2eeb06c 100644
--- a/browser/devtools/webaudioeditor/webaudioeditor-view.js
+++ b/browser/devtools/webaudioeditor/webaudioeditor-view.js
@@ -334,32 +334,35 @@ let WebAudioInspectorView = {
// Hide inspector view on startup
this._inspectorPane.setAttribute("width", INSPECTOR_WIDTH);
this.toggleInspector({ visible: false, delayed: false, animated: false });
this._onEval = this._onEval.bind(this);
this._onNodeSelect = this._onNodeSelect.bind(this);
this._onTogglePaneClick = this._onTogglePaneClick.bind(this);
this._onDestroyNode = this._onDestroyNode.bind(this);
+ this._onChangeParam = this._onChangeParam.bind(this);
this._inspectorPaneToggleButton.addEventListener("mousedown", this._onTogglePaneClick, false);
this._propsView = new VariablesView($("#properties-tabpanel-content"), GENERIC_VARIABLES_VIEW_SETTINGS);
this._propsView.eval = this._onEval;
window.on(EVENTS.UI_SELECT_NODE, this._onNodeSelect);
window.on(EVENTS.DESTROY_NODE, this._onDestroyNode);
+ window.on(EVENTS.CHANGE_PARAM, this._onChangeParam);
},
/**
* Destruction function called when the tool cleans up.
*/
destroy: function () {
this._inspectorPaneToggleButton.removeEventListener("mousedown", this._onTogglePaneClick);
window.off(EVENTS.UI_SELECT_NODE, this._onNodeSelect);
window.off(EVENTS.DESTROY_NODE, this._onDestroyNode);
+ window.off(EVENTS.CHANGE_PARAM, this._onChangeParam);
this._inspectorPane = null;
this._inspectorPaneToggleButton = null;
this._tabsPane = null;
},
/**
* Toggles the visibility of the AudioNode Inspector.
@@ -569,17 +572,32 @@ let WebAudioInspectorView = {
/**
* Called when `DESTROY_NODE` is fired to remove the node from props view if
* it's currently selected.
*/
_onDestroyNode: function (_, id) {
if (this._currentNode && this._currentNode.id === id) {
this.setCurrentAudioNode(null);
}
- }
+ },
+
+ /**
+ * Called when `CHANGE_PARAM` is fired. We should ensure that this event is
+ * for the same node that is currently selected. We check the existence
+ * of each part of the scope to make sure that if this event was fired
+ * during a VariablesView rebuild, then we just ignore it.
+ */
+ _onChangeParam: function (_, { param, newValue, oldValue, actorID }) {
+ if (!this._currentNode || this._currentNode.actor.actorID !== actorID) return;
+ let scope = this._getAudioPropertiesScope();
+ if (!scope) return;
+ let property = scope.get(param);
+ if (!property) return;
+ property.setGrip(newValue);
+ },
};
/**
* Takes an element in an SVG graph and iterates over
* ancestors until it finds the graph node container. If not found,
* returns null.
*/
diff --git a/toolkit/devtools/server/actors/webaudio.js b/toolkit/devtools/server/actors/webaudio.js
index 4cea0f9..ef9b0fe 100644
--- a/toolkit/devtools/server/actors/webaudio.js
+++ b/toolkit/devtools/server/actors/webaudio.js
@@ -1,37 +1,39 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const {Cc, Ci, Cu, Cr} = require("chrome");
-
const Services = require("Services");
-
const { Promise: promise } = Cu.import("resource://gre/modules/Promise.jsm", {});
const events = require("sdk/event/core");
const { on: systemOn, off: systemOff } = require("sdk/system/events");
+const { setTimeout, clearTimeout } = require("sdk/timers");
const protocol = require("devtools/server/protocol");
const { CallWatcherActor, CallWatcherFront } = require("devtools/server/actors/call-watcher");
const { ThreadActor } = require("devtools/server/actors/script");
-
const { on, once, off, emit } = events;
const { method, Arg, Option, RetVal } = protocol;
exports.register = function(handle) {
handle.addTabActor(WebAudioActor, "webaudioActor");
handle.addGlobalActor(WebAudioActor, "webaudioActor");
};
exports.unregister = function(handle) {
handle.removeTabActor(WebAudioActor);
handle.removeGlobalActor(WebAudioActor);
};
+// In milliseconds, how often should AudioNodes poll to see
+// if an AudioParam's value has changed to emit to the client.
+const PARAM_POLLING_FREQUENCY = 1000;
+
const AUDIO_GLOBALS = [
"AudioContext", "AudioNode"
];
const NODE_CREATION_METHODS = [
"createBufferSource", "createMediaElementSource", "createMediaStreamSource",
"createMediaStreamDestination", "createScriptProcessor", "createAnalyser",
"createGain", "createDelay", "createBiquadFilter", "createWaveShaper",
@@ -141,16 +143,20 @@ let AudioNodeActor = exports.AudioNodeActor = protocol.ActorClass({
try {
this.type = getConstructorName(node);
} catch (e) {
this.type = "";
}
},
+ destroy: function(conn) {
+ protocol.Actor.prototype.destroy.call(this, conn);
+ },
+
/**
* Returns the name of the audio type.
* Examples: "OscillatorNode", "MediaElementAudioSourceNode"
*/
getType: method(function () {
return this.type;
}, {
response: { type: RetVal("string") }
@@ -182,16 +188,17 @@ let AudioNodeActor = exports.AudioNodeActor = protocol.ActorClass({
return CollectedAudioNodeError();
}
try {
if (isAudioParam(node, param))
node[param].value = value;
else
node[param] = value;
+
return undefined;
} catch (e) {
return constructError(e);
}
}, {
request: {
param: Arg(0, "string"),
value: Arg(1, "nullable:primitive")
@@ -216,24 +223,17 @@ let AudioNodeActor = exports.AudioNodeActor = protocol.ActorClass({
// return the `value` property of the parameter.
let value = isAudioParam(node, param) ? node[param].value : node[param];
// Return the grip form of the value; at this time,
// there shouldn't be any non-primitives at the moment, other than
// AudioBuffer or Float32Array references and the like,
// so this just formats the value to be displayed in the VariablesView,
// without using real grips and managing via actor pools.
- let grip;
- try {
- grip = ThreadActor.prototype.createValueGrip(value);
- }
- catch (e) {
- grip = createObjectGrip(value);
- }
- return grip;
+ return createGrip(value);
}, {
request: {
param: Arg(0, "string")
},
response: { text: RetVal("nullable:primitive") }
}),
/**
@@ -247,26 +247,37 @@ let AudioNodeActor = exports.AudioNodeActor = protocol.ActorClass({
getParamFlags: method(function (param) {
return (NODE_PROPERTIES[this.type] || {})[param];
}, {
request: { param: Arg(0, "string") },
response: { flags: RetVal("nullable:primitive") }
}),
/**
- * Get an array of objects each containing a `param` and `value` property,
- * corresponding to a property name and current value of the audio node.
+ * Get an array of objects each containing a `param`, `value` and `flags` property,
+ * corresponding to a property name and current value of the audio node, and any
+ * associated flags as defined by NODE_PROPERTIES.
*/
- getParams: method(function (param) {
+ getParams: method(function () {
let props = Object.keys(NODE_PROPERTIES[this.type]);
return props.map(prop =>
({ param: prop, value: this.getParam(prop), flags: this.getParamFlags(prop) }));
}, {
response: { params: RetVal("json") }
- })
+ }),
+
+ /**
+ * Returns a boolean indicating whether or not
+ * the underlying AudioNode has been collected yet or not.
+ *
+ * @return Boolean
+ */
+ isAlive: function () {
+ return !!this.node.get();
+ }
});
/**
* The corresponding Front object for the AudioNodeActor.
*/
let AudioNodeFront = protocol.FrontClass(AudioNodeActor, {
initialize: function (client, form) {
protocol.Front.prototype.initialize.call(this, client, form);
@@ -402,25 +413,79 @@ let WebAudioActor = exports.WebAudioActor = protocol.ActorClass({
*/
finalize: method(function() {
if (!this._initialized) {
return;
}
this.tabActor = null;
this._initialized = false;
off(this._callWatcher._contentObserver, "global-destroyed", this._onGlobalDestroyed);
+ this.disableChangeParamEvents();
this._nativeToActorID = null;
this._callWatcher.eraseRecording();
this._callWatcher.finalize();
this._callWatcher = null;
}, {
oneway: true
}),
/**
+ * Takes an AudioNodeActor and a duration specifying how often
+ * should the node's parameters be polled to detect changes. Emits
+ * `change-param` when a change is found.
+ *
+ * Currently, only one AudioNodeActor can be listened to at a time.
+ *
+ * `wait` is used in tests to specify the poll timer.
+ */
+ enableChangeParamEvents: method(function (nodeActor, wait) {
+ // For now, only have one node being polled
+ this.disableChangeParamEvents();
+
+ // Ignore if node is dead
+ if (!nodeActor.isAlive()) {
+ return;
+ }
+
+ let previous = mapAudioParams(nodeActor);
+
+ // Store the ID of the node being polled
+ this._pollingID = nodeActor.actorID;
+
+ this.poller = new Poller(() => {
+ // If node has been collected, disable param polling
+ if (!nodeActor.isAlive()) {
+ this.disableChangeParamEvents();
+ return;
+ }
+
+ let current = mapAudioParams(nodeActor);
+ diffAudioParams(previous, current).forEach(changed => {
+ this._onChangeParam(nodeActor, changed);
+ });
+ previous = current;
+ }).on(wait || PARAM_POLLING_FREQUENCY);
+ }, {
+ request: {
+ node: Arg(0, "audionode"),
+ wait: Arg(1, "nullable:number"),
+ },
+ oneway: true
+ }),
+
+ disableChangeParamEvents: method(function () {
+ if (this.poller) {
+ this.poller.off();
+ }
+ this._pollingID = null;
+ }, {
+ oneway: true
+ }),
+
+ /**
* Events emitted by this actor.
*/
events: {
"start-context": {
type: "startContext"
},
"connect-node": {
type: "connectNode",
@@ -432,29 +497,30 @@ let WebAudioActor = exports.WebAudioActor = protocol.ActorClass({
source: Arg(0, "audionode")
},
"connect-param": {
type: "connectParam",
source: Option(0, "audionode"),
dest: Option(0, "audionode"),
param: Option(0, "string")
},
- "change-param": {
- type: "changeParam",
- source: Option(0, "audionode"),
- param: Option(0, "string"),
- value: Option(0, "string")
- },
"create-node": {
type: "createNode",
source: Arg(0, "audionode")
},
"destroy-node": {
type: "destroyNode",
source: Arg(0, "audionode")
+ },
+ "change-param": {
+ type: "changeParam",
+ param: Option(0, "string"),
+ newValue: Option(0, "json"),
+ oldValue: Option(0, "json"),
+ actorID: Option(0, "string")
}
},
/**
* Helper for constructing an AudioNodeActor, assigning to
* internal weak map, and tracking via `manage` so it is assigned
* an `actorID`.
*/
@@ -468,17 +534,17 @@ let WebAudioActor = exports.WebAudioActor = protocol.ActorClass({
this.manage(actor);
this._nativeToActorID.set(node.id, actor.actorID);
return actor;
},
/**
* Takes an XrayWrapper node, and attaches the node's `nativeID`
* to the AudioParams as `_parentID`, as well as the the type of param
- * as a string on `_paramName`.
+ * as a string on `_paramName`. Used to tag AudioParams for `connect-param` events.
*/
_instrumentParams: function (node) {
let type = getConstructorName(node);
Object.keys(NODE_PROPERTIES[type])
.filter(isAudioParam.bind(null, node))
.forEach(paramName => {
let param = node[paramName];
param._parentID = node.id;
@@ -488,16 +554,24 @@ let WebAudioActor = exports.WebAudioActor = protocol.ActorClass({
/**
* Takes an AudioNode and returns the stored actor for it.
* In some cases, we won't have an actor stored (for example,
* connecting to an AudioDestinationNode, since it's implicitly
* created), so make a new actor and store that.
*/
_getActorByNativeID: function (nativeID) {
+ // If the WebAudioActor has already been finalized, the `_nativeToActorID`
+ // map will already be destroyed -- the lingering destruction events
+ // seem to only occur in e10s, so add an extra check here to disregard
+ // these late events
+ if (!this._nativeToActorID) {
+ return null;
+ }
+
// Ensure we have a Number, rather than a string
// return via notification.
nativeID = ~~nativeID;
let actorID = this._nativeToActorID.get(nativeID);
let actor = actorID != null ? this.conn.getActor(actorID) : null;
return actor;
},
@@ -539,48 +613,50 @@ let WebAudioActor = exports.WebAudioActor = protocol.ActorClass({
* Called when an audio node is disconnected.
*/
_onDisconnectNode: function (node) {
let actor = this._getActorByNativeID(node.id);
emit(this, "disconnect-node", actor);
},
/**
- * Called when a parameter changes on an audio node
+ * Called when an AudioParam that's being listened to changes.
+ * Takes an AudioNodeActor and an object with `newValue`, `oldValue`, and `param` name.
*/
- _onParamChange: function (node, param, value) {
- let actor = this._getActorByNativeID(node.id);
- emit(this, "param-change", {
- source: actor,
- param: param,
- value: value
- });
+ _onChangeParam: function (actor, changed) {
+ changed.actorID = actor.actorID;
+ emit(this, "change-param", changed);
},
/**
* Called on node creation.
*/
_onCreateNode: function (node) {
let actor = this._constructAudioNode(node);
emit(this, "create-node", actor);
},
- /** Called when `webaudio-node-demise` is triggered,
+ /**
+ * Called when `webaudio-node-demise` is triggered,
* and emits the associated actor to the front if found.
*/
_onDestroyNode: function ({data}) {
// Cast to integer.
let nativeID = ~~data;
let actor = this._getActorByNativeID(nativeID);
// If actorID exists, emit; in the case where we get demise
// notifications for a document that no longer exists,
// the mapping should not be found, so we do not emit an event.
if (actor) {
+ // Turn off polling for changes if on for this node
+ if (this._pollingID === actor.actorID) {
+ this.disableChangeParamEvents();
+ }
this._nativeToActorID.delete(nativeID);
emit(this, "destroy-node", actor);
}
},
/**
* Called when the underlying ContentObserver fires `global-destroyed`
* so we can cleanup some things between the global being destroyed and
@@ -658,22 +734,114 @@ function CollectedAudioNodeError () {
* to a string of just the constructor name, like "OscillatorNode",
* or "Float32Array".
*/
function getConstructorName (obj) {
return obj.toString().match(/\[object ([^\[\]]*)\]\]?$/)[1];