1 |
// qsamplerDevice.cpp |
// qsamplerDevice.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2005, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
|
Copyright (C) 2007, Christian Schoenebeck |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
GNU General Public License for more details. |
GNU General Public License for more details. |
16 |
|
|
17 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License along |
18 |
along with this program; if not, write to the Free Software |
with this program; if not, write to the Free Software Foundation, Inc., |
19 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
|
|
21 |
*****************************************************************************/ |
*****************************************************************************/ |
22 |
|
|
23 |
|
#include "qsamplerAbout.h" |
24 |
#include "qsamplerDevice.h" |
#include "qsamplerDevice.h" |
25 |
|
|
|
#include <qspinbox.h> |
|
|
#include <qlineedit.h> |
|
|
|
|
26 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
27 |
#include "qsamplerDeviceForm.h" |
#include "qsamplerDeviceForm.h" |
28 |
|
|
29 |
#include "config.h" |
#include <qspinbox.h> |
30 |
|
#include <qlineedit.h> |
31 |
|
|
32 |
|
using namespace QSampler; |
33 |
|
|
34 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
35 |
// qsamplerDeviceParam - MIDI/Audio Device parameter structure. |
// qsamplerDeviceParam - MIDI/Audio Device parameter structure. |
105 |
// |
// |
106 |
|
|
107 |
// Constructor. |
// Constructor. |
108 |
qsamplerDevice::qsamplerDevice ( qsamplerMainForm *pMainForm, |
qsamplerDevice::qsamplerDevice ( qsamplerDeviceType deviceType, int iDeviceID ) |
|
qsamplerDeviceType deviceType, int iDeviceID ) |
|
109 |
{ |
{ |
|
m_pMainForm = pMainForm; |
|
|
|
|
110 |
m_ports.setAutoDelete(true); |
m_ports.setAutoDelete(true); |
111 |
|
|
112 |
setDevice(deviceType, iDeviceID); |
setDevice(deviceType, iDeviceID); |
121 |
qsamplerDevice::qsamplerDevice ( const qsamplerDevice& device ) |
qsamplerDevice::qsamplerDevice ( const qsamplerDevice& device ) |
122 |
: m_params(device.m_params), m_ports(m_ports) |
: m_params(device.m_params), m_ports(m_ports) |
123 |
{ |
{ |
|
m_pMainForm = device.m_pMainForm; |
|
124 |
m_iDeviceID = device.m_iDeviceID; |
m_iDeviceID = device.m_iDeviceID; |
125 |
m_deviceType = device.m_deviceType; |
m_deviceType = device.m_deviceType; |
126 |
m_sDeviceType = device.m_sDeviceType; |
m_sDeviceType = device.m_sDeviceType; |
132 |
// Initializer. |
// Initializer. |
133 |
void qsamplerDevice::setDevice ( qsamplerDeviceType deviceType, int iDeviceID ) |
void qsamplerDevice::setDevice ( qsamplerDeviceType deviceType, int iDeviceID ) |
134 |
{ |
{ |
135 |
|
MainForm *pMainForm = MainForm::getInstance(); |
136 |
|
if (pMainForm == NULL) |
137 |
|
return; |
138 |
|
if (pMainForm->client() == NULL) |
139 |
|
return; |
140 |
|
|
141 |
// Device id and type should be always set. |
// Device id and type should be always set. |
142 |
m_iDeviceID = iDeviceID; |
m_iDeviceID = iDeviceID; |
143 |
m_deviceType = deviceType; |
m_deviceType = deviceType; |
152 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
153 |
m_sDeviceType = QObject::tr("Audio"); |
m_sDeviceType = QObject::tr("Audio"); |
154 |
if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_audio_device_info( |
if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_audio_device_info( |
155 |
client(), m_iDeviceID)) == NULL) |
pMainForm->client(), m_iDeviceID)) == NULL) |
156 |
appendMessagesClient("lscp_get_audio_device_info"); |
appendMessagesClient("lscp_get_audio_device_info"); |
157 |
break; |
break; |
158 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
159 |
m_sDeviceType = QObject::tr("MIDI"); |
m_sDeviceType = QObject::tr("MIDI"); |
160 |
if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_midi_device_info( |
if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_midi_device_info( |
161 |
client(), m_iDeviceID)) == NULL) |
pMainForm->client(), m_iDeviceID)) == NULL) |
162 |
appendMessagesClient("lscp_get_midi_device_info"); |
appendMessagesClient("lscp_get_midi_device_info"); |
163 |
break; |
break; |
164 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
183 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
184 |
switch (deviceType) { |
switch (deviceType) { |
185 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
186 |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(client(), |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(pMainForm->client(), |
187 |
m_sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
m_sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
188 |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
189 |
break; |
break; |
190 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
191 |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(client(), |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(pMainForm->client(), |
192 |
m_sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
m_sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
193 |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
194 |
break; |
break; |
211 |
// Driver name initializer/settler. |
// Driver name initializer/settler. |
212 |
void qsamplerDevice::setDriver ( const QString& sDriverName ) |
void qsamplerDevice::setDriver ( const QString& sDriverName ) |
213 |
{ |
{ |
214 |
|
MainForm *pMainForm = MainForm::getInstance(); |
215 |
|
if (pMainForm == NULL) |
216 |
|
return; |
217 |
|
if (pMainForm->client() == NULL) |
218 |
|
return; |
219 |
|
|
220 |
// Valid only for scratch devices. |
// Valid only for scratch devices. |
221 |
if (m_sDriverName == sDriverName) |
if (m_sDriverName == sDriverName) |
222 |
return; |
return; |
229 |
lscp_driver_info_t *pDriverInfo = NULL; |
lscp_driver_info_t *pDriverInfo = NULL; |
230 |
switch (m_deviceType) { |
switch (m_deviceType) { |
231 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
232 |
if ((pDriverInfo = ::lscp_get_audio_driver_info(client(), |
if ((pDriverInfo = ::lscp_get_audio_driver_info(pMainForm->client(), |
233 |
sDriverName.latin1())) == NULL) |
sDriverName.latin1())) == NULL) |
234 |
appendMessagesClient("lscp_get_audio_driver_info"); |
appendMessagesClient("lscp_get_audio_driver_info"); |
235 |
break; |
break; |
236 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
237 |
if ((pDriverInfo = ::lscp_get_midi_driver_info(client(), |
if ((pDriverInfo = ::lscp_get_midi_driver_info(pMainForm->client(), |
238 |
sDriverName.latin1())) == NULL) |
sDriverName.latin1())) == NULL) |
239 |
appendMessagesClient("lscp_get_midi_driver_info"); |
appendMessagesClient("lscp_get_midi_driver_info"); |
240 |
break; |
break; |
255 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
256 |
switch (m_deviceType) { |
switch (m_deviceType) { |
257 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
258 |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(client(), |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(pMainForm->client(), |
259 |
sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
260 |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
261 |
break; |
break; |
262 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
263 |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(client(), |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(pMainForm->client(), |
264 |
sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
265 |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
266 |
break; |
break; |
280 |
} |
} |
281 |
|
|
282 |
|
|
|
// The client descriptor delegated property. |
|
|
lscp_client_t *qsamplerDevice::client (void) const |
|
|
{ |
|
|
if (m_pMainForm == NULL) |
|
|
return NULL; |
|
|
|
|
|
return m_pMainForm->client(); |
|
|
} |
|
|
|
|
|
|
|
283 |
// Device property accessors. |
// Device property accessors. |
284 |
int qsamplerDevice::deviceID (void) const |
int qsamplerDevice::deviceID (void) const |
285 |
{ |
{ |
315 |
bool qsamplerDevice::setParam ( const QString& sParam, |
bool qsamplerDevice::setParam ( const QString& sParam, |
316 |
const QString& sValue ) |
const QString& sValue ) |
317 |
{ |
{ |
318 |
|
MainForm *pMainForm = MainForm::getInstance(); |
319 |
|
if (pMainForm == NULL) |
320 |
|
return false; |
321 |
|
if (pMainForm->client() == NULL) |
322 |
|
return false; |
323 |
|
|
324 |
// Set proper device parameter. |
// Set proper device parameter. |
325 |
m_params[sParam.upper()].value = sValue; |
m_params[sParam.upper()].value = sValue; |
326 |
|
|
327 |
// If the device already exists, things get immediate... |
// If the device already exists, things get immediate... |
328 |
int iRefresh = 0; |
int iRefresh = 0; |
329 |
if (m_iDeviceID >= 0) { |
if (m_iDeviceID >= 0 && sValue != QString::null) { |
330 |
// Prepare parameter struct. |
// Prepare parameter struct. |
331 |
lscp_param_t param; |
lscp_param_t param; |
332 |
param.key = (char *) sParam.latin1(); |
param.key = (char *) sParam.latin1(); |
336 |
switch (m_deviceType) { |
switch (m_deviceType) { |
337 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
338 |
if (sParam == "CHANNELS") iRefresh++; |
if (sParam == "CHANNELS") iRefresh++; |
339 |
if ((ret = ::lscp_set_audio_device_param(client(), |
if ((ret = ::lscp_set_audio_device_param(pMainForm->client(), |
340 |
m_iDeviceID, ¶m)) != LSCP_OK) |
m_iDeviceID, ¶m)) != LSCP_OK) |
341 |
appendMessagesClient("lscp_set_audio_device_param"); |
appendMessagesClient("lscp_set_audio_device_param"); |
342 |
break; |
break; |
343 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
344 |
if (sParam == "PORTS") iRefresh++; |
if (sParam == "PORTS") iRefresh++; |
345 |
if ((ret = ::lscp_set_midi_device_param(client(), |
if ((ret = ::lscp_set_midi_device_param(pMainForm->client(), |
346 |
m_iDeviceID, ¶m)) != LSCP_OK) |
m_iDeviceID, ¶m)) != LSCP_OK) |
347 |
appendMessagesClient("lscp_set_midi_device_param"); |
appendMessagesClient("lscp_set_midi_device_param"); |
348 |
break; |
break; |
385 |
// Create a new device, as a copy of this current one. |
// Create a new device, as a copy of this current one. |
386 |
bool qsamplerDevice::createDevice (void) |
bool qsamplerDevice::createDevice (void) |
387 |
{ |
{ |
388 |
if (client() == NULL) |
MainForm *pMainForm = MainForm::getInstance(); |
389 |
|
if (pMainForm == NULL) |
390 |
|
return false; |
391 |
|
if (pMainForm->client() == NULL) |
392 |
return false; |
return false; |
393 |
|
|
394 |
// Build the parameter list... |
// Build the parameter list... |
396 |
int iParam = 0; |
int iParam = 0; |
397 |
qsamplerDeviceParamMap::ConstIterator iter; |
qsamplerDeviceParamMap::ConstIterator iter; |
398 |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
399 |
|
if (iter.data().value == QString::null) continue; |
400 |
pParams[iParam].key = (char *) iter.key().latin1(); |
pParams[iParam].key = (char *) iter.key().latin1(); |
401 |
pParams[iParam].value = (char *) iter.data().value.latin1(); |
pParams[iParam].value = (char *) iter.data().value.latin1(); |
402 |
++iParam; |
++iParam; |
408 |
// Now it depends on the device type... |
// Now it depends on the device type... |
409 |
switch (m_deviceType) { |
switch (m_deviceType) { |
410 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
411 |
if ((m_iDeviceID = ::lscp_create_audio_device(client(), |
if ((m_iDeviceID = ::lscp_create_audio_device(pMainForm->client(), |
412 |
m_sDriverName.latin1(), pParams)) < 0) |
m_sDriverName.latin1(), pParams)) < 0) |
413 |
appendMessagesClient("lscp_create_audio_device"); |
appendMessagesClient("lscp_create_audio_device"); |
414 |
break; |
break; |
415 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
416 |
if ((m_iDeviceID = ::lscp_create_midi_device(client(), |
if ((m_iDeviceID = ::lscp_create_midi_device(pMainForm->client(), |
417 |
m_sDriverName.latin1(), pParams)) < 0) |
m_sDriverName.latin1(), pParams)) < 0) |
418 |
appendMessagesClient("lscp_create_midi_device"); |
appendMessagesClient("lscp_create_midi_device"); |
419 |
break; |
break; |
441 |
// Destroy existing device. |
// Destroy existing device. |
442 |
bool qsamplerDevice::deleteDevice (void) |
bool qsamplerDevice::deleteDevice (void) |
443 |
{ |
{ |
444 |
|
MainForm *pMainForm = MainForm::getInstance(); |
445 |
|
if (pMainForm == NULL) |
446 |
|
return false; |
447 |
|
if (pMainForm->client() == NULL) |
448 |
|
return false; |
449 |
|
|
450 |
// Now it depends on the device type... |
// Now it depends on the device type... |
451 |
lscp_status_t ret = LSCP_FAILED; |
lscp_status_t ret = LSCP_FAILED; |
452 |
switch (m_deviceType) { |
switch (m_deviceType) { |
453 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
454 |
if ((ret = ::lscp_destroy_audio_device(client(), |
if ((ret = ::lscp_destroy_audio_device(pMainForm->client(), |
455 |
m_iDeviceID)) != LSCP_OK) |
m_iDeviceID)) != LSCP_OK) |
456 |
appendMessagesClient("lscp_destroy_audio_device"); |
appendMessagesClient("lscp_destroy_audio_device"); |
457 |
break; |
break; |
458 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
459 |
if ((ret = ::lscp_destroy_midi_device(client(), |
if ((ret = ::lscp_destroy_midi_device(pMainForm->client(), |
460 |
m_iDeviceID)) != LSCP_OK) |
m_iDeviceID)) != LSCP_OK) |
461 |
appendMessagesClient("lscp_destroy_midi_device"); |
appendMessagesClient("lscp_destroy_midi_device"); |
462 |
break; |
break; |
542 |
// Refresh/set given parameter based on driver supplied dependencies. |
// Refresh/set given parameter based on driver supplied dependencies. |
543 |
int qsamplerDevice::refreshParam ( const QString& sParam ) |
int qsamplerDevice::refreshParam ( const QString& sParam ) |
544 |
{ |
{ |
545 |
|
MainForm *pMainForm = MainForm::getInstance(); |
546 |
|
if (pMainForm == NULL) |
547 |
|
return 0; |
548 |
|
if (pMainForm->client() == NULL) |
549 |
|
return 0; |
550 |
|
|
551 |
// Check if we have dependencies... |
// Check if we have dependencies... |
552 |
qsamplerDeviceParam& param = m_params[sParam.upper()]; |
qsamplerDeviceParam& param = m_params[sParam.upper()]; |
553 |
if (param.depends.isEmpty()) |
if (param.depends.isEmpty()) |
578 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
579 |
switch (m_deviceType) { |
switch (m_deviceType) { |
580 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
581 |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(client(), |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(pMainForm->client(), |
582 |
m_sDriverName.latin1(), sParam.latin1(), pDepends)) == NULL) |
m_sDriverName.latin1(), sParam.latin1(), pDepends)) == NULL) |
583 |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
584 |
break; |
break; |
585 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
586 |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(client(), |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(pMainForm->client(), |
587 |
m_sDriverName.latin1(), sParam.latin1(), pDepends)) == NULL) |
m_sDriverName.latin1(), sParam.latin1(), pDepends)) == NULL) |
588 |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
589 |
break; |
break; |
591 |
break; |
break; |
592 |
} |
} |
593 |
if (pParamInfo) { |
if (pParamInfo) { |
594 |
param = qsamplerDeviceParam(pParamInfo, QString(param.value)); |
if (param.value != QString::null) |
595 |
|
param = qsamplerDeviceParam(pParamInfo, param.value); |
596 |
|
else |
597 |
|
param = qsamplerDeviceParam(pParamInfo, NULL); |
598 |
iRefresh++; |
iRefresh++; |
599 |
} |
} |
600 |
|
|
609 |
// Redirected messages output methods. |
// Redirected messages output methods. |
610 |
void qsamplerDevice::appendMessages( const QString& s ) const |
void qsamplerDevice::appendMessages( const QString& s ) const |
611 |
{ |
{ |
612 |
if (m_pMainForm) |
MainForm *pMainForm = MainForm::getInstance(); |
613 |
m_pMainForm->appendMessages(deviceName() + ' ' + s); |
if (pMainForm) |
614 |
|
pMainForm->appendMessages(deviceName() + ' ' + s); |
615 |
} |
} |
616 |
|
|
617 |
void qsamplerDevice::appendMessagesColor( const QString& s, |
void qsamplerDevice::appendMessagesColor( const QString& s, |
618 |
const QString& c ) const |
const QString& c ) const |
619 |
{ |
{ |
620 |
if (m_pMainForm) |
MainForm *pMainForm = MainForm::getInstance(); |
621 |
m_pMainForm->appendMessagesColor(deviceName() + ' ' + s, c); |
if (pMainForm) |
622 |
|
pMainForm->appendMessagesColor(deviceName() + ' ' + s, c); |
623 |
} |
} |
624 |
|
|
625 |
void qsamplerDevice::appendMessagesText( const QString& s ) const |
void qsamplerDevice::appendMessagesText( const QString& s ) const |
626 |
{ |
{ |
627 |
if (m_pMainForm) |
MainForm *pMainForm = MainForm::getInstance(); |
628 |
m_pMainForm->appendMessagesText(deviceName() + ' ' + s); |
if (pMainForm) |
629 |
|
pMainForm->appendMessagesText(deviceName() + ' ' + s); |
630 |
} |
} |
631 |
|
|
632 |
void qsamplerDevice::appendMessagesError( const QString& s ) const |
void qsamplerDevice::appendMessagesError( const QString& s ) const |
633 |
{ |
{ |
634 |
if (m_pMainForm) |
MainForm *pMainForm = MainForm::getInstance(); |
635 |
m_pMainForm->appendMessagesError(deviceName() + "\n\n" + s); |
if (pMainForm) |
636 |
|
pMainForm->appendMessagesError(deviceName() + "\n\n" + s); |
637 |
} |
} |
638 |
|
|
639 |
void qsamplerDevice::appendMessagesClient( const QString& s ) const |
void qsamplerDevice::appendMessagesClient( const QString& s ) const |
640 |
{ |
{ |
641 |
if (m_pMainForm) |
MainForm *pMainForm = MainForm::getInstance(); |
642 |
m_pMainForm->appendMessagesClient(deviceName() + ' ' + s); |
if (pMainForm) |
643 |
|
pMainForm->appendMessagesClient(deviceName() + ' ' + s); |
644 |
} |
} |
645 |
|
|
646 |
|
|
681 |
break; |
break; |
682 |
} |
} |
683 |
|
|
684 |
for (int iDriver = 0; ppszDrivers[iDriver]; iDriver++) |
for (int iDriver = 0; ppszDrivers && ppszDrivers[iDriver]; iDriver++) |
685 |
drivers.append(ppszDrivers[iDriver]); |
drivers.append(ppszDrivers[iDriver]); |
686 |
|
|
687 |
return drivers; |
return drivers; |
708 |
// Initializer. |
// Initializer. |
709 |
void qsamplerDevicePort::setDevicePort ( int iPortID ) |
void qsamplerDevicePort::setDevicePort ( int iPortID ) |
710 |
{ |
{ |
711 |
|
MainForm *pMainForm = MainForm::getInstance(); |
712 |
|
if (pMainForm == NULL) |
713 |
|
return; |
714 |
|
if (pMainForm->client() == NULL) |
715 |
|
return; |
716 |
|
|
717 |
// Device port id should be always set. |
// Device port id should be always set. |
718 |
m_iPortID = iPortID; |
m_iPortID = iPortID; |
719 |
|
|
724 |
lscp_device_port_info_t *pPortInfo = NULL; |
lscp_device_port_info_t *pPortInfo = NULL; |
725 |
switch (m_device.deviceType()) { |
switch (m_device.deviceType()) { |
726 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
727 |
if ((pPortInfo = ::lscp_get_audio_channel_info(m_device.client(), |
if ((pPortInfo = ::lscp_get_audio_channel_info(pMainForm->client(), |
728 |
m_device.deviceID(), m_iPortID)) == NULL) |
m_device.deviceID(), m_iPortID)) == NULL) |
729 |
m_device.appendMessagesClient("lscp_get_audio_channel_info"); |
m_device.appendMessagesClient("lscp_get_audio_channel_info"); |
730 |
break; |
break; |
731 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
732 |
if ((pPortInfo = ::lscp_get_midi_port_info(m_device.client(), |
if ((pPortInfo = ::lscp_get_midi_port_info(pMainForm->client(), |
733 |
m_device.deviceID(), m_iPortID)) == NULL) |
m_device.deviceID(), m_iPortID)) == NULL) |
734 |
m_device.appendMessagesClient("lscp_get_midi_port_info"); |
m_device.appendMessagesClient("lscp_get_midi_port_info"); |
735 |
break; |
break; |
754 |
switch (m_device.deviceType()) { |
switch (m_device.deviceType()) { |
755 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
756 |
if ((pParamInfo = ::lscp_get_audio_channel_param_info( |
if ((pParamInfo = ::lscp_get_audio_channel_param_info( |
757 |
m_device.client(), m_device.deviceID(), |
pMainForm->client(), m_device.deviceID(), |
758 |
m_iPortID, sParam.latin1())) == NULL) |
m_iPortID, sParam.latin1())) == NULL) |
759 |
m_device.appendMessagesClient("lscp_get_audio_channel_param_info"); |
m_device.appendMessagesClient("lscp_get_audio_channel_param_info"); |
760 |
break; |
break; |
761 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
762 |
if ((pParamInfo = ::lscp_get_midi_port_param_info( |
if ((pParamInfo = ::lscp_get_midi_port_param_info( |
763 |
m_device.client(), m_device.deviceID(), |
pMainForm->client(), m_device.deviceID(), |
764 |
m_iPortID, sParam.latin1())) == NULL) |
m_iPortID, sParam.latin1())) == NULL) |
765 |
m_device.appendMessagesClient("lscp_get_midi_port_param_info"); |
m_device.appendMessagesClient("lscp_get_midi_port_param_info"); |
766 |
break; |
break; |
797 |
bool qsamplerDevicePort::setParam ( const QString& sParam, |
bool qsamplerDevicePort::setParam ( const QString& sParam, |
798 |
const QString& sValue ) |
const QString& sValue ) |
799 |
{ |
{ |
800 |
|
MainForm *pMainForm = MainForm::getInstance(); |
801 |
|
if (pMainForm == NULL) |
802 |
|
return false; |
803 |
|
if (pMainForm->client() == NULL) |
804 |
|
return false; |
805 |
|
|
806 |
// Set proper port/channel parameter. |
// Set proper port/channel parameter. |
807 |
m_params[sParam.upper()].value = sValue; |
m_params[sParam.upper()].value = sValue; |
808 |
|
|
817 |
lscp_status_t ret = LSCP_FAILED; |
lscp_status_t ret = LSCP_FAILED; |
818 |
switch (m_device.deviceType()) { |
switch (m_device.deviceType()) { |
819 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
820 |
if ((ret = ::lscp_set_audio_channel_param(m_device.client(), |
if ((ret = ::lscp_set_audio_channel_param(pMainForm->client(), |
821 |
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
822 |
m_device.appendMessagesClient("lscp_set_audio_channel_param"); |
m_device.appendMessagesClient("lscp_set_audio_channel_param"); |
823 |
break; |
break; |
824 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
825 |
if ((ret = ::lscp_set_midi_port_param(m_device.client(), |
if ((ret = ::lscp_set_midi_port_param(pMainForm->client(), |
826 |
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
827 |
m_device.appendMessagesClient("lscp_set_midi_port_param"); |
m_device.appendMessagesClient("lscp_set_midi_port_param"); |
828 |
break; |
break; |
847 |
|
|
848 |
|
|
849 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
850 |
// qsamplerDeviceItem - QListView device item. |
// qsamplerDeviceItem - QTreeWidget device item. |
851 |
// |
// |
852 |
|
|
853 |
// Constructors. |
// Constructors. |
854 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListView *pListView, |
qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidget* pTreeWidget, |
855 |
qsamplerMainForm *pMainForm, qsamplerDevice::qsamplerDeviceType deviceType ) |
qsamplerDevice::qsamplerDeviceType deviceType ) |
856 |
: QListViewItem(pListView), m_device(pMainForm, deviceType) |
: QTreeWidgetItem(pTreeWidget, QSAMPLER_DEVICE_ITEM), |
857 |
|
m_device(deviceType) |
858 |
{ |
{ |
859 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
860 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
861 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio1.png")); |
setIcon(0, QPixmap(":/icons/audio1.png")); |
862 |
QListViewItem::setText(0, QObject::tr("Audio Devices")); |
setText(0, QObject::tr("Audio Devices")); |
863 |
break; |
break; |
864 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
865 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi1.png")); |
setIcon(0, QPixmap(":/icons/midi1.png")); |
866 |
QListViewItem::setText(0, QObject::tr("MIDI Devices")); |
setText(0, QObject::tr("MIDI Devices")); |
867 |
break; |
break; |
868 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
869 |
break; |
break; |
870 |
} |
} |
871 |
} |
} |
872 |
|
|
873 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListViewItem *pItem, |
qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidgetItem* pItem, |
874 |
qsamplerMainForm *pMainForm, qsamplerDevice::qsamplerDeviceType deviceType, |
qsamplerDevice::qsamplerDeviceType deviceType, |
875 |
int iDeviceID ) |
int iDeviceID ) |
876 |
: QListViewItem(pItem), m_device(pMainForm, deviceType, iDeviceID) |
: QTreeWidgetItem(pItem, QSAMPLER_DEVICE_ITEM), |
877 |
|
m_device(deviceType, iDeviceID) |
878 |
{ |
{ |
879 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
880 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
881 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio2.png")); |
setIcon(0, QPixmap(":/icons/audio2.png")); |
882 |
break; |
break; |
883 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
884 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi2.png")); |
setIcon(0, QPixmap(":/icons/midi2.png")); |
885 |
break; |
break; |
886 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
887 |
break; |
break; |
888 |
} |
} |
889 |
|
|
890 |
QListViewItem::setText(0, m_device.deviceName()); |
setText(0, m_device.deviceName()); |
891 |
} |
} |
892 |
|
|
893 |
// Default destructor. |
// Default destructor. |
894 |
qsamplerDeviceItem::~qsamplerDeviceItem (void) |
qsamplerDeviceItem::~qsamplerDeviceItem () |
895 |
{ |
{ |
896 |
} |
} |
897 |
|
|
898 |
// Instance accessors. |
// Instance accessors. |
899 |
qsamplerDevice& qsamplerDeviceItem::device (void) |
qsamplerDevice& qsamplerDeviceItem::device () |
900 |
{ |
{ |
901 |
return m_device; |
return m_device; |
902 |
} |
} |
903 |
|
|
|
// To virtually distinguish between list view items. |
|
|
int qsamplerDeviceItem::rtti() const |
|
|
{ |
|
|
return QSAMPLER_DEVICE_ITEM; |
|
|
} |
|
|
|
|
|
|
|
904 |
|
|
905 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
906 |
// qsamplerDeviceParamTable - Device parameter view table. |
// AbstractDeviceParamModel - data model base class for device parameters |
907 |
// |
// |
908 |
|
|
909 |
// Constructor. |
AbstractDeviceParamModel::AbstractDeviceParamModel(QObject* parent) : QAbstractTableModel(parent), bEditable(false) { |
910 |
qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, |
params = NULL; |
|
const char *pszName ) |
|
|
: QTable(pParent, pszName) |
|
|
{ |
|
|
// Set fixed number of columns. |
|
|
QTable::setNumCols(3); |
|
|
QTable::setShowGrid(false); |
|
|
QTable::setSorting(false); |
|
|
QTable::setFocusStyle(QTable::FollowStyle); |
|
|
QTable::setSelectionMode(QTable::NoSelection); |
|
|
// No vertical header. |
|
|
QTable::verticalHeader()->hide(); |
|
|
QTable::setLeftMargin(0); |
|
|
// Initialize the fixed table column headings. |
|
|
QHeader *pHeader = QTable::horizontalHeader(); |
|
|
pHeader->setLabel(0, tr("Parameter")); |
|
|
pHeader->setLabel(1, tr("Description")); |
|
|
pHeader->setLabel(2, tr("Value")); |
|
|
// Set read-onlyness of each column |
|
|
QTable::setColumnReadOnly(0, true); |
|
|
QTable::setColumnReadOnly(1, true); |
|
|
// QTable::setColumnReadOnly(2, false); -- of course not. |
|
|
QTable::setColumnStretchable(1, true); |
|
911 |
} |
} |
912 |
|
|
913 |
// Default destructor. |
int AbstractDeviceParamModel::rowCount(const QModelIndex& /*parent*/) const { |
914 |
qsamplerDeviceParamTable::~qsamplerDeviceParamTable (void) |
//std::cout << "model size=" << params.size() << "\n" << std::flush; |
915 |
{ |
return (params) ? params->size() : 0; |
916 |
} |
} |
917 |
|
|
918 |
|
int AbstractDeviceParamModel::columnCount(const QModelIndex& /*parent*/) const { |
919 |
|
return 3; |
920 |
|
} |
921 |
|
|
922 |
// Common parameter table renderer. |
Qt::ItemFlags AbstractDeviceParamModel::flags(const QModelIndex& /*index*/) const { |
923 |
void qsamplerDeviceParamTable::refresh ( const qsamplerDeviceParamMap& params, |
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled; |
924 |
bool bEditable ) |
} |
|
{ |
|
|
// Always (re)start it empty. |
|
|
QTable::setUpdatesEnabled(false); |
|
|
QTable::setNumRows(0); |
|
925 |
|
|
926 |
// Fill the parameter table... |
QVariant AbstractDeviceParamModel::data(const QModelIndex &index, int role) const { |
927 |
QTable::insertRows(0, params.count()); |
if (!index.isValid()) { |
928 |
int iRow = 0; |
//std::cout << "inavlid device model index\n" << std::flush; |
929 |
qsamplerDeviceParamMap::ConstIterator iter; |
return QVariant(); |
930 |
for (iter = params.begin(); iter != params.end(); ++iter) { |
} |
931 |
const qsamplerDeviceParam& param = iter.data(); |
if (role != Qt::DisplayRole) { |
932 |
bool bEnabled = (bEditable || !param.fix); |
//std::cout << "inavlid display role\n" << std::flush; |
933 |
QTable::setText(iRow, 0, iter.key()); |
return QVariant(); |
934 |
QTable::setText(iRow, 1, param.description); |
} |
935 |
if (param.type == LSCP_TYPE_BOOL) { |
|
936 |
QStringList opts; |
DeviceParameterRow item; |
937 |
opts.append(tr("false")); |
item.name = params->keys()[index.row()]; |
938 |
opts.append(tr("true")); |
item.param = (*params)[item.name]; |
939 |
QComboTableItem *pComboItem = new QComboTableItem(this, opts); |
|
940 |
pComboItem->setCurrentItem(param.value.lower() == "true" ? 1 : 0); |
//std::cout << "item["<<index.row()<<"]=[" << item.name.toLatin1().data() << "]\n" << std::flush; |
|
pComboItem->setEnabled(bEnabled); |
|
|
QTable::setItem(iRow, 2, pComboItem); |
|
|
} else if (param.possibilities.count() > 0 && bEnabled) { |
|
|
QStringList opts = param.possibilities; |
|
|
if (param.multiplicity) |
|
|
opts.prepend(tr("(none)")); |
|
|
QComboTableItem *pComboItem = new QComboTableItem(this, opts); |
|
|
if (param.value.isEmpty()) |
|
|
pComboItem->setCurrentItem(0); |
|
|
else |
|
|
pComboItem->setCurrentItem(param.value); |
|
|
pComboItem->setEnabled(bEnabled); |
|
|
QTable::setItem(iRow, 2, pComboItem); |
|
|
} else if (param.type == LSCP_TYPE_INT && bEnabled |
|
|
&& !param.range_min.isEmpty() |
|
|
&& !param.range_max.isEmpty()) { |
|
|
qsamplerDeviceParamTableSpinBox *pSpinItem = |
|
|
new qsamplerDeviceParamTableSpinBox(this, |
|
|
bEnabled ? QTableItem::OnTyping : QTableItem::Never, |
|
|
param.value); |
|
|
pSpinItem->setMinValue(param.range_min.toInt()); |
|
|
pSpinItem->setMaxValue(param.range_max.toInt()); |
|
|
QTable::setItem(iRow, 2, pSpinItem); |
|
|
} else { |
|
|
qsamplerDeviceParamTableEditBox *pEditItem = |
|
|
new qsamplerDeviceParamTableEditBox(this, |
|
|
bEnabled ? QTableItem::OnTyping : QTableItem::Never, |
|
|
param.value); |
|
|
QTable::setItem(iRow, 2, pEditItem); |
|
|
} |
|
|
++iRow; |
|
|
} |
|
941 |
|
|
942 |
// Adjust optimal column widths. |
return QVariant::fromValue(item); |
943 |
QTable::adjustColumn(0); |
} |
944 |
QTable::adjustColumn(2); |
|
945 |
|
QVariant AbstractDeviceParamModel::headerData(int section, Qt::Orientation orientation, int role) const { |
946 |
|
if (role != Qt::DisplayRole) return QVariant(); |
947 |
|
|
948 |
|
if (orientation == Qt::Horizontal) { |
949 |
|
switch (section) { |
950 |
|
case 0: return tr("Parameter"); |
951 |
|
case 1: return tr("Value"); |
952 |
|
case 2: return tr("Description"); |
953 |
|
default: return QVariant(); |
954 |
|
} |
955 |
|
} |
956 |
|
|
957 |
|
return QVariant(); |
958 |
|
} |
959 |
|
|
960 |
QTable::setUpdatesEnabled(true); |
void AbstractDeviceParamModel::refresh(const qsamplerDeviceParamMap* params, bool bEditable) { |
961 |
QTable::updateContents(); |
this->params = params; |
962 |
|
this->bEditable = bEditable; |
963 |
|
// inform the outer world (QTableView) that our data changed |
964 |
|
QAbstractTableModel::reset(); |
965 |
|
} |
966 |
|
|
967 |
|
void AbstractDeviceParamModel::clear() { |
968 |
|
params = NULL; |
969 |
|
// inform the outer world (QTableView) that our data changed |
970 |
|
QAbstractTableModel::reset(); |
971 |
} |
} |
972 |
|
|
973 |
|
|
974 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
975 |
// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. |
// DeviceParamModel - data model for device parameters (used for QTableView) |
976 |
// |
// |
977 |
|
|
978 |
// Constructor. |
DeviceParamModel::DeviceParamModel(QObject* parent) : AbstractDeviceParamModel(parent) { |
979 |
qsamplerDeviceParamTableSpinBox::qsamplerDeviceParamTableSpinBox ( |
device = NULL; |
|
QTable *pTable, EditType editType, const QString& sText ) |
|
|
: QTableItem(pTable, editType, sText) |
|
|
{ |
|
|
m_iValue = sText.toInt(); |
|
|
m_iMinValue = m_iMaxValue = 0; |
|
980 |
} |
} |
981 |
|
|
982 |
// Public accessors. |
bool DeviceParamModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) { |
983 |
void qsamplerDeviceParamTableSpinBox::setValue ( int iValue ) |
if (!index.isValid()) { |
984 |
{ |
return false; |
985 |
m_iValue = iValue; |
} |
986 |
QTableItem::setText(QString::number(m_iValue)); |
QString key = params->keys()[index.row()]; |
987 |
|
//params[key].value = value.toString(); |
988 |
|
device->setParam(key, value.toString()); |
989 |
|
emit dataChanged(index, index); |
990 |
|
return true; |
991 |
} |
} |
992 |
|
|
993 |
void qsamplerDeviceParamTableSpinBox::setMinValue ( int iMinValue ) |
void DeviceParamModel::refresh(qsamplerDevice* pDevice, bool bEditable) { |
994 |
{ |
device = pDevice; |
995 |
m_iMinValue = iMinValue; |
AbstractDeviceParamModel::refresh(&pDevice->params(), bEditable); |
996 |
} |
} |
997 |
|
|
998 |
void qsamplerDeviceParamTableSpinBox::setMaxValue ( int iMaxValue ) |
void DeviceParamModel::clear() { |
999 |
{ |
AbstractDeviceParamModel::clear(); |
1000 |
m_iMaxValue = iMaxValue; |
device = NULL; |
1001 |
} |
} |
1002 |
|
|
1003 |
// Virtual implemetations. |
|
1004 |
QWidget *qsamplerDeviceParamTableSpinBox::createEditor (void) const |
//------------------------------------------------------------------------- |
1005 |
{ |
// PortParamModel - data model for port parameters (used for QTableView) |
1006 |
QSpinBox *pSpinBox = new QSpinBox(QTableItem::table()->viewport()); |
// |
1007 |
QObject::connect(pSpinBox, SIGNAL(valueChanged(int)), |
|
1008 |
QTableItem::table(), SLOT(doValueChanged())); |
PortParamModel::PortParamModel(QObject* parent) : AbstractDeviceParamModel(parent) { |
1009 |
if (m_iValue >= m_iMinValue && m_iMaxValue >= m_iValue) { |
port = NULL; |
|
pSpinBox->setMinValue(m_iMinValue); |
|
|
pSpinBox->setMaxValue(m_iMaxValue); |
|
|
} |
|
|
pSpinBox->setValue(m_iValue); |
|
|
return pSpinBox; |
|
1010 |
} |
} |
1011 |
|
|
1012 |
void qsamplerDeviceParamTableSpinBox::setContentFromEditor ( QWidget *pWidget ) |
bool PortParamModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) { |
1013 |
{ |
if (!index.isValid()) { |
1014 |
if (pWidget->inherits("QSpinBox")) |
return false; |
1015 |
QTableItem::setText(QString::number(((QSpinBox *) pWidget)->value())); |
} |
1016 |
else |
QString key = params->keys()[index.row()]; |
1017 |
QTableItem::setContentFromEditor(pWidget); |
//params[key].value = value.toString(); |
1018 |
|
port->setParam(key, value.toString()); |
1019 |
|
emit dataChanged(index, index); |
1020 |
|
return true; |
1021 |
|
} |
1022 |
|
|
1023 |
|
void PortParamModel::refresh(qsamplerDevicePort* pPort, bool bEditable) { |
1024 |
|
port = pPort; |
1025 |
|
AbstractDeviceParamModel::refresh(&pPort->params(), bEditable); |
1026 |
|
} |
1027 |
|
|
1028 |
|
void PortParamModel::clear() { |
1029 |
|
AbstractDeviceParamModel::clear(); |
1030 |
|
port = NULL; |
1031 |
} |
} |
1032 |
|
|
1033 |
|
|
1034 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
1035 |
// qsamplerDeviceParamTableEditBox - Custom edit box for parameter table. |
// DeviceParamDelegate - table cell renderer for device/port parameters |
1036 |
// |
// |
1037 |
|
|
1038 |
// Constructor. |
DeviceParamDelegate::DeviceParamDelegate(QObject *parent) : QItemDelegate(parent) { |
|
qsamplerDeviceParamTableEditBox::qsamplerDeviceParamTableEditBox ( |
|
|
QTable *pTable, EditType editType, const QString& sText ) |
|
|
: QTableItem(pTable, editType, sText) |
|
|
{ |
|
1039 |
} |
} |
1040 |
|
|
1041 |
// Virtual implemetations. |
QWidget* DeviceParamDelegate::createEditor(QWidget *parent, |
1042 |
QWidget *qsamplerDeviceParamTableEditBox::createEditor (void) const |
const QStyleOptionViewItem &/* option */, |
1043 |
{ |
const QModelIndex& index) const |
1044 |
QLineEdit *pEditBox = new QLineEdit(QTableItem::table()->viewport()); |
{ |
1045 |
QObject::connect(pEditBox, SIGNAL(returnPressed()), |
if (!index.isValid()) { |
1046 |
QTableItem::table(), SLOT(doValueChanged())); |
return NULL; |
1047 |
pEditBox->setText(QTableItem::text()); |
} |
1048 |
return pEditBox; |
|
1049 |
|
DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>(); |
1050 |
|
|
1051 |
|
const bool bEnabled = (/*index.model()->bEditable ||*/ !r.param.fix); |
1052 |
|
|
1053 |
|
switch (index.column()) { |
1054 |
|
case 0: |
1055 |
|
return new QLabel(r.name, parent); |
1056 |
|
case 1: { |
1057 |
|
if (r.param.type == LSCP_TYPE_BOOL) { |
1058 |
|
QCheckBox* pCheckBox = new QCheckBox(parent); |
1059 |
|
pCheckBox->setChecked(r.param.value.lower() == "true"); |
1060 |
|
pCheckBox->setEnabled(bEnabled); |
1061 |
|
return pCheckBox; |
1062 |
|
} else if (r.param.possibilities.count() > 0) { |
1063 |
|
QStringList opts = r.param.possibilities; |
1064 |
|
if (r.param.multiplicity) |
1065 |
|
opts.prepend(tr("(none)")); |
1066 |
|
QComboBox* pComboBox = new QComboBox(parent); |
1067 |
|
pComboBox->addItems(opts); |
1068 |
|
if (r.param.value.isEmpty()) |
1069 |
|
pComboBox->setCurrentIndex(0); |
1070 |
|
else |
1071 |
|
pComboBox->setCurrentIndex(pComboBox->findText(r.param.value)); |
1072 |
|
pComboBox->setEnabled(bEnabled); |
1073 |
|
return pComboBox; |
1074 |
|
} else if (r.param.type == LSCP_TYPE_INT |
1075 |
|
&& !r.param.range_min.isEmpty() |
1076 |
|
&& !r.param.range_max.isEmpty()) { |
1077 |
|
QSpinBox* pSpinBox = new QSpinBox(parent); |
1078 |
|
pSpinBox->setValue(r.param.value.toInt()); |
1079 |
|
pSpinBox->setMinimum(r.param.range_min.toInt()); |
1080 |
|
pSpinBox->setMaximum(r.param.range_max.toInt()); |
1081 |
|
pSpinBox->setEnabled(bEnabled); |
1082 |
|
return pSpinBox; |
1083 |
|
} else { |
1084 |
|
QLineEdit* pLineEdit = new QLineEdit(r.param.value, parent); |
1085 |
|
pLineEdit->setEnabled(bEnabled); |
1086 |
|
return pLineEdit; |
1087 |
|
} |
1088 |
|
} |
1089 |
|
case 2: |
1090 |
|
return new QLabel(r.param.description, parent); |
1091 |
|
default: |
1092 |
|
return NULL; |
1093 |
|
} |
1094 |
|
} |
1095 |
|
|
1096 |
|
void DeviceParamDelegate::setEditorData(QWidget* /*editor*/, const QModelIndex& /*index*/) const { |
1097 |
|
// unused, since we set the editor data already in createEditor() |
1098 |
|
} |
1099 |
|
|
1100 |
|
void DeviceParamDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const { |
1101 |
|
if (index.column() == 1) { |
1102 |
|
DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>(); |
1103 |
|
if (r.param.type == LSCP_TYPE_BOOL) { |
1104 |
|
QCheckBox* pCheckBox = static_cast<QCheckBox*>(editor); |
1105 |
|
model->setData(index, QVariant(pCheckBox->checkState() == Qt::Checked)); |
1106 |
|
} else if (r.param.possibilities.count() > 0) { |
1107 |
|
QComboBox* pComboBox = static_cast<QComboBox*>(editor); |
1108 |
|
model->setData(index, pComboBox->currentText()); |
1109 |
|
} else if (r.param.type == LSCP_TYPE_INT) { |
1110 |
|
QSpinBox* pSpinBox = static_cast<QSpinBox*>(editor); |
1111 |
|
model->setData(index, pSpinBox->value()); |
1112 |
|
} else { |
1113 |
|
QLineEdit* pLineEdit = static_cast<QLineEdit*>(editor); |
1114 |
|
model->setData(index, pLineEdit->text()); |
1115 |
|
} |
1116 |
|
} |
1117 |
} |
} |
1118 |
|
|
1119 |
void qsamplerDeviceParamTableEditBox::setContentFromEditor ( QWidget *pWidget ) |
void DeviceParamDelegate::updateEditorGeometry(QWidget* editor, |
1120 |
|
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
1121 |
{ |
{ |
1122 |
if (pWidget->inherits("QLineEdit")) |
if (editor) editor->setGeometry(option.rect); |
|
QTableItem::setText(((QLineEdit *) pWidget)->text()); |
|
|
else |
|
|
QTableItem::setContentFromEditor(pWidget); |
|
1123 |
} |
} |
1124 |
|
|
|
|
|
1125 |
// end of qsamplerDevice.cpp |
// end of qsamplerDevice.cpp |
|
|
|