OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | |
2 // | |
3 // Use of this source code is governed by a BSD-style license | |
4 // that can be found in the LICENSE file in the root of the source | |
5 // tree. An additional intellectual property rights grant can be found | |
6 // in the file PATENTS. All contributing project authors may | |
7 // be found in the AUTHORS file in the root of the source tree. | |
8 | |
9 /** | |
10 * Inspector UI class. | |
11 * @constructor | |
12 */ | |
13 function Inspector() { | |
14 this.audioPlayer_ = new Audio(); | |
15 this.inspectorNode_ = document.createElement('div'); | |
16 this.divNoiseGenerator_ = document.createElement('div'); | |
17 this.divNoiseParameters_ = document.createElement('div'); | |
18 this.buttonPlayAudioIn_ = document.createElement('button'); | |
19 this.buttonPlayAudioOut_ = document.createElement('button'); | |
20 this.buttonPlayAudioRef_ = document.createElement('button'); | |
21 this.buttonStopAudio_ = document.createElement('button'); | |
22 | |
23 this.selectedItem_ = null; | |
24 this.audioInUrl_ = null; | |
25 this.audioOutUrl_ = null; | |
26 this.audioRefUrl_ = null; | |
27 } | |
28 | |
29 /** | |
30 * Initialize. | |
31 */ | |
32 Inspector.prototype.init = function() { | |
33 window.event.stopPropagation(); | |
34 | |
35 // Create inspector UI. | |
36 this.buildInspector_(); | |
37 var body = document.getElementsByTagName('body')[0]; | |
38 body.appendChild(this.inspectorNode_); | |
39 | |
40 // Bind click handler. | |
41 var self = this; | |
42 var items = document.getElementsByClassName('score'); | |
43 for (var index = 0; index < items.length; index++) { | |
44 items[index].onclick = function() { | |
45 self.openInspector(this); | |
46 }; | |
47 } | |
48 | |
49 // Bind pressed key handlers. | |
50 var self = this; | |
51 window.onkeyup = function(e) { | |
52 var key = e.keyCode ? e.keyCode : e.which; | |
53 switch (key) { | |
54 case 49: // 1. | |
55 self.playAudioIn(); | |
56 break; | |
57 case 50: // 2. | |
58 self.playAudioOut(); | |
59 break; | |
60 case 51: // 3. | |
61 self.playAudioRef(); | |
62 break; | |
63 case 83: // S. | |
64 case 115: // s. | |
65 self.stopAudio(); | |
66 break; | |
67 } | |
68 }; | |
69 }; | |
70 | |
71 /** | |
72 * Open the inspector. | |
73 * @param {DOMElement} target: score element that has been clicked. | |
74 */ | |
75 Inspector.prototype.openInspector = function(target) { | |
76 if (this.selectedItem_ != null) { | |
77 this.selectedItem_.classList.remove('selected'); | |
78 } | |
79 this.selectedItem_ = target; | |
80 this.selectedItem_.classList.add('selected'); | |
81 | |
82 var target = this.selectedItem_.querySelector('.noise-desc'); | |
83 var noiseName = target.querySelector('input[name=noise_name]').value; | |
84 var noiseParams = target.querySelector('input[name=noise_params]').value; | |
85 var audioIn = target.querySelector('input[name=audio_in]').value; | |
86 var audioOut = target.querySelector('input[name=audio_out]').value; | |
87 var audioRef = target.querySelector('input[name=audio_ref]').value; | |
88 | |
89 this.divNoiseGenerator_.innerHTML = noiseName; | |
90 this.divNoiseParameters_.innerHTML = noiseParams; | |
91 | |
92 this.audioInUrl_ = audioIn; | |
93 this.audioOutUrl_ = audioOut; | |
94 this.audioRefUrl_ = audioRef; | |
95 }; | |
96 | |
97 /** | |
98 * Play APM audio input signal. | |
99 */ | |
100 Inspector.prototype.playAudioIn = function() { | |
101 this.play_(this.audioInUrl_); | |
102 }; | |
103 | |
104 /** | |
105 * Play APM audio output signal. | |
106 */ | |
107 Inspector.prototype.playAudioOut = function() { | |
108 this.play_(this.audioOutUrl_); | |
109 }; | |
110 | |
111 /** | |
112 * Play APM audio reference signal. | |
113 */ | |
114 Inspector.prototype.playAudioRef = function() { | |
115 this.play_(this.audioRefUrl_); | |
116 }; | |
117 | |
118 /** | |
119 * Stop playing audio. | |
120 */ | |
121 Inspector.prototype.stopAudio = function() { | |
122 this.audioPlayer_.pause(); | |
123 }; | |
124 | |
125 /** | |
126 * Play audio file from url. | |
127 * @param {string} url | |
128 */ | |
129 Inspector.prototype.play_ = function(url) { | |
130 if (url == null) { | |
131 alert('Select a score first.'); | |
132 return; | |
133 } | |
134 | |
135 this.audioPlayer_.src = url; | |
136 this.audioPlayer_.play(); | |
137 }; | |
138 | |
139 /** | |
140 * Build inspector. | |
141 */ | |
142 Inspector.prototype.buildInspector_ = function() { | |
143 var self = this; | |
144 | |
145 this.inspectorNode_.setAttribute('class', 'inspector'); | |
146 this.inspectorNode_.innerHTML = '<div class="property noise-generator">' + | |
147 '<div class="name">noise generator</div>' + | |
148 '</div>' + | |
kjellander_webrtc
2017/03/03 04:58:40
-1 indent on line 147-152
| |
149 '<div class="property noise-parmas">' + | |
150 '<div class="name">parameters</div>' + | |
151 '</div>' + | |
152 '<div class="buttons"></div>'; | |
153 | |
154 // Add value nodes. | |
155 function addValueNode(node, parent_selector) { | |
156 node.setAttribute('class', 'value'); | |
157 node.innerHTML = '-'; | |
158 var parentNode = self.inspectorNode_.querySelector(parent_selector); | |
159 parentNode.appendChild(node); | |
160 } | |
161 addValueNode(this.divNoiseGenerator_, 'div.noise-generator'); | |
162 addValueNode(this.divNoiseParameters_, 'div.noise-parmas'); | |
163 | |
164 // Add buttons. | |
165 var buttonsNode = this.inspectorNode_.querySelector('div.buttons'); | |
166 function addButton(node, caption, callback) { | |
167 node.innerHTML = caption; | |
168 buttonsNode.appendChild(node); | |
169 node.onclick = callback.bind(self); | |
170 } | |
171 addButton(this.buttonPlayAudioIn_, 'A_in (<strong>1</strong>)', | |
172 this.playAudioIn); | |
173 addButton(this.buttonPlayAudioOut_, 'A_out (<strong>2</strong>)', | |
174 this.playAudioOut); | |
175 addButton(this.buttonPlayAudioRef_, 'A_ref (<strong>3</strong>)', | |
176 this.playAudioRef); | |
177 addButton(this.buttonStopAudio_, '<strong>S</strong>top', this.stopAudio); | |
178 }; | |
179 | |
180 /** | |
181 * Instance and initialize the inspector. | |
182 */ | |
183 function initialize() { | |
184 var inspector = new Inspector(); | |
185 inspector.init(); | |
186 } | |
OLD | NEW |