root/trunk/libffado/src/libcontrol/ClockSelect.cpp

Revision 1568, 8.0 kB (checked in by holin, 14 years ago)

gcc 4.4 fixes (r1566, r1567, DICE) to trunk

Line 
1 /*
2  * Copyright (C) 2005-2008 by Pieter Palmers
3  *
4  * This file is part of FFADO
5  * FFADO = Free Firewire (pro-)audio drivers for linux
6  *
7  * FFADO is based upon FreeBoB
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 2 of the License, or
12  * (at your option) version 3 of the License.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  */
23
24 #include "ClockSelect.h"
25 #include "ffadodevice.h"
26
27 #include <cstdio>
28
29 namespace Control {
30
31 //// --- ClockSelect --- ////
32 ClockSelect::ClockSelect(FFADODevice &d)
33 : AttributeEnum(&d)
34 , m_Device( d )
35 {
36     setName("ClockSelect");
37     setLabel("Clock Source");
38     setDescription("Select the device clock source");
39 }
40
41 bool
42 ClockSelect::select(int idx)
43 {
44     debugOutput(DEBUG_LEVEL_VERBOSE, "Selecting clock idx: %d\n", idx);
45     FFADODevice::ClockSourceVector v = m_Device.getSupportedClockSources();
46     if(idx >= (int)v.size()) {
47         debugError("index out of range\n");
48         return false;
49     }
50     if(idx < 0) {
51         debugError("index < 0\n");
52         return false;
53     }
54     if(!m_Device.setActiveClockSource(v.at(idx))) {
55         debugWarning("could not set active clocksource\n");
56         return false;
57     }
58     debugOutput(DEBUG_LEVEL_VERBOSE, " clock id: %d\n", v.at(idx).id);
59     return true;
60 }
61
62 int
63 ClockSelect::selected()
64 {
65     debugOutput(DEBUG_LEVEL_VERBOSE, "Finding active clock\n");
66     FFADODevice::ClockSourceVector v = m_Device.getSupportedClockSources();
67     FFADODevice::ClockSource active = m_Device.getActiveClockSource();
68     int i=0;
69     for (i=0; i < (int)v.size(); i++) {
70         FFADODevice::ClockSource c = v.at(i);
71         if(c.id == active.id) {
72             debugOutput(DEBUG_LEVEL_VERBOSE, " Active clock at %d, id %d\n", i, c.id);
73             return i;
74         }
75     }
76     debugError("No active clock source found!\n");
77     return -1;
78 }
79
80 int
81 ClockSelect::count()
82 {
83     return m_Device.getSupportedClockSources().size();
84 }
85
86 std::string
87 ClockSelect::getEnumLabel(int idx)
88 {
89     FFADODevice::ClockSourceVector v = m_Device.getSupportedClockSources();
90     if(idx >= (int)v.size()) {
91         debugError("index out of range\n");
92         return "Error";
93     }
94     if(idx < 0) {
95         debugError("index < 0\n");
96         return "Error";
97     }
98     return v.at(idx).description;
99 }
100
101 int
102 ClockSelect::attributeCount()
103 {
104 /*
105         /// indicates the type of the clock source (e.g. eCT_ADAT)
106         enum eClockSourceType type;
107         /// indicated the id of the clock source (e.g. id=1 => clocksource is ADAT_1)
108         unsigned int id;
109         /// is the clock source valid (i.e. can be selected) at this moment?
110         bool valid;
111         /// is the clock source active at this moment?
112         bool active;
113         /// is the clock source locked?
114         bool locked;
115         /// is the clock source slipping?
116         bool slipping;
117         /// description of the clock struct (optional)
118         std::string description;
119 */
120     return 7;
121 }
122
123 std::string
124 ClockSelect::getAttributeValue(int attridx)
125 {
126     char tmp[16];
127     std::string retval = "bad attr index";
128     FFADODevice::ClockSource active = m_Device.getActiveClockSource();
129    
130     switch(attridx) {
131         case 0:
132             retval = FFADODevice::ClockSourceTypeToString(active.type);
133             break;
134         case 1:
135             snprintf(tmp, 16, "%u", active.id);
136             retval = tmp;
137             break;
138         case 2:
139             snprintf(tmp, 16, "%u", active.valid);
140             retval = tmp;
141             break;
142         case 3:
143             snprintf(tmp, 16, "%u", active.active);
144             retval = tmp;
145             break;
146         case 4:
147             snprintf(tmp, 16, "%u", active.locked);
148             retval = tmp;
149             break;
150         case 5:
151             snprintf(tmp, 16, "%u", active.slipping);
152             retval = tmp;
153             break;
154         case 6:
155             retval = active.description;
156     }
157     return retval;
158 }
159
160 std::string
161 ClockSelect::getAttributeName(int attridx)
162 {
163     switch(attridx) {
164         case 0: return "type";
165         case 1: return "id";
166         case 2: return "valid";
167         case 3: return "active";
168         case 4: return "locked";
169         case 5: return "slipping";
170         case 6: return "description";
171         default: return "bad attr index";
172     }
173 }
174
175 bool
176 ClockSelect::canChangeValue()
177 {
178     return m_Device.getStreamingState() == FFADODevice::eSS_Idle;
179 }
180
181 void
182 ClockSelect::show()
183 {
184     debugOutput( DEBUG_LEVEL_NORMAL, "ClockSelect Element %s, active: %s\n",
185         getName().c_str(), m_Device.getActiveClockSource().description.c_str());
186 }
187
188 // --- samplerate selection ---
189
190 SamplerateSelect::SamplerateSelect(FFADODevice &d)
191 : Enum(&d)
192 , m_Device( d )
193 {
194     setName("SamplerateSelect");
195     setLabel("Samplerate Select");
196     setDescription("Select the device sample rate");
197 }
198
199 bool
200 SamplerateSelect::select(int idx)
201 {
202     std::vector<int> freqs = m_Device.getSupportedSamplingFrequencies();
203     if (idx >= 0 && idx < (int)freqs.size()) {
204         if(!m_Device.setSamplingFrequency(freqs.at(idx))) {
205             debugWarning("Could not select samplerate\n");
206             return false;
207         }
208         return true;
209     } else {
210         debugWarning("bad index specified\n");
211         return false;
212     }
213 }
214
215 int
216 SamplerateSelect::selected()
217 {
218     std::vector<int> freqs = m_Device.getSupportedSamplingFrequencies();
219     int samplerate = m_Device.getSamplingFrequency();
220     for (int i = 0; i < (int)freqs.size(); i++) {
221         if (samplerate == freqs.at(i)) {
222             return i;
223         }
224     }
225     debugError("could not find the selected samplerate\n");
226     return -1;
227 }
228
229 int
230 SamplerateSelect::count()
231 {
232     return  m_Device.getSupportedSamplingFrequencies().size();
233 }
234
235 std::string
236 SamplerateSelect::getEnumLabel(int idx)
237 {
238     char tmp[16];
239     std::string retval = "Error";
240     std::vector<int> freqs = m_Device.getSupportedSamplingFrequencies();
241     if (idx >= 0 && idx < (int)freqs.size()) {
242         snprintf(tmp, 16, "%u", freqs.at(idx));
243         retval = tmp;
244     } else {
245         debugWarning("bad index specified\n");
246     }
247     return retval;
248 }
249
250 bool
251 SamplerateSelect::canChangeValue()
252 {
253     return m_Device.getStreamingState() == FFADODevice::eSS_Idle;
254 }
255
256 void
257 SamplerateSelect::show()
258 {
259     debugOutput( DEBUG_LEVEL_NORMAL, "SamplerateSelect Element %s, current: %d\n",
260         getName().c_str(), m_Device.getSamplingFrequency());
261
262 }
263
264 // --- stream status feedback selection ---
265
266 StreamingStatus::StreamingStatus(FFADODevice &d)
267 : Enum(&d)
268 , m_Device( d )
269 {
270     setName("StreamingStatus");
271     setLabel("Streaming Status");
272     setDescription("Obtain information of the current streaming status of a device");
273 }
274
275 bool
276 StreamingStatus::select(int idx)
277 {
278     debugWarning("Cannot change stream status through control interface\n");
279     return false;
280 }
281
282 int
283 StreamingStatus::selected()
284 {
285     return m_Device.getStreamingState();
286 }
287
288 int
289 StreamingStatus::count()
290 {
291     // NOTE: this should correspond to the number of enums in FFADODevice::eStreamingState
292     return 4;
293 }
294
295 std::string
296 StreamingStatus::getEnumLabel(int idx)
297 {
298     switch(idx) {
299         case FFADODevice::eSS_Idle:
300             return "Idle";
301         case FFADODevice::eSS_Sending:
302             return "Sending";
303         case FFADODevice::eSS_Receiving:
304             return "Receiving";
305         case FFADODevice::eSS_Both:
306             return "Both";
307         default:
308             debugError("Invalid enum index specified: %d\n", idx);
309             return "Invalid enum index";
310     }
311 }
312
313 bool
314 StreamingStatus::canChangeValue()
315 {
316     return false;
317 }
318
319 void
320 StreamingStatus::show()
321 {
322     debugOutput( DEBUG_LEVEL_NORMAL, "StreamingStatus Element %s, current: %d\n",
323         getName().c_str(), m_Device.getStreamingState());
324 }
325
326
327 } // namespace Control
Note: See TracBrowser for help on using the browser.