/[svn]/qsampler/trunk/src/qsamplerDevice.cpp
ViewVC logotype

Contents of /qsampler/trunk/src/qsamplerDevice.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 430 - (show annotations) (download)
Tue Mar 8 17:23:29 2005 UTC (19 years ago) by capela
File size: 10258 byte(s)
Still on-going with this new device configuration stuff.

1 // qsamplerDevice.cpp
2 //
3 /****************************************************************************
4 Copyright (C) 2005, rncbc aka Rui Nuno Capela. All rights reserved.
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 *****************************************************************************/
21
22 #include "qsamplerDevice.h"
23
24 #include "qsamplerMainForm.h"
25 #include "qsamplerDeviceForm.h"
26
27 #include "config.h"
28
29
30 //-------------------------------------------------------------------------
31 // qsamplerDeviceParam - MIDI/Audio Device parameter structure.
32 //
33
34 // Constructors.
35 qsamplerDeviceParam::qsamplerDeviceParam ( lscp_param_info_t *pParamInfo,
36 const char *pszValue )
37 {
38 setParam(pParamInfo, pszValue);
39 }
40
41
42 // Default destructor.
43 qsamplerDeviceParam::~qsamplerDeviceParam (void)
44 {
45 }
46
47
48 // Initializer.
49 void qsamplerDeviceParam::setParam ( lscp_param_info_t *pParamInfo,
50 const char *pszValue )
51 {
52 if (pParamInfo == NULL)
53 return;
54
55 // Info structure field members.
56
57 type = pParamInfo->type;
58
59 if (pParamInfo->description)
60 description = pParamInfo->description;
61 else
62 description = QString::null;
63
64 mandatory = (bool) pParamInfo->multiplicity;
65 fix = (bool) pParamInfo->fix;
66 multiplicity = (bool) pParamInfo->multiplicity;
67
68 depends.clear();
69 for (int i = 0; pParamInfo->depends && pParamInfo->depends[i]; i++)
70 depends.append(pParamInfo->depends[i]);
71
72 if (pParamInfo->defaultv)
73 defaultv = pParamInfo->defaultv;
74 else
75 defaultv = QString::null;
76
77 if (pParamInfo->range_min)
78 range_min = pParamInfo->range_min;
79 else
80 range_min = QString::null;
81
82 if (pParamInfo->range_max)
83 range_max = pParamInfo->range_max;
84 else
85 range_max = QString::null;
86
87 possibilities.clear();
88 for (int i = 0; pParamInfo->possibilities && pParamInfo->possibilities[i]; i++)
89 possibilities.append(pParamInfo->possibilities[i]);
90
91 // The current parameter value.
92 if (pszValue)
93 value = pszValue;
94 else
95 value = QString::null;
96 }
97
98
99 //-------------------------------------------------------------------------
100 // qsamplerDevice - MIDI/Audio Device structure.
101 //
102
103 // Constructor.
104 qsamplerDevice::qsamplerDevice ( lscp_client_t *pClient,
105 qsamplerDeviceType deviceType, int iDeviceID )
106 {
107 setDevice(pClient, deviceType, iDeviceID);
108 }
109
110 // Default destructor.
111 qsamplerDevice::~qsamplerDevice (void)
112 {
113 }
114
115
116 // Initializer.
117 void qsamplerDevice::setDevice ( lscp_client_t *pClient,
118 qsamplerDeviceType deviceType, int iDeviceID )
119 {
120 // Device id and type should be always set.
121 m_iDeviceID = iDeviceID;
122 m_deviceType = deviceType;
123
124 // Retrieve device info, if any.
125 QString sDeviceType;
126 lscp_device_info_t *pDeviceInfo = NULL;
127 switch (deviceType) {
128 case qsamplerDevice::Audio:
129 sDeviceType = QObject::tr("Audio");
130 pDeviceInfo = ::lscp_get_audio_device_info(pClient, iDeviceID);
131 break;
132 case qsamplerDevice::Midi:
133 sDeviceType = QObject::tr("MIDI");
134 pDeviceInfo = ::lscp_get_midi_device_info(pClient, iDeviceID);
135 break;
136 }
137
138 // If we're bogus, bail out...
139 if (pDeviceInfo == NULL) {
140 m_sDriverName = QString::null;
141 m_sDeviceName = QObject::tr("New %1 device").arg(sDeviceType);
142 return;
143 }
144
145 // Other device properties...
146 m_sDriverName = pDeviceInfo->driver;
147 m_sDeviceName = m_sDriverName + ' '
148 + QObject::tr("Device %1").arg(m_iDeviceID);
149
150 // Grab device/driver parameters...
151 m_params.clear();
152 for (int i = 0; pDeviceInfo->params && pDeviceInfo->params[i].key; i++) {
153 const char *pszParam = pDeviceInfo->params[i].key;
154 lscp_param_info_t *pParamInfo = NULL;
155 switch (deviceType) {
156 case qsamplerDevice::Audio:
157 pParamInfo = ::lscp_get_audio_driver_param_info(pClient,
158 m_sDriverName.latin1(), pszParam, NULL);
159 break;
160 case qsamplerDevice::Midi:
161 pParamInfo = ::lscp_get_midi_driver_param_info(pClient,
162 m_sDriverName.latin1(), pszParam, NULL);
163 break;
164 }
165 m_params[pszParam] = qsamplerDeviceParam(pParamInfo, pDeviceInfo->params[i].value);
166 }
167 }
168
169
170 // Device property accessors.
171 int qsamplerDevice::deviceID (void) const
172 {
173 return m_iDeviceID;
174 }
175
176 qsamplerDevice::qsamplerDeviceType qsamplerDevice::deviceType (void) const
177 {
178 return m_deviceType;
179 }
180
181 const QString& qsamplerDevice::driverName (void) const
182 {
183 return m_sDriverName;
184 }
185
186 const QString& qsamplerDevice::deviceName (void) const
187 {
188 return m_sDeviceName;
189 }
190
191 // Device parameter accessor.
192 qsamplerDeviceParamMap& qsamplerDevice::params (void)
193 {
194 return m_params;
195 }
196
197
198 // Update/refresh device/driver data.
199 void qsamplerDevice::refresh (void)
200 {
201 }
202
203 // Device ids enumerator.
204 int *qsamplerDevice::getDevices ( lscp_client_t *pClient,
205 qsamplerDeviceType deviceType )
206 {
207 int *piDeviceIDs = NULL;
208 switch (deviceType) {
209 case qsamplerDevice::Audio:
210 piDeviceIDs = ::lscp_list_audio_devices(pClient);
211 break;
212 case qsamplerDevice::Midi:
213 piDeviceIDs = ::lscp_list_midi_devices(pClient);
214 break;
215 }
216 return piDeviceIDs;
217 }
218
219
220 // Driver names enumerator.
221 QStringList qsamplerDevice::getDrivers ( lscp_client_t *pClient,
222 qsamplerDeviceType deviceType )
223 {
224 QStringList drivers;
225
226 const char **ppszDrivers = NULL;
227 switch (deviceType) {
228 case qsamplerDevice::Audio:
229 ppszDrivers = ::lscp_get_available_audio_drivers(pClient);
230 break;
231 case qsamplerDevice::Midi:
232 ppszDrivers = ::lscp_get_available_midi_drivers(pClient);
233 break;
234 }
235
236 for (int iDriver = 0; ppszDrivers[iDriver]; iDriver++)
237 drivers.append(ppszDrivers[iDriver]);
238
239 return drivers;
240 }
241
242
243 //-------------------------------------------------------------------------
244 // qsamplerDeviceItem - QListView device item.
245 //
246
247 // Constructors.
248 qsamplerDeviceItem::qsamplerDeviceItem ( QListView *pListView, lscp_client_t *pClient,
249 qsamplerDevice::qsamplerDeviceType deviceType )
250 : QListViewItem(pListView), m_device(pClient, deviceType)
251 {
252 switch(m_device.deviceType()) {
253 case qsamplerDevice::Audio:
254 QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio1.png"));
255 QListViewItem::setText(0, QObject::tr("Audio devices"));
256 break;
257 case qsamplerDevice::Midi:
258 QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi1.png"));
259 QListViewItem::setText(0, QObject::tr("MIDI devices"));
260 break;
261 }
262 }
263
264 qsamplerDeviceItem::qsamplerDeviceItem ( QListViewItem *pItem, lscp_client_t *pClient,
265 qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID )
266 : QListViewItem(pItem), m_device(pClient, deviceType, iDeviceID)
267 {
268 switch(m_device.deviceType()) {
269 case qsamplerDevice::Audio:
270 QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio2.png"));
271 break;
272 case qsamplerDevice::Midi:
273 QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi2.png"));
274 break;
275 }
276
277 QListViewItem::setText(0, m_device.deviceName());
278 }
279
280 // Default destructor.
281 qsamplerDeviceItem::~qsamplerDeviceItem (void)
282 {
283 }
284
285 // Instance accessors.
286 const qsamplerDevice& qsamplerDeviceItem::device (void)
287 {
288 return m_device;
289 }
290
291 // To virtually distinguish between list view items.
292 int qsamplerDeviceItem::rtti() const
293 {
294 return QSAMPLER_DEVICE_ITEM;
295 }
296
297
298
299 //-------------------------------------------------------------------------
300 // qsamplerDeviceParamTable - Device parameter view table.
301 //
302
303 // Constructor.
304 qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, const char *pszName )
305 : QTable(pParent, pszName)
306 {
307 m_pClient = NULL;
308 m_iDeviceID = -1;
309
310 // Set fixed number of columns.
311 QTable::setNumCols(3);
312 QTable::setShowGrid(false);
313 QTable::setSorting(false);
314 QTable::setFocusStyle(QTable::FollowStyle);
315 QTable::setSelectionMode(QTable::NoSelection);
316 // No vertical header.
317 QTable::verticalHeader()->hide();
318 QTable::setLeftMargin(0);
319 // Initialize the fixed table column headings.
320 QHeader *pHeader = QTable::horizontalHeader();
321 pHeader->setLabel(0, tr("Parameter"));
322 pHeader->setLabel(1, tr("Description"));
323 pHeader->setLabel(2, tr("Value"));
324 // Set read-onlyness of each column
325 QTable::setColumnReadOnly(0, true);
326 QTable::setColumnReadOnly(1, true);
327 // QTable::setColumnReadOnly(2, true); -- of course not.
328 }
329
330 // Default destructor.
331 qsamplerDeviceParamTable::~qsamplerDeviceParamTable (void)
332 {
333 }
334
335
336 // Client/device descriptor selector.
337 void qsamplerDeviceParamTable::setDevice ( lscp_client_t *pClient,
338 qsamplerDevice::qsamplerDeviceType deviceType, int iDeviceID )
339 {
340 if (m_pClient
341 && m_pClient == pClient
342 && m_deviceType == deviceType
343 && m_iDeviceID == iDeviceID)
344 return;
345
346 m_pClient = pClient;
347 m_deviceType = deviceType;
348 m_iDeviceID = iDeviceID;
349
350 refresh();
351 }
352
353
354 // Client/device descriptor accessors.
355 lscp_client_t *qsamplerDeviceParamTable::client (void)
356 {
357 return m_pClient;
358 }
359
360 int qsamplerDeviceParamTable::deviceID (void)
361 {
362 return m_iDeviceID;
363 }
364
365
366 // The main table refresher.
367 void qsamplerDeviceParamTable::refresh (void)
368 {
369 // Always (re)start it empty.
370 QTable::setNumRows(0);
371
372 if (m_pClient == NULL)
373 return;
374
375 // Construct the local device object here.
376 qsamplerDevice device(m_pClient, m_deviceType, m_iDeviceID);
377
378
379 // Now fill the parameter table...
380 QHeader *pHeader = QTable::verticalHeader();
381 qsamplerDeviceParamMap& params = device.params();
382 QTable::insertRows(0, params.count());
383 int iRow = 0;
384 qsamplerDeviceParamMap::Iterator iter;
385 for (iter = params.begin(); iter != params.end(); ++iter) {
386 QTable::setText(iRow, 0, iter.key());
387 QTable::setText(iRow, 1, iter.data().description);
388 QTable::setText(iRow, 2, iter.data().value);
389 ++iRow;
390 }
391
392 // Adjust optimal column width.
393 for (int iCol = 0; iCol < QTable::numCols(); iCol++)
394 QTable::adjustColumn(iCol);
395 }
396
397
398 // end of qsamplerDevice.cpp

  ViewVC Help
Powered by ViewVC