1 |
/* |
---|
2 |
* Copyright (C) 2005-2007 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 3 of the License, or |
---|
12 |
* (at your option) any later version. |
---|
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 "efc_cmd.h" |
---|
25 |
#include "efc_cmds_mixer.h" |
---|
26 |
|
---|
27 |
#include <netinet/in.h> |
---|
28 |
#include <iostream> |
---|
29 |
|
---|
30 |
using namespace std; |
---|
31 |
|
---|
32 |
namespace FireWorks { |
---|
33 |
|
---|
34 |
EfcGenericMixerCmd::EfcGenericMixerCmd(enum eMixerTarget target, |
---|
35 |
enum eMixerCommand command) |
---|
36 |
: EfcCmd() |
---|
37 |
, m_channel ( -1 ) |
---|
38 |
, m_value ( 0 ) |
---|
39 |
{ |
---|
40 |
m_type=eCT_Get; |
---|
41 |
m_target=target; |
---|
42 |
m_command=command; |
---|
43 |
setTarget(target); |
---|
44 |
setCommand(command); |
---|
45 |
setType(eCT_Get); |
---|
46 |
} |
---|
47 |
|
---|
48 |
EfcGenericMixerCmd::EfcGenericMixerCmd(enum eMixerTarget target, |
---|
49 |
enum eMixerCommand command, |
---|
50 |
int channel) |
---|
51 |
: EfcCmd() |
---|
52 |
, m_channel ( channel ) |
---|
53 |
, m_value ( 0 ) |
---|
54 |
{ |
---|
55 |
m_type=eCT_Get; |
---|
56 |
m_target=target; |
---|
57 |
m_command=command; |
---|
58 |
setTarget(target); |
---|
59 |
setCommand(command); |
---|
60 |
setType(eCT_Get); |
---|
61 |
} |
---|
62 |
|
---|
63 |
bool |
---|
64 |
EfcGenericMixerCmd::serialize( Util::Cmd::IOSSerialize& se ) |
---|
65 |
{ |
---|
66 |
bool result=true; |
---|
67 |
|
---|
68 |
if (m_type == eCT_Get) { |
---|
69 |
// the length should be specified before |
---|
70 |
// the header is serialized |
---|
71 |
m_length=EFC_HEADER_LENGTH_QUADLETS+1; |
---|
72 |
|
---|
73 |
result &= EfcCmd::serialize ( se ); |
---|
74 |
|
---|
75 |
result &= se.write(htonl(m_channel), "Channel" ); |
---|
76 |
|
---|
77 |
} else { |
---|
78 |
// the length should be specified before |
---|
79 |
// the header is serialized |
---|
80 |
m_length=EFC_HEADER_LENGTH_QUADLETS+2; |
---|
81 |
|
---|
82 |
result &= EfcCmd::serialize ( se ); |
---|
83 |
|
---|
84 |
result &= se.write(htonl(m_channel), "Channel" ); |
---|
85 |
result &= se.write(htonl(m_value), "Value" ); |
---|
86 |
} |
---|
87 |
|
---|
88 |
if(!result) { |
---|
89 |
debugWarning("Serialization failed\n"); |
---|
90 |
} |
---|
91 |
|
---|
92 |
return result; |
---|
93 |
} |
---|
94 |
|
---|
95 |
bool |
---|
96 |
EfcGenericMixerCmd::deserialize( Util::Cmd::IISDeserialize& de ) |
---|
97 |
{ |
---|
98 |
bool result=true; |
---|
99 |
|
---|
100 |
result &= EfcCmd::deserialize ( de ); |
---|
101 |
|
---|
102 |
if (m_type == eCT_Get) { |
---|
103 |
EFC_DESERIALIZE_AND_SWAP(de, (quadlet_t *)&m_channel, result); |
---|
104 |
EFC_DESERIALIZE_AND_SWAP(de, &m_value, result); |
---|
105 |
} |
---|
106 |
|
---|
107 |
if(!result) { |
---|
108 |
debugWarning("Deserialization failed\n"); |
---|
109 |
} |
---|
110 |
|
---|
111 |
return result; |
---|
112 |
} |
---|
113 |
|
---|
114 |
bool |
---|
115 |
EfcGenericMixerCmd::setType( enum eCmdType type ) |
---|
116 |
{ |
---|
117 |
m_type=type; |
---|
118 |
if (type == eCT_Get) { |
---|
119 |
switch (m_command) { |
---|
120 |
case eMC_Gain: |
---|
121 |
m_command_id=EFC_CMD_MIXER_GET_GAIN; |
---|
122 |
break; |
---|
123 |
case eMC_Solo: |
---|
124 |
m_command_id=EFC_CMD_MIXER_GET_SOLO; |
---|
125 |
break; |
---|
126 |
case eMC_Mute: |
---|
127 |
m_command_id=EFC_CMD_MIXER_GET_MUTE; |
---|
128 |
break; |
---|
129 |
case eMC_Pan: |
---|
130 |
m_command_id=EFC_CMD_MIXER_GET_PAN; |
---|
131 |
break; |
---|
132 |
case eMC_Nominal: |
---|
133 |
m_command_id=EFC_CMD_MIXER_GET_NOMINAL; |
---|
134 |
break; |
---|
135 |
default: |
---|
136 |
debugError("Invalid mixer get command: %d\n", m_command); |
---|
137 |
return false; |
---|
138 |
} |
---|
139 |
} else { |
---|
140 |
switch (m_command) { |
---|
141 |
case eMC_Gain: |
---|
142 |
m_command_id=EFC_CMD_MIXER_SET_GAIN; |
---|
143 |
break; |
---|
144 |
case eMC_Solo: |
---|
145 |
m_command_id=EFC_CMD_MIXER_SET_SOLO; |
---|
146 |
break; |
---|
147 |
case eMC_Mute: |
---|
148 |
m_command_id=EFC_CMD_MIXER_SET_MUTE; |
---|
149 |
break; |
---|
150 |
case eMC_Pan: |
---|
151 |
m_command_id=EFC_CMD_MIXER_SET_PAN; |
---|
152 |
break; |
---|
153 |
case eMC_Nominal: |
---|
154 |
m_command_id=EFC_CMD_MIXER_SET_NOMINAL; |
---|
155 |
break; |
---|
156 |
default: |
---|
157 |
debugError("Invalid mixer set command: %d\n", m_command); |
---|
158 |
return false; |
---|
159 |
} |
---|
160 |
} |
---|
161 |
return true; |
---|
162 |
} |
---|
163 |
|
---|
164 |
bool |
---|
165 |
EfcGenericMixerCmd::setTarget( enum eMixerTarget target ) |
---|
166 |
{ |
---|
167 |
m_target=target; |
---|
168 |
switch (target) { |
---|
169 |
case eMT_PhysicalOutputMix: |
---|
170 |
m_category_id=EFC_CAT_PHYSICAL_OUTPUT_MIX; |
---|
171 |
break; |
---|
172 |
case eMT_PhysicalInputMix: |
---|
173 |
m_category_id=EFC_CAT_PHYSICAL_INPUT_MIX; |
---|
174 |
break; |
---|
175 |
case eMT_PlaybackMix: |
---|
176 |
m_category_id=EFC_CAT_PLAYBACK_MIX; |
---|
177 |
break; |
---|
178 |
case eMT_RecordMix: |
---|
179 |
m_category_id=EFC_CAT_RECORD_MIX; |
---|
180 |
break; |
---|
181 |
default: |
---|
182 |
debugError("Invalid mixer target: %d\n", target); |
---|
183 |
return false; |
---|
184 |
} |
---|
185 |
return true; |
---|
186 |
} |
---|
187 |
|
---|
188 |
bool |
---|
189 |
EfcGenericMixerCmd::setCommand( enum eMixerCommand command ) |
---|
190 |
{ |
---|
191 |
m_command=command; |
---|
192 |
if (m_type == eCT_Get) { |
---|
193 |
switch (command) { |
---|
194 |
case eMC_Gain: |
---|
195 |
m_command_id=EFC_CMD_MIXER_GET_GAIN; |
---|
196 |
break; |
---|
197 |
case eMC_Solo: |
---|
198 |
m_command_id=EFC_CMD_MIXER_GET_SOLO; |
---|
199 |
break; |
---|
200 |
case eMC_Mute: |
---|
201 |
m_command_id=EFC_CMD_MIXER_GET_MUTE; |
---|
202 |
break; |
---|
203 |
case eMC_Pan: |
---|
204 |
m_command_id=EFC_CMD_MIXER_GET_PAN; |
---|
205 |
break; |
---|
206 |
case eMC_Nominal: |
---|
207 |
m_command_id=EFC_CMD_MIXER_GET_NOMINAL; |
---|
208 |
break; |
---|
209 |
default: |
---|
210 |
debugError("Invalid mixer get command: %d\n", command); |
---|
211 |
return false; |
---|
212 |
} |
---|
213 |
} else { |
---|
214 |
switch (command) { |
---|
215 |
case eMC_Gain: |
---|
216 |
m_command_id=EFC_CMD_MIXER_SET_GAIN; |
---|
217 |
break; |
---|
218 |
case eMC_Solo: |
---|
219 |
m_command_id=EFC_CMD_MIXER_SET_SOLO; |
---|
220 |
break; |
---|
221 |
case eMC_Mute: |
---|
222 |
m_command_id=EFC_CMD_MIXER_SET_MUTE; |
---|
223 |
break; |
---|
224 |
case eMC_Pan: |
---|
225 |
m_command_id=EFC_CMD_MIXER_SET_PAN; |
---|
226 |
break; |
---|
227 |
case eMC_Nominal: |
---|
228 |
m_command_id=EFC_CMD_MIXER_SET_NOMINAL; |
---|
229 |
break; |
---|
230 |
default: |
---|
231 |
debugError("Invalid mixer set command: %d\n", command); |
---|
232 |
return false; |
---|
233 |
} |
---|
234 |
} |
---|
235 |
return true; |
---|
236 |
} |
---|
237 |
|
---|
238 |
|
---|
239 |
void |
---|
240 |
EfcGenericMixerCmd::showEfcCmd() |
---|
241 |
{ |
---|
242 |
EfcCmd::showEfcCmd(); |
---|
243 |
debugOutput(DEBUG_LEVEL_NORMAL, "EFC %s %s %s:\n", |
---|
244 |
(m_type==eCT_Get?"GET":"SET"), |
---|
245 |
eMixerTargetToString(m_target), |
---|
246 |
eMixerCommandToString(m_command)); |
---|
247 |
debugOutput(DEBUG_LEVEL_NORMAL, " Channel : %ld\n", m_channel); |
---|
248 |
debugOutput(DEBUG_LEVEL_NORMAL, " Value : %lu\n", m_value); |
---|
249 |
} |
---|
250 |
|
---|
251 |
// --- The specific commands |
---|
252 |
|
---|
253 |
|
---|
254 |
|
---|
255 |
} // namespace FireWorks |
---|