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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 482 - (show annotations) (download)
Mon Mar 21 10:29:49 2005 UTC (15 years, 4 months ago) by capela
File size: 21649 byte(s)
Multiplicity support is now officialy bogus.

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 <qspinbox.h>
25 #include <qlineedit.h>
26
27 #include "qsamplerMainForm.h"
28 #include "qsamplerDeviceForm.h"
29
30 #include "config.h"
31
32
33 //-------------------------------------------------------------------------
34 // qsamplerDeviceParam - MIDI/Audio Device parameter structure.
35 //
36
37 // Constructors.
38 qsamplerDeviceParam::qsamplerDeviceParam ( lscp_param_info_t *pParamInfo,
39 const char *pszValue )
40 {
41 setParam(pParamInfo, pszValue);
42 }
43
44
45 // Default destructor.
46 qsamplerDeviceParam::~qsamplerDeviceParam (void)
47 {
48 }
49
50
51 // Initializer.
52 void qsamplerDeviceParam::setParam ( lscp_param_info_t *pParamInfo,
53 const char *pszValue )
54 {
55 if (pParamInfo == NULL)
56 return;
57
58 // Info structure field members.
59
60 type = pParamInfo->type;
61
62 if (pParamInfo->description)
63 description = pParamInfo->description;
64 else
65 description = QString::null;
66
67 mandatory = (bool) pParamInfo->mandatory;
68 fix = (bool) pParamInfo->fix;
69 multiplicity = (bool) pParamInfo->multiplicity;
70
71 depends.clear();
72 for (int i = 0; pParamInfo->depends && pParamInfo->depends[i]; i++)
73 depends.append(pParamInfo->depends[i]);
74
75 if (pParamInfo->defaultv)
76 defaultv = pParamInfo->defaultv;
77 else
78 defaultv = QString::null;
79
80 if (pParamInfo->range_min)
81 range_min = pParamInfo->range_min;
82 else
83 range_min = QString::null;
84
85 if (pParamInfo->range_max)
86 range_max = pParamInfo->range_max;
87 else
88 range_max = QString::null;
89
90 possibilities.clear();
91 for (int i = 0; pParamInfo->possibilities && pParamInfo->possibilities[i]; i++)
92 possibilities.append(pParamInfo->possibilities[i]);
93
94 // The current parameter value.
95 if (pszValue)
96 value = pszValue;
97 else
98 value = QString::null;
99 }
100
101
102 //-------------------------------------------------------------------------
103 // qsamplerDevice - MIDI/Audio Device structure.
104 //
105
106 // Constructor.
107 qsamplerDevice::qsamplerDevice ( lscp_client_t *pClient,
108 qsamplerDeviceType deviceType, int iDeviceID )
109 {
110 m_ports.setAutoDelete(true);
111
112 setDevice(pClient, deviceType, iDeviceID);
113 }
114
115 // Default destructor.
116 qsamplerDevice::~qsamplerDevice (void)
117 {
118 }
119
120
121 // Initializer.
122 void qsamplerDevice::setDevice ( lscp_client_t *pClient,
123 qsamplerDeviceType deviceType, int iDeviceID )
124 {
125 // Device id and type should be always set.
126 m_iDeviceID = iDeviceID;
127 m_deviceType = deviceType;
128
129 // Reset device parameters and ports anyway.
130 m_params.clear();
131 m_ports.clear();
132
133 // Retrieve device info, if any.
134 lscp_device_info_t *pDeviceInfo = NULL;
135 switch (deviceType) {
136 case qsamplerDevice::Audio:
137 m_sDeviceType = QObject::tr("Audio");
138 pDeviceInfo = ::lscp_get_audio_device_info(pClient, iDeviceID);
139 break;
140 case qsamplerDevice::Midi:
141 m_sDeviceType = QObject::tr("MIDI");
142 pDeviceInfo = ::lscp_get_midi_device_info(pClient, iDeviceID);
143 break;
144 case qsamplerDevice::None:
145 m_sDeviceType = QString::null;
146 break;
147 }
148
149 // If we're bogus, bail out...
150 if (pDeviceInfo == NULL) {
151 m_sDriverName = QString::null;
152 m_sDeviceName = QObject::tr("New %1 device").arg(m_sDeviceType);
153 return;
154 }
155
156 // Other device properties...
157 m_sDriverName = pDeviceInfo->driver;
158 m_sDeviceName = m_sDriverName + ' '
159 + QObject::tr("Device %1").arg(m_iDeviceID);
160
161 // Grab device parameters...
162 for (int i = 0; pDeviceInfo->params && pDeviceInfo->params[i].key; i++) {
163 const QString sParam = pDeviceInfo->params[i].key;
164 lscp_param_info_t *pParamInfo = NULL;
165 switch (deviceType) {
166 case qsamplerDevice::Audio:
167 pParamInfo = ::lscp_get_audio_driver_param_info(pClient,
168 m_sDriverName.latin1(), sParam.latin1(), NULL);
169 break;
170 case qsamplerDevice::Midi:
171 pParamInfo = ::lscp_get_midi_driver_param_info(pClient,
172 m_sDriverName.latin1(), sParam.latin1(), NULL);
173 break;
174 case qsamplerDevice::None:
175 break;
176 }
177 if (pParamInfo) {
178 m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo,
179 pDeviceInfo->params[i].value);
180 }
181 }
182
183 // Refresh parameter dependencies...
184 refreshParams(pClient);
185 // Set port/channel list...
186 refreshPorts(pClient);
187 }
188
189
190 // Driver name initializer/settler.
191 void qsamplerDevice::setDriver ( lscp_client_t *pClient,
192 const QString& sDriverName )
193 {
194 // Valid only for scratch devices.
195 if (m_sDriverName == sDriverName)
196 return;
197
198 // Reset device parameters and ports anyway.
199 m_params.clear();
200 m_ports.clear();
201
202 // Retrieve driver info, if any.
203 lscp_driver_info_t *pDriverInfo = NULL;
204 switch (m_deviceType) {
205 case qsamplerDevice::Audio:
206 pDriverInfo = ::lscp_get_audio_driver_info(pClient,
207 sDriverName.latin1());
208 break;
209 case qsamplerDevice::Midi:
210 pDriverInfo = ::lscp_get_midi_driver_info(pClient,
211 sDriverName.latin1());
212 break;
213 case qsamplerDevice::None:
214 break;
215 }
216
217 // If we're bogus, bail out...
218 if (pDriverInfo == NULL)
219 return;
220
221 // Remember device parameters...
222 m_sDriverName = sDriverName;
223
224 // Grab driver parameters...
225 for (int i = 0; pDriverInfo->parameters && pDriverInfo->parameters[i]; i++) {
226 const QString sParam = pDriverInfo->parameters[i];
227 lscp_param_info_t *pParamInfo = NULL;
228 switch (m_deviceType) {
229 case qsamplerDevice::Audio:
230 pParamInfo = ::lscp_get_audio_driver_param_info(pClient,
231 sDriverName.latin1(), sParam.latin1(), NULL);
232 break;
233 case qsamplerDevice::Midi:
234 pParamInfo = ::lscp_get_midi_driver_param_info(pClient,
235 sDriverName.latin1(), sParam.latin1(), NULL);
236 break;
237 case qsamplerDevice::None:
238 break;
239 }
240 if (pParamInfo) {
241 m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo,
242 pParamInfo->defaultv);
243 }
244 }
245
246 // Refresh parameter dependencies...
247 refreshParams(pClient);
248 // Set port/channel list...
249 refreshPorts(pClient);
250 }
251
252
253 // Device property accessors.
254 int qsamplerDevice::deviceID (void) const
255 {
256 return m_iDeviceID;
257 }
258
259 qsamplerDevice::qsamplerDeviceType qsamplerDevice::deviceType (void) const
260 {
261 return m_deviceType;
262 }
263
264 const QString& qsamplerDevice::deviceTypeName (void) const
265 {
266 return m_sDeviceType;
267 }
268
269 const QString& qsamplerDevice::driverName (void) const
270 {
271 return m_sDriverName;
272 }
273
274 const QString& qsamplerDevice::deviceName (void) const
275 {
276 return m_sDeviceName;
277 }
278
279
280 // Set the proper device parameter value.
281 void qsamplerDevice::setParam ( const QString& sParam,
282 const QString& sValue )
283 {
284 m_params[sParam.upper()].value = sValue;
285 }
286
287
288 // Device parameter accessor.
289 const qsamplerDeviceParamMap& qsamplerDevice::params (void) const
290 {
291 return m_params;
292 }
293
294
295 // Device port/channel list accessor.
296 qsamplerDevicePortList& qsamplerDevice::ports (void)
297 {
298 return m_ports;
299 }
300
301
302 // Device parameter dependencies refreshner.
303 int qsamplerDevice::refreshParams ( lscp_client_t *pClient )
304 {
305 // This should only make sense for scratch devices...
306 if (m_iDeviceID >= 0)
307 return 0;
308 // Refresh all parameters that have dependencies...
309 int iParams = 0;
310 qsamplerDeviceParamMap::ConstIterator iter;
311 for (iter = m_params.begin(); iter != m_params.end(); ++iter)
312 iParams += refreshParam(pClient, iter.key());
313 // Return how many parameters have been refreshed...
314 return iParams;
315 }
316
317
318 // Device port/channel list refreshner.
319 int qsamplerDevice::refreshPorts ( lscp_client_t *pClient )
320 {
321 // This should only make sense for actual devices...
322 if (m_iDeviceID < 0)
323 return 0;
324 // Port/channel count determination...
325 int iPorts = 0;
326 switch (m_deviceType) {
327 case qsamplerDevice::Audio:
328 iPorts = m_params["CHANNELS"].value.toInt();
329 break;
330 case qsamplerDevice::Midi:
331 iPorts = m_params["PORTS"].value.toInt();
332 break;
333 case qsamplerDevice::None:
334 break;
335 }
336 // Retrieve port/channel information...
337 m_ports.clear();
338 for (int iPort = 0; iPort < iPorts; iPort++)
339 m_ports.append(new qsamplerDevicePort(pClient, *this, iPort));
340 // Return how many ports have been refreshed...
341 return iPorts;
342 }
343
344
345 // Refresh/set dependencies given that some parameter has changed.
346 int qsamplerDevice::refreshDepends ( lscp_client_t *pClient,
347 const QString& sParam )
348 {
349 // This should only make sense for scratch devices...
350 if (m_iDeviceID >= 0)
351 return 0;
352 // Refresh all parameters that depend on this one...
353 int iDepends = 0;
354 qsamplerDeviceParamMap::ConstIterator iter;
355 for (iter = m_params.begin(); iter != m_params.end(); ++iter) {
356 const QStringList& depends = iter.data().depends;
357 if (depends.find(sParam) != depends.end())
358 iDepends += refreshParam(pClient, iter.key());
359 }
360 // Return how many dependencies have been refreshed...
361 return iDepends;
362 }
363
364
365 // Refresh/set given parameter based on driver supplied dependencies.
366 int qsamplerDevice::refreshParam ( lscp_client_t *pClient,
367 const QString& sParam )
368 {
369 // Check if we have dependencies...
370 qsamplerDeviceParam& param = m_params[sParam.upper()];
371 if (param.depends.isEmpty())
372 return 0;
373
374 int iRefresh = 0;
375
376 // Build dependency list...
377 lscp_param_t *pDepends = new lscp_param_t [param.depends.count() + 1];
378 int iDepend = 0;
379 QStringList::ConstIterator iter;
380 for (iter = param.depends.begin(); iter != param.depends.end(); ++iter) {
381 const QString& sDepend = *iter;
382 pDepends[iDepend].key = (char *) sDepend.latin1();
383 pDepends[iDepend].value = (char *) m_params[sDepend.upper()].value.latin1();
384 ++iDepend;
385 }
386 // Null terminated.
387 pDepends[iDepend].key = NULL;
388 pDepends[iDepend].value = NULL;
389
390 // FIXME: Some parameter dependencies (e.g.ALSA CARD)
391 // are blocking for no reason, causing potential timeout-crashes.
392 // hopefully this gets mitigated if this dependency hell is only
393 // carried out for scratch devices...
394
395 // Retrieve some modern parameters...
396 lscp_param_info_t *pParamInfo = NULL;
397 switch (m_deviceType) {
398 case qsamplerDevice::Audio:
399 pParamInfo = ::lscp_get_audio_driver_param_info(pClient,
400 m_sDriverName.latin1(), sParam.latin1(), pDepends);
401 break;
402 case qsamplerDevice::Midi:
403 pParamInfo = ::lscp_get_midi_driver_param_info(pClient,
404 m_sDriverName.latin1(), sParam.latin1(), pDepends);
405 break;
406 case qsamplerDevice::None:
407 break;
408 }
409 if (pParamInfo) {
410 param = qsamplerDeviceParam(pParamInfo, QString(param.value));
411 iRefresh++;
412 }
413
414 // Free used parameter array.
415 delete pDepends;
416
417 // Return whether the parameters has been changed...
418 return iRefresh;
419 }
420
421
422 // Device ids enumerator.
423 int *qsamplerDevice::getDevices ( lscp_client_t *pClient,
424 qsamplerDeviceType deviceType )
425 {
426 int *piDeviceIDs = NULL;
427 switch (deviceType) {
428 case qsamplerDevice::Audio:
429 piDeviceIDs = ::lscp_list_audio_devices(pClient);
430 break;
431 case qsamplerDevice::Midi:
432 piDeviceIDs = ::lscp_list_midi_devices(pClient);
433 break;
434 case qsamplerDevice::None:
435 break;
436 }
437 return piDeviceIDs;
438 }
439
440
441 // Driver names enumerator.
442 QStringList qsamplerDevice::getDrivers ( lscp_client_t *pClient,
443 qsamplerDeviceType deviceType )
444 {
445 QStringList drivers;
446
447 const char **ppszDrivers = NULL;
448 switch (deviceType) {
449 case qsamplerDevice::Audio:
450 ppszDrivers = ::lscp_get_available_audio_drivers(pClient);
451 break;
452 case qsamplerDevice::Midi:
453 ppszDrivers = ::lscp_get_available_midi_drivers(pClient);
454 break;
455 case qsamplerDevice::None:
456 break;
457 }
458
459 for (int iDriver = 0; ppszDrivers[iDriver]; iDriver++)
460 drivers.append(ppszDrivers[iDriver]);
461
462 return drivers;
463 }
464
465
466 //-------------------------------------------------------------------------
467 // qsamplerDevicePort - MIDI/Audio Device port/channel structure.
468 //
469
470 // Constructor.
471 qsamplerDevicePort::qsamplerDevicePort ( lscp_client_t *pClient,
472 const qsamplerDevice& device, int iPortID )
473 {
474 setDevicePort(pClient, device, iPortID);
475 }
476
477 // Default destructor.
478 qsamplerDevicePort::~qsamplerDevicePort (void)
479 {
480 }
481
482
483 // Initializer.
484 void qsamplerDevicePort::setDevicePort ( lscp_client_t *pClient,
485 const qsamplerDevice& device, int iPortID )
486 {
487 // Device port id should be always set.
488 m_iPortID = iPortID;
489
490 // Reset port parameters anyway.
491 m_params.clear();
492
493 // Retrieve device port/channel info, if any.
494 lscp_device_port_info_t *pPortInfo = NULL;
495 switch (device.deviceType()) {
496 case qsamplerDevice::Audio:
497 pPortInfo = ::lscp_get_audio_channel_info(pClient, device.deviceID(), iPortID);
498 break;
499 case qsamplerDevice::Midi:
500 pPortInfo = ::lscp_get_midi_port_info(pClient, device.deviceID(), iPortID);
501 break;
502 case qsamplerDevice::None:
503 break;
504 }
505
506 // If we're bogus, bail out...
507 if (pPortInfo == NULL) {
508 m_sPortName = QString::null;
509 return;
510 }
511
512 // Set device port/channel properties...
513 m_sPortName += device.driverName() + ' ' + pPortInfo->name;
514
515 // Grab device port/channel parameters...
516 m_params.clear();
517 for (int i = 0; pPortInfo->params && pPortInfo->params[i].key; i++) {
518 const QString sParam = pPortInfo->params[i].key;
519 lscp_param_info_t *pParamInfo = NULL;
520 switch (device.deviceType()) {
521 case qsamplerDevice::Audio:
522 pParamInfo = ::lscp_get_audio_channel_param_info(pClient,
523 device.deviceID(), iPortID, sParam.latin1());
524 break;
525 case qsamplerDevice::Midi:
526 pParamInfo = ::lscp_get_midi_port_param_info(pClient,
527 device.deviceID(), iPortID, sParam.latin1());
528 break;
529 case qsamplerDevice::None:
530 break;
531 }
532 if (pParamInfo) {
533 m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo,
534 pPortInfo->params[i].value);
535 }
536 }
537 }
538
539
540 // Device port/channel property accessors.
541 int qsamplerDevicePort::portID (void) const
542 {
543 return m_iPortID;
544 }
545
546 const QString& qsamplerDevicePort::portName (void) const
547 {
548 return m_sPortName;
549 }
550
551 // Device port/channel parameter accessor.
552 const qsamplerDeviceParamMap& qsamplerDevicePort::params (void) const
553 {
554 return m_params;
555 }
556
557
558 // Set the proper device port/channel parameter value.
559 void qsamplerDevicePort::setParam ( const QString& sParam,
560 const QString& sValue )
561 {
562 m_params[sParam.upper()].value = sValue;
563 }
564
565
566 //-------------------------------------------------------------------------
567 // qsamplerDeviceItem - QListView device item.
568 //
569
570 // Constructors.
571 qsamplerDeviceItem::qsamplerDeviceItem ( QListView *pListView,
572 lscp_client_t *pClient, qsamplerDevice::qsamplerDeviceType deviceType )
573 : QListViewItem(pListView), m_device(pClient, deviceType)
574 {
575 switch(m_device.deviceType()) {
576 case qsamplerDevice::Audio:
577 QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio1.png"));
578 QListViewItem::setText(0, QObject::tr("Audio Devices"));
579 break;
580 case qsamplerDevice::Midi:
581 QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi1.png"));
582 QListViewItem::setText(0, QObject::tr("MIDI Devices"));
583 break;
584 case qsamplerDevice::None:
585 break;
586 }
587 }
588
589 qsamplerDeviceItem::qsamplerDeviceItem ( QListViewItem *pItem,
590 lscp_client_t *pClient, qsamplerDevice::qsamplerDeviceType deviceType,
591 int iDeviceID )
592 : QListViewItem(pItem), m_device(pClient, deviceType, iDeviceID)
593 {
594 switch(m_device.deviceType()) {
595 case qsamplerDevice::Audio:
596 QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio2.png"));
597 break;
598 case qsamplerDevice::Midi:
599 QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi2.png"));
600 break;
601 case qsamplerDevice::None:
602 break;
603 }
604
605 QListViewItem::setText(0, m_device.deviceName());
606 }
607
608 // Default destructor.
609 qsamplerDeviceItem::~qsamplerDeviceItem (void)
610 {
611 }
612
613 // Instance accessors.
614 qsamplerDevice& qsamplerDeviceItem::device (void)
615 {
616 return m_device;
617 }
618
619 // To virtually distinguish between list view items.
620 int qsamplerDeviceItem::rtti() const
621 {
622 return QSAMPLER_DEVICE_ITEM;
623 }
624
625
626
627 //-------------------------------------------------------------------------
628 // qsamplerDeviceParamTable - Device parameter view table.
629 //
630
631 // Constructor.
632 qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent,
633 const char *pszName )
634 : QTable(pParent, pszName)
635 {
636 // Set fixed number of columns.
637 QTable::setNumCols(3);
638 QTable::setShowGrid(false);
639 QTable::setSorting(false);
640 QTable::setFocusStyle(QTable::FollowStyle);
641 QTable::setSelectionMode(QTable::NoSelection);
642 // No vertical header.
643 QTable::verticalHeader()->hide();
644 QTable::setLeftMargin(0);
645 // Initialize the fixed table column headings.
646 QHeader *pHeader = QTable::horizontalHeader();
647 pHeader->setLabel(0, tr("Parameter"));
648 pHeader->setLabel(1, tr("Description"));
649 pHeader->setLabel(2, tr("Value"));
650 // Set read-onlyness of each column
651 QTable::setColumnReadOnly(0, true);
652 QTable::setColumnReadOnly(1, true);
653 // QTable::setColumnReadOnly(2, false); -- of course not.
654 QTable::setColumnStretchable(1, true);
655 }
656
657 // Default destructor.
658 qsamplerDeviceParamTable::~qsamplerDeviceParamTable (void)
659 {
660 }
661
662
663 // Common parameter table renderer.
664 void qsamplerDeviceParamTable::refresh ( const qsamplerDeviceParamMap& params,
665 bool bEditable )
666 {
667 // Always (re)start it empty.
668 QTable::setUpdatesEnabled(false);
669 QTable::setNumRows(0);
670
671 // Fill the parameter table...
672 QTable::insertRows(0, params.count());
673 int iRow = 0;
674 qsamplerDeviceParamMap::ConstIterator iter;
675 for (iter = params.begin(); iter != params.end(); ++iter) {
676 const qsamplerDeviceParam& param = iter.data();
677 bool bEnabled = (bEditable || !param.fix);
678 QTable::setText(iRow, 0, iter.key());
679 QTable::setText(iRow, 1, param.description);
680 if (param.type == LSCP_TYPE_BOOL) {
681 QStringList opts;
682 opts.append(tr("false"));
683 opts.append(tr("true"));
684 QComboTableItem *pComboItem = new QComboTableItem(this, opts);
685 pComboItem->setCurrentItem(param.value.lower() == "true" ? 1 : 0);
686 pComboItem->setEnabled(bEnabled);
687 QTable::setItem(iRow, 2, pComboItem);
688 } else if (param.possibilities.count() > 0 && bEnabled) {
689 QComboTableItem *pComboItem = new QComboTableItem(this,
690 param.possibilities);
691 pComboItem->setCurrentItem(param.value);
692 pComboItem->setEnabled(bEnabled);
693 // pComboItem->setEditable(bEnabled && param.multiplicity);
694 QTable::setItem(iRow, 2, pComboItem);
695 } else if (param.type == LSCP_TYPE_INT && bEnabled
696 && !param.range_min.isEmpty()
697 && !param.range_max.isEmpty()) {
698 qsamplerDeviceParamTableSpinBox *pSpinItem =
699 new qsamplerDeviceParamTableSpinBox(this,
700 bEnabled ? QTableItem::OnTyping : QTableItem::Never,
701 param.value);
702 pSpinItem->setMinValue(param.range_min.toInt());
703 pSpinItem->setMaxValue(param.range_max.toInt());
704 QTable::setItem(iRow, 2, pSpinItem);
705 } else {
706 qsamplerDeviceParamTableEditBox *pEditItem =
707 new qsamplerDeviceParamTableEditBox(this,
708 bEnabled ? QTableItem::OnTyping : QTableItem::Never,
709 param.value);
710 QTable::setItem(iRow, 2, pEditItem);
711 }
712 ++iRow;
713 }
714
715 // Adjust optimal column widths.
716 QTable::adjustColumn(0);
717 QTable::adjustColumn(2);
718
719 QTable::setUpdatesEnabled(true);
720 QTable::updateContents();
721 }
722
723
724 //-------------------------------------------------------------------------
725 // qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table.
726 //
727
728 // Constructor.
729 qsamplerDeviceParamTableSpinBox::qsamplerDeviceParamTableSpinBox (
730 QTable *pTable, EditType editType, const QString& sText )
731 : QTableItem(pTable, editType, sText)
732 {
733 m_iValue = sText.toInt();
734 m_iMinValue = m_iMaxValue = 0;
735 }
736
737 // Public accessors.
738 void qsamplerDeviceParamTableSpinBox::setValue ( int iValue )
739 {
740 m_iValue = iValue;
741 QTableItem::setText(QString::number(m_iValue));
742 }
743
744 void qsamplerDeviceParamTableSpinBox::setMinValue ( int iMinValue )
745 {
746 m_iMinValue = iMinValue;
747 }
748
749 void qsamplerDeviceParamTableSpinBox::setMaxValue ( int iMaxValue )
750 {
751 m_iMaxValue = iMaxValue;
752 }
753
754 // Virtual implemetations.
755 QWidget *qsamplerDeviceParamTableSpinBox::createEditor (void) const
756 {
757 QSpinBox *pSpinBox = new QSpinBox(QTableItem::table()->viewport());
758 QObject::connect(pSpinBox, SIGNAL(valueChanged(int)),
759 QTableItem::table(), SLOT(doValueChanged()));
760 if (m_iValue >= m_iMinValue && m_iMaxValue >= m_iValue) {
761 pSpinBox->setMinValue(m_iMinValue);
762 pSpinBox->setMaxValue(m_iMaxValue);
763 }
764 pSpinBox->setValue(m_iValue);
765 return pSpinBox;
766 }
767
768 void qsamplerDeviceParamTableSpinBox::setContentFromEditor ( QWidget *pWidget )
769 {
770 if (pWidget->inherits("QSpinBox"))
771 QTableItem::setText(QString::number(((QSpinBox *) pWidget)->value()));
772 else
773 QTableItem::setContentFromEditor(pWidget);
774 }
775
776
777 //-------------------------------------------------------------------------
778 // qsamplerDeviceParamTableEditBox - Custom edit box for parameter table.
779 //
780
781 // Constructor.
782 qsamplerDeviceParamTableEditBox::qsamplerDeviceParamTableEditBox (
783 QTable *pTable, EditType editType, const QString& sText )
784 : QTableItem(pTable, editType, sText)
785 {
786 }
787
788 // Virtual implemetations.
789 QWidget *qsamplerDeviceParamTableEditBox::createEditor (void) const
790 {
791 QLineEdit *pEditBox = new QLineEdit(QTableItem::table()->viewport());
792 QObject::connect(pEditBox, SIGNAL(returnPressed()),
793 QTableItem::table(), SLOT(doValueChanged()));
794 pEditBox->setText(QTableItem::text());
795 return pEditBox;
796 }
797
798 void qsamplerDeviceParamTableEditBox::setContentFromEditor ( QWidget *pWidget )
799 {
800 if (pWidget->inherits("QLineEdit"))
801 QTableItem::setText(((QLineEdit *) pWidget)->text());
802 else
803 QTableItem::setContentFromEditor(pWidget);
804 }
805
806
807 // end of qsamplerDevice.cpp

  ViewVC Help
Powered by ViewVC