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} */ var AudioNodeType = { | |
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. Set to arbitrary default. | |
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 * AudioNodeType |type| is based on the AudioType emumation. | |
67 * {@type !Array<!{name: string, type: string}>} | |
stevenjb
2015/08/10 21:47:34
Shouldn't this be !Array<!{name: string, type: Aud
mozartalouis
2015/08/10 23:02:07
michaelpg@ suggested that in order for the pre-sub
michaelpg
2015/08/11 00:25:09
We've been following the @type {...} convention fr
| |
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() { | |
96 this.push('nodes', new AudioNode()); | |
97 }, | |
98 | |
99 /** | |
100 * This adds or modifies an audio node to the AudioNodeList. | |
101 * @param {model: {index: number}} e Event with a model containing | |
102 * the index in |nodes| to add. | |
103 */ | |
104 insertAudioNode: function(e) { | |
105 // Create a new audio node and add all the properties from |nodes[i]|. | |
106 // Also, send the corresponding type value based on the name of |info.type|. | |
107 var info = this.nodes[e.model.index]; | |
108 chrome.send('insertAudioNode', [info, this.getAudioTypeForName(info.type)]); | |
stevenjb
2015/08/10 21:47:34
I still don't understand why we are passing info.t
mozartalouis
2015/08/10 23:02:07
You have to pass info.type because with insertAudi
stevenjb
2015/08/10 23:14:09
This is super confusing. At minimum this needs to
| |
109 }, | |
110 | |
111 /** | |
112 * Removes the audio node with id |id|. | |
113 * @param {model: {index: number}} e Event with a model containing | |
114 * the index in |nodes| to add. | |
115 */ | |
116 removeAudioNode: function(e) { | |
117 var info = this.nodes[e.model.index]; | |
118 chrome.send('removeAudioNode', [info.id]); | |
119 }, | |
120 | |
121 /** | |
122 * Returns the text for the label that corresponds to |type|. | |
123 * @param {string} type A string representing an AudioType | |
124 * of a node. | |
stevenjb
2015/08/10 21:47:34
Shouldn't |type| be of type {AudioNodeType} ?
mozartalouis
2015/08/10 23:02:07
Done. should i rename them
getAudioTypeName
get
| |
125 * @return {string} The display name corresponding to |type|. | |
126 */ | |
127 getNameForAudioType: function(type) { | |
128 for (var i = 0; i < this.nodeTypeOptions.length; ++i) { | |
129 if (this.nodeTypeOptions[i].type == type) | |
130 return this.nodeTypeOptions[i].name; | |
131 } | |
132 }, | |
133 | |
134 /** | |
135 * Returns the text for the label that corresponds to |name|. | |
136 * @param {string} name A string representing an AudioType | |
137 * of a nodes name. | |
138 * @return {string} The label which represents |name|. | |
stevenjb
2015/08/10 21:47:34
Sill unclear. This returns this.nodeTypeOptions[i]
mozartalouis
2015/08/10 23:02:07
Done.
| |
139 */ | |
140 getAudioTypeForName: function(name) { | |
141 for (var i = 0; i < this.nodeTypeOptions.length; ++i) { | |
142 if (this.nodeTypeOptions[i].name == name) | |
143 return this.nodeTypeOptions[i].type; | |
144 } | |
145 }, | |
146 | |
147 /** | |
148 * Called by the WebUI which provides a list of nodes. | |
149 * @param {!Array<!AudioNode>} nodeList A list of audio nodes. | |
150 */ | |
151 updateAudioNodes: function(nodeList) { | |
152 /** @type {!Array<!AudioNode>} */ var newNodeList = []; | |
153 for (var i = 0; i < nodeList.length; ++i) { | |
154 // create a new audio node and add all the properties from |nodeList[i]| | |
155 var node = new AudioNode(); | |
156 | |
157 node.isInput = nodeList[i]['isInput']; | |
158 node.id = nodeList[i]['id']; | |
159 node.deviceName = nodeList[i]['deviceName']; | |
160 node.type = this.getNameForAudioType(nodeList[i]['type']); | |
161 node.name = nodeList[i]['name']; | |
162 node.active = nodeList[i]['active']; | |
stevenjb
2015/08/10 21:47:34
Now we can do:
Object.assign(node, nodeList[i]);
mozartalouis
2015/08/10 23:02:07
Done.
| |
163 | |
164 newNodeList.push(node); | |
165 } | |
166 this.nodes = newNodeList; | |
167 } | |
168 }); | |
OLD | NEW |