Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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 | |
| 5 /** @enum {string} */ AudioNodeType = { | |
|
xiyuan
2015/08/07 20:17:12
nit: var AudioNodeType = {...
"var" was missing.
mozartalouis
2015/08/07 22:44:07
Done.
| |
| 6 HEADPHONE: 'HEADPHONE', | |
| 7 MIC: 'MIC', | |
| 8 USB: 'USB', | |
| 9 BLUETOOTH: 'BLUETOOTH', | |
| 10 HDMI: 'HDMI', | |
| 11 INTERNAL_SPEAKER: 'INTERNAL_SPEAKER', | |
| 12 INTERNAL_MIC: 'INTERNAL_MIC', | |
| 13 KEYBOARD_MIC: 'KEYBOARD_MIC', | |
| 14 AOKR: 'AOKR', | |
| 15 POST_MIX_LOOPBACK: 'POST_MIX_LOOPBACK', | |
| 16 POST_DSP_LOOPBACK: 'POST_DSP_LOOPBACK', | |
| 17 OTHER: 'OTHER', | |
| 18 NONE: '', | |
| 19 }; | |
| 20 | |
| 21 /** | |
| 22 * An audio node. Based on the struct AudioNode found in audio_node.h. | |
| 23 * @constructor | |
| 24 */ | |
| 25 var AudioNode = function() { | |
| 26 // Whether node will input or output audio. | |
| 27 this.isInput = false; | |
| 28 | |
| 29 // Node ID. | |
| 30 this.id = '30001'; | |
| 31 | |
| 32 // Display name of the node. When this is empty, cras will automatically | |
| 33 // use |this.deviceName| as the display name. | |
| 34 this.name = ''; | |
| 35 | |
| 36 // The text label of the selected node name. | |
| 37 this.deviceName = 'New Device'; | |
| 38 | |
| 39 // Based on the AudioNodeType enum. | |
| 40 this.type = AudioNodeType.HEADPHONE; | |
| 41 | |
| 42 // Whether the node is active or not. | |
| 43 this.active = false; | |
| 44 | |
| 45 // The time the node was plugged in (in seconds). | |
| 46 this.pluggedTime = 0; | |
| 47 }; | |
| 48 | |
| 49 Polymer({ | |
| 50 is: 'audio-settings', | |
| 51 | |
| 52 properties: { | |
| 53 /** | |
| 54 * The title to be displayed in a heading element for the element. | |
| 55 */ | |
| 56 title: {type: String}, | |
| 57 | |
| 58 /** | |
| 59 * A set of audio nodes. | |
| 60 * @type !Array<!AudioNode> | |
| 61 */ | |
| 62 nodes: {type: Array, value: function() { return []; }}, | |
| 63 | |
| 64 /** | |
| 65 * A set of options for the possible audio node types. | |
| 66 * int |value| is based on the AudioType emumation. | |
| 67 * @type !Array<! {name: string, type: string} > | |
| 68 */ | |
| 69 nodeTypeOptions: { | |
| 70 type: Array, | |
| 71 value: function() { | |
| 72 return [ | |
| 73 {name: 'Headphones', type: AudioNodeType.HEADPHONE}, | |
| 74 {name: 'Mic', type: AudioNodeType.MIC}, | |
| 75 {name: 'Usb', type: AudioNodeType.USB}, | |
| 76 {name: 'Bluetooth', type: AudioNodeType.BLUETOOTH}, | |
| 77 {name: 'HDMI', type: AudioNodeType.HDMI}, | |
| 78 {name: 'Internal Speaker', type: AudioNodeType.INTERNAL_SPEAKER}, | |
| 79 {name: 'Internal Mic', type: AudioNodeType.INTERNAL_MIC}, | |
| 80 {name: 'Keyboard Mic', type: AudioNodeType.KEYBOARD_MIC}, | |
| 81 {name: 'Aokr', type: AudioNodeType.AOKR}, | |
| 82 {name: 'Post Mix Loopback', type: AudioNodeType.POST_MIX_LOOPBACK}, | |
| 83 {name: 'Post Dsp Loopback', type: AudioNodeType.POST_DSP_LOOPBACK}, | |
| 84 {name: 'Other', type: AudioNodeType.OTHER} | |
| 85 ]; | |
| 86 } | |
| 87 }, | |
| 88 }, | |
| 89 | |
| 90 ready: function() { this.title = 'Audio Settings'; }, | |
| 91 | |
| 92 /** | |
| 93 * Adds a new node with default settings to the list of nodes. | |
| 94 */ | |
| 95 appendNewNode: function() { this.push('nodes', new AudioNode()); }, | |
|
michaelpg
2015/08/07 22:47:42
nit: don't put non-trivial functions all on one li
mozartalouis
2015/08/07 23:16:50
i think this was the work of clang-format. :/ won'
| |
| 96 | |
| 97 /** | |
| 98 * This adds or modifes an audio node to the AudioNodeList. | |
|
michaelpg
2015/08/07 22:47:42
nit: modifies
mozartalouis
2015/08/07 23:16:50
Done.
| |
| 99 * @param {event} node. | |
|
michaelpg
2015/08/07 22:47:42
event -> Event
mozartalouis
2015/08/07 23:16:50
Done.
| |
| 100 */ | |
| 101 insertAudioNode: function(node) { | |
| 102 // Create a new audio node and add all the properties from |nodes[i]| | |
|
michaelpg
2015/08/07 22:47:42
nit: end w/ period
mozartalouis
2015/08/07 23:16:50
Done.
| |
| 103 var info = this.nodes[node.path[2].dataIndex]; | |
|
michaelpg
2015/08/07 22:47:42
node is an event, right? Rename the parameter to e
mozartalouis
2015/08/07 23:16:50
Done.
| |
| 104 info.type = this.getAudioTypeForName(info.type); | |
| 105 chrome.send('insertAudioNode', [info]); | |
| 106 }, | |
| 107 | |
| 108 /** | |
| 109 * Removes the audio node with id |id|. | |
| 110 * @param {event} node. | |
| 111 */ | |
| 112 removeAudioNode: function(node) { | |
| 113 var info = this.nodes[node.path[2].dataIndex]; | |
| 114 chrome.send('removeAudioNode', [info.id]); | |
| 115 }, | |
| 116 | |
| 117 /** | |
| 118 * Returns the text for the label that corresponds to |type|. | |
| 119 * @param {string} type A string representing an AudioType | |
| 120 * of a node. | |
| 121 * @return {string} The label which represents |type|. | |
| 122 */ | |
| 123 getNameForAudioType: function(type) { | |
| 124 for (var i = 0; i < this.nodeTypeOptions.length; ++i) { | |
| 125 if (this.nodeTypeOptions[i].type == type) | |
| 126 return this.nodeTypeOptions[i].name; | |
| 127 } | |
| 128 }, | |
| 129 | |
| 130 /** | |
| 131 * Returns the text for the label that corresponds to |name|. | |
| 132 * @param {string} name A string representing an AudioType | |
| 133 * of a nodes name. | |
| 134 * @return {string} The label which represents |name|. | |
| 135 */ | |
| 136 getAudioTypeForName: function(name) { | |
| 137 for (var i = 0; i < this.nodeTypeOptions.length; ++i) { | |
| 138 if (this.nodeTypeOptions[i].name == name) | |
| 139 return this.nodeTypeOptions[i].type; | |
| 140 } | |
| 141 }, | |
| 142 | |
| 143 /** | |
| 144 * Called by the WebUI which provides a list of nodes. | |
| 145 * @param {!Array<!AudioNode>} nodeList A list of audio nodes. | |
| 146 */ | |
| 147 updateAudioNodes: function(nodeList) { | |
| 148 /** @type {!Array<!AudioNode>} */ var newNodeList = []; | |
| 149 for (var i = 0; i < nodeList.length; ++i) { | |
| 150 | |
| 151 // create a new audio node and add all the properties from |nodeList[i]| | |
| 152 var node = new AudioNode(); | |
| 153 | |
| 154 node.isInput = nodeList[i]['is_input']; | |
| 155 node.id = nodeList[i]['id']; | |
| 156 node.deviceName = nodeList[i]['device_name']; | |
| 157 node.type = this.getNameForAudioType(nodeList[i]['type']); | |
| 158 node.name = nodeList[i]['name']; | |
| 159 node.active = nodeList[i]['active']; | |
| 160 | |
| 161 newNodeList.push(node); | |
| 162 } | |
| 163 this.nodes = newNodeList; | |
| 164 }, | |
|
xiyuan
2015/08/07 20:17:12
nit: remove "," for the last property
mozartalouis
2015/08/07 22:44:07
Done.
michaelpg
2015/08/07 22:47:42
Some people like this as it makes it easier to add
| |
| 165 }); | |
| OLD | NEW |