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 |
|
|
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... |
407 |
// Now it depends on the device type... |
// Now it depends on the device type... |
408 |
switch (m_deviceType) { |
switch (m_deviceType) { |
409 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
410 |
if ((m_iDeviceID = ::lscp_create_audio_device(client(), |
if ((m_iDeviceID = ::lscp_create_audio_device(pMainForm->client(), |
411 |
m_sDriverName.latin1(), pParams)) < 0) |
m_sDriverName.latin1(), pParams)) < 0) |
412 |
appendMessagesClient("lscp_create_audio_device"); |
appendMessagesClient("lscp_create_audio_device"); |
413 |
break; |
break; |
414 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
415 |
if ((m_iDeviceID = ::lscp_create_midi_device(client(), |
if ((m_iDeviceID = ::lscp_create_midi_device(pMainForm->client(), |
416 |
m_sDriverName.latin1(), pParams)) < 0) |
m_sDriverName.latin1(), pParams)) < 0) |
417 |
appendMessagesClient("lscp_create_midi_device"); |
appendMessagesClient("lscp_create_midi_device"); |
418 |
break; |
break; |
440 |
// Destroy existing device. |
// Destroy existing device. |
441 |
bool qsamplerDevice::deleteDevice (void) |
bool qsamplerDevice::deleteDevice (void) |
442 |
{ |
{ |
443 |
|
MainForm *pMainForm = MainForm::getInstance(); |
444 |
|
if (pMainForm == NULL) |
445 |
|
return false; |
446 |
|
if (pMainForm->client() == NULL) |
447 |
|
return false; |
448 |
|
|
449 |
// Now it depends on the device type... |
// Now it depends on the device type... |
450 |
lscp_status_t ret = LSCP_FAILED; |
lscp_status_t ret = LSCP_FAILED; |
451 |
switch (m_deviceType) { |
switch (m_deviceType) { |
452 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
453 |
if ((ret = ::lscp_destroy_audio_device(client(), |
if ((ret = ::lscp_destroy_audio_device(pMainForm->client(), |
454 |
m_iDeviceID)) != LSCP_OK) |
m_iDeviceID)) != LSCP_OK) |
455 |
appendMessagesClient("lscp_destroy_audio_device"); |
appendMessagesClient("lscp_destroy_audio_device"); |
456 |
break; |
break; |
457 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
458 |
if ((ret = ::lscp_destroy_midi_device(client(), |
if ((ret = ::lscp_destroy_midi_device(pMainForm->client(), |
459 |
m_iDeviceID)) != LSCP_OK) |
m_iDeviceID)) != LSCP_OK) |
460 |
appendMessagesClient("lscp_destroy_midi_device"); |
appendMessagesClient("lscp_destroy_midi_device"); |
461 |
break; |
break; |
541 |
// Refresh/set given parameter based on driver supplied dependencies. |
// Refresh/set given parameter based on driver supplied dependencies. |
542 |
int qsamplerDevice::refreshParam ( const QString& sParam ) |
int qsamplerDevice::refreshParam ( const QString& sParam ) |
543 |
{ |
{ |
544 |
|
MainForm *pMainForm = MainForm::getInstance(); |
545 |
|
if (pMainForm == NULL) |
546 |
|
return 0; |
547 |
|
if (pMainForm->client() == NULL) |
548 |
|
return 0; |
549 |
|
|
550 |
// Check if we have dependencies... |
// Check if we have dependencies... |
551 |
qsamplerDeviceParam& param = m_params[sParam.upper()]; |
qsamplerDeviceParam& param = m_params[sParam.upper()]; |
552 |
if (param.depends.isEmpty()) |
if (param.depends.isEmpty()) |
577 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
578 |
switch (m_deviceType) { |
switch (m_deviceType) { |
579 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
580 |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(client(), |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(pMainForm->client(), |
581 |
m_sDriverName.latin1(), sParam.latin1(), pDepends)) == NULL) |
m_sDriverName.latin1(), sParam.latin1(), pDepends)) == NULL) |
582 |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
583 |
break; |
break; |
584 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
585 |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(client(), |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(pMainForm->client(), |
586 |
m_sDriverName.latin1(), sParam.latin1(), pDepends)) == NULL) |
m_sDriverName.latin1(), sParam.latin1(), pDepends)) == NULL) |
587 |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
588 |
break; |
break; |
605 |
// Redirected messages output methods. |
// Redirected messages output methods. |
606 |
void qsamplerDevice::appendMessages( const QString& s ) const |
void qsamplerDevice::appendMessages( const QString& s ) const |
607 |
{ |
{ |
608 |
if (m_pMainForm) |
MainForm *pMainForm = MainForm::getInstance(); |
609 |
m_pMainForm->appendMessages(deviceName() + ' ' + s); |
if (pMainForm) |
610 |
|
pMainForm->appendMessages(deviceName() + ' ' + s); |
611 |
} |
} |
612 |
|
|
613 |
void qsamplerDevice::appendMessagesColor( const QString& s, |
void qsamplerDevice::appendMessagesColor( const QString& s, |
614 |
const QString& c ) const |
const QString& c ) const |
615 |
{ |
{ |
616 |
if (m_pMainForm) |
MainForm *pMainForm = MainForm::getInstance(); |
617 |
m_pMainForm->appendMessagesColor(deviceName() + ' ' + s, c); |
if (pMainForm) |
618 |
|
pMainForm->appendMessagesColor(deviceName() + ' ' + s, c); |
619 |
} |
} |
620 |
|
|
621 |
void qsamplerDevice::appendMessagesText( const QString& s ) const |
void qsamplerDevice::appendMessagesText( const QString& s ) const |
622 |
{ |
{ |
623 |
if (m_pMainForm) |
MainForm *pMainForm = MainForm::getInstance(); |
624 |
m_pMainForm->appendMessagesText(deviceName() + ' ' + s); |
if (pMainForm) |
625 |
|
pMainForm->appendMessagesText(deviceName() + ' ' + s); |
626 |
} |
} |
627 |
|
|
628 |
void qsamplerDevice::appendMessagesError( const QString& s ) const |
void qsamplerDevice::appendMessagesError( const QString& s ) const |
629 |
{ |
{ |
630 |
if (m_pMainForm) |
MainForm *pMainForm = MainForm::getInstance(); |
631 |
m_pMainForm->appendMessagesError(deviceName() + "\n\n" + s); |
if (pMainForm) |
632 |
|
pMainForm->appendMessagesError(deviceName() + "\n\n" + s); |
633 |
} |
} |
634 |
|
|
635 |
void qsamplerDevice::appendMessagesClient( const QString& s ) const |
void qsamplerDevice::appendMessagesClient( const QString& s ) const |
636 |
{ |
{ |
637 |
if (m_pMainForm) |
MainForm *pMainForm = MainForm::getInstance(); |
638 |
m_pMainForm->appendMessagesClient(deviceName() + ' ' + s); |
if (pMainForm) |
639 |
|
pMainForm->appendMessagesClient(deviceName() + ' ' + s); |
640 |
} |
} |
641 |
|
|
642 |
|
|
668 |
const char **ppszDrivers = NULL; |
const char **ppszDrivers = NULL; |
669 |
switch (deviceType) { |
switch (deviceType) { |
670 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
671 |
ppszDrivers = ::lscp_get_available_audio_drivers(pClient); |
ppszDrivers = ::lscp_list_available_audio_drivers(pClient); |
672 |
break; |
break; |
673 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
674 |
ppszDrivers = ::lscp_get_available_midi_drivers(pClient); |
ppszDrivers = ::lscp_list_available_midi_drivers(pClient); |
675 |
break; |
break; |
676 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
677 |
break; |
break; |
678 |
} |
} |
679 |
|
|
680 |
for (int iDriver = 0; ppszDrivers[iDriver]; iDriver++) |
for (int iDriver = 0; ppszDrivers && ppszDrivers[iDriver]; iDriver++) |
681 |
drivers.append(ppszDrivers[iDriver]); |
drivers.append(ppszDrivers[iDriver]); |
682 |
|
|
683 |
return drivers; |
return drivers; |
704 |
// Initializer. |
// Initializer. |
705 |
void qsamplerDevicePort::setDevicePort ( int iPortID ) |
void qsamplerDevicePort::setDevicePort ( int iPortID ) |
706 |
{ |
{ |
707 |
|
MainForm *pMainForm = MainForm::getInstance(); |
708 |
|
if (pMainForm == NULL) |
709 |
|
return; |
710 |
|
if (pMainForm->client() == NULL) |
711 |
|
return; |
712 |
|
|
713 |
// Device port id should be always set. |
// Device port id should be always set. |
714 |
m_iPortID = iPortID; |
m_iPortID = iPortID; |
715 |
|
|
720 |
lscp_device_port_info_t *pPortInfo = NULL; |
lscp_device_port_info_t *pPortInfo = NULL; |
721 |
switch (m_device.deviceType()) { |
switch (m_device.deviceType()) { |
722 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
723 |
if ((pPortInfo = ::lscp_get_audio_channel_info(m_device.client(), |
if ((pPortInfo = ::lscp_get_audio_channel_info(pMainForm->client(), |
724 |
m_device.deviceID(), m_iPortID)) == NULL) |
m_device.deviceID(), m_iPortID)) == NULL) |
725 |
m_device.appendMessagesClient("lscp_get_audio_channel_info"); |
m_device.appendMessagesClient("lscp_get_audio_channel_info"); |
726 |
break; |
break; |
727 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
728 |
if ((pPortInfo = ::lscp_get_midi_port_info(m_device.client(), |
if ((pPortInfo = ::lscp_get_midi_port_info(pMainForm->client(), |
729 |
m_device.deviceID(), m_iPortID)) == NULL) |
m_device.deviceID(), m_iPortID)) == NULL) |
730 |
m_device.appendMessagesClient("lscp_get_midi_port_info"); |
m_device.appendMessagesClient("lscp_get_midi_port_info"); |
731 |
break; |
break; |
750 |
switch (m_device.deviceType()) { |
switch (m_device.deviceType()) { |
751 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
752 |
if ((pParamInfo = ::lscp_get_audio_channel_param_info( |
if ((pParamInfo = ::lscp_get_audio_channel_param_info( |
753 |
m_device.client(), m_device.deviceID(), |
pMainForm->client(), m_device.deviceID(), |
754 |
m_iPortID, sParam.latin1())) == NULL) |
m_iPortID, sParam.latin1())) == NULL) |
755 |
m_device.appendMessagesClient("lscp_get_audio_channel_param_info"); |
m_device.appendMessagesClient("lscp_get_audio_channel_param_info"); |
756 |
break; |
break; |
757 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
758 |
if ((pParamInfo = ::lscp_get_midi_port_param_info( |
if ((pParamInfo = ::lscp_get_midi_port_param_info( |
759 |
m_device.client(), m_device.deviceID(), |
pMainForm->client(), m_device.deviceID(), |
760 |
m_iPortID, sParam.latin1())) == NULL) |
m_iPortID, sParam.latin1())) == NULL) |
761 |
m_device.appendMessagesClient("lscp_get_midi_port_param_info"); |
m_device.appendMessagesClient("lscp_get_midi_port_param_info"); |
762 |
break; |
break; |
793 |
bool qsamplerDevicePort::setParam ( const QString& sParam, |
bool qsamplerDevicePort::setParam ( const QString& sParam, |
794 |
const QString& sValue ) |
const QString& sValue ) |
795 |
{ |
{ |
796 |
|
MainForm *pMainForm = MainForm::getInstance(); |
797 |
|
if (pMainForm == NULL) |
798 |
|
return false; |
799 |
|
if (pMainForm->client() == NULL) |
800 |
|
return false; |
801 |
|
|
802 |
// Set proper port/channel parameter. |
// Set proper port/channel parameter. |
803 |
m_params[sParam.upper()].value = sValue; |
m_params[sParam.upper()].value = sValue; |
804 |
|
|
813 |
lscp_status_t ret = LSCP_FAILED; |
lscp_status_t ret = LSCP_FAILED; |
814 |
switch (m_device.deviceType()) { |
switch (m_device.deviceType()) { |
815 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
816 |
if ((ret = ::lscp_set_audio_channel_param(m_device.client(), |
if ((ret = ::lscp_set_audio_channel_param(pMainForm->client(), |
817 |
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
818 |
m_device.appendMessagesClient("lscp_set_audio_channel_param"); |
m_device.appendMessagesClient("lscp_set_audio_channel_param"); |
819 |
break; |
break; |
820 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
821 |
if ((ret = ::lscp_set_midi_port_param(m_device.client(), |
if ((ret = ::lscp_set_midi_port_param(pMainForm->client(), |
822 |
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
823 |
m_device.appendMessagesClient("lscp_set_midi_port_param"); |
m_device.appendMessagesClient("lscp_set_midi_port_param"); |
824 |
break; |
break; |
843 |
|
|
844 |
|
|
845 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
846 |
// qsamplerDeviceItem - QListView device item. |
// qsamplerDeviceItem - QTreeWidget device item. |
847 |
// |
// |
848 |
|
|
849 |
// Constructors. |
// Constructors. |
850 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListView *pListView, |
qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidget* pTreeWidget, |
851 |
qsamplerMainForm *pMainForm, qsamplerDevice::qsamplerDeviceType deviceType ) |
qsamplerDevice::qsamplerDeviceType deviceType ) |
852 |
: QListViewItem(pListView), m_device(pMainForm, deviceType) |
: QTreeWidgetItem(pTreeWidget, QSAMPLER_DEVICE_ITEM), |
853 |
|
m_device(deviceType) |
854 |
{ |
{ |
855 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
856 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
857 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio1.png")); |
setIcon(0, QPixmap(":/icons/audio1.png")); |
858 |
QListViewItem::setText(0, QObject::tr("Audio Devices")); |
setText(0, QObject::tr("Audio Devices")); |
859 |
break; |
break; |
860 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
861 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi1.png")); |
setIcon(0, QPixmap(":/icons/midi1.png")); |
862 |
QListViewItem::setText(0, QObject::tr("MIDI Devices")); |
setText(0, QObject::tr("MIDI Devices")); |
863 |
break; |
break; |
864 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
865 |
break; |
break; |
866 |
} |
} |
867 |
} |
} |
868 |
|
|
869 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListViewItem *pItem, |
qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidgetItem* pItem, |
870 |
qsamplerMainForm *pMainForm, qsamplerDevice::qsamplerDeviceType deviceType, |
qsamplerDevice::qsamplerDeviceType deviceType, |
871 |
int iDeviceID ) |
int iDeviceID ) |
872 |
: QListViewItem(pItem), m_device(pMainForm, deviceType, iDeviceID) |
: QTreeWidgetItem(pItem, QSAMPLER_DEVICE_ITEM), |
873 |
|
m_device(deviceType, iDeviceID) |
874 |
{ |
{ |
875 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
876 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
877 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio2.png")); |
setIcon(0, QPixmap(":/icons/audio2.png")); |
878 |
break; |
break; |
879 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
880 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi2.png")); |
setIcon(0, QPixmap(":/icons/midi2.png")); |
881 |
break; |
break; |
882 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
883 |
break; |
break; |
884 |
} |
} |
885 |
|
|
886 |
QListViewItem::setText(0, m_device.deviceName()); |
setText(1, m_device.deviceName()); |
887 |
} |
} |
888 |
|
|
889 |
// Default destructor. |
// Default destructor. |
890 |
qsamplerDeviceItem::~qsamplerDeviceItem (void) |
qsamplerDeviceItem::~qsamplerDeviceItem () |
891 |
{ |
{ |
892 |
} |
} |
893 |
|
|
894 |
// Instance accessors. |
// Instance accessors. |
895 |
qsamplerDevice& qsamplerDeviceItem::device (void) |
qsamplerDevice& qsamplerDeviceItem::device () |
896 |
{ |
{ |
897 |
return m_device; |
return m_device; |
898 |
} |
} |
899 |
|
|
|
// To virtually distinguish between list view items. |
|
|
int qsamplerDeviceItem::rtti() const |
|
|
{ |
|
|
return QSAMPLER_DEVICE_ITEM; |
|
|
} |
|
|
|
|
900 |
|
|
901 |
|
|
902 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
903 |
// qsamplerDeviceParamTable - Device parameter view table. |
// qsamplerDeviceParamTable - Device parameter view table. |
904 |
// |
// |
905 |
|
#if 0 |
906 |
// Constructor. |
// Constructor. |
907 |
qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, |
qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, |
908 |
const char *pszName ) |
const char *pszName ) |
961 |
pComboItem->setEnabled(bEnabled); |
pComboItem->setEnabled(bEnabled); |
962 |
QTable::setItem(iRow, 2, pComboItem); |
QTable::setItem(iRow, 2, pComboItem); |
963 |
} else if (param.possibilities.count() > 0 && bEnabled) { |
} else if (param.possibilities.count() > 0 && bEnabled) { |
964 |
QComboTableItem *pComboItem = new QComboTableItem(this, |
QStringList opts = param.possibilities; |
965 |
param.possibilities); |
if (param.multiplicity) |
966 |
pComboItem->setCurrentItem(param.value); |
opts.prepend(tr("(none)")); |
967 |
|
QComboTableItem *pComboItem = new QComboTableItem(this, opts); |
968 |
|
if (param.value.isEmpty()) |
969 |
|
pComboItem->setCurrentItem(0); |
970 |
|
else |
971 |
|
pComboItem->setCurrentItem(param.value); |
972 |
pComboItem->setEnabled(bEnabled); |
pComboItem->setEnabled(bEnabled); |
|
// pComboItem->setEditable(bEnabled && param.multiplicity); |
|
973 |
QTable::setItem(iRow, 2, pComboItem); |
QTable::setItem(iRow, 2, pComboItem); |
974 |
} else if (param.type == LSCP_TYPE_INT && bEnabled |
} else if (param.type == LSCP_TYPE_INT && bEnabled |
975 |
&& !param.range_min.isEmpty() |
&& !param.range_min.isEmpty() |
998 |
QTable::setUpdatesEnabled(true); |
QTable::setUpdatesEnabled(true); |
999 |
QTable::updateContents(); |
QTable::updateContents(); |
1000 |
} |
} |
1001 |
|
#endif |
1002 |
|
|
1003 |
|
DeviceParamModel::DeviceParamModel(QObject* parent) : QAbstractTableModel(parent), bEditable(false) { |
1004 |
|
} |
1005 |
|
|
1006 |
|
int DeviceParamModel::rowCount(const QModelIndex& /*parent*/) const { |
1007 |
|
return params.size(); |
1008 |
|
} |
1009 |
|
|
1010 |
|
int DeviceParamModel::columnCount(const QModelIndex& /*parent*/) const { |
1011 |
|
return 3; |
1012 |
|
} |
1013 |
|
|
1014 |
|
QVariant DeviceParamModel::data(const QModelIndex &index, int role) const { |
1015 |
|
if (!index.isValid()) |
1016 |
|
return QVariant(); |
1017 |
|
if (role != Qt::DisplayRole) |
1018 |
|
return QVariant(); |
1019 |
|
|
1020 |
|
DeviceParameterRow item; |
1021 |
|
item.name = params.keys()[index.row()]; |
1022 |
|
item.param = params[item.name]; |
1023 |
|
|
1024 |
|
return QVariant::fromValue(item); |
1025 |
|
} |
1026 |
|
|
1027 |
|
QVariant DeviceParamModel::headerData(int section, Qt::Orientation orientation, int role) const { |
1028 |
|
if (role != Qt::DisplayRole) return QVariant(); |
1029 |
|
|
1030 |
|
if (orientation == Qt::Horizontal) { |
1031 |
|
switch (section) { |
1032 |
|
case 0: return tr("Parameter"); |
1033 |
|
case 1: return tr("Value"); |
1034 |
|
case 2: return tr("Description"); |
1035 |
|
default: return QVariant(); |
1036 |
|
} |
1037 |
|
} |
1038 |
|
|
1039 |
|
return QVariant(); |
1040 |
|
} |
1041 |
|
|
1042 |
|
void DeviceParamModel::refresh(const qsamplerDeviceParamMap& params, bool bEditable) |
1043 |
|
{ |
1044 |
|
this->params = params; |
1045 |
|
this->bEditable = bEditable; |
1046 |
|
} |
1047 |
|
|
1048 |
|
void DeviceParamModel::clear() { |
1049 |
|
params.clear(); |
1050 |
|
} |
1051 |
|
|
1052 |
|
|
1053 |
|
DeviceParamDelegate::DeviceParamDelegate(QObject *parent) : QItemDelegate(parent) { |
1054 |
|
} |
1055 |
|
|
1056 |
|
QWidget* DeviceParamDelegate::createEditor(QWidget *parent, |
1057 |
|
const QStyleOptionViewItem &/* option */, |
1058 |
|
const QModelIndex& index) const |
1059 |
|
{ |
1060 |
|
DeviceParameterRow r = index.model()->data(index, Qt::DisplayRole).value<DeviceParameterRow>(); |
1061 |
|
|
1062 |
|
const bool bEnabled = (/*index.model()->bEditable ||*/ !r.param.fix); |
1063 |
|
|
1064 |
|
switch (index.column()) { |
1065 |
|
case 0: |
1066 |
|
return new QLabel(r.name, parent); |
1067 |
|
case 1: { |
1068 |
|
if (r.param.type == LSCP_TYPE_BOOL) { |
1069 |
|
QCheckBox* pCheckBox = new QCheckBox(parent); |
1070 |
|
pCheckBox->setChecked(r.param.value.lower() == "true"); |
1071 |
|
pCheckBox->setEnabled(bEnabled); |
1072 |
|
return pCheckBox; |
1073 |
|
} else if (r.param.possibilities.count() > 0 && bEnabled) { |
1074 |
|
QStringList opts = r.param.possibilities; |
1075 |
|
if (r.param.multiplicity) |
1076 |
|
opts.prepend(tr("(none)")); |
1077 |
|
QComboBox* pComboBox = new QComboBox(parent); |
1078 |
|
pComboBox->addItems(opts); |
1079 |
|
if (r.param.value.isEmpty()) |
1080 |
|
pComboBox->setCurrentIndex(0); |
1081 |
|
else |
1082 |
|
pComboBox->setCurrentIndex(pComboBox->findText(r.param.value)); |
1083 |
|
pComboBox->setEnabled(bEnabled); |
1084 |
|
return pComboBox; |
1085 |
|
} else if (r.param.type == LSCP_TYPE_INT && bEnabled |
1086 |
|
&& !r.param.range_min.isEmpty() |
1087 |
|
&& !r.param.range_max.isEmpty()) { |
1088 |
|
QSpinBox* pSpinBox = new QSpinBox(parent); |
1089 |
|
pSpinBox->setValue(r.param.value.toInt()); |
1090 |
|
pSpinBox->setMinimum(r.param.range_min.toInt()); |
1091 |
|
pSpinBox->setMaximum(r.param.range_max.toInt()); |
1092 |
|
return pSpinBox; |
1093 |
|
} else { |
1094 |
|
QLineEdit* pLineEdit = new QLineEdit(r.param.value, parent); |
1095 |
|
return pLineEdit; |
1096 |
|
} |
1097 |
|
} |
1098 |
|
case 2: |
1099 |
|
return new QLabel(r.param.description, parent); |
1100 |
|
default: |
1101 |
|
return NULL; |
1102 |
|
} |
1103 |
|
} |
1104 |
|
|
1105 |
|
void DeviceParamDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { |
1106 |
|
/* |
1107 |
|
ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>(); |
1108 |
|
QComboBox* comboBox = static_cast<QComboBox*>(editor); |
1109 |
|
comboBox->setCurrentIndex(item.selection); |
1110 |
|
*/ |
1111 |
|
} |
1112 |
|
|
1113 |
|
void DeviceParamDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { |
1114 |
|
/* |
1115 |
|
QComboBox* comboBox = static_cast<QComboBox*>(editor); |
1116 |
|
model->setData(index, comboBox->currentIndex()); |
1117 |
|
*/ |
1118 |
|
} |
1119 |
|
|
1120 |
|
void DeviceParamDelegate::updateEditorGeometry(QWidget* editor, |
1121 |
|
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
1122 |
|
{ |
1123 |
|
if (editor) editor->setGeometry(option.rect); |
1124 |
|
} |
1125 |
|
|
1126 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
1127 |
// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. |
// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. |
1128 |
// |
// |
1129 |
|
|
1130 |
|
#if 0 |
1131 |
// Constructor. |
// Constructor. |
1132 |
qsamplerDeviceParamTableSpinBox::qsamplerDeviceParamTableSpinBox ( |
qsamplerDeviceParamTableSpinBox::qsamplerDeviceParamTableSpinBox ( |
1133 |
QTable *pTable, EditType editType, const QString& sText ) |
QTable *pTable, EditType editType, const QString& sText ) |
1205 |
else |
else |
1206 |
QTableItem::setContentFromEditor(pWidget); |
QTableItem::setContentFromEditor(pWidget); |
1207 |
} |
} |
1208 |
|
#endif |
1209 |
|
|
1210 |
|
|
1211 |
// end of qsamplerDevice.cpp |
// end of qsamplerDevice.cpp |