Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 5 | import * as Common from '../common/common.js'; // eslint-disable-line no-unused-vars |
Tim van der Lippe | 9081c90 | 2020-01-24 14:32:42 | [diff] [blame] | 6 | import * as SDK from '../sdk/sdk.js'; // eslint-disable-line no-unused-vars |
| 7 | import * as UI from '../ui/ui.js'; |
| 8 | |
Hongchan Choi | 0927e70 | 2020-01-15 20:13:37 | [diff] [blame] | 9 | import {ContextDetailBuilder, ContextSummaryBuilder} from './AudioContextContentBuilder.js'; |
| 10 | import {AudioContextSelector, Events as SelectorEvents} from './AudioContextSelector.js'; |
| 11 | import {GraphManager} from './graph_visualizer/GraphManager.js'; |
| 12 | import {Events as ModelEvents, WebAudioModel} from './WebAudioModel.js'; |
| 13 | |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 14 | /** |
Tim van der Lippe | 9081c90 | 2020-01-24 14:32:42 | [diff] [blame] | 15 | * @implements {SDK.SDKModel.SDKModelObserver<!WebAudioModel>} |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 16 | */ |
Tim van der Lippe | 9081c90 | 2020-01-24 14:32:42 | [diff] [blame] | 17 | export class WebAudioView extends UI.ThrottledWidget.ThrottledWidget { |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 18 | constructor() { |
| 19 | super(true, 1000); |
| 20 | this.element.classList.add('web-audio-drawer'); |
Jack Franklin | 71519f8 | 2020-11-03 12:08:59 | [diff] [blame^] | 21 | this.registerRequiredCSS('web_audio/webAudio.css', {enableLegacyPatching: true}); |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 22 | |
| 23 | // Creates the toolbar. |
Hongchan Choi | 0927e70 | 2020-01-15 20:13:37 | [diff] [blame] | 24 | const toolbarContainer = this.contentElement.createChild('div', 'web-audio-toolbar-container vbox'); |
| 25 | this._contextSelector = new AudioContextSelector(); |
Tim van der Lippe | 9081c90 | 2020-01-24 14:32:42 | [diff] [blame] | 26 | const toolbar = new UI.Toolbar.Toolbar('web-audio-toolbar', toolbarContainer); |
| 27 | toolbar.appendToolbarItem(UI.Toolbar.Toolbar.createActionButtonForId('components.collect-garbage')); |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 28 | toolbar.appendSeparator(); |
| 29 | toolbar.appendToolbarItem(this._contextSelector.toolbarItem()); |
| 30 | |
John Emau | c7d63f9 | 2020-01-15 20:15:45 | [diff] [blame] | 31 | // Create content container |
| 32 | this._contentContainer = this.contentElement.createChild('div', 'web-audio-content-container vbox flex-auto'); |
| 33 | |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 34 | // Creates the detail view. |
John Emau | c7d63f9 | 2020-01-15 20:15:45 | [diff] [blame] | 35 | this._detailViewContainer = this._contentContainer.createChild('div', 'web-audio-details-container vbox flex-auto'); |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 36 | |
Hongchan Choi | 0927e70 | 2020-01-15 20:13:37 | [diff] [blame] | 37 | this._graphManager = new GraphManager(); |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 38 | |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 39 | // Creates the landing page. |
Tim van der Lippe | 9081c90 | 2020-01-24 14:32:42 | [diff] [blame] | 40 | this._landingPage = new UI.Widget.VBox(); |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 41 | this._landingPage.contentElement.classList.add('web-audio-landing-page', 'fill'); |
Tim van der Lippe | 9081c90 | 2020-01-24 14:32:42 | [diff] [blame] | 42 | this._landingPage.contentElement.appendChild(UI.Fragment.html` |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 43 | <div> |
| 44 | <p>${ls`Open a page that uses Web Audio API to start monitoring.`}</p> |
| 45 | </div> |
| 46 | `); |
| 47 | this._landingPage.show(this._detailViewContainer); |
| 48 | |
| 49 | // Creates the summary bar. |
John Emau | c7d63f9 | 2020-01-15 20:15:45 | [diff] [blame] | 50 | this._summaryBarContainer = this._contentContainer.createChild('div', 'web-audio-summary-container'); |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 51 | |
Hongchan Choi | 0927e70 | 2020-01-15 20:13:37 | [diff] [blame] | 52 | this._contextSelector.addEventListener(SelectorEvents.ContextSelected, event => { |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 53 | const context = |
| 54 | /** @type {!Protocol.WebAudio.BaseAudioContext} */ (event.data); |
| 55 | this._updateDetailView(context); |
| 56 | this.doUpdate(); |
| 57 | }); |
| 58 | |
Paul Lewis | daac106 | 2020-03-05 14:37:10 | [diff] [blame] | 59 | SDK.SDKModel.TargetManager.instance().observeModels(WebAudioModel, this); |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @override |
| 64 | */ |
| 65 | wasShown() { |
Hongchan Choi | de21c96 | 2019-06-06 22:15:08 | [diff] [blame] | 66 | super.wasShown(); |
Paul Lewis | daac106 | 2020-03-05 14:37:10 | [diff] [blame] | 67 | for (const model of SDK.SDKModel.TargetManager.instance().models(WebAudioModel)) { |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 68 | this._addEventListeners(model); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 69 | } |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /** |
| 73 | * @override |
| 74 | */ |
| 75 | willHide() { |
Paul Lewis | daac106 | 2020-03-05 14:37:10 | [diff] [blame] | 76 | for (const model of SDK.SDKModel.TargetManager.instance().models(WebAudioModel)) { |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 77 | this._removeEventListeners(model); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 78 | } |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | /** |
| 82 | * @override |
Hongchan Choi | 0927e70 | 2020-01-15 20:13:37 | [diff] [blame] | 83 | * @param {!WebAudioModel} webAudioModel |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 84 | */ |
| 85 | modelAdded(webAudioModel) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 86 | if (this.isShowing()) { |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 87 | this._addEventListeners(webAudioModel); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 88 | } |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /** |
| 92 | * @override |
Hongchan Choi | 0927e70 | 2020-01-15 20:13:37 | [diff] [blame] | 93 | * @param {!WebAudioModel} webAudioModel |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 94 | */ |
| 95 | modelRemoved(webAudioModel) { |
| 96 | this._removeEventListeners(webAudioModel); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * @override |
| 101 | * @return {!Promise<?>} |
| 102 | */ |
| 103 | async doUpdate() { |
| 104 | await this._pollRealtimeData(); |
| 105 | this.update(); |
| 106 | } |
| 107 | |
| 108 | /** |
Hongchan Choi | 0927e70 | 2020-01-15 20:13:37 | [diff] [blame] | 109 | * @param {!WebAudioModel} webAudioModel |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 110 | */ |
| 111 | _addEventListeners(webAudioModel) { |
| 112 | webAudioModel.ensureEnabled(); |
Hongchan Choi | 0927e70 | 2020-01-15 20:13:37 | [diff] [blame] | 113 | webAudioModel.addEventListener(ModelEvents.ContextCreated, this._contextCreated, this); |
| 114 | webAudioModel.addEventListener(ModelEvents.ContextDestroyed, this._contextDestroyed, this); |
| 115 | webAudioModel.addEventListener(ModelEvents.ContextChanged, this._contextChanged, this); |
| 116 | webAudioModel.addEventListener(ModelEvents.ModelReset, this._reset, this); |
| 117 | webAudioModel.addEventListener(ModelEvents.ModelSuspend, this._suspendModel, this); |
| 118 | webAudioModel.addEventListener(ModelEvents.AudioListenerCreated, this._audioListenerCreated, this); |
| 119 | webAudioModel.addEventListener(ModelEvents.AudioListenerWillBeDestroyed, this._audioListenerWillBeDestroyed, this); |
| 120 | webAudioModel.addEventListener(ModelEvents.AudioNodeCreated, this._audioNodeCreated, this); |
| 121 | webAudioModel.addEventListener(ModelEvents.AudioNodeWillBeDestroyed, this._audioNodeWillBeDestroyed, this); |
| 122 | webAudioModel.addEventListener(ModelEvents.AudioParamCreated, this._audioParamCreated, this); |
| 123 | webAudioModel.addEventListener(ModelEvents.AudioParamWillBeDestroyed, this._audioParamWillBeDestroyed, this); |
| 124 | webAudioModel.addEventListener(ModelEvents.NodesConnected, this._nodesConnected, this); |
| 125 | webAudioModel.addEventListener(ModelEvents.NodesDisconnected, this._nodesDisconnected, this); |
| 126 | webAudioModel.addEventListener(ModelEvents.NodeParamConnected, this._nodeParamConnected, this); |
| 127 | webAudioModel.addEventListener(ModelEvents.NodeParamDisconnected, this._nodeParamDisconnected, this); |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /** |
Paul Lewis | 9f21a77 | 2020-10-05 13:22:08 | [diff] [blame] | 131 | * @param {!WebAudioModel} webAudioModel |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 132 | */ |
| 133 | _removeEventListeners(webAudioModel) { |
Hongchan Choi | 0927e70 | 2020-01-15 20:13:37 | [diff] [blame] | 134 | webAudioModel.removeEventListener(ModelEvents.ContextCreated, this._contextCreated, this); |
| 135 | webAudioModel.removeEventListener(ModelEvents.ContextDestroyed, this._contextDestroyed, this); |
| 136 | webAudioModel.removeEventListener(ModelEvents.ContextChanged, this._contextChanged, this); |
| 137 | webAudioModel.removeEventListener(ModelEvents.ModelReset, this._reset, this); |
| 138 | webAudioModel.removeEventListener(ModelEvents.ModelSuspend, this._suspendModel, this); |
| 139 | webAudioModel.removeEventListener(ModelEvents.AudioListenerCreated, this._audioListenerCreated, this); |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 140 | webAudioModel.removeEventListener( |
Hongchan Choi | 0927e70 | 2020-01-15 20:13:37 | [diff] [blame] | 141 | ModelEvents.AudioListenerWillBeDestroyed, this._audioListenerWillBeDestroyed, this); |
| 142 | webAudioModel.removeEventListener(ModelEvents.AudioNodeCreated, this._audioNodeCreated, this); |
| 143 | webAudioModel.removeEventListener(ModelEvents.AudioNodeWillBeDestroyed, this._audioNodeWillBeDestroyed, this); |
| 144 | webAudioModel.removeEventListener(ModelEvents.AudioParamCreated, this._audioParamCreated, this); |
| 145 | webAudioModel.removeEventListener(ModelEvents.AudioParamWillBeDestroyed, this._audioParamWillBeDestroyed, this); |
| 146 | webAudioModel.removeEventListener(ModelEvents.NodesConnected, this._nodesConnected, this); |
| 147 | webAudioModel.removeEventListener(ModelEvents.NodesDisconnected, this._nodesDisconnected, this); |
| 148 | webAudioModel.removeEventListener(ModelEvents.NodeParamConnected, this._nodeParamConnected, this); |
| 149 | webAudioModel.removeEventListener(ModelEvents.NodeParamDisconnected, this._nodeParamDisconnected, this); |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 153 | * @param {!Common.EventTarget.EventTargetEvent} event |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 154 | */ |
| 155 | _contextCreated(event) { |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 156 | const context = /** @type {!Protocol.WebAudio.BaseAudioContext} */ (event.data); |
| 157 | this._graphManager.createContext(context.contextId); |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 158 | this._contextSelector.contextCreated(event); |
| 159 | } |
| 160 | |
| 161 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 162 | * @param {!Common.EventTarget.EventTargetEvent} event |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 163 | */ |
| 164 | _contextDestroyed(event) { |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 165 | const contextId = /** @type {!Protocol.WebAudio.GraphObjectId} */ (event.data); |
| 166 | this._graphManager.destroyContext(contextId); |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 167 | this._contextSelector.contextDestroyed(event); |
| 168 | } |
| 169 | |
| 170 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 171 | * @param {!Common.EventTarget.EventTargetEvent} event |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 172 | */ |
| 173 | _contextChanged(event) { |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 174 | const context = /** @type {!Protocol.WebAudio.BaseAudioContext} */ (event.data); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 175 | if (!this._graphManager.hasContext(context.contextId)) { |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 176 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 177 | } |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 178 | |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 179 | this._contextSelector.contextChanged(event); |
| 180 | } |
| 181 | |
| 182 | _reset() { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 183 | if (this._landingPage.isShowing()) { |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 184 | this._landingPage.detach(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 185 | } |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 186 | this._contextSelector.reset(); |
| 187 | this._detailViewContainer.removeChildren(); |
| 188 | this._landingPage.show(this._detailViewContainer); |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 189 | this._graphManager.clearGraphs(); |
| 190 | } |
| 191 | |
| 192 | _suspendModel() { |
| 193 | this._graphManager.clearGraphs(); |
| 194 | } |
| 195 | |
| 196 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 197 | * @param {!Common.EventTarget.EventTargetEvent} event |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 198 | */ |
| 199 | _audioListenerCreated(event) { |
| 200 | const listener = /** @type {!Protocol.WebAudio.AudioListener} */ (event.data); |
| 201 | const graph = this._graphManager.getGraph(listener.contextId); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 202 | if (!graph) { |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 203 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 204 | } |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 205 | graph.addNode({ |
| 206 | nodeId: listener.listenerId, |
| 207 | nodeType: 'Listener', |
| 208 | numberOfInputs: 0, |
| 209 | numberOfOutputs: 0, |
| 210 | }); |
| 211 | } |
| 212 | |
| 213 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 214 | * @param {!Common.EventTarget.EventTargetEvent} event |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 215 | */ |
| 216 | _audioListenerWillBeDestroyed(event) { |
| 217 | const {contextId, listenerId} = event.data; |
| 218 | const graph = this._graphManager.getGraph(contextId); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 219 | if (!graph) { |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 220 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 221 | } |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 222 | graph.removeNode(listenerId); |
| 223 | } |
| 224 | |
| 225 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 226 | * @param {!Common.EventTarget.EventTargetEvent} event |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 227 | */ |
| 228 | _audioNodeCreated(event) { |
| 229 | const node = /** @type {!Protocol.WebAudio.AudioNode} */ (event.data); |
| 230 | const graph = this._graphManager.getGraph(node.contextId); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 231 | if (!graph) { |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 232 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 233 | } |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 234 | graph.addNode({ |
| 235 | nodeId: node.nodeId, |
| 236 | nodeType: node.nodeType, |
| 237 | numberOfInputs: node.numberOfInputs, |
| 238 | numberOfOutputs: node.numberOfOutputs, |
| 239 | }); |
| 240 | } |
| 241 | |
| 242 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 243 | * @param {!Common.EventTarget.EventTargetEvent} event |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 244 | */ |
| 245 | _audioNodeWillBeDestroyed(event) { |
| 246 | const {contextId, nodeId} = event.data; |
| 247 | const graph = this._graphManager.getGraph(contextId); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 248 | if (!graph) { |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 249 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 250 | } |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 251 | graph.removeNode(nodeId); |
| 252 | } |
| 253 | |
| 254 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 255 | * @param {!Common.EventTarget.EventTargetEvent} event |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 256 | */ |
| 257 | _audioParamCreated(event) { |
| 258 | const param = /** @type {!Protocol.WebAudio.AudioParam} */ (event.data); |
| 259 | const graph = this._graphManager.getGraph(param.contextId); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 260 | if (!graph) { |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 261 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 262 | } |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 263 | graph.addParam({ |
| 264 | paramId: param.paramId, |
| 265 | paramType: param.paramType, |
| 266 | nodeId: param.nodeId, |
| 267 | }); |
| 268 | } |
| 269 | |
| 270 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 271 | * @param {!Common.EventTarget.EventTargetEvent} event |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 272 | */ |
| 273 | _audioParamWillBeDestroyed(event) { |
| 274 | const {contextId, paramId} = event.data; |
| 275 | const graph = this._graphManager.getGraph(contextId); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 276 | if (!graph) { |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 277 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 278 | } |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 279 | graph.removeParam(paramId); |
| 280 | } |
| 281 | |
| 282 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 283 | * @param {!Common.EventTarget.EventTargetEvent} event |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 284 | */ |
| 285 | _nodesConnected(event) { |
| 286 | const {contextId, sourceId, destinationId, sourceOutputIndex, destinationInputIndex} = event.data; |
| 287 | const graph = this._graphManager.getGraph(contextId); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 288 | if (!graph) { |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 289 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 290 | } |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 291 | graph.addNodeToNodeConnection({ |
| 292 | sourceId, |
| 293 | destinationId, |
| 294 | sourceOutputIndex, |
| 295 | destinationInputIndex, |
| 296 | }); |
| 297 | } |
| 298 | |
| 299 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 300 | * @param {!Common.EventTarget.EventTargetEvent} event |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 301 | */ |
| 302 | _nodesDisconnected(event) { |
| 303 | const {contextId, sourceId, destinationId, sourceOutputIndex, destinationInputIndex} = event.data; |
| 304 | const graph = this._graphManager.getGraph(contextId); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 305 | if (!graph) { |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 306 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 307 | } |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 308 | graph.removeNodeToNodeConnection({ |
| 309 | sourceId, |
| 310 | destinationId, |
| 311 | sourceOutputIndex, |
| 312 | destinationInputIndex, |
| 313 | }); |
| 314 | } |
| 315 | |
| 316 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 317 | * @param {!Common.EventTarget.EventTargetEvent} event |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 318 | */ |
| 319 | _nodeParamConnected(event) { |
| 320 | const {contextId, sourceId, destinationId, sourceOutputIndex} = event.data; |
| 321 | const graph = this._graphManager.getGraph(contextId); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 322 | if (!graph) { |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 323 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 324 | } |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 325 | // Since the destinationId is AudioParamId, we need to find the nodeId as the |
| 326 | // real destinationId. |
| 327 | const nodeId = graph.getNodeIdByParamId(destinationId); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 328 | if (!nodeId) { |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 329 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 330 | } |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 331 | graph.addNodeToParamConnection({ |
| 332 | sourceId, |
| 333 | destinationId: nodeId, |
| 334 | sourceOutputIndex, |
| 335 | destinationParamId: destinationId, |
| 336 | }); |
| 337 | } |
| 338 | |
| 339 | /** |
Tim van der Lippe | c02a97c | 2020-02-14 14:39:27 | [diff] [blame] | 340 | * @param {!Common.EventTarget.EventTargetEvent} event |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 341 | */ |
| 342 | _nodeParamDisconnected(event) { |
| 343 | const {contextId, sourceId, destinationId, sourceOutputIndex} = event.data; |
| 344 | const graph = this._graphManager.getGraph(contextId); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 345 | if (!graph) { |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 346 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 347 | } |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 348 | // Since the destinationId is AudioParamId, we need to find the nodeId as the |
| 349 | // real destinationId. |
| 350 | const nodeId = graph.getNodeIdByParamId(destinationId); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 351 | if (!nodeId) { |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 352 | return; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 353 | } |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 354 | graph.removeNodeToParamConnection({ |
| 355 | sourceId, |
| 356 | destinationId: nodeId, |
| 357 | sourceOutputIndex, |
| 358 | destinationParamId: destinationId, |
| 359 | }); |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | /** |
| 363 | * @param {!Protocol.WebAudio.BaseAudioContext} context |
| 364 | */ |
| 365 | _updateDetailView(context) { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 366 | if (this._landingPage.isShowing()) { |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 367 | this._landingPage.detach(); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 368 | } |
Hongchan Choi | 0927e70 | 2020-01-15 20:13:37 | [diff] [blame] | 369 | const detailBuilder = new ContextDetailBuilder(context); |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 370 | this._detailViewContainer.removeChildren(); |
| 371 | this._detailViewContainer.appendChild(detailBuilder.getFragment()); |
| 372 | } |
| 373 | |
| 374 | /** |
Hongchan Choi | 6508833 | 2019-08-08 01:12:33 | [diff] [blame] | 375 | * @param {!Protocol.WebAudio.GraphObjectId} contextId |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 376 | * @param {!Protocol.WebAudio.ContextRealtimeData} contextRealtimeData |
| 377 | */ |
| 378 | _updateSummaryBar(contextId, contextRealtimeData) { |
Hongchan Choi | 0927e70 | 2020-01-15 20:13:37 | [diff] [blame] | 379 | const summaryBuilder = new ContextSummaryBuilder(contextId, contextRealtimeData); |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 380 | this._summaryBarContainer.removeChildren(); |
| 381 | this._summaryBarContainer.appendChild(summaryBuilder.getFragment()); |
| 382 | } |
| 383 | |
| 384 | _clearSummaryBar() { |
| 385 | this._summaryBarContainer.removeChildren(); |
| 386 | } |
| 387 | |
| 388 | async _pollRealtimeData() { |
| 389 | const context = this._contextSelector.selectedContext(); |
| 390 | if (!context) { |
| 391 | this._clearSummaryBar(); |
| 392 | return; |
| 393 | } |
| 394 | |
Paul Lewis | 9f21a77 | 2020-10-05 13:22:08 | [diff] [blame] | 395 | for (const model of SDK.SDKModel.TargetManager.instance().models(WebAudioModel)) { |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 396 | // Display summary only for real-time context. |
| 397 | if (context.contextType === 'realtime') { |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 398 | if (!this._graphManager.hasContext(context.contextId)) { |
Gaoping Huang | a471b30 | 2019-08-23 16:48:29 | [diff] [blame] | 399 | continue; |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 400 | } |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 401 | const realtimeData = await model.requestRealtimeData(context.contextId); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 402 | if (realtimeData) { |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 403 | this._updateSummaryBar(context.contextId, realtimeData); |
Tim van der Lippe | 1d6e57a | 2019-09-30 11:55:34 | [diff] [blame] | 404 | } |
Hongchan Choi | 7dd0b3e | 2019-05-13 21:19:03 | [diff] [blame] | 405 | } else { |
| 406 | this._clearSummaryBar(); |
| 407 | } |
| 408 | } |
| 409 | } |
Paul Lewis | 2766f08 | 2019-11-28 13:42:57 | [diff] [blame] | 410 | } |