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

Revision 665, 6.7 kB (checked in by ppalmers, 15 years ago)

Implement support for Phantom power on the fireworks devices

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     return result;
88 }
89
90 bool
91 EfcGenericMixerCmd::deserialize( Util::IISDeserialize& de )
92 {
93     bool result=true;
94
95     result &= EfcCmd::deserialize ( de );
96
97     EFC_DESERIALIZE_AND_SWAP(de, (quadlet_t *)&m_channel, result);
98     EFC_DESERIALIZE_AND_SWAP(de, &m_value, result);
99
100     return result;
101 }
102
103 bool
104 EfcGenericMixerCmd::setType( enum eCmdType type )
105 {
106     m_type=type;
107     if (type == eCT_Get) {
108         switch (m_command) {
109             case eMC_Gain:
110                 m_command_id=EFC_CMD_MIXER_GET_GAIN;
111                 break;
112             case eMC_Solo:
113                 m_command_id=EFC_CMD_MIXER_GET_SOLO;
114                 break;
115             case eMC_Mute:
116                 m_command_id=EFC_CMD_MIXER_GET_MUTE;
117                 break;
118             case eMC_Pan:
119                 m_command_id=EFC_CMD_MIXER_GET_PAN;
120                 break;
121             case eMC_Nominal:
122                 m_command_id=EFC_CMD_MIXER_GET_NOMINAL;
123                 break;
124             default:
125                 debugError("Invalid mixer get command: %d\n", m_command);
126                 return false;
127         }
128     } else {
129         switch (m_command) {
130             case eMC_Gain:
131                 m_command_id=EFC_CMD_MIXER_SET_GAIN;
132                 break;
133             case eMC_Solo:
134                 m_command_id=EFC_CMD_MIXER_SET_SOLO;
135                 break;
136             case eMC_Mute:
137                 m_command_id=EFC_CMD_MIXER_SET_MUTE;
138                 break;
139             case eMC_Pan:
140                 m_command_id=EFC_CMD_MIXER_SET_PAN;
141                 break;
142             case eMC_Nominal:
143                 m_command_id=EFC_CMD_MIXER_SET_NOMINAL;
144                 break;
145             default:
146                 debugError("Invalid mixer set command: %d\n", m_command);
147                 return false;
148         }
149     }
150     return true;
151 }
152
153 bool
154 EfcGenericMixerCmd::setTarget( enum eMixerTarget target )
155 {
156     m_target=target;
157     switch (target) {
158         case eMT_PhysicalOutputMix:
159             m_category_id=EFC_CAT_PHYSICAL_OUTPUT_MIX;
160             break;
161         case eMT_PhysicalInputMix:
162             m_category_id=EFC_CAT_PHYSICAL_INPUT_MIX;
163             break;
164         case eMT_PlaybackMix:
165             m_category_id=EFC_CAT_PLAYBACK_MIX;
166             break;
167         case eMT_RecordMix:
168             m_category_id=EFC_CAT_RECORD_MIX;
169             break;
170         default:
171             debugError("Invalid mixer target: %d\n", target);
172             return false;
173     }
174     return true;
175 }
176
177 bool
178 EfcGenericMixerCmd::setCommand( enum eMixerCommand command )
179 {
180     m_command=command;
181     if (m_type == eCT_Get) {
182         switch (command) {
183             case eMC_Gain:
184                 m_command_id=EFC_CMD_MIXER_GET_GAIN;
185                 break;
186             case eMC_Solo:
187                 m_command_id=EFC_CMD_MIXER_GET_SOLO;
188                 break;
189             case eMC_Mute:
190                 m_command_id=EFC_CMD_MIXER_GET_MUTE;
191                 break;
192             case eMC_Pan:
193                 m_command_id=EFC_CMD_MIXER_GET_PAN;
194                 break;
195             case eMC_Nominal:
196                 m_command_id=EFC_CMD_MIXER_GET_NOMINAL;
197                 break;
198             default:
199                 debugError("Invalid mixer get command: %d\n", command);
200                 return false;
201         }
202     } else {
203         switch (command) {
204             case eMC_Gain:
205                 m_command_id=EFC_CMD_MIXER_SET_GAIN;
206                 break;
207             case eMC_Solo:
208                 m_command_id=EFC_CMD_MIXER_SET_SOLO;
209                 break;
210             case eMC_Mute:
211                 m_command_id=EFC_CMD_MIXER_SET_MUTE;
212                 break;
213             case eMC_Pan:
214                 m_command_id=EFC_CMD_MIXER_SET_PAN;
215                 break;
216             case eMC_Nominal:
217                 m_command_id=EFC_CMD_MIXER_SET_NOMINAL;
218                 break;
219             default:
220                 debugError("Invalid mixer set command: %d\n", command);
221                 return false;
222         }
223     }
224     return true;
225 }
226
227
228 void
229 EfcGenericMixerCmd::showEfcCmd()
230 {
231     EfcCmd::showEfcCmd();
232     debugOutput(DEBUG_LEVEL_NORMAL, "EFC %s %s %s:\n",
233                                     (m_type==eCT_Get?"GET":"SET"),
234                                     eMixerTargetToString(m_target),
235                                     eMixerCommandToString(m_command));
236     debugOutput(DEBUG_LEVEL_NORMAL, " Channel     : %ld\n", m_channel);
237     debugOutput(DEBUG_LEVEL_NORMAL, " Value       : %lu\n", m_value);
238 }
239
240 // --- The specific commands
241
242
243
244 } // namespace FireWorks
Note: See TracBrowser for help on using the browser.