motu: the 4pre channel layout within packets is now believed to be correct. Thanks...
[ffado.git] / libffado / src / fireworks / efc / efc_cmds_mixer.cpp
blob3d96266e5ce9ff74c1cbc8c59a4d919f8524d2c6
1 /*
2 * Copyright (C) 2005-2008 by Pieter Palmers
4 * This file is part of FFADO
5 * FFADO = Free Firewire (pro-)audio drivers for linux
7 * FFADO is based upon FreeBoB
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.
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.
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/>.
24 #include "efc_cmd.h"
25 #include "efc_cmds_mixer.h"
27 #include "libutil/ByteSwap.h"
28 #include <iostream>
30 using namespace std;
32 namespace FireWorks {
34 EfcGenericMixerCmd::EfcGenericMixerCmd(enum eMixerTarget target,
35 enum eMixerCommand command)
36 : EfcCmd()
37 , m_channel ( -1 )
38 , m_value ( 0 )
40 m_type=eCT_Get;
41 m_target=target;
42 m_command=command;
43 setTarget(target);
44 setCommand(command);
45 setType(eCT_Get);
48 EfcGenericMixerCmd::EfcGenericMixerCmd(enum eMixerTarget target,
49 enum eMixerCommand command,
50 int channel)
51 : EfcCmd()
52 , m_channel ( channel )
53 , m_value ( 0 )
55 m_type=eCT_Get;
56 m_target=target;
57 m_command=command;
58 setTarget(target);
59 setCommand(command);
60 setType(eCT_Get);
63 bool
64 EfcGenericMixerCmd::serialize( Util::Cmd::IOSSerialize& se )
66 bool result=true;
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;
73 result &= EfcCmd::serialize ( se );
75 result &= se.write(CondSwapToBus32(m_channel), "Channel" );
77 } else {
78 // the length should be specified before
79 // the header is serialized
80 m_length=EFC_HEADER_LENGTH_QUADLETS+2;
82 result &= EfcCmd::serialize ( se );
84 result &= se.write(CondSwapToBus32(m_channel), "Channel" );
85 result &= se.write(CondSwapToBus32(m_value), "Value" );
88 if(!result) {
89 debugWarning("Serialization failed\n");
92 return result;
95 bool
96 EfcGenericMixerCmd::deserialize( Util::Cmd::IISDeserialize& de )
98 bool result=true;
100 result &= EfcCmd::deserialize ( de );
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);
107 if(!result) {
108 debugWarning("Deserialization failed\n");
111 return result;
114 bool
115 EfcGenericMixerCmd::setType( enum eCmdType type )
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;
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;
161 return true;
164 bool
165 EfcGenericMixerCmd::setTarget( enum eMixerTarget target )
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;
185 return true;
188 bool
189 EfcGenericMixerCmd::setCommand( enum eMixerCommand command )
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;
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;
235 return true;
239 void
240 EfcGenericMixerCmd::showEfcCmd()
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 : %d\n", m_channel);
248 debugOutput(DEBUG_LEVEL_NORMAL, " Value : %u\n", m_value);
251 // --- The specific commands
255 } // namespace FireWorks