root/trunk/libffado/src/fireworks/efc/efc_cmds_mixer.cpp

Revision 668, 6.9 kB (checked in by ppalmers, 16 years ago)

fix small bug in ECHO mixer commands

Line 
1 /*
2  * Copyright (C) 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 library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License version 2.1, as published by the Free Software Foundation;
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21  * MA 02110-1301 USA
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::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::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
Note: See TracBrowser for help on using the browser.