root/trunk/libffado/src/bebob/focusrite/focusrite_generic.cpp

Revision 661, 6.4 kB (checked in by ppalmers, 15 years ago)

- Implement more complete mixer support for the saffire pro
- fix some cleanup issues with control elements

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 "focusrite_saffirepro.h"
25 #include "focusrite_cmd.h"
26
27 namespace BeBoB {
28 namespace Focusrite {
29
30 FocusriteDevice::FocusriteDevice( Ieee1394Service& ieee1394Service,
31                             std::auto_ptr<ConfigRom>( configRom ))
32     : BeBoB::AvDevice( ieee1394Service, configRom)
33 {
34     debugOutput( DEBUG_LEVEL_VERBOSE, "Created BeBoB::Focusrite::FocusriteDevice (NodeID %d)\n",
35                  getConfigRom().getNodeId() );
36
37 }
38
39 void
40 FocusriteDevice::showDevice()
41 {
42     debugOutput(DEBUG_LEVEL_NORMAL, "This is a BeBoB::Focusrite::FocusriteDevice\n");
43     BeBoB::AvDevice::showDevice();
44 }
45
46 void
47 FocusriteDevice::setVerboseLevel(int l)
48 {
49     debugOutput( DEBUG_LEVEL_VERBOSE, "Setting verbose level to %d...\n", l );
50
51     BeBoB::AvDevice::setVerboseLevel(l);
52 }
53
54 bool
55 FocusriteDevice::setSpecificValue(uint32_t id, uint32_t v)
56 {
57    
58     FocusriteVendorDependentCmd cmd( get1394Service() );
59     cmd.setCommandType( AVC::AVCCommand::eCT_Control );
60     cmd.setNodeId( getConfigRom().getNodeId() );
61     cmd.setSubunitType( AVC::eST_Unit  );
62     cmd.setSubunitId( 0xff );
63    
64     cmd.setVerbose( getDebugLevel() );
65 //         cmd.setVerbose( DEBUG_LEVEL_VERY_VERBOSE );
66    
67     cmd.m_id=id;
68     cmd.m_value=v;
69    
70     if ( !cmd.fire() ) {
71         debugError( "FocusriteVendorDependentCmd info command failed\n" );
72         return false;
73     }
74    
75     return true;
76 }
77
78 bool
79 FocusriteDevice::getSpecificValue(uint32_t id, uint32_t *v)
80 {
81    
82     FocusriteVendorDependentCmd cmd( get1394Service() );
83     cmd.setCommandType( AVC::AVCCommand::eCT_Status );
84     cmd.setNodeId( getConfigRom().getNodeId() );
85     cmd.setSubunitType( AVC::eST_Unit  );
86     cmd.setSubunitId( 0xff );
87    
88     cmd.setVerbose( getDebugLevel() );
89 //         cmd.setVerbose( DEBUG_LEVEL_VERY_VERBOSE );
90    
91     cmd.m_id=id;
92    
93     if ( !cmd.fire() ) {
94         debugError( "FocusriteVendorDependentCmd info command failed\n" );
95         return false;
96     }
97    
98     *v=cmd.m_value;
99
100     return true;
101 }
102
103 int
104 FocusriteDevice::convertDefToSr( uint32_t def ) {
105     switch(def) {
106         case FOCUSRITE_CMD_SAMPLERATE_44K1:  return 44100;
107         case FOCUSRITE_CMD_SAMPLERATE_48K:   return 48000;
108         case FOCUSRITE_CMD_SAMPLERATE_88K2:  return 88200;
109         case FOCUSRITE_CMD_SAMPLERATE_96K:   return 96000;
110         case FOCUSRITE_CMD_SAMPLERATE_176K4: return 176400;
111         case FOCUSRITE_CMD_SAMPLERATE_192K:  return 192000;
112         default: return 0;
113     }
114 }
115
116 uint32_t
117 FocusriteDevice::convertSrToDef( int sr ) {
118     switch(sr) {
119         case 44100:  return FOCUSRITE_CMD_SAMPLERATE_44K1;
120         case 48000:  return FOCUSRITE_CMD_SAMPLERATE_48K;
121         case 88200:  return FOCUSRITE_CMD_SAMPLERATE_88K2;
122         case 96000:  return FOCUSRITE_CMD_SAMPLERATE_96K;
123         case 176400: return FOCUSRITE_CMD_SAMPLERATE_176K4;
124         case 192000: return FOCUSRITE_CMD_SAMPLERATE_192K;
125         default:
126             debugWarning("Unsupported samplerate: %d\n", sr);
127             return 0;
128     }
129 }
130
131 // --- element implementation classes
132
133 BinaryControl::BinaryControl(FocusriteDevice& parent, int id, int bit)
134 : Control::Discrete()
135 , m_Parent(parent)
136 , m_cmd_id ( id )
137 , m_cmd_bit ( bit )
138 {}
139 BinaryControl::BinaryControl(FocusriteDevice& parent, int id, int bit,
140                 std::string name, std::string label, std::string descr)
141 : Control::Discrete()
142 , m_Parent(parent)
143 , m_cmd_id ( id )
144 , m_cmd_bit ( bit )
145 {
146     setName(name);
147     setLabel(label);
148     setDescription(descr);
149 }
150
151 bool
152 BinaryControl::setValue(int v)
153 {
154     uint32_t reg;
155     uint32_t old_reg;
156
157     if ( !m_Parent.getSpecificValue(m_cmd_id, &reg) ) {
158         debugError( "getSpecificValue failed\n" );
159         return 0;
160     }
161    
162     old_reg=reg;
163     if (v) {
164         reg |= (1<<m_cmd_bit);
165     } else {
166         reg &= ~(1<<m_cmd_bit);
167     }
168     debugOutput(DEBUG_LEVEL_VERBOSE, "setValue for id %d to %d (reg: 0x%08X => 0x%08X)\n",
169                                      m_cmd_id, v, old_reg, reg);
170
171     if ( !m_Parent.setSpecificValue(m_cmd_id, reg) ) {
172         debugError( "setSpecificValue failed\n" );
173         return false;
174     } else return true;
175 }
176
177 int
178 BinaryControl::getValue()
179 {
180     uint32_t reg;
181
182     if ( !m_Parent.getSpecificValue(m_cmd_id, &reg) ) {
183         debugError( "getSpecificValue failed\n" );
184         return 0;
185     } else {
186         bool val= (reg & (1<<m_cmd_bit)) != 0;
187         debugOutput(DEBUG_LEVEL_VERBOSE, "getValue for %d: reg: 0x%08X, result=%d\n",
188                                          m_cmd_id, reg, val);
189         return val;
190     }
191 }
192
193 // --- element implementation classes
194
195 VolumeControl::VolumeControl(FocusriteDevice& parent, int id)
196 : Control::Discrete()
197 , m_Parent(parent)
198 , m_cmd_id ( id )
199 {}
200 VolumeControl::VolumeControl(FocusriteDevice& parent, int id,
201                 std::string name, std::string label, std::string descr)
202 : Control::Discrete()
203 , m_Parent(parent)
204 , m_cmd_id ( id )
205 {
206     setName(name);
207     setLabel(label);
208     setDescription(descr);
209 }
210
211
212 bool
213 VolumeControl::setValue(int v)
214 {
215     if (v>0x07FFF) v=0x07FFF;
216     else if (v<0) v=0;
217
218     debugOutput(DEBUG_LEVEL_VERBOSE, "setValue for id %d to %d\n",
219                                      m_cmd_id, v);
220
221     if ( !m_Parent.setSpecificValue(m_cmd_id, v) ) {
222         debugError( "setSpecificValue failed\n" );
223         return false;
224     } else return true;
225 }
226
227 int
228 VolumeControl::getValue()
229 {
230     uint32_t val=0;
231
232     if ( !m_Parent.getSpecificValue(m_cmd_id, &val) ) {
233         debugError( "getSpecificValue failed\n" );
234         return 0;
235     } else {
236         debugOutput(DEBUG_LEVEL_VERBOSE, "getValue for %d = %d\n",
237                                          m_cmd_id, val);
238         return val;
239     }
240 }
241
242 } // Focusrite
243 } // BeBoB
Note: See TracBrowser for help on using the browser.