Chromium Code Reviews| 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._audio_player = new Audio(); | |
|
janssonWebRTC
2017/03/02 10:19:33
The snake_case looks like a carry over from python
AleBzk
2017/03/02 11:06:11
Done.
AleBzk
2017/03/02 11:06:11
Done.
| |
| 15 this._inspector_node = document.createElement('div'); | |
| 16 this._div_noise_generator = document.createElement('div'); | |
| 17 this._div_noise_parameters = document.createElement('div'); | |
| 18 this._button_play_audio_in = document.createElement('button'); | |
| 19 this._button_play_audio_out = document.createElement('button'); | |
| 20 this._button_play_audio_ref = document.createElement('button'); | |
| 21 this._button_stop_audio = document.createElement('button'); | |
| 22 | |
| 23 this._selected_item = null; | |
| 24 this._audio_in_url = null; | |
| 25 this._audio_out_url = null; | |
| 26 this._audio_ref_url = null; | |
| 27 } | |
| 28 | |
| 29 /** | |
| 30 * Initialize. | |
| 31 */ | |
| 32 Inspector.prototype.init = function() { | |
| 33 window.event.stopPropagation(); | |
| 34 | |
| 35 // Create inspector UI. | |
| 36 this._build_inspector(); | |
| 37 var body = document.getElementsByTagName('body')[0]; | |
| 38 body.appendChild(this._inspector_node); | |
| 39 | |
| 40 // Bind click handler. | |
| 41 var self = this; | |
| 42 var items = document.getElementsByClassName('score'); | |
| 43 console.debug('number of "score" items: ' + items.length); | |
|
janssonWebRTC
2017/03/02 10:19:33
This is the only place where you have used the con
AleBzk
2017/03/02 11:06:11
Done.
AleBzk
2017/03/02 11:06:11
Thanks, it's the second :)
I'll remove the line.
| |
| 44 for (var index = 0; index < items.length; index++) { | |
| 45 items[index].onclick = function() { | |
| 46 self.open_inspector(this); | |
| 47 }; | |
| 48 } | |
| 49 | |
| 50 // Bind pressed key handlers. | |
| 51 var self = this; | |
| 52 window.onkeyup = function(e) { | |
| 53 var key = e.keyCode ? e.keyCode : e.which; | |
| 54 switch (key) { | |
| 55 case 49: | |
|
janssonWebRTC
2017/03/02 10:19:33
Since there are so few key bindings, maybe include
AleBzk
2017/03/02 11:06:11
Done.
| |
| 56 self.play_audio_in(); | |
| 57 break; | |
| 58 case 50: | |
| 59 self.play_audio_out(); | |
| 60 break; | |
| 61 case 51: | |
| 62 self.play_audio_ref(); | |
| 63 break; | |
| 64 case 83: | |
| 65 case 115: | |
| 66 self.stop_audio(); | |
| 67 break; | |
|
janssonWebRTC
2017/03/02 10:19:33
Unnecessary break.
AleBzk
2017/03/02 11:06:11
True, but isn't it safer to keep it?
If someone ad
janssonWebRTC
2017/03/02 12:03:20
That's true, will leave it up to you.
| |
| 68 } | |
| 69 }; | |
| 70 }; | |
| 71 | |
| 72 /** | |
| 73 * Open the inspector. | |
| 74 * @param {DOMElement} target: score element that has been clicked. | |
| 75 */ | |
| 76 Inspector.prototype.open_inspector = function(target) { | |
| 77 if (this._selected_item != null) { | |
| 78 this._selected_item.classList.remove('selected'); | |
| 79 } | |
| 80 this._selected_item = target; | |
| 81 this._selected_item.classList.add('selected'); | |
| 82 | |
| 83 var target = this._selected_item.querySelector('.noise-desc'); | |
| 84 var noise_name = target.querySelector('input[name=noise_name]').value; | |
| 85 var noise_params = target.querySelector('input[name=noise_params]').value; | |
| 86 var audio_in = target.querySelector('input[name=audio_in]').value; | |
| 87 var audio_out = target.querySelector('input[name=audio_out]').value; | |
| 88 var audio_ref = target.querySelector('input[name=audio_ref]').value; | |
| 89 | |
| 90 this._div_noise_generator.innerHTML = noise_name; | |
| 91 this._div_noise_parameters.innerHTML = noise_params; | |
| 92 | |
| 93 this._audio_in_url = audio_in; | |
| 94 this._audio_out_url = audio_out; | |
| 95 this._audio_ref_url = audio_ref; | |
| 96 }; | |
| 97 | |
| 98 /** | |
| 99 * Play APM audio input signal. | |
| 100 * @param {string} url | |
| 101 */ | |
| 102 Inspector.prototype.play_audio_in = function(url) { | |
|
janssonWebRTC
2017/03/02 10:19:33
url is unused.
AleBzk
2017/03/02 11:06:11
Done.
| |
| 103 this._play(this._audio_in_url); | |
| 104 }; | |
| 105 | |
| 106 /** | |
| 107 * Play APM audio output signal. | |
| 108 * @param {string} url | |
| 109 */ | |
| 110 Inspector.prototype.play_audio_out = function(url) { | |
|
janssonWebRTC
2017/03/02 10:19:33
url is unused.
AleBzk
2017/03/02 11:06:11
Done.
| |
| 111 this._play(this._audio_out_url); | |
| 112 }; | |
| 113 | |
| 114 /** | |
| 115 * Play APM audio reference signal. | |
| 116 * @param {string} url | |
| 117 */ | |
| 118 Inspector.prototype.play_audio_ref = function(url) { | |
|
janssonWebRTC
2017/03/02 10:19:32
url is unused.
AleBzk
2017/03/02 11:06:11
Done.
| |
| 119 this._play(this._audio_ref_url); | |
| 120 }; | |
| 121 | |
| 122 /** | |
| 123 * Stop playing audio. | |
| 124 */ | |
| 125 Inspector.prototype.stop_audio = function() { | |
| 126 this._audio_player.pause(); | |
| 127 }; | |
| 128 | |
| 129 /** | |
| 130 * Play audio file from url. | |
| 131 * @param {string} url | |
| 132 */ | |
| 133 Inspector.prototype._play = function(url) { | |
| 134 if (url == null) { | |
| 135 alert('Select a score firts.'); | |
|
janssonWebRTC
2017/03/02 10:19:33
firts > first
AleBzk
2017/03/02 11:06:11
Done.
| |
| 136 return; | |
| 137 } | |
| 138 | |
| 139 this._audio_player.src = url; | |
| 140 this._audio_player.play(); | |
| 141 }; | |
| 142 | |
| 143 /** | |
| 144 * Build inspector. | |
| 145 */ | |
| 146 Inspector.prototype._build_inspector = function() { | |
| 147 var self = this; | |
| 148 | |
| 149 this._inspector_node.setAttribute('class', 'inspector'); | |
| 150 this._inspector_node.innerHTML = '<div class="property noise-generator">' + | |
|
janssonWebRTC
2017/03/02 10:19:33
Maybe you could use document.createElement() here
AleBzk
2017/03/02 11:06:11
Thanks for your comment.
I used createElement() fo
janssonWebRTC
2017/03/02 12:03:20
Ah right, I get your point.
| |
| 151 '<div class="name">noise generator</div>' + | |
| 152 '</div>' + | |
| 153 '<div class="property noise-parmas">' + | |
| 154 '<div class="name">parameters</div>' + | |
| 155 '</div>' + | |
| 156 '<div class="buttons"></div>'; | |
| 157 | |
| 158 // Add value nodes. | |
| 159 function add_value_node(node, parent_selector) { | |
| 160 node.setAttribute('class', 'value'); | |
| 161 node.innerHTML = '-'; | |
| 162 var parent_node = self._inspector_node.querySelector(parent_selector); | |
| 163 parent_node.appendChild(node); | |
| 164 } | |
| 165 add_value_node(this._div_noise_generator, 'div.noise-generator'); | |
| 166 add_value_node(this._div_noise_parameters, 'div.noise-parmas'); | |
| 167 | |
| 168 // Add buttons. | |
| 169 var buttons_node = this._inspector_node.querySelector('div.buttons'); | |
| 170 function add_button(node, caption, callback) { | |
| 171 node.innerHTML = caption; | |
| 172 buttons_node.appendChild(node); | |
| 173 node.onclick = callback.bind(self); | |
| 174 } | |
| 175 add_button(this._button_play_audio_in, 'A_in (<strong>1</strong>)', | |
| 176 this.play_audio_in); | |
| 177 add_button(this._button_play_audio_out, 'A_out (<strong>2</strong>)', | |
| 178 this.play_audio_out); | |
| 179 add_button(this._button_play_audio_ref, 'A_ref (<strong>3</strong>)', | |
| 180 this.play_audio_ref); | |
| 181 add_button(this._button_stop_audio, '<strong>S</strong>top', this.stop_audio); | |
| 182 }; | |
| 183 | |
| 184 /** | |
| 185 * Instance and initialize the inspector. | |
| 186 */ | |
| 187 function initialize() { | |
| 188 var inspector = new Inspector(); | |
| 189 inspector.init(); | |
| 190 } | |
| OLD | NEW |