forked from jsantell/firefox-patches
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1057042-wae-refactor.patch
3262 lines (3119 loc) · 113 KB
/
1057042-wae-refactor.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 312fba4b5f4fc56b4b0d2ec549cc204f90c6362b Mon Sep 17 00:00:00 2001
From: Jordan Santell <[email protected]>
Date: Tue, 23 Sep 2014 08:29:13 -0700
Subject: Bug 1057042 - Refactor front end of the web audio editor. r=vp
---
browser/devtools/jar.mn | 10 +-
browser/devtools/webaudioeditor/controller.js | 223 ++++++++
browser/devtools/webaudioeditor/includes.js | 98 ++++
browser/devtools/webaudioeditor/models.js | 274 +++++++++
browser/devtools/webaudioeditor/panel.js | 1 +
browser/devtools/webaudioeditor/test/browser.ini | 2 +
.../test/browser_wa_destroy-node-01.js | 14 +-
.../webaudioeditor/test/browser_wa_graph-click.js | 23 +-
.../test/browser_wa_graph-markers.js | 2 +-
.../test/browser_wa_graph-render-01.js | 6 +-
.../test/browser_wa_graph-render-02.js | 2 +-
.../test/browser_wa_graph-render-05.js | 27 +
.../webaudioeditor/test/browser_wa_graph-zoom.js | 24 +-
.../test/browser_wa_inspector-toggle.js | 12 +-
.../webaudioeditor/test/browser_wa_inspector.js | 8 +-
.../test/browser_wa_properties-view-edit-01.js | 4 +-
.../test/browser_wa_properties-view-edit-02.js | 4 +-
.../test/browser_wa_properties-view-media-nodes.js | 4 +-
.../browser_wa_properties-view-params-objects.js | 4 +-
.../test/browser_wa_properties-view-params.js | 4 +-
.../test/browser_wa_properties-view.js | 4 +-
.../webaudioeditor/test/browser_wa_reset-03.js | 14 +-
.../test/doc_connect-toggle-param.html | 27 +
browser/devtools/webaudioeditor/test/head.js | 9 +-
browser/devtools/webaudioeditor/views/context.js | 305 ++++++++++
browser/devtools/webaudioeditor/views/inspector.js | 240 ++++++++
browser/devtools/webaudioeditor/views/utils.js | 103 ++++
.../webaudioeditor/webaudioeditor-controller.js | 428 --------------
.../devtools/webaudioeditor/webaudioeditor-view.js | 636 ---------------------
browser/devtools/webaudioeditor/webaudioeditor.xul | 8 +-
30 files changed, 1381 insertions(+), 1139 deletions(-)
create mode 100644 browser/devtools/webaudioeditor/controller.js
create mode 100644 browser/devtools/webaudioeditor/includes.js
create mode 100644 browser/devtools/webaudioeditor/models.js
create mode 100644 browser/devtools/webaudioeditor/test/browser_wa_graph-render-05.js
create mode 100644 browser/devtools/webaudioeditor/test/doc_connect-toggle-param.html
create mode 100644 browser/devtools/webaudioeditor/views/context.js
create mode 100644 browser/devtools/webaudioeditor/views/inspector.js
create mode 100644 browser/devtools/webaudioeditor/views/utils.js
delete mode 100644 browser/devtools/webaudioeditor/webaudioeditor-controller.js
delete mode 100644 browser/devtools/webaudioeditor/webaudioeditor-view.js
diff --git a/browser/devtools/jar.mn b/browser/devtools/jar.mn
index 192ac9ac..1b58101 100644
--- a/browser/devtools/jar.mn
+++ b/browser/devtools/jar.mn
@@ -68,21 +68,25 @@ browser.jar:
content/browser/devtools/debugger-controller.js (debugger/debugger-controller.js)
content/browser/devtools/debugger-view.js (debugger/debugger-view.js)
content/browser/devtools/debugger-toolbar.js (debugger/debugger-toolbar.js)
content/browser/devtools/debugger-panes.js (debugger/debugger-panes.js)
content/browser/devtools/shadereditor.xul (shadereditor/shadereditor.xul)
content/browser/devtools/shadereditor.js (shadereditor/shadereditor.js)
content/browser/devtools/canvasdebugger.xul (canvasdebugger/canvasdebugger.xul)
content/browser/devtools/canvasdebugger.js (canvasdebugger/canvasdebugger.js)
- content/browser/devtools/webaudioeditor.xul (webaudioeditor/webaudioeditor.xul)
content/browser/devtools/d3.js (shared/d3.js)
+ content/browser/devtools/webaudioeditor.xul (webaudioeditor/webaudioeditor.xul)
content/browser/devtools/dagre-d3.js (webaudioeditor/lib/dagre-d3.js)
- content/browser/devtools/webaudioeditor-controller.js (webaudioeditor/webaudioeditor-controller.js)
- content/browser/devtools/webaudioeditor-view.js (webaudioeditor/webaudioeditor-view.js)
+ content/browser/devtools/webaudioeditor/includes.js (webaudioeditor/includes.js)
+ content/browser/devtools/webaudioeditor/models.js (webaudioeditor/models.js)
+ content/browser/devtools/webaudioeditor/controller.js (webaudioeditor/controller.js)
+ content/browser/devtools/webaudioeditor/views/utils.js (webaudioeditor/views/utils.js)
+ content/browser/devtools/webaudioeditor/views/context.js (webaudioeditor/views/context.js)
+ content/browser/devtools/webaudioeditor/views/inspector.js (webaudioeditor/views/inspector.js)
content/browser/devtools/profiler.xul (profiler/profiler.xul)
content/browser/devtools/profiler.js (profiler/profiler.js)
content/browser/devtools/ui-recordings.js (profiler/ui-recordings.js)
content/browser/devtools/ui-profile.js (profiler/ui-profile.js)
content/browser/devtools/responsivedesign/resize-commands.js (responsivedesign/resize-commands.js)
content/browser/devtools/commandline.css (commandline/commandline.css)
content/browser/devtools/commandlineoutput.xhtml (commandline/commandlineoutput.xhtml)
content/browser/devtools/commandlinetooltip.xhtml (commandline/commandlinetooltip.xhtml)
diff --git a/browser/devtools/webaudioeditor/controller.js b/browser/devtools/webaudioeditor/controller.js
new file mode 100644
index 0000000..ee8dc45
--- /dev/null
+++ b/browser/devtools/webaudioeditor/controller.js
@@ -0,0 +1,223 @@
+/* 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/. */
+
+/**
+ * A collection of `AudioNodeModel`s used throughout the editor
+ * to keep track of audio nodes within the audio context.
+ */
+let gAudioNodes = new AudioNodesCollection();
+
+/**
+ * Initializes the web audio editor views
+ */
+function startupWebAudioEditor() {
+ return all([
+ WebAudioEditorController.initialize(),
+ ContextView.initialize(),
+ InspectorView.initialize()
+ ]);
+}
+
+/**
+ * Destroys the web audio editor controller and views.
+ */
+function shutdownWebAudioEditor() {
+ return all([
+ WebAudioEditorController.destroy(),
+ ContextView.destroy(),
+ InspectorView.destroy(),
+ ]);
+}
+
+/**
+ * Functions handling target-related lifetime events.
+ */
+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);
+
+ 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("connect-param", this._onConnectParam);
+ gFront.on("disconnect-node", this._onDisconnectNode);
+ gFront.on("change-param", this._onChangeParam);
+ gFront.on("destroy-node", this._onDestroyNode);
+
+ // Hook into theme change so we can change
+ // the graph's marker styling, since we can't do this
+ // with CSS
+ gDevTools.on("pref-changed", this._onThemeChange);
+ },
+
+ /**
+ * Remove events emitted by the current tab target.
+ */
+ destroy: 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("connect-param", this._onConnectParam);
+ gFront.off("disconnect-node", this._onDisconnectNode);
+ gFront.off("change-param", this._onChangeParam);
+ gFront.off("destroy-node", this._onDestroyNode);
+ gDevTools.off("pref-changed", this._onThemeChange);
+ },
+
+ /**
+ * Called when page is reloaded to show the reload notice and waiting
+ * for an audio context notice.
+ */
+ reset: function () {
+ $("#content").hidden = true;
+ ContextView.resetUI();
+ InspectorView.resetUI();
+ },
+
+ // Since node create and connect are probably executed back to back,
+ // and the controller's `_onCreateNode` needs to look up type,
+ // the edge creation could be called before the graph node is actually
+ // created. This way, we can check and listen for the event before
+ // adding an edge.
+ _waitForNodeCreation: function (sourceActor, destActor) {
+ let deferred = defer();
+ let source = gAudioNodes.get(sourceActor.actorID);
+ let dest = gAudioNodes.get(destActor.actorID);
+
+ if (!source || !dest) {
+ gAudioNodes.on("add", function createNodeListener (createdNode) {
+ if (sourceActor.actorID === createdNode.id)
+ source = createdNode;
+ if (destActor.actorID === createdNode.id)
+ dest = createdNode;
+ if (source && dest) {
+ gAudioNodes.off("add", createNodeListener);
+ deferred.resolve([source, dest]);
+ }
+ });
+ }
+ else {
+ deferred.resolve([source, dest]);
+ }
+ return deferred.promise;
+ },
+
+ /**
+ * Fired when the devtools theme changes (light, dark, etc.)
+ * so that the graph can update marker styling, as that
+ * cannot currently be done with CSS.
+ */
+ _onThemeChange: function (event, data) {
+ window.emit(EVENTS.THEME_CHANGE, data.newValue);
+ },
+
+ /**
+ * Called for each location change in the debugged tab.
+ */
+ _onTabNavigated: Task.async(function* (event, {isFrameSwitching}) {
+ switch (event) {
+ case "will-navigate": {
+ // Make sure the backend is prepared to handle audio contexts.
+ if (!isFrameSwitching) {
+ yield gFront.setup({ reload: false });
+ }
+
+ // Clear out current UI.
+ this.reset();
+
+ // When switching to an iframe, ensure displaying the reload button.
+ // As the document has already been loaded without being hooked.
+ if (isFrameSwitching) {
+ $("#reload-notice").hidden = false;
+ $("#waiting-notice").hidden = true;
+ } else {
+ // Otherwise, we are loading a new top level document,
+ // so we don't need to reload anymore and should receive
+ // new node events.
+ $("#reload-notice").hidden = true;
+ $("#waiting-notice").hidden = false;
+ }
+
+ // Clear out stored audio nodes
+ gAudioNodes.reset();
+
+ window.emit(EVENTS.UI_RESET);
+ break;
+ }
+ case "navigate": {
+ // TODO Case of bfcache, needs investigating
+ // bug 994250
+ break;
+ }
+ }
+ }),
+
+ /**
+ * Called after the first audio node is created in an audio context,
+ * signaling that the audio context is being used.
+ */
+ _onStartContext: function() {
+ $("#reload-notice").hidden = true;
+ $("#waiting-notice").hidden = true;
+ $("#content").hidden = false;
+ window.emit(EVENTS.START_CONTEXT);
+ },
+
+ /**
+ * Called when a new node is created. Creates an `AudioNodeView` instance
+ * for tracking throughout the editor.
+ */
+ _onCreateNode: Task.async(function* (nodeActor) {
+ yield gAudioNodes.add(nodeActor);
+ }),
+
+ /**
+ * Called on `destroy-node` when an AudioNode is GC'd. Removes
+ * from the AudioNode array and fires an event indicating the removal.
+ */
+ _onDestroyNode: function (nodeActor) {
+ gAudioNodes.remove(gAudioNodes.get(nodeActor.actorID));
+ },
+
+ /**
+ * Called when a node is connected to another node.
+ */
+ _onConnectNode: Task.async(function* ({ source: sourceActor, dest: destActor }) {
+ let [source, dest] = yield WebAudioEditorController._waitForNodeCreation(sourceActor, destActor);
+ source.connect(dest);
+ }),
+
+ /**
+ * Called when a node is conneceted to another node's AudioParam.
+ */
+ _onConnectParam: Task.async(function* ({ source: sourceActor, dest: destActor, param }) {
+ let [source, dest] = yield WebAudioEditorController._waitForNodeCreation(sourceActor, destActor);
+ source.connect(dest, param);
+ }),
+
+ /**
+ * Called when a node is disconnected.
+ */
+ _onDisconnectNode: function(nodeActor) {
+ let node = gAudioNodes.get(nodeActor.actorID);
+ node.disconnect();
+ },
+
+ /**
+ * Called when a node param is changed.
+ */
+ _onChangeParam: function({ actor, param, value }) {
+ window.emit(EVENTS.CHANGE_PARAM, gAudioNodes.get(actor.actorID), param, value);
+ }
+};
diff --git a/browser/devtools/webaudioeditor/includes.js b/browser/devtools/webaudioeditor/includes.js
new file mode 100644
index 0000000..ddac056
--- /dev/null
+++ b/browser/devtools/webaudioeditor/includes.js
@@ -0,0 +1,98 @@
+/* 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 { classes: Cc, interfaces: Ci, utils: Cu, results: Cr } = Components;
+
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+Cu.import("resource:///modules/devtools/ViewHelpers.jsm");
+Cu.import("resource:///modules/devtools/gDevTools.jsm");
+
+const require = Cu.import("resource://gre/modules/devtools/Loader.jsm", {}).devtools.require;
+
+let { console } = Cu.import("resource://gre/modules/devtools/Console.jsm", {});
+let { EventTarget } = require("sdk/event/target");
+const { Task } = Cu.import("resource://gre/modules/Task.jsm", {});
+const { Class } = require("sdk/core/heritage");
+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();
+
+// Override DOM promises with Promise.jsm helpers
+const { defer, all } = Cu.import("resource://gre/modules/Promise.jsm", {}).Promise;
+
+/* Events fired on `window` to indicate state or actions*/
+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",
+
+ // When the devtools theme changes.
+ THEME_CHANGE: "WebAudioEditor:ThemeChange",
+
+ // When the UI is reset from tab navigation.
+ UI_RESET: "WebAudioEditor:UIReset",
+
+ // When a param has been changed via the UI and successfully
+ // pushed via the actor to the raw audio node.
+ UI_SET_PARAM: "WebAudioEditor:UISetParam",
+
+ // When a node is to be set in the InspectorView.
+ UI_SELECT_NODE: "WebAudioEditor:UISelectNode",
+
+ // When the inspector is finished setting a new node.
+ UI_INSPECTOR_NODE_SET: "WebAudioEditor:UIInspectorNodeSet",
+
+ // When the inspector is finished rendering in or out of view.
+ UI_INSPECTOR_TOGGLED: "WebAudioEditor:UIInspectorToggled",
+
+ // When an audio node is finished loading in the Properties tab.
+ UI_PROPERTIES_TAB_RENDERED: "WebAudioEditor:UIPropertiesTabRendered",
+
+ // When the Audio Context graph finishes rendering.
+ // Is called with two arguments, first representing number of nodes
+ // rendered, second being the number of edge connections rendering (not counting
+ // param edges), followed by the count of the param edges rendered.
+ UI_GRAPH_RENDERED: "WebAudioEditor:UIGraphRendered"
+};
+
+/**
+ * The current target and the Web Audio Editor front, set by this tool's host.
+ */
+let gToolbox, gTarget, gFront;
+
+/**
+ * Convenient way of emitting events from the panel window.
+ */
+EventEmitter.decorate(this);
+
+/**
+ * DOM query helper.
+ */
+function $(selector, target = document) { return target.querySelector(selector); }
+function $$(selector, target = document) { return target.querySelectorAll(selector); }
+
+/**
+ * Takes an iterable collection, and a hash. Return the first
+ * object in the collection that matches the values in the hash.
+ * From Backbone.Collection#findWhere
+ * http://backbonejs.org/#Collection-findWhere
+ */
+function findWhere (collection, attrs) {
+ let keys = Object.keys(attrs);
+ for (let model of collection) {
+ if (keys.every(key => model[key] === attrs[key])) {
+ return model;
+ }
+ }
+ return void 0;
+}
+
+function mixin (source, ...args) {
+ args.forEach(obj => Object.keys(obj).forEach(prop => source[prop] = obj[prop]));
+ return source;
+}
diff --git a/browser/devtools/webaudioeditor/models.js b/browser/devtools/webaudioeditor/models.js
new file mode 100644
index 0000000..e9ce10c
--- /dev/null
+++ b/browser/devtools/webaudioeditor/models.js
@@ -0,0 +1,274 @@
+/* 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";
+
+// Import as different name `coreEmit`, so we don't conflict
+// with the global `window` listener itself.
+const { emit: coreEmit } = require("sdk/event/core");
+
+/**
+ * Representational wrapper around AudioNodeActors. Adding and destroying
+ * AudioNodes should be performed through the AudioNodes collection.
+ *
+ * Events:
+ * - `connect`: node, destinationNode, parameter
+ * - `disconnect`: node
+ */
+const AudioNodeModel = Class({
+ extends: EventTarget,
+
+ // Will be added via AudioNodes `add`
+ collection: null,
+
+ initialize: function (actor) {
+ this.actor = actor;
+ this.id = actor.actorID;
+ this.connections = [];
+ },
+
+ /**
+ * After instantiating the AudioNodeModel, calling `setup` caches values
+ * from the actor onto the model. In this case, only the type of audio node.
+ *
+ * @return promise
+ */
+ setup: Task.async(function* () {
+ yield this.getType();
+ }),
+
+ /**
+ * A proxy for the underlying AudioNodeActor to fetch its type
+ * and subsequently assign the type to the instance.
+ *
+ * @return Promise->String
+ */
+ getType: Task.async(function* () {
+ this.type = yield this.actor.getType();
+ return this.type;
+ }),
+
+ /**
+ * Stores connection data inside this instance of this audio node connecting
+ * to another node (destination). If connecting to another node's AudioParam,
+ * the second argument (param) must be populated with a string.
+ *
+ * Connecting nodes is idempotent. Upon new connection, emits "connect" event.
+ *
+ * @param AudioNodeModel destination
+ * @param String param
+ */
+ connect: function (destination, param) {
+ let edge = findWhere(this.connections, { destination: destination.id, param: param });
+
+ if (!edge) {
+ this.connections.push({ source: this.id, destination: destination.id, param: param });
+ coreEmit(this, "connect", this, destination, param);
+ }
+ },
+
+ /**
+ * Clears out all internal connection data. Emits "disconnect" event.
+ */
+ disconnect: function () {
+ this.connections.length = 0;
+ coreEmit(this, "disconnect", this);
+ },
+
+ /**
+ * Returns a promise that resolves to an array of objects containing
+ * both a `param` name property and a `value` property.
+ *
+ * @return Promise->Object
+ */
+ getParams: function () {
+ return this.actor.getParams();
+ },
+
+ /**
+ * Takes a `dagreD3.Digraph` object and adds this node to
+ * the graph to be rendered.
+ *
+ * @param dagreD3.Digraph
+ */
+ addToGraph: function (graph) {
+ graph.addNode(this.id, {
+ type: this.type,
+ label: this.type.replace(/Node$/, ""),
+ id: this.id
+ });
+ },
+
+ /**
+ * Takes a `dagreD3.Digraph` object and adds edges to
+ * the graph to be rendered. Separate from `addToGraph`,
+ * as while we depend on D3/Dagre's constraints, we cannot
+ * add edges for nodes that have not yet been added to the graph.
+ *
+ * @param dagreD3.Digraph
+ */
+ addEdgesToGraph: function (graph) {
+ for (let edge of this.connections) {
+ let options = {
+ source: this.id,
+ target: edge.destination
+ };
+
+ // Only add `label` if `param` specified, as this is an AudioParam
+ // connection then. `label` adds the magic to render with dagre-d3,
+ // and `param` is just more explicitly the param, ignoring
+ // implementation details.
+ if (edge.param) {
+ options.label = options.param = edge.param;
+ }
+
+ graph.addEdge(null, this.id, edge.destination, options);
+ }
+ }
+});
+
+
+/**
+ * Constructor for a Collection of `AudioNodeModel` models.
+ *
+ * Events:
+ * - `add`: node
+ * - `remove`: node
+ * - `connect`: node, destinationNode, parameter
+ * - `disconnect`: node
+ */
+const AudioNodesCollection = Class({
+ extends: EventTarget,
+
+ model: AudioNodeModel,
+
+ initialize: function () {
+ this.models = new Set();
+ this._onModelEvent = this._onModelEvent.bind(this);
+ },
+
+ /**
+ * Iterates over all models within the collection, calling `fn` with the
+ * model as the first argument.
+ *
+ * @param Function fn
+ */
+ forEach: function (fn) {
+ this.models.forEach(fn);
+ },
+
+ /**
+ * Creates a new AudioNodeModel, passing through arguments into the AudioNodeModel
+ * constructor, and adds the model to the internal collection store of this
+ * instance.
+ *
+ * Also calls `setup` on the model itself, and sets up event piping, so that
+ * events emitted on each model propagate to the collection itself.
+ *
+ * Emits "add" event on instance when completed.
+ *
+ * @param Object obj
+ * @return Promise->AudioNodeModel
+ */
+ add: Task.async(function* (obj) {
+ let node = new this.model(obj);
+ node.collection = this;
+ yield node.setup();
+
+ this.models.add(node);
+
+ node.on("*", this._onModelEvent);
+ coreEmit(this, "add", node);
+ return node;
+ }),
+
+ /**
+ * Removes an AudioNodeModel from the internal collection. Calls `delete` method
+ * on the model, and emits "remove" on this instance.
+ *
+ * @param AudioNodeModel node
+ */
+ remove: function (node) {
+ this.models.delete(node);
+ coreEmit(this, "remove", node);
+ },
+
+ /**
+ * Empties out the internal collection of all AudioNodeModels.
+ */
+ reset: function () {
+ this.models.clear();
+ },
+
+ /**
+ * Takes an `id` from an AudioNodeModel and returns the corresponding
+ * AudioNodeModel within the collection that matches that id. Returns `null`
+ * if not found.
+ *
+ * @param Number id
+ * @return AudioNodeModel|null
+ */
+ get: function (id) {
+ return findWhere(this.models, { id: id });
+ },
+
+ /**
+ * Returns the count for how many models are a part of this collection.
+ *
+ * @return Number
+ */
+ get length() {
+ return this.models.size;
+ },
+
+ /**
+ * Returns detailed information about the collection. used during tests
+ * to query state. Returns an object with information on node count,
+ * how many edges are within the data graph, as well as how many of those edges
+ * are for AudioParams.
+ *
+ * @return Object
+ */
+ getInfo: function () {
+ let info = {
+ nodes: this.length,
+ edges: 0,
+ paramEdges: 0
+ };
+
+ this.models.forEach(node => {
+ let paramEdgeCount = node.connections.filter(edge => edge.param).length;
+ info.edges += node.connections.length - paramEdgeCount;
+ info.paramEdges += paramEdgeCount;
+ });
+ return info;
+ },
+
+ /**
+ * Adds all nodes within the collection to the passed in graph,
+ * as well as their corresponding edges.
+ *
+ * @param dagreD3.Digraph
+ */
+ populateGraph: function (graph) {
+ this.models.forEach(node => node.addToGraph(graph));
+ this.models.forEach(node => node.addEdgesToGraph(graph));
+ },
+
+ /**
+ * Called when a stored model emits any event. Used to manage
+ * event propagation, or listening to model events to react, like
+ * removing a model from the collection when it's destroyed.
+ */
+ _onModelEvent: function (eventName, node, ...args) {
+ if (eventName === "remove") {
+ // If a `remove` event from the model, remove it
+ // from the collection, and let the method handle the emitting on
+ // the collection
+ this.remove(node);
+ } else {
+ // Pipe the event to the collection
+ coreEmit(this, eventName, [node].concat(args));
+ }
+ }
+});
diff --git a/browser/devtools/webaudioeditor/panel.js b/browser/devtools/webaudioeditor/panel.js
index f138b7c..fd4c7b9 100644
--- a/browser/devtools/webaudioeditor/panel.js
+++ b/browser/devtools/webaudioeditor/panel.js
@@ -30,16 +30,17 @@ WebAudioEditorPanel.prototype = {
} else {
targetPromise = Promise.resolve(this.target);
}
return targetPromise
.then(() => {
this.panelWin.gToolbox = this._toolbox;
this.panelWin.gTarget = this.target;
+
this.panelWin.gFront = new WebAudioFront(this.target.client, this.target.form);
return this.panelWin.startupWebAudioEditor();
})
.then(() => {
this.isReady = true;
this.emit("ready");
return this;
})
diff --git a/browser/devtools/webaudioeditor/test/browser.ini b/browser/devtools/webaudioeditor/test/browser.ini
index 9545b68..ec28d7d 100644
--- a/browser/devtools/webaudioeditor/test/browser.ini
+++ b/browser/devtools/webaudioeditor/test/browser.ini
@@ -3,16 +3,17 @@ subsuite = devtools
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-toggle-param.html
doc_connect-param.html
doc_connect-multi-param.html
doc_iframe-context.html
440hz_sine.ogg
head.js
[browser_audionode-actor-get-param-flags.js]
[browser_audionode-actor-get-params-01.js]
@@ -34,16 +35,17 @@ support-files =
[browser_wa_navigate.js]
[browser_wa_graph-click.js]
[browser_wa_graph-markers.js]
[browser_wa_graph-render-01.js]
[browser_wa_graph-render-02.js]
[browser_wa_graph-render-03.js]
[browser_wa_graph-render-04.js]
+[browser_wa_graph-render-05.js]
[browser_wa_graph-selected.js]
[browser_wa_graph-zoom.js]
[browser_wa_inspector.js]
[browser_wa_inspector-toggle.js]
[browser_wa_properties-view.js]
[browser_wa_properties-view-edit-01.js]
diff --git a/browser/devtools/webaudioeditor/test/browser_wa_destroy-node-01.js b/browser/devtools/webaudioeditor/test/browser_wa_destroy-node-01.js
index 6343cfd..d3f14a2 100644
--- a/browser/devtools/webaudioeditor/test/browser_wa_destroy-node-01.js
+++ b/browser/devtools/webaudioeditor/test/browser_wa_destroy-node-01.js
@@ -7,45 +7,45 @@
* that selecting a soon-to-be dead node clears the inspector.
*
* All done in one test since this test takes a few seconds to clear GC.
*/
function spawnTest() {
let [target, debuggee, panel] = yield initWebAudioEditor(DESTROY_NODES_URL);
let { panelWin } = panel;
- let { gFront, $, $$, EVENTS } = panelWin;
+ let { gFront, $, $$, gAudioNodes } = panelWin;
let started = once(gFront, "start-context");
reload(target);
- let destroyed = getN(panelWin, EVENTS.DESTROY_NODE, 10);
+ let destroyed = getN(gAudioNodes, "remove", 10);
forceCC();
let [created] = yield Promise.all([
- getNSpread(panelWin, EVENTS.CREATE_NODE, 13),
+ getNSpread(gAudioNodes, "add", 13),
waitForGraphRendered(panelWin, 13, 2)
]);
- // Since CREATE_NODE emits several arguments (eventName and actorID), let's
- // flatten it to just the actorIDs
- let actorIDs = created.map(ev => ev[1]);
+ // Flatten arrays of event arguments and take the first (AudioNodeModel)
+ // and get its ID.
+ let actorIDs = created.map(ev => ev[0].id);
// Click a soon-to-be dead buffer node
yield clickGraphNode(panelWin, actorIDs[5]);
forceCC();
// Wait for destruction and graph to re-render
yield Promise.all([destroyed, waitForGraphRendered(panelWin, 3, 2)]);
// Test internal storage
- is(panelWin.AudioNodes.length, 3, "All nodes should be GC'd except one gain, osc and dest node.");
+ is(panelWin.gAudioNodes.length, 3, "All nodes should be GC'd except one gain, osc and dest node.");
// Test graph rendering
ok(findGraphNode(panelWin, actorIDs[0]), "dest should be in graph");
ok(findGraphNode(panelWin, actorIDs[1]), "osc should be in graph");
ok(findGraphNode(panelWin, actorIDs[2]), "gain should be in graph");
let { nodes, edges } = countGraphObjects(panelWin);
diff --git a/browser/devtools/webaudioeditor/test/browser_wa_graph-click.js b/browser/devtools/webaudioeditor/test/browser_wa_graph-click.js
index 8e000fa..d6b3071 100644
--- a/browser/devtools/webaudioeditor/test/browser_wa_graph-click.js
+++ b/browser/devtools/webaudioeditor/test/browser_wa_graph-click.js
@@ -1,54 +1,51 @@
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/**
* Tests that the clicking on a node in the GraphView opens and sets
* the correct node in the InspectorView
*/
-let EVENTS = null;
-
function spawnTest() {
let [target, debuggee, panel] = yield initWebAudioEditor(COMPLEX_CONTEXT_URL);
let panelWin = panel.panelWin;
- let { gFront, $, $$, WebAudioInspectorView } = panelWin;
- EVENTS = panelWin.EVENTS;
+ let { gFront, $, $$, InspectorView } = panelWin;
let started = once(gFront, "start-context");
reload(target);
let [actors, _] = yield Promise.all([
getN(gFront, "create-node", 8),
waitForGraphRendered(panel.panelWin, 8, 8)
]);
let nodeIds = actors.map(actor => actor.actorID);
- ok(!WebAudioInspectorView.isVisible(), "InspectorView hidden on start.");
+ ok(!InspectorView.isVisible(), "InspectorView hidden on start.");
yield clickGraphNode(panelWin, nodeIds[1], true);
- ok(WebAudioInspectorView.isVisible(), "InspectorView visible after selecting a node.");
- is(WebAudioInspectorView.getCurrentAudioNode().id, nodeIds[1], "InspectorView has correct node set.");
+ ok(InspectorView.isVisible(), "InspectorView visible after selecting a node.");
+ is(InspectorView.getCurrentAudioNode().id, nodeIds[1], "InspectorView has correct node set.");
yield clickGraphNode(panelWin, nodeIds[2]);
- ok(WebAudioInspectorView.isVisible(), "InspectorView still visible after selecting another node.");
- is(WebAudioInspectorView.getCurrentAudioNode().id, nodeIds[2], "InspectorView has correct node set on second node.");
+ ok(InspectorView.isVisible(), "InspectorView still visible after selecting another node.");
+ is(InspectorView.getCurrentAudioNode().id, nodeIds[2], "InspectorView has correct node set on second node.");
yield clickGraphNode(panelWin, nodeIds[2]);
- is(WebAudioInspectorView.getCurrentAudioNode().id, nodeIds[2], "Clicking the same node again works (idempotent).");
+ is(InspectorView.getCurrentAudioNode().id, nodeIds[2], "Clicking the same node again works (idempotent).");
yield clickGraphNode(panelWin, $("rect", findGraphNode(panelWin, nodeIds[3])));
- is(WebAudioInspectorView.getCurrentAudioNode().id, nodeIds[3], "Clicking on a <rect> works as expected.");
+ is(InspectorView.getCurrentAudioNode().id, nodeIds[3], "Clicking on a <rect> works as expected.");
yield clickGraphNode(panelWin, $("tspan", findGraphNode(panelWin, nodeIds[4])));
- is(WebAudioInspectorView.getCurrentAudioNode().id, nodeIds[4], "Clicking on a <tspan> works as expected.");
+ is(InspectorView.getCurrentAudioNode().id, nodeIds[4], "Clicking on a <tspan> works as expected.");
- ok(WebAudioInspectorView.isVisible(),
+ ok(InspectorView.isVisible(),
"InspectorView still visible after several nodes have been clicked.");
yield teardown(panel);
finish();
}
diff --git a/browser/devtools/webaudioeditor/test/browser_wa_graph-markers.js b/browser/devtools/webaudioeditor/test/browser_wa_graph-markers.js
index c04a15e..5961837 100644
--- a/browser/devtools/webaudioeditor/test/browser_wa_graph-markers.js
+++ b/browser/devtools/webaudioeditor/test/browser_wa_graph-markers.js
@@ -3,17 +3,17 @@
/**
* Tests that the SVG marker styling is updated when devtools theme changes.
*/
function spawnTest() {
let [target, debuggee, panel] = yield initWebAudioEditor(SIMPLE_CONTEXT_URL);
let { panelWin } = panel;
- let { gFront, $, $$, EVENTS, MARKER_STYLING } = panelWin;
+ let { gFront, $, $$, MARKER_STYLING } = panelWin;
let currentTheme = Services.prefs.getCharPref("devtools.theme");
ok(MARKER_STYLING.light, "Marker styling exists for light theme.");
ok(MARKER_STYLING.dark, "Marker styling exists for dark theme.");
let started = once(gFront, "start-context");
diff --git a/browser/devtools/webaudioeditor/test/browser_wa_graph-render-01.js b/browser/devtools/webaudioeditor/test/browser_wa_graph-render-01.js
index 137d5ee..b036cc17 100644
--- a/browser/devtools/webaudioeditor/test/browser_wa_graph-render-01.js
+++ b/browser/devtools/webaudioeditor/test/browser_wa_graph-render-01.js
@@ -5,23 +5,23 @@
* Tests that SVG nodes and edges were created for the Graph View.
*/
let connectCount = 0;
function spawnTest() {
let [target, debuggee, panel] = yield initWebAudioEditor(SIMPLE_CONTEXT_URL);
let { panelWin } = panel;
- let { gFront, $, $$, EVENTS } = panelWin;
+ let { gFront, $, $$, EVENTS, gAudioNodes } = panelWin;
let started = once(gFront, "start-context");
reload(target);
- panelWin.on(EVENTS.CONNECT_NODE, onConnectNode);
+ gAudioNodes.on("connect", onConnectNode);
let [actors] = yield Promise.all([
get3(gFront, "create-node"),
waitForGraphRendered(panelWin, 3, 2)
]);
let [destId, oscId, gainId] = actors.map(actor => actor.actorID);
@@ -30,17 +30,17 @@ function spawnTest() {
ok(findGraphNode(panelWin, destId).classList.contains("type-AudioDestinationNode"), "found AudioDestinationNode with class");
is(findGraphEdge(panelWin, oscId, gainId).toString(), "[object SVGGElement]", "found edge for osc -> gain");
is(findGraphEdge(panelWin, gainId, destId).toString(), "[object SVGGElement]", "found edge for gain -> dest");
yield wait(1000);
is(connectCount, 2, "Only two node connect events should be fired.");
- panelWin.off(EVENTS.CONNECT_NODE, onConnectNode);
+ gAudioNodes.off("connect", onConnectNode);
yield teardown(panel);
finish();
}
function onConnectNode () {
++connectCount;
}
diff --git a/browser/devtools/webaudioeditor/test/browser_wa_graph-render-02.js b/browser/devtools/webaudioeditor/test/browser_wa_graph-render-02.js
index dadf4a7..aa3b18d 100644
--- a/browser/devtools/webaudioeditor/test/browser_wa_graph-render-02.js
+++ b/browser/devtools/webaudioeditor/test/browser_wa_graph-render-02.js
@@ -3,17 +3,17 @@
/**
* Tests more edge rendering for complex graphs.
*/
function spawnTest() {
let [target, debuggee, panel] = yield initWebAudioEditor(COMPLEX_CONTEXT_URL);
let { panelWin } = panel;
- let { gFront, $, $$, EVENTS } = panelWin;
+ let { gFront, $, $$ } = panelWin;
let started = once(gFront, "start-context");
reload(target);
let [actors] = yield Promise.all([
getN(gFront, "create-node", 8),
waitForGraphRendered(panelWin, 8, 8)
diff --git a/browser/devtools/webaudioeditor/test/browser_wa_graph-render-05.js b/browser/devtools/webaudioeditor/test/browser_wa_graph-render-05.js
new file mode 100644
index 0000000..708227e
--- /dev/null
+++ b/browser/devtools/webaudioeditor/test/browser_wa_graph-render-05.js
@@ -0,0 +1,27 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Tests to ensure that param connections trigger graph redraws
+ */
+
+function spawnTest() {
+ let [target, debuggee, panel] = yield initWebAudioEditor(CONNECT_TOGGLE_PARAM_URL);
+ let { panelWin } = panel;
+ let { gFront, $, $$, EVENTS } = panelWin;
+
+ reload(target);
+
+ let [actors] = yield Promise.all([
+ getN(gFront, "create-node", 3),
+ waitForGraphRendered(panelWin, 3, 1, 0)