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 |
namespace Control { |
---|
28 |
|
---|
29 |
//// --- ClockSelect --- //// |
---|
30 |
ClockSelect::ClockSelect(FFADODevice &d) |
---|
31 |
: AttributeEnum(&d) |
---|
32 |
, m_Device( d ) |
---|
33 |
{ |
---|
34 |
setName("ClockSelect"); |
---|
35 |
setLabel("Clock Source"); |
---|
36 |
setDescription("Select the device clock source"); |
---|
37 |
} |
---|
38 |
|
---|
39 |
bool |
---|
40 |
ClockSelect::select(int idx) |
---|
41 |
{ |
---|
42 |
debugOutput(DEBUG_LEVEL_VERBOSE, "Selecting clock idx: %d\n", idx); |
---|
43 |
FFADODevice::ClockSourceVector v = m_Device.getSupportedClockSources(); |
---|
44 |
if(idx >= (int)v.size()) { |
---|
45 |
debugError("index out of range\n"); |
---|
46 |
return false; |
---|
47 |
} |
---|
48 |
if(!m_Device.setActiveClockSource(v.at(idx))) { |
---|
49 |
debugWarning("could not set active clocksource\n"); |
---|
50 |
return false; |
---|
51 |
} |
---|
52 |
debugOutput(DEBUG_LEVEL_VERBOSE, " clock id: %d\n", v.at(idx).id); |
---|
53 |
return true; |
---|
54 |
} |
---|
55 |
|
---|
56 |
int |
---|
57 |
ClockSelect::selected() |
---|
58 |
{ |
---|
59 |
debugOutput(DEBUG_LEVEL_VERBOSE, "Finding active clock\n"); |
---|
60 |
FFADODevice::ClockSourceVector v = m_Device.getSupportedClockSources(); |
---|
61 |
FFADODevice::ClockSource active = m_Device.getActiveClockSource(); |
---|
62 |
int i=0; |
---|
63 |
for (i=0; i < (int)v.size(); i++) { |
---|
64 |
FFADODevice::ClockSource c = v.at(i); |
---|
65 |
if(c.id == active.id) { |
---|
66 |
debugOutput(DEBUG_LEVEL_VERBOSE, " Active clock at %d, id %d\n", i, c.id); |
---|
67 |
return i; |
---|
68 |
} |
---|
69 |
} |
---|
70 |
debugError("No active clock source found!\n"); |
---|
71 |
return -1; |
---|
72 |
} |
---|
73 |
|
---|
74 |
int |
---|
75 |
ClockSelect::count() |
---|
76 |
{ |
---|
77 |
return m_Device.getSupportedClockSources().size(); |
---|
78 |
} |
---|
79 |
|
---|
80 |
std::string |
---|
81 |
ClockSelect::getEnumLabel(int idx) |
---|
82 |
{ |
---|
83 |
FFADODevice::ClockSourceVector v = m_Device.getSupportedClockSources(); |
---|
84 |
if(idx >= (int)v.size()) { |
---|
85 |
debugError("index out of range\n"); |
---|
86 |
return false; |
---|
87 |
} |
---|
88 |
return v.at(idx).description; |
---|
89 |
} |
---|
90 |
|
---|
91 |
int |
---|
92 |
ClockSelect::attributeCount() |
---|
93 |
{ |
---|
94 |
/* |
---|
95 |
/// indicates the type of the clock source (e.g. eCT_ADAT) |
---|
96 |
enum eClockSourceType type; |
---|
97 |
/// indicated the id of the clock source (e.g. id=1 => clocksource is ADAT_1) |
---|
98 |
unsigned int id; |
---|
99 |
/// is the clock source valid (i.e. can be selected) at this moment? |
---|
100 |
bool valid; |
---|
101 |
/// is the clock source active at this moment? |
---|
102 |
bool active; |
---|
103 |
/// is the clock source locked? |
---|
104 |
bool locked; |
---|
105 |
/// is the clock source slipping? |
---|
106 |
bool slipping; |
---|
107 |
/// description of the clock struct (optional) |
---|
108 |
std::string description; |
---|
109 |
*/ |
---|
110 |
return 7; |
---|
111 |
} |
---|
112 |
|
---|
113 |
std::string |
---|
114 |
ClockSelect::getAttributeValue(int attridx) |
---|
115 |
{ |
---|
116 |
char tmp[16]; |
---|
117 |
std::string retval = "bad attr index"; |
---|
118 |
FFADODevice::ClockSource active = m_Device.getActiveClockSource(); |
---|
119 |
|
---|
120 |
switch(attridx) { |
---|
121 |
case 0: |
---|
122 |
retval = FFADODevice::ClockSourceTypeToString(active.type); |
---|
123 |
break; |
---|
124 |
case 1: |
---|
125 |
snprintf(tmp, 16, "%u", active.id); |
---|
126 |
retval = tmp; |
---|
127 |
break; |
---|
128 |
case 2: |
---|
129 |
snprintf(tmp, 16, "%u", active.valid); |
---|
130 |
retval = tmp; |
---|
131 |
break; |
---|
132 |
case 3: |
---|
133 |
snprintf(tmp, 16, "%u", active.active); |
---|
134 |
retval = tmp; |
---|
135 |
break; |
---|
136 |
case 4: |
---|
137 |
snprintf(tmp, 16, "%u", active.locked); |
---|
138 |
retval = tmp; |
---|
139 |
break; |
---|
140 |
case 5: |
---|
141 |
snprintf(tmp, 16, "%u", active.slipping); |
---|
142 |
retval = tmp; |
---|
143 |
break; |
---|
144 |
case 6: |
---|
145 |
retval = active.description; |
---|
146 |
} |
---|
147 |
return retval; |
---|
148 |
} |
---|
149 |
|
---|
150 |
std::string |
---|
151 |
ClockSelect::getAttributeName(int attridx) |
---|
152 |
{ |
---|
153 |
switch(attridx) { |
---|
154 |
case 0: return "type"; |
---|
155 |
case 1: return "id"; |
---|
156 |
case 2: return "valid"; |
---|
157 |
case 3: return "active"; |
---|
158 |
case 4: return "locked"; |
---|
159 |
case 5: return "slipping"; |
---|
160 |
case 6: return "description"; |
---|
161 |
default: return "bad attr index"; |
---|
162 |
} |
---|
163 |
} |
---|
164 |
|
---|
165 |
void |
---|
166 |
ClockSelect::show() |
---|
167 |
{ |
---|
168 |
debugOutput( DEBUG_LEVEL_NORMAL, "ClockSelect Element %s, active: %s\n", |
---|
169 |
getName().c_str(), m_Device.getActiveClockSource().description.c_str()); |
---|
170 |
} |
---|
171 |
|
---|
172 |
} // namespace Control |
---|