root/trunk/libffado/src/fireworks/fireworks_control.cpp

Revision 864, 12.3 kB (checked in by ppalmers, 16 years ago)

update license to GPLv2 or GPLv3 instead of GPLv2 or any later version. Update copyrights to reflect the new year

Line 
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 "fireworks_device.h"
25 #include "fireworks_control.h"
26 #include "efc/efc_avc_cmd.h"
27 #include "efc/efc_cmd.h"
28 #include "efc/efc_cmds_mixer.h"
29 #include "efc/efc_cmds_monitor.h"
30
31 #include <string>
32 #include <sstream>
33
34 using namespace std;
35
36 // These classes provide support for the controls on the echo devices
37 namespace FireWorks {
38
39 MonitorControl::MonitorControl(FireWorks::Device& p, enum eMonitorControl c)
40 : Control::MatrixMixer("MonitorControl")
41 , m_control(c)
42 , m_Parent(p)
43 {
44 }
45
46 MonitorControl::MonitorControl(FireWorks::Device& p, enum eMonitorControl c, std::string n)
47 : Control::MatrixMixer(n)
48 , m_control(c)
49 , m_Parent(p)
50 {
51 }
52
53 void MonitorControl::show()
54 {
55     debugOutput(DEBUG_LEVEL_NORMAL, "MonitorControl\n");
56 }
57
58 std::string MonitorControl::getRowName( const int row )
59 {
60     std::ostringstream rowname;
61     rowname << "IN" << row;
62     debugOutput(DEBUG_LEVEL_VERBOSE, "name for row %d is %s\n",
63                                      row, rowname.str().c_str());
64     return rowname.str();
65 }
66
67 std::string MonitorControl::getColName( const int col )
68 {
69     std::ostringstream colname;
70     colname << "OUT" << col;
71     debugOutput(DEBUG_LEVEL_VERBOSE, "name for col %d is %s\n",
72                                      col, colname.str().c_str());
73     return colname.str();
74 }
75
76 int MonitorControl::canWrite( const int row, const int col )
77 {
78     debugOutput(DEBUG_LEVEL_VERBOSE, "canWrite for row %d col %d is %d\n",
79                                      row, col, true);
80     return true;
81 }
82
83 double MonitorControl::setValue( const int row, const int col, const double val )
84 {
85     double retval=0.0;
86     bool did_command=false;
87
88     if(row >= (int)m_Parent.getHwInfo().m_nb_phys_audio_in) {
89         debugError("specified row (%u) larger than number of rows (%d)\n",
90             row, m_Parent.getHwInfo().m_nb_phys_audio_in);
91         return 0.0;
92     }
93     if(col >= (int)m_Parent.getHwInfo().m_nb_phys_audio_out) {
94         debugError("specified col (%u) larger than number of cols (%d)\n",
95             col, m_Parent.getHwInfo().m_nb_phys_audio_out);
96         return 0.0;
97     }
98
99     if(m_control==eMC_Gain) {
100         EfcSetMonitorGainCmd setCmd;
101         setCmd.m_input=row;
102         setCmd.m_output=col;
103         setCmd.m_value=(uint32_t)val;
104         if (!m_Parent.doEfcOverAVC(setCmd))
105         {
106             debugFatal("Cmd failed\n");
107         }
108         retval=setCmd.m_value;
109         did_command=true;
110     }
111     if(m_control==eMC_Pan) {
112         EfcSetMonitorPanCmd setCmd;
113         setCmd.m_input=row;
114         setCmd.m_output=col;
115         setCmd.m_value=(uint32_t)val;
116         if (!m_Parent.doEfcOverAVC(setCmd))
117         {
118             debugFatal("Cmd failed\n");
119         }
120         retval=setCmd.m_value;
121         did_command=true;
122     }
123     if(m_control==eMC_Mute) {
124         EfcSetMonitorMuteCmd setCmd;
125         setCmd.m_input=row;
126         setCmd.m_output=col;
127         setCmd.m_value=(uint32_t)val;
128         if (!m_Parent.doEfcOverAVC(setCmd))
129         {
130             debugFatal("Cmd failed\n");
131         }
132         retval=setCmd.m_value;
133         did_command=true;
134     }
135     if(m_control==eMC_Solo) {
136         EfcSetMonitorSoloCmd setCmd;
137         setCmd.m_input=row;
138         setCmd.m_output=col;
139         setCmd.m_value=(uint32_t)val;
140         if (!m_Parent.doEfcOverAVC(setCmd))
141         {
142             debugFatal("Cmd failed\n");
143         }
144         retval=setCmd.m_value;
145         did_command=true;
146     }
147
148     debugOutput(DEBUG_LEVEL_VERBOSE, "setValue for row %d col %d = %lf\n",
149                                          row, col, retval);
150
151     if (!did_command) {
152         debugError("BUG: this should never happen due to enum\n");
153     }
154     return retval;
155 }
156
157 double MonitorControl::getValue( const int row, const int col )
158 {
159     double retval=0.0;
160     bool did_command=false;
161
162     if(row >= (int)m_Parent.getHwInfo().m_nb_phys_audio_in) {
163         debugError("specified row (%u) larger than number of rows (%d)\n",
164             row, m_Parent.getHwInfo().m_nb_phys_audio_in);
165         return 0.0;
166     }
167     if(col >= (int)m_Parent.getHwInfo().m_nb_phys_audio_out) {
168         debugError("specified col (%u) larger than number of cols (%d)\n",
169             col, m_Parent.getHwInfo().m_nb_phys_audio_out);
170         return 0.0;
171     }
172
173     if(m_control==eMC_Gain) {
174         EfcGetMonitorGainCmd getCmd;
175         getCmd.m_input=row;
176         getCmd.m_output=col;
177         if (!m_Parent.doEfcOverAVC(getCmd))
178         {
179             debugFatal("Cmd failed\n");
180         }
181         retval=getCmd.m_value;
182         did_command=true;
183     }
184     if(m_control==eMC_Pan) {
185         EfcGetMonitorPanCmd getCmd;
186         getCmd.m_input=row;
187         getCmd.m_output=col;
188         if (!m_Parent.doEfcOverAVC(getCmd))
189         {
190             debugFatal("Cmd failed\n");
191         }
192         retval=getCmd.m_value;
193         did_command=true;
194     }
195     if(m_control==eMC_Mute) {
196         EfcGetMonitorMuteCmd getCmd;
197         getCmd.m_input=row;
198         getCmd.m_output=col;
199         if (!m_Parent.doEfcOverAVC(getCmd))
200         {
201             debugFatal("Cmd failed\n");
202         }
203         retval=getCmd.m_value;
204         did_command=true;
205     }
206     if(m_control==eMC_Solo) {
207         EfcGetMonitorSoloCmd getCmd;
208         getCmd.m_input=row;
209         getCmd.m_output=col;
210         if (!m_Parent.doEfcOverAVC(getCmd))
211         {
212             debugFatal("Cmd failed\n");
213         }
214         retval=getCmd.m_value;
215         did_command=true;
216     }
217
218     debugOutput(DEBUG_LEVEL_VERBOSE, "getValue for row %d col %d = %lf\n",
219                                          row, col, retval);
220
221     if (!did_command) {
222         debugError("BUG: this should never happen due to enum\n");
223     }
224     return retval;
225 }
226
227 int MonitorControl::getRowCount( )
228 {
229     return m_Parent.getHwInfo().m_nb_phys_audio_in;
230 }
231
232 int MonitorControl::getColCount( )
233 {
234     return m_Parent.getHwInfo().m_nb_phys_audio_out;
235 }
236
237 // --- the generic control element for single-value controls
238
239 SimpleControl::SimpleControl(FireWorks::Device& p,
240                              enum eMixerTarget t,
241                              enum eMixerCommand c,
242                              int channel)
243 : Control::Continuous("SimpleControl")
244 , m_Slave(new EfcGenericMixerCmd(t, c, channel))
245 , m_Parent(p)
246 {
247 }
248
249 SimpleControl::SimpleControl(FireWorks::Device& p,
250                              enum eMixerTarget t,
251                              enum eMixerCommand c,
252                              int channel,
253                              std::string n)
254 : Control::Continuous(n)
255 , m_Slave(new EfcGenericMixerCmd(t, c, channel))
256 , m_Parent(p)
257 {
258 }
259
260 SimpleControl::~SimpleControl()
261 {
262     delete m_Slave;
263 }
264
265 void SimpleControl::show()
266 {
267     debugOutput(DEBUG_LEVEL_NORMAL, "SimpleControl\n");
268     if(m_Slave) m_Slave->showEfcCmd();
269 }
270
271 bool SimpleControl::setValue( const double val )
272 {
273     if(m_Slave) {
274         m_Slave->setType(eCT_Set);
275         m_Slave->m_value=(uint32_t)val;
276         if (!m_Parent.doEfcOverAVC(*m_Slave))
277         {
278             debugFatal("Cmd failed\n");
279             return 0.0;
280         }
281         debugOutput(DEBUG_LEVEL_VERBOSE, "setValue for channel %d to %lf = %lf\n",
282                                             m_Slave->m_channel, val, m_Slave->m_value);
283         return true;
284     } else {
285         debugError("No slave EFC command present\n");
286         return false;
287     }
288 }
289
290 double SimpleControl::getValue( )
291 {
292     if(m_Slave) {
293         m_Slave->setType(eCT_Get);
294         if (!m_Parent.doEfcOverAVC(*m_Slave))
295         {
296             debugFatal("Cmd failed\n");
297             return 0.0;
298         }
299         debugOutput(DEBUG_LEVEL_VERBOSE, "getValue for channel %d = %lf\n",
300                                             m_Slave->m_channel, m_Slave->m_value);
301         return m_Slave->m_value;
302     } else {
303         debugError("No slave EFC command present\n");
304         return 0.0;
305     }
306 }
307
308 // --- the generic control element for on-off controls
309
310 BinaryControl::BinaryControl(FireWorks::Device& p,
311                              enum eMixerTarget t,
312                              enum eMixerCommand c,
313                              int channel, int bit)
314 : Control::Discrete("BinaryControl")
315 , m_bit(bit)
316 , m_Slave(new EfcGenericMixerCmd(t, c, channel))
317 , m_Parent(p)
318 {
319 }
320
321 BinaryControl::BinaryControl(FireWorks::Device& p,
322                              enum eMixerTarget t,
323                              enum eMixerCommand c,
324                              int channel, int bit,
325                              std::string n)
326 : Control::Discrete(n)
327 , m_bit(bit)
328 , m_Slave(new EfcGenericMixerCmd(t, c, channel))
329 , m_Parent(p)
330 {
331 }
332
333 BinaryControl::~BinaryControl()
334 {
335     delete m_Slave;
336 }
337
338 void BinaryControl::show()
339 {
340     debugOutput(DEBUG_LEVEL_NORMAL, "BinaryControl\n");
341     if(m_Slave) m_Slave->showEfcCmd();
342 }
343
344 bool BinaryControl::setValue( const int val )
345 {
346
347     if(m_Slave) {
348         uint32_t reg;
349         uint32_t old_reg;
350        
351         m_Slave->setType(eCT_Get);
352         reg=m_Slave->m_value;
353        
354         old_reg=reg;
355         if (val) {
356             reg |= (1<<m_bit);
357         } else {
358             reg &= ~(1<<m_bit);
359         }
360    
361         m_Slave->setType(eCT_Set);
362         m_Slave->m_value=reg;
363         if (!m_Parent.doEfcOverAVC(*m_Slave))
364         {
365             debugFatal("Cmd failed\n");
366             return 0;
367         }
368         debugOutput(DEBUG_LEVEL_VERBOSE, "setValue for channel %d to %ld (reg: 0x%08X => 0x%08X)\n",
369                                             m_Slave->m_channel, val, old_reg, reg);
370         return true;
371     } else {
372         debugError("No slave EFC command present\n");
373         return false;
374     }
375 }
376
377 int BinaryControl::getValue( )
378 {
379     if(m_Slave) {
380         m_Slave->setType(eCT_Get);
381         if (!m_Parent.doEfcOverAVC(*m_Slave))
382         {
383             debugFatal("Cmd failed\n");
384             return 0;
385         }
386         bool val= (m_Slave->m_value & (1<<m_bit)) != 0;
387         debugOutput(DEBUG_LEVEL_VERBOSE, "getValue for channel %d: reg: 0x%08X, result=%d\n",
388                                          m_Slave->m_channel, m_Slave->m_value, val);
389         return val;
390     } else {
391         debugError("No slave EFC command present\n");
392         return 0;
393     }
394 }
395
396 // --- io config controls
397
398 IOConfigControl::IOConfigControl(FireWorks::Device& parent,
399                                  enum eIOConfigRegister r)
400 : Control::Discrete("IOConfigControl")
401 , m_Slave(new EfcGenericIOConfigCmd(r))
402 , m_Parent(parent)
403 {
404 }
405
406 IOConfigControl::IOConfigControl(FireWorks::Device& parent,
407                                  enum eIOConfigRegister r,
408                                  std::string n)
409 : Control::Discrete(n)
410 , m_Slave(new EfcGenericIOConfigCmd(r))
411 , m_Parent(parent)
412 {
413 }
414
415 IOConfigControl::~IOConfigControl()
416 {
417     delete m_Slave;
418 }
419
420 void IOConfigControl::show()
421 {
422     debugOutput(DEBUG_LEVEL_NORMAL, "IOConfigControl\n");
423     if(m_Slave) m_Slave->showEfcCmd();
424 }
425
426 bool IOConfigControl::setValue( const int val )
427 {
428     if(m_Slave) {
429         m_Slave->setType(eCT_Set);
430         m_Slave->m_value=val;
431         if (!m_Parent.doEfcOverAVC(*m_Slave))
432         {
433             debugFatal("Cmd failed\n");
434             return 0;
435         }
436         debugOutput(DEBUG_LEVEL_VERBOSE, "setValue to %ld \n", val);
437         return true;
438     } else {
439         debugError("No slave EFC command present\n");
440         return false;
441     }
442 }
443
444 int IOConfigControl::getValue( )
445 {
446     if(m_Slave) {
447         m_Slave->setType(eCT_Get);
448         if (!m_Parent.doEfcOverAVC(*m_Slave))
449         {
450             debugFatal("Cmd failed\n");
451             return 0;
452         }
453         debugOutput(DEBUG_LEVEL_VERBOSE, "getValue: result=%d\n",
454                                           m_Slave->m_value);
455         return m_Slave->m_value;
456     } else {
457         debugError("No slave EFC command present\n");
458         return 0;
459     }
460 }
461
462
463
464 } // FireWorks
Note: See TracBrowser for help on using the browser.