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 <QCheckBox> |
30 |
|
#include <QSpinBox> |
31 |
|
#include <QLineEdit> |
32 |
|
|
33 |
|
|
34 |
|
using namespace QSampler; |
35 |
|
|
36 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
37 |
// qsamplerDeviceParam - MIDI/Audio Device parameter structure. |
// qsamplerDeviceParam - MIDI/Audio Device parameter structure. |
57 |
{ |
{ |
58 |
if (pParamInfo == NULL) |
if (pParamInfo == NULL) |
59 |
return; |
return; |
60 |
|
|
61 |
// Info structure field members. |
// Info structure field members. |
62 |
|
|
63 |
type = pParamInfo->type; |
type = pParamInfo->type; |
64 |
|
|
65 |
if (pParamInfo->description) |
if (pParamInfo->description) |
66 |
description = pParamInfo->description; |
description = pParamInfo->description; |
67 |
else |
else |
68 |
description = QString::null; |
description = QString::null; |
69 |
|
|
70 |
mandatory = (bool) pParamInfo->mandatory; |
mandatory = (bool) pParamInfo->mandatory; |
71 |
fix = (bool) pParamInfo->fix; |
fix = (bool) pParamInfo->fix; |
72 |
multiplicity = (bool) pParamInfo->multiplicity; |
multiplicity = (bool) pParamInfo->multiplicity; |
73 |
|
|
74 |
depends.clear(); |
depends.clear(); |
75 |
for (int i = 0; pParamInfo->depends && pParamInfo->depends[i]; i++) |
for (int i = 0; pParamInfo->depends && pParamInfo->depends[i]; i++) |
76 |
depends.append(pParamInfo->depends[i]); |
depends.append(pParamInfo->depends[i]); |
77 |
|
|
78 |
if (pParamInfo->defaultv) |
if (pParamInfo->defaultv) |
79 |
defaultv = pParamInfo->defaultv; |
defaultv = pParamInfo->defaultv; |
80 |
else |
else |
81 |
defaultv = QString::null; |
defaultv = QString::null; |
82 |
|
|
83 |
if (pParamInfo->range_min) |
if (pParamInfo->range_min) |
84 |
range_min = pParamInfo->range_min; |
range_min = pParamInfo->range_min; |
85 |
else |
else |
86 |
range_min = QString::null; |
range_min = QString::null; |
87 |
|
|
88 |
if (pParamInfo->range_max) |
if (pParamInfo->range_max) |
89 |
range_max = pParamInfo->range_max; |
range_max = pParamInfo->range_max; |
90 |
else |
else |
91 |
range_max = QString::null; |
range_max = QString::null; |
92 |
|
|
93 |
possibilities.clear(); |
possibilities.clear(); |
94 |
for (int i = 0; pParamInfo->possibilities && pParamInfo->possibilities[i]; i++) |
for (int i = 0; pParamInfo->possibilities && pParamInfo->possibilities[i]; i++) |
95 |
possibilities.append(pParamInfo->possibilities[i]); |
possibilities.append(pParamInfo->possibilities[i]); |
96 |
|
|
97 |
// The current parameter value. |
// The current parameter value. |
98 |
if (pszValue) |
if (pszValue) |
99 |
value = pszValue; |
value = pszValue; |
107 |
// |
// |
108 |
|
|
109 |
// Constructor. |
// Constructor. |
110 |
qsamplerDevice::qsamplerDevice ( qsamplerMainForm *pMainForm, |
qsamplerDevice::qsamplerDevice ( DeviceType deviceType, int iDeviceID ) |
|
qsamplerDeviceType deviceType, int iDeviceID ) |
|
111 |
{ |
{ |
112 |
m_pMainForm = pMainForm; |
// m_ports.setAutoDelete(true); |
113 |
|
|
|
m_ports.setAutoDelete(true); |
|
|
|
|
114 |
setDevice(deviceType, iDeviceID); |
setDevice(deviceType, iDeviceID); |
115 |
} |
} |
116 |
|
|
117 |
// Default destructor. |
// Default destructor. |
118 |
qsamplerDevice::~qsamplerDevice (void) |
qsamplerDevice::~qsamplerDevice (void) |
119 |
{ |
{ |
120 |
|
qDeleteAll(m_ports); |
121 |
|
m_ports.clear(); |
122 |
} |
} |
123 |
|
|
124 |
// Copy constructor. |
// Copy constructor. |
125 |
qsamplerDevice::qsamplerDevice ( const qsamplerDevice& device ) |
qsamplerDevice::qsamplerDevice ( const qsamplerDevice& device ) |
126 |
: m_params(device.m_params), m_ports(m_ports) |
: m_params(device.m_params), m_ports(device.m_ports) |
127 |
{ |
{ |
|
m_pMainForm = device.m_pMainForm; |
|
128 |
m_iDeviceID = device.m_iDeviceID; |
m_iDeviceID = device.m_iDeviceID; |
129 |
m_deviceType = device.m_deviceType; |
m_deviceType = device.m_deviceType; |
130 |
m_sDeviceType = device.m_sDeviceType; |
m_sDeviceType = device.m_sDeviceType; |
134 |
|
|
135 |
|
|
136 |
// Initializer. |
// Initializer. |
137 |
void qsamplerDevice::setDevice ( qsamplerDeviceType deviceType, int iDeviceID ) |
void qsamplerDevice::setDevice ( DeviceType deviceType, int iDeviceID ) |
138 |
{ |
{ |
139 |
|
MainForm *pMainForm = MainForm::getInstance(); |
140 |
|
if (pMainForm == NULL) |
141 |
|
return; |
142 |
|
if (pMainForm->client() == NULL) |
143 |
|
return; |
144 |
|
|
145 |
// Device id and type should be always set. |
// Device id and type should be always set. |
146 |
m_iDeviceID = iDeviceID; |
m_iDeviceID = iDeviceID; |
147 |
m_deviceType = deviceType; |
m_deviceType = deviceType; |
148 |
|
|
149 |
// Reset device parameters and ports anyway. |
// Reset device parameters and ports anyway. |
150 |
m_params.clear(); |
m_params.clear(); |
151 |
|
qDeleteAll(m_ports); |
152 |
m_ports.clear(); |
m_ports.clear(); |
153 |
|
|
154 |
// Retrieve device info, if any. |
// Retrieve device info, if any. |
157 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
158 |
m_sDeviceType = QObject::tr("Audio"); |
m_sDeviceType = QObject::tr("Audio"); |
159 |
if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_audio_device_info( |
if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_audio_device_info( |
160 |
client(), m_iDeviceID)) == NULL) |
pMainForm->client(), m_iDeviceID)) == NULL) |
161 |
appendMessagesClient("lscp_get_audio_device_info"); |
appendMessagesClient("lscp_get_audio_device_info"); |
162 |
break; |
break; |
163 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
164 |
m_sDeviceType = QObject::tr("MIDI"); |
m_sDeviceType = QObject::tr("MIDI"); |
165 |
if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_midi_device_info( |
if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_midi_device_info( |
166 |
client(), m_iDeviceID)) == NULL) |
pMainForm->client(), m_iDeviceID)) == NULL) |
167 |
appendMessagesClient("lscp_get_midi_device_info"); |
appendMessagesClient("lscp_get_midi_device_info"); |
168 |
break; |
break; |
169 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
188 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
189 |
switch (deviceType) { |
switch (deviceType) { |
190 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
191 |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(client(), |
if ((pParamInfo = ::lscp_get_audio_driver_param_info( |
192 |
m_sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
193 |
|
sParam.toUtf8().constData(), NULL)) == NULL) |
194 |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
195 |
break; |
break; |
196 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
197 |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(client(), |
if ((pParamInfo = ::lscp_get_midi_driver_param_info( |
198 |
m_sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
199 |
|
sParam.toUtf8().constData(), NULL)) == NULL) |
200 |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
201 |
break; |
break; |
202 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
203 |
break; |
break; |
204 |
} |
} |
205 |
if (pParamInfo) { |
if (pParamInfo) { |
206 |
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
m_params[sParam.toUpper()] = qsamplerDeviceParam(pParamInfo, |
207 |
pDeviceInfo->params[i].value); |
pDeviceInfo->params[i].value); |
208 |
} |
} |
209 |
} |
} |
218 |
// Driver name initializer/settler. |
// Driver name initializer/settler. |
219 |
void qsamplerDevice::setDriver ( const QString& sDriverName ) |
void qsamplerDevice::setDriver ( const QString& sDriverName ) |
220 |
{ |
{ |
221 |
|
MainForm *pMainForm = MainForm::getInstance(); |
222 |
|
if (pMainForm == NULL) |
223 |
|
return; |
224 |
|
if (pMainForm->client() == NULL) |
225 |
|
return; |
226 |
|
|
227 |
// Valid only for scratch devices. |
// Valid only for scratch devices. |
228 |
if (m_sDriverName == sDriverName) |
if (m_sDriverName == sDriverName) |
229 |
return; |
return; |
230 |
|
|
231 |
// Reset device parameters and ports anyway. |
// Reset device parameters and ports anyway. |
232 |
m_params.clear(); |
m_params.clear(); |
233 |
|
qDeleteAll(m_ports); |
234 |
m_ports.clear(); |
m_ports.clear(); |
235 |
|
|
236 |
// Retrieve driver info, if any. |
// Retrieve driver info, if any. |
237 |
lscp_driver_info_t *pDriverInfo = NULL; |
lscp_driver_info_t *pDriverInfo = NULL; |
238 |
switch (m_deviceType) { |
switch (m_deviceType) { |
239 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
240 |
if ((pDriverInfo = ::lscp_get_audio_driver_info(client(), |
if ((pDriverInfo = ::lscp_get_audio_driver_info(pMainForm->client(), |
241 |
sDriverName.latin1())) == NULL) |
sDriverName.toUtf8().constData())) == NULL) |
242 |
appendMessagesClient("lscp_get_audio_driver_info"); |
appendMessagesClient("lscp_get_audio_driver_info"); |
243 |
break; |
break; |
244 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
245 |
if ((pDriverInfo = ::lscp_get_midi_driver_info(client(), |
if ((pDriverInfo = ::lscp_get_midi_driver_info(pMainForm->client(), |
246 |
sDriverName.latin1())) == NULL) |
sDriverName.toUtf8().constData())) == NULL) |
247 |
appendMessagesClient("lscp_get_midi_driver_info"); |
appendMessagesClient("lscp_get_midi_driver_info"); |
248 |
break; |
break; |
249 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
263 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
264 |
switch (m_deviceType) { |
switch (m_deviceType) { |
265 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
266 |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(client(), |
if ((pParamInfo = ::lscp_get_audio_driver_param_info( |
267 |
sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
pMainForm->client(), sDriverName.toUtf8().constData(), |
268 |
|
sParam.toUtf8().constData(), NULL)) == NULL) |
269 |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
270 |
break; |
break; |
271 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
272 |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(client(), |
if ((pParamInfo = ::lscp_get_midi_driver_param_info( |
273 |
sDriverName.latin1(), sParam.latin1(), NULL)) == NULL) |
pMainForm->client(), sDriverName.toUtf8().constData(), |
274 |
|
sParam.toUtf8().constData(), NULL)) == NULL) |
275 |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
276 |
break; |
break; |
277 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
278 |
break; |
break; |
279 |
} |
} |
280 |
if (pParamInfo) { |
if (pParamInfo) { |
281 |
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
m_params[sParam.toUpper()] = qsamplerDeviceParam(pParamInfo, |
282 |
pParamInfo->defaultv); |
pParamInfo->defaultv); |
283 |
} |
} |
284 |
} |
} |
290 |
} |
} |
291 |
|
|
292 |
|
|
|
// The client descriptor delegated property. |
|
|
lscp_client_t *qsamplerDevice::client (void) const |
|
|
{ |
|
|
if (m_pMainForm == NULL) |
|
|
return NULL; |
|
|
|
|
|
return m_pMainForm->client(); |
|
|
} |
|
|
|
|
|
|
|
293 |
// Device property accessors. |
// Device property accessors. |
294 |
int qsamplerDevice::deviceID (void) const |
int qsamplerDevice::deviceID (void) const |
295 |
{ |
{ |
296 |
return m_iDeviceID; |
return m_iDeviceID; |
297 |
} |
} |
298 |
|
|
299 |
qsamplerDevice::qsamplerDeviceType qsamplerDevice::deviceType (void) const |
qsamplerDevice::DeviceType qsamplerDevice::deviceType (void) const |
300 |
{ |
{ |
301 |
return m_deviceType; |
return m_deviceType; |
302 |
} |
} |
316 |
{ |
{ |
317 |
QString sPrefix; |
QString sPrefix; |
318 |
if (m_iDeviceID >= 0) |
if (m_iDeviceID >= 0) |
319 |
sPrefix += m_sDeviceType + ' '; |
sPrefix += m_sDeviceType + ' '; |
320 |
return sPrefix + m_sDeviceName; |
return sPrefix + m_sDeviceName; |
321 |
} |
} |
322 |
|
|
325 |
bool qsamplerDevice::setParam ( const QString& sParam, |
bool qsamplerDevice::setParam ( const QString& sParam, |
326 |
const QString& sValue ) |
const QString& sValue ) |
327 |
{ |
{ |
328 |
|
MainForm *pMainForm = MainForm::getInstance(); |
329 |
|
if (pMainForm == NULL) |
330 |
|
return false; |
331 |
|
if (pMainForm->client() == NULL) |
332 |
|
return false; |
333 |
|
|
334 |
// Set proper device parameter. |
// Set proper device parameter. |
335 |
m_params[sParam.upper()].value = sValue; |
m_params[sParam.toUpper()].value = sValue; |
336 |
|
|
337 |
// If the device already exists, things get immediate... |
// If the device already exists, things get immediate... |
338 |
int iRefresh = 0; |
int iRefresh = 0; |
339 |
if (m_iDeviceID >= 0) { |
if (m_iDeviceID >= 0 && sValue != QString::null) { |
340 |
|
|
341 |
|
// we need temporary byte arrrays with the final strings, because |
342 |
|
// i.e. QString::toUtf8() only returns a temporary object and the |
343 |
|
// C-style char* pointers for liblscp would immediately be invalidated |
344 |
|
QByteArray finalParamKey = sParam.toUtf8(); |
345 |
|
QByteArray finalParamVal = sValue.toUtf8(); |
346 |
|
|
347 |
// Prepare parameter struct. |
// Prepare parameter struct. |
348 |
lscp_param_t param; |
lscp_param_t param; |
349 |
param.key = (char *) sParam.latin1(); |
param.key = (char *) finalParamKey.constData(); |
350 |
param.value = (char *) sValue.latin1(); |
param.value = (char *) finalParamVal.constData(); |
351 |
// Now it depends on the device type... |
// Now it depends on the device type... |
352 |
lscp_status_t ret = LSCP_FAILED; |
lscp_status_t ret = LSCP_FAILED; |
353 |
switch (m_deviceType) { |
switch (m_deviceType) { |
354 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
355 |
if (sParam == "CHANNELS") iRefresh++; |
if (sParam == "CHANNELS") iRefresh++; |
356 |
if ((ret = ::lscp_set_audio_device_param(client(), |
if ((ret = ::lscp_set_audio_device_param(pMainForm->client(), |
357 |
m_iDeviceID, ¶m)) != LSCP_OK) |
m_iDeviceID, ¶m)) != LSCP_OK) |
358 |
appendMessagesClient("lscp_set_audio_device_param"); |
appendMessagesClient("lscp_set_audio_device_param"); |
359 |
break; |
break; |
360 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
361 |
if (sParam == "PORTS") iRefresh++; |
if (sParam == "PORTS") iRefresh++; |
362 |
if ((ret = ::lscp_set_midi_device_param(client(), |
if ((ret = ::lscp_set_midi_device_param(pMainForm->client(), |
363 |
m_iDeviceID, ¶m)) != LSCP_OK) |
m_iDeviceID, ¶m)) != LSCP_OK) |
364 |
appendMessagesClient("lscp_set_midi_device_param"); |
appendMessagesClient("lscp_set_midi_device_param"); |
365 |
break; |
break; |
379 |
QObject::tr("Could not set device parameter value.\n\nSorry.")); |
QObject::tr("Could not set device parameter value.\n\nSorry.")); |
380 |
} |
} |
381 |
} |
} |
382 |
|
|
383 |
// Return whether we're need a view refresh. |
// Return whether we're need a view refresh. |
384 |
return (iRefresh > 0); |
return (iRefresh > 0); |
385 |
} |
} |
402 |
// Create a new device, as a copy of this current one. |
// Create a new device, as a copy of this current one. |
403 |
bool qsamplerDevice::createDevice (void) |
bool qsamplerDevice::createDevice (void) |
404 |
{ |
{ |
405 |
if (client() == NULL) |
MainForm *pMainForm = MainForm::getInstance(); |
406 |
|
if (pMainForm == NULL) |
407 |
|
return false; |
408 |
|
if (pMainForm->client() == NULL) |
409 |
return false; |
return false; |
410 |
|
|
411 |
// Build the parameter list... |
// we need temporary lists with the final strings, because i.e. |
412 |
lscp_param_t *pParams = new lscp_param_t [m_params.count() + 1]; |
// QString::toUtf8() only returns a temporary object and the |
413 |
int iParam = 0; |
// C-style char* pointers for liblscp would immediately be invalidated |
414 |
|
QList<QByteArray> finalKeys; |
415 |
|
QList<QByteArray> finalVals; |
416 |
|
|
417 |
qsamplerDeviceParamMap::ConstIterator iter; |
qsamplerDeviceParamMap::ConstIterator iter; |
418 |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
419 |
pParams[iParam].key = (char *) iter.key().latin1(); |
if (iter.value().value == QString::null) continue; |
420 |
pParams[iParam].value = (char *) iter.data().value.latin1(); |
finalKeys.push_back(iter.key().toUtf8()); |
421 |
++iParam; |
finalVals.push_back(iter.value().value.toUtf8()); |
422 |
|
} |
423 |
|
|
424 |
|
// yeah, we DO HAVE to do the two loops separately ! |
425 |
|
|
426 |
|
// Build the parameter list... |
427 |
|
lscp_param_t *pParams = new lscp_param_t [finalKeys.count() + 1]; |
428 |
|
int iParam; |
429 |
|
for (iParam = 0; iParam < finalKeys.count(); iParam++) { |
430 |
|
pParams[iParam].key = (char *) finalKeys[iParam].constData(); |
431 |
|
pParams[iParam].value = (char *) finalVals[iParam].constData(); |
432 |
} |
} |
433 |
// Null terminated. |
// Null terminated. |
434 |
pParams[iParam].key = NULL; |
pParams[iParam].key = NULL; |
437 |
// Now it depends on the device type... |
// Now it depends on the device type... |
438 |
switch (m_deviceType) { |
switch (m_deviceType) { |
439 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
440 |
if ((m_iDeviceID = ::lscp_create_audio_device(client(), |
if ((m_iDeviceID = ::lscp_create_audio_device(pMainForm->client(), |
441 |
m_sDriverName.latin1(), pParams)) < 0) |
m_sDriverName.toUtf8().constData(), pParams)) < 0) |
442 |
appendMessagesClient("lscp_create_audio_device"); |
appendMessagesClient("lscp_create_audio_device"); |
443 |
break; |
break; |
444 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
445 |
if ((m_iDeviceID = ::lscp_create_midi_device(client(), |
if ((m_iDeviceID = ::lscp_create_midi_device(pMainForm->client(), |
446 |
m_sDriverName.latin1(), pParams)) < 0) |
m_sDriverName.toUtf8().constData(), pParams)) < 0) |
447 |
appendMessagesClient("lscp_create_midi_device"); |
appendMessagesClient("lscp_create_midi_device"); |
448 |
break; |
break; |
449 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
455 |
|
|
456 |
// Show result. |
// Show result. |
457 |
if (m_iDeviceID >= 0) { |
if (m_iDeviceID >= 0) { |
458 |
|
// Refresh our own stuff... |
459 |
|
setDevice(m_deviceType, m_iDeviceID); |
460 |
appendMessages(QObject::tr("created.")); |
appendMessages(QObject::tr("created.")); |
461 |
} else { |
} else { |
462 |
appendMessagesError(QObject::tr("Could not create device.\n\nSorry.")); |
appendMessagesError(QObject::tr("Could not create device.\n\nSorry.")); |
463 |
} |
} |
464 |
|
|
465 |
// Return whether we're a valid device... |
// Return whether we're a valid device... |
466 |
return (m_iDeviceID >= 0); |
return (m_iDeviceID >= 0); |
467 |
} |
} |
470 |
// Destroy existing device. |
// Destroy existing device. |
471 |
bool qsamplerDevice::deleteDevice (void) |
bool qsamplerDevice::deleteDevice (void) |
472 |
{ |
{ |
473 |
|
MainForm *pMainForm = MainForm::getInstance(); |
474 |
|
if (pMainForm == NULL) |
475 |
|
return false; |
476 |
|
if (pMainForm->client() == NULL) |
477 |
|
return false; |
478 |
|
|
479 |
// Now it depends on the device type... |
// Now it depends on the device type... |
480 |
lscp_status_t ret = LSCP_FAILED; |
lscp_status_t ret = LSCP_FAILED; |
481 |
switch (m_deviceType) { |
switch (m_deviceType) { |
482 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
483 |
if ((ret = ::lscp_destroy_audio_device(client(), |
if ((ret = ::lscp_destroy_audio_device(pMainForm->client(), |
484 |
m_iDeviceID)) != LSCP_OK) |
m_iDeviceID)) != LSCP_OK) |
485 |
appendMessagesClient("lscp_destroy_audio_device"); |
appendMessagesClient("lscp_destroy_audio_device"); |
486 |
break; |
break; |
487 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
488 |
if ((ret = ::lscp_destroy_midi_device(client(), |
if ((ret = ::lscp_destroy_midi_device(pMainForm->client(), |
489 |
m_iDeviceID)) != LSCP_OK) |
m_iDeviceID)) != LSCP_OK) |
490 |
appendMessagesClient("lscp_destroy_midi_device"); |
appendMessagesClient("lscp_destroy_midi_device"); |
491 |
break; |
break; |
500 |
} else { |
} else { |
501 |
appendMessagesError(QObject::tr("Could not delete device.\n\nSorry.")); |
appendMessagesError(QObject::tr("Could not delete device.\n\nSorry.")); |
502 |
} |
} |
503 |
|
|
504 |
// Return whether we've done it.. |
// Return whether we've done it.. |
505 |
return (ret == LSCP_OK); |
return (ret == LSCP_OK); |
506 |
} |
} |
511 |
{ |
{ |
512 |
// This should only make sense for scratch devices... |
// This should only make sense for scratch devices... |
513 |
if (m_iDeviceID >= 0) |
if (m_iDeviceID >= 0) |
514 |
return 0; |
return 0; |
515 |
// Refresh all parameters that have dependencies... |
// Refresh all parameters that have dependencies... |
516 |
int iParams = 0; |
int iParams = 0; |
517 |
qsamplerDeviceParamMap::ConstIterator iter; |
qsamplerDeviceParamMap::ConstIterator iter; |
527 |
{ |
{ |
528 |
// This should only make sense for actual devices... |
// This should only make sense for actual devices... |
529 |
if (m_iDeviceID < 0) |
if (m_iDeviceID < 0) |
530 |
return 0; |
return 0; |
531 |
// Port/channel count determination... |
// Port/channel count determination... |
532 |
int iPorts = 0; |
int iPorts = 0; |
533 |
switch (m_deviceType) { |
switch (m_deviceType) { |
541 |
break; |
break; |
542 |
} |
} |
543 |
// Retrieve port/channel information... |
// Retrieve port/channel information... |
544 |
|
qDeleteAll(m_ports); |
545 |
m_ports.clear(); |
m_ports.clear(); |
546 |
for (int iPort = 0; iPort < iPorts; iPort++) |
for (int iPort = 0; iPort < iPorts; iPort++) |
547 |
m_ports.append(new qsamplerDevicePort(*this, iPort)); |
m_ports.append(new qsamplerDevicePort(*this, iPort)); |
555 |
{ |
{ |
556 |
// This should only make sense for scratch devices... |
// This should only make sense for scratch devices... |
557 |
if (m_iDeviceID >= 0) |
if (m_iDeviceID >= 0) |
558 |
return 0; |
return 0; |
559 |
// Refresh all parameters that depend on this one... |
// Refresh all parameters that depend on this one... |
560 |
int iDepends = 0; |
int iDepends = 0; |
561 |
qsamplerDeviceParamMap::ConstIterator iter; |
qsamplerDeviceParamMap::ConstIterator iter; |
562 |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
563 |
const QStringList& depends = iter.data().depends; |
const QStringList& depends = iter.value().depends; |
564 |
if (depends.find(sParam) != depends.end()) |
if (depends.indexOf(sParam) >= 0) |
565 |
iDepends += refreshParam(iter.key()); |
iDepends += refreshParam(iter.key()); |
566 |
} |
} |
567 |
// Return how many dependencies have been refreshed... |
// Return how many dependencies have been refreshed... |
572 |
// Refresh/set given parameter based on driver supplied dependencies. |
// Refresh/set given parameter based on driver supplied dependencies. |
573 |
int qsamplerDevice::refreshParam ( const QString& sParam ) |
int qsamplerDevice::refreshParam ( const QString& sParam ) |
574 |
{ |
{ |
575 |
|
MainForm *pMainForm = MainForm::getInstance(); |
576 |
|
if (pMainForm == NULL) |
577 |
|
return 0; |
578 |
|
if (pMainForm->client() == NULL) |
579 |
|
return 0; |
580 |
|
|
581 |
// Check if we have dependencies... |
// Check if we have dependencies... |
582 |
qsamplerDeviceParam& param = m_params[sParam.upper()]; |
qsamplerDeviceParam& param = m_params[sParam.toUpper()]; |
583 |
if (param.depends.isEmpty()) |
if (param.depends.isEmpty()) |
584 |
return 0; |
return 0; |
585 |
|
|
588 |
// Build dependency list... |
// Build dependency list... |
589 |
lscp_param_t *pDepends = new lscp_param_t [param.depends.count() + 1]; |
lscp_param_t *pDepends = new lscp_param_t [param.depends.count() + 1]; |
590 |
int iDepend = 0; |
int iDepend = 0; |
591 |
QStringList::ConstIterator iter; |
|
592 |
for (iter = param.depends.begin(); iter != param.depends.end(); ++iter) { |
// we need temporary lists with the final strings, because i.e. |
593 |
const QString& sDepend = *iter; |
// QString::toUtf8() only returns a temporary object and the |
594 |
pDepends[iDepend].key = (char *) sDepend.latin1(); |
// C-style char* pointers for liblscp would immediately be invalidated |
595 |
pDepends[iDepend].value = (char *) m_params[sDepend.upper()].value.latin1(); |
QList<QByteArray> finalKeys; |
596 |
|
QList<QByteArray> finalVals; |
597 |
|
for (int i = 0; i < param.depends.count(); i++) { |
598 |
|
const QString& sDepend = param.depends[i]; |
599 |
|
finalKeys.push_back(sDepend.toUtf8()); |
600 |
|
finalVals.push_back(m_params[sDepend.toUpper()].value.toUtf8()); |
601 |
|
} |
602 |
|
// yeah, we DO HAVE to do those two loops separately ! |
603 |
|
for (int i = 0; i < param.depends.count(); i++) { |
604 |
|
pDepends[iDepend].key = (char *) finalKeys[i].constData(); |
605 |
|
pDepends[iDepend].value = (char *) finalVals[i].constData(); |
606 |
++iDepend; |
++iDepend; |
607 |
} |
} |
608 |
// Null terminated. |
// Null terminated. |
618 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
619 |
switch (m_deviceType) { |
switch (m_deviceType) { |
620 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
621 |
if ((pParamInfo = ::lscp_get_audio_driver_param_info(client(), |
if ((pParamInfo = ::lscp_get_audio_driver_param_info( |
622 |
m_sDriverName.latin1(), sParam.latin1(), pDepends)) == NULL) |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
623 |
|
sParam.toUtf8().constData(), pDepends)) == NULL) |
624 |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
625 |
break; |
break; |
626 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
627 |
if ((pParamInfo = ::lscp_get_midi_driver_param_info(client(), |
if ((pParamInfo = ::lscp_get_midi_driver_param_info( |
628 |
m_sDriverName.latin1(), sParam.latin1(), pDepends)) == NULL) |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
629 |
|
sParam.toUtf8().constData(), pDepends)) == NULL) |
630 |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
appendMessagesClient("lscp_get_midi_driver_param_info"); |
631 |
break; |
break; |
632 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
633 |
break; |
break; |
634 |
} |
} |
635 |
if (pParamInfo) { |
if (pParamInfo) { |
636 |
param = qsamplerDeviceParam(pParamInfo, QString(param.value)); |
param = qsamplerDeviceParam(pParamInfo, |
637 |
|
param.value.isEmpty() ? NULL : param.value.toUtf8().constData()); |
638 |
iRefresh++; |
iRefresh++; |
639 |
} |
} |
640 |
|
|
649 |
// Redirected messages output methods. |
// Redirected messages output methods. |
650 |
void qsamplerDevice::appendMessages( const QString& s ) const |
void qsamplerDevice::appendMessages( const QString& s ) const |
651 |
{ |
{ |
652 |
if (m_pMainForm) |
MainForm *pMainForm = MainForm::getInstance(); |
653 |
m_pMainForm->appendMessages(deviceName() + ' ' + s); |
if (pMainForm) |
654 |
|
pMainForm->appendMessages(deviceName() + ' ' + s); |
655 |
} |
} |
656 |
|
|
657 |
void qsamplerDevice::appendMessagesColor( const QString& s, |
void qsamplerDevice::appendMessagesColor( const QString& s, |
658 |
const QString& c ) const |
const QString& c ) const |
659 |
{ |
{ |
660 |
if (m_pMainForm) |
MainForm *pMainForm = MainForm::getInstance(); |
661 |
m_pMainForm->appendMessagesColor(deviceName() + ' ' + s, c); |
if (pMainForm) |
662 |
|
pMainForm->appendMessagesColor(deviceName() + ' ' + s, c); |
663 |
} |
} |
664 |
|
|
665 |
void qsamplerDevice::appendMessagesText( const QString& s ) const |
void qsamplerDevice::appendMessagesText( const QString& s ) const |
666 |
{ |
{ |
667 |
if (m_pMainForm) |
MainForm *pMainForm = MainForm::getInstance(); |
668 |
m_pMainForm->appendMessagesText(deviceName() + ' ' + s); |
if (pMainForm) |
669 |
|
pMainForm->appendMessagesText(deviceName() + ' ' + s); |
670 |
} |
} |
671 |
|
|
672 |
void qsamplerDevice::appendMessagesError( const QString& s ) const |
void qsamplerDevice::appendMessagesError( const QString& s ) const |
673 |
{ |
{ |
674 |
if (m_pMainForm) |
MainForm *pMainForm = MainForm::getInstance(); |
675 |
m_pMainForm->appendMessagesError(deviceName() + "\n\n" + s); |
if (pMainForm) |
676 |
|
pMainForm->appendMessagesError(deviceName() + "\n\n" + s); |
677 |
} |
} |
678 |
|
|
679 |
void qsamplerDevice::appendMessagesClient( const QString& s ) const |
void qsamplerDevice::appendMessagesClient( const QString& s ) const |
680 |
{ |
{ |
681 |
if (m_pMainForm) |
MainForm *pMainForm = MainForm::getInstance(); |
682 |
m_pMainForm->appendMessagesClient(deviceName() + ' ' + s); |
if (pMainForm) |
683 |
|
pMainForm->appendMessagesClient(deviceName() + ' ' + s); |
684 |
} |
} |
685 |
|
|
686 |
|
|
687 |
// Device ids enumerator. |
// Device ids enumerator. |
688 |
int *qsamplerDevice::getDevices ( lscp_client_t *pClient, |
int *qsamplerDevice::getDevices ( lscp_client_t *pClient, |
689 |
qsamplerDeviceType deviceType ) |
DeviceType deviceType ) |
690 |
{ |
{ |
691 |
int *piDeviceIDs = NULL; |
int *piDeviceIDs = NULL; |
692 |
switch (deviceType) { |
switch (deviceType) { |
705 |
|
|
706 |
// Driver names enumerator. |
// Driver names enumerator. |
707 |
QStringList qsamplerDevice::getDrivers ( lscp_client_t *pClient, |
QStringList qsamplerDevice::getDrivers ( lscp_client_t *pClient, |
708 |
qsamplerDeviceType deviceType ) |
DeviceType deviceType ) |
709 |
{ |
{ |
710 |
QStringList drivers; |
QStringList drivers; |
711 |
|
|
712 |
const char **ppszDrivers = NULL; |
const char **ppszDrivers = NULL; |
713 |
switch (deviceType) { |
switch (deviceType) { |
714 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
715 |
ppszDrivers = ::lscp_get_available_audio_drivers(pClient); |
ppszDrivers = ::lscp_list_available_audio_drivers(pClient); |
716 |
break; |
break; |
717 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
718 |
ppszDrivers = ::lscp_get_available_midi_drivers(pClient); |
ppszDrivers = ::lscp_list_available_midi_drivers(pClient); |
719 |
break; |
break; |
720 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
721 |
break; |
break; |
722 |
} |
} |
723 |
|
|
724 |
for (int iDriver = 0; ppszDrivers[iDriver]; iDriver++) |
for (int iDriver = 0; ppszDrivers && ppszDrivers[iDriver]; iDriver++) |
725 |
drivers.append(ppszDrivers[iDriver]); |
drivers.append(ppszDrivers[iDriver]); |
726 |
|
|
727 |
return drivers; |
return drivers; |
748 |
// Initializer. |
// Initializer. |
749 |
void qsamplerDevicePort::setDevicePort ( int iPortID ) |
void qsamplerDevicePort::setDevicePort ( int iPortID ) |
750 |
{ |
{ |
751 |
|
MainForm *pMainForm = MainForm::getInstance(); |
752 |
|
if (pMainForm == NULL) |
753 |
|
return; |
754 |
|
if (pMainForm->client() == NULL) |
755 |
|
return; |
756 |
|
|
757 |
// Device port id should be always set. |
// Device port id should be always set. |
758 |
m_iPortID = iPortID; |
m_iPortID = iPortID; |
759 |
|
|
764 |
lscp_device_port_info_t *pPortInfo = NULL; |
lscp_device_port_info_t *pPortInfo = NULL; |
765 |
switch (m_device.deviceType()) { |
switch (m_device.deviceType()) { |
766 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
767 |
if ((pPortInfo = ::lscp_get_audio_channel_info(m_device.client(), |
if ((pPortInfo = ::lscp_get_audio_channel_info(pMainForm->client(), |
768 |
m_device.deviceID(), m_iPortID)) == NULL) |
m_device.deviceID(), m_iPortID)) == NULL) |
769 |
m_device.appendMessagesClient("lscp_get_audio_channel_info"); |
m_device.appendMessagesClient("lscp_get_audio_channel_info"); |
770 |
break; |
break; |
771 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
772 |
if ((pPortInfo = ::lscp_get_midi_port_info(m_device.client(), |
if ((pPortInfo = ::lscp_get_midi_port_info(pMainForm->client(), |
773 |
m_device.deviceID(), m_iPortID)) == NULL) |
m_device.deviceID(), m_iPortID)) == NULL) |
774 |
m_device.appendMessagesClient("lscp_get_midi_port_info"); |
m_device.appendMessagesClient("lscp_get_midi_port_info"); |
775 |
break; |
break; |
794 |
switch (m_device.deviceType()) { |
switch (m_device.deviceType()) { |
795 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
796 |
if ((pParamInfo = ::lscp_get_audio_channel_param_info( |
if ((pParamInfo = ::lscp_get_audio_channel_param_info( |
797 |
m_device.client(), m_device.deviceID(), |
pMainForm->client(), m_device.deviceID(), |
798 |
m_iPortID, sParam.latin1())) == NULL) |
m_iPortID, sParam.toUtf8().constData())) == NULL) |
799 |
m_device.appendMessagesClient("lscp_get_audio_channel_param_info"); |
m_device.appendMessagesClient("lscp_get_audio_channel_param_info"); |
800 |
break; |
break; |
801 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
802 |
if ((pParamInfo = ::lscp_get_midi_port_param_info( |
if ((pParamInfo = ::lscp_get_midi_port_param_info( |
803 |
m_device.client(), m_device.deviceID(), |
pMainForm->client(), m_device.deviceID(), |
804 |
m_iPortID, sParam.latin1())) == NULL) |
m_iPortID, sParam.toUtf8().constData())) == NULL) |
805 |
m_device.appendMessagesClient("lscp_get_midi_port_param_info"); |
m_device.appendMessagesClient("lscp_get_midi_port_param_info"); |
806 |
break; |
break; |
807 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
808 |
break; |
break; |
809 |
} |
} |
810 |
if (pParamInfo) { |
if (pParamInfo) { |
811 |
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
m_params[sParam.toUpper()] = qsamplerDeviceParam(pParamInfo, |
812 |
pPortInfo->params[i].value); |
pPortInfo->params[i].value); |
813 |
} |
} |
814 |
} |
} |
837 |
bool qsamplerDevicePort::setParam ( const QString& sParam, |
bool qsamplerDevicePort::setParam ( const QString& sParam, |
838 |
const QString& sValue ) |
const QString& sValue ) |
839 |
{ |
{ |
840 |
|
MainForm *pMainForm = MainForm::getInstance(); |
841 |
|
if (pMainForm == NULL) |
842 |
|
return false; |
843 |
|
if (pMainForm->client() == NULL) |
844 |
|
return false; |
845 |
|
|
846 |
// Set proper port/channel parameter. |
// Set proper port/channel parameter. |
847 |
m_params[sParam.upper()].value = sValue; |
m_params[sParam.toUpper()].value = sValue; |
848 |
|
|
849 |
// If the device already exists, things get immediate... |
// If the device already exists, things get immediate... |
850 |
int iRefresh = 0; |
int iRefresh = 0; |
851 |
if (m_device.deviceID() >= 0 && m_iPortID >= 0) { |
if (m_device.deviceID() >= 0 && m_iPortID >= 0) { |
852 |
|
|
853 |
|
// we need temporary byte arrrays with the final strings, because |
854 |
|
// i.e. QString::toUtf8() only returns a temporary object and the |
855 |
|
// C-style char* pointers for liblscp would immediately be invalidated |
856 |
|
QByteArray finalParamKey = sParam.toUtf8(); |
857 |
|
QByteArray finalParamVal = sValue.toUtf8(); |
858 |
|
|
859 |
// Prepare parameter struct. |
// Prepare parameter struct. |
860 |
lscp_param_t param; |
lscp_param_t param; |
861 |
param.key = (char *) sParam.latin1(); |
param.key = (char *) finalParamKey.constData(); |
862 |
param.value = (char *) sValue.latin1(); |
param.value = (char *) finalParamVal.constData(); |
863 |
// Now it depends on the device type... |
// Now it depends on the device type... |
864 |
lscp_status_t ret = LSCP_FAILED; |
lscp_status_t ret = LSCP_FAILED; |
865 |
switch (m_device.deviceType()) { |
switch (m_device.deviceType()) { |
866 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
867 |
if ((ret = ::lscp_set_audio_channel_param(m_device.client(), |
if ((ret = ::lscp_set_audio_channel_param(pMainForm->client(), |
868 |
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
869 |
m_device.appendMessagesClient("lscp_set_audio_channel_param"); |
m_device.appendMessagesClient("lscp_set_audio_channel_param"); |
870 |
break; |
break; |
871 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
872 |
if ((ret = ::lscp_set_midi_port_param(m_device.client(), |
if ((ret = ::lscp_set_midi_port_param(pMainForm->client(), |
873 |
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
874 |
m_device.appendMessagesClient("lscp_set_midi_port_param"); |
m_device.appendMessagesClient("lscp_set_midi_port_param"); |
875 |
break; |
break; |
894 |
|
|
895 |
|
|
896 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
897 |
// qsamplerDeviceItem - QListView device item. |
// qsamplerDeviceItem - QTreeWidget device item. |
898 |
// |
// |
899 |
|
|
900 |
// Constructors. |
// Constructors. |
901 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListView *pListView, |
qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidget* pTreeWidget, |
902 |
qsamplerMainForm *pMainForm, qsamplerDevice::qsamplerDeviceType deviceType ) |
qsamplerDevice::DeviceType deviceType ) |
903 |
: QListViewItem(pListView), m_device(pMainForm, deviceType) |
: QTreeWidgetItem(pTreeWidget, QSAMPLER_DEVICE_ITEM), |
904 |
|
m_device(deviceType) |
905 |
{ |
{ |
906 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
907 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
908 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio1.png")); |
setIcon(0, QPixmap(":/icons/audio1.png")); |
909 |
QListViewItem::setText(0, QObject::tr("Audio Devices")); |
setText(0, QObject::tr("Audio Devices")); |
910 |
break; |
break; |
911 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
912 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi1.png")); |
setIcon(0, QPixmap(":/icons/midi1.png")); |
913 |
QListViewItem::setText(0, QObject::tr("MIDI Devices")); |
setText(0, QObject::tr("MIDI Devices")); |
914 |
break; |
break; |
915 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
916 |
break; |
break; |
917 |
} |
} |
918 |
} |
} |
919 |
|
|
920 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListViewItem *pItem, |
qsamplerDeviceItem::qsamplerDeviceItem ( QTreeWidgetItem* pItem, |
921 |
qsamplerMainForm *pMainForm, qsamplerDevice::qsamplerDeviceType deviceType, |
qsamplerDevice::DeviceType deviceType, |
922 |
int iDeviceID ) |
int iDeviceID ) |
923 |
: QListViewItem(pItem), m_device(pMainForm, deviceType, iDeviceID) |
: QTreeWidgetItem(pItem, QSAMPLER_DEVICE_ITEM), |
924 |
|
m_device(deviceType, iDeviceID) |
925 |
{ |
{ |
926 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
927 |
case qsamplerDevice::Audio: |
case qsamplerDevice::Audio: |
928 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio2.png")); |
setIcon(0, QPixmap(":/icons/audio2.png")); |
929 |
break; |
break; |
930 |
case qsamplerDevice::Midi: |
case qsamplerDevice::Midi: |
931 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi2.png")); |
setIcon(0, QPixmap(":/icons/midi2.png")); |
932 |
break; |
break; |
933 |
case qsamplerDevice::None: |
case qsamplerDevice::None: |
934 |
break; |
break; |
935 |
} |
} |
936 |
|
|
937 |
QListViewItem::setText(0, m_device.deviceName()); |
setText(0, m_device.deviceName()); |
938 |
} |
} |
939 |
|
|
940 |
// Default destructor. |
// Default destructor. |
941 |
qsamplerDeviceItem::~qsamplerDeviceItem (void) |
qsamplerDeviceItem::~qsamplerDeviceItem () |
942 |
{ |
{ |
943 |
} |
} |
944 |
|
|
945 |
// Instance accessors. |
// Instance accessors. |
946 |
qsamplerDevice& qsamplerDeviceItem::device (void) |
qsamplerDevice& qsamplerDeviceItem::device () |
947 |
{ |
{ |
948 |
return m_device; |
return m_device; |
949 |
} |
} |
950 |
|
|
951 |
// To virtually distinguish between list view items. |
|
952 |
int qsamplerDeviceItem::rtti() const |
//------------------------------------------------------------------------- |
953 |
|
// AbstractDeviceParamModel - data model base class for device parameters |
954 |
|
// |
955 |
|
|
956 |
|
AbstractDeviceParamModel::AbstractDeviceParamModel ( QObject* pParent ) |
957 |
|
: QAbstractTableModel(pParent), m_bEditable(false) |
958 |
{ |
{ |
959 |
return QSAMPLER_DEVICE_ITEM; |
m_pParams = NULL; |
960 |
} |
} |
961 |
|
|
962 |
|
|
963 |
|
int AbstractDeviceParamModel::rowCount ( const QModelIndex& /*parent*/) const |
964 |
|
{ |
965 |
|
//std::cout << "model size=" << params.size() << "\n" << std::flush; |
966 |
|
return (m_pParams ? m_pParams->size() : 0); |
967 |
|
} |
968 |
|
|
|
//------------------------------------------------------------------------- |
|
|
// qsamplerDeviceParamTable - Device parameter view table. |
|
|
// |
|
969 |
|
|
970 |
// Constructor. |
int AbstractDeviceParamModel::columnCount ( const QModelIndex& /*parent*/) const |
971 |
qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, |
{ |
972 |
const char *pszName ) |
return 3; |
|
: 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); |
|
973 |
} |
} |
974 |
|
|
975 |
// Default destructor. |
|
976 |
qsamplerDeviceParamTable::~qsamplerDeviceParamTable (void) |
Qt::ItemFlags AbstractDeviceParamModel::flags ( const QModelIndex& /*index*/) const |
977 |
{ |
{ |
978 |
|
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled; |
979 |
} |
} |
980 |
|
|
981 |
|
|
982 |
// Common parameter table renderer. |
QVariant AbstractDeviceParamModel::headerData ( |
983 |
void qsamplerDeviceParamTable::refresh ( const qsamplerDeviceParamMap& params, |
int section, Qt::Orientation orientation, int role) const |
|
bool bEditable ) |
|
984 |
{ |
{ |
985 |
// Always (re)start it empty. |
if (role != Qt::DisplayRole) |
986 |
QTable::setUpdatesEnabled(false); |
return QVariant(); |
|
QTable::setNumRows(0); |
|
987 |
|
|
988 |
// Fill the parameter table... |
if (orientation == Qt::Horizontal) { |
989 |
QTable::insertRows(0, params.count()); |
switch (section) { |
990 |
int iRow = 0; |
case 0: return tr("Parameter"); |
991 |
qsamplerDeviceParamMap::ConstIterator iter; |
case 1: return tr("Value"); |
992 |
for (iter = params.begin(); iter != params.end(); ++iter) { |
case 2: return tr("Description"); |
993 |
const qsamplerDeviceParam& param = iter.data(); |
default: return QVariant(); |
|
bool bEnabled = (bEditable || !param.fix); |
|
|
QTable::setText(iRow, 0, iter.key()); |
|
|
QTable::setText(iRow, 1, param.description); |
|
|
if (param.type == LSCP_TYPE_BOOL) { |
|
|
QStringList opts; |
|
|
opts.append(tr("false")); |
|
|
opts.append(tr("true")); |
|
|
QComboTableItem *pComboItem = new QComboTableItem(this, opts); |
|
|
pComboItem->setCurrentItem(param.value.lower() == "true" ? 1 : 0); |
|
|
pComboItem->setEnabled(bEnabled); |
|
|
QTable::setItem(iRow, 2, pComboItem); |
|
|
} else if (param.possibilities.count() > 0 && bEnabled) { |
|
|
QComboTableItem *pComboItem = new QComboTableItem(this, |
|
|
param.possibilities); |
|
|
pComboItem->setCurrentItem(param.value); |
|
|
pComboItem->setEnabled(bEnabled); |
|
|
// pComboItem->setEditable(bEnabled && param.multiplicity); |
|
|
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); |
|
994 |
} |
} |
|
++iRow; |
|
995 |
} |
} |
996 |
|
|
997 |
// Adjust optimal column widths. |
return QVariant(); |
998 |
QTable::adjustColumn(0); |
} |
999 |
QTable::adjustColumn(2); |
|
1000 |
|
|
1001 |
QTable::setUpdatesEnabled(true); |
void AbstractDeviceParamModel::refresh ( |
1002 |
QTable::updateContents(); |
const qsamplerDeviceParamMap* pParams, bool bEditable ) |
1003 |
|
{ |
1004 |
|
m_pParams = pParams; |
1005 |
|
m_bEditable = bEditable; |
1006 |
|
// inform the outer world (QTableView) that our data changed |
1007 |
|
QAbstractTableModel::reset(); |
1008 |
|
} |
1009 |
|
|
1010 |
|
|
1011 |
|
void AbstractDeviceParamModel::clear (void) |
1012 |
|
{ |
1013 |
|
m_pParams = NULL; |
1014 |
|
// inform the outer world (QTableView) that our data changed |
1015 |
|
QAbstractTableModel::reset(); |
1016 |
} |
} |
1017 |
|
|
1018 |
|
|
1019 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
1020 |
// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. |
// DeviceParamModel - data model for device parameters (used for QTableView) |
1021 |
// |
// |
1022 |
|
|
1023 |
// Constructor. |
DeviceParamModel::DeviceParamModel ( QObject *pParent ) |
1024 |
qsamplerDeviceParamTableSpinBox::qsamplerDeviceParamTableSpinBox ( |
: AbstractDeviceParamModel(pParent) |
|
QTable *pTable, EditType editType, const QString& sText ) |
|
|
: QTableItem(pTable, editType, sText) |
|
1025 |
{ |
{ |
1026 |
m_iValue = sText.toInt(); |
m_pDevice = NULL; |
|
m_iMinValue = m_iMaxValue = 0; |
|
1027 |
} |
} |
1028 |
|
|
1029 |
// Public accessors. |
QVariant DeviceParamModel::data ( |
1030 |
void qsamplerDeviceParamTableSpinBox::setValue ( int iValue ) |
const QModelIndex &index, int role) const |
1031 |
{ |
{ |
1032 |
m_iValue = iValue; |
if (!index.isValid()) |
1033 |
QTableItem::setText(QString::number(m_iValue)); |
return QVariant(); |
1034 |
|
|
1035 |
|
if (role != Qt::DisplayRole) |
1036 |
|
return QVariant(); |
1037 |
|
|
1038 |
|
DeviceParameterRow item; |
1039 |
|
item.name = m_pParams->keys()[index.row()]; |
1040 |
|
item.param = (*m_pParams)[item.name]; |
1041 |
|
item.alive = (m_pDevice && m_pDevice->deviceID() >= 0); |
1042 |
|
|
1043 |
|
return QVariant::fromValue(item); |
1044 |
} |
} |
1045 |
|
|
1046 |
void qsamplerDeviceParamTableSpinBox::setMinValue ( int iMinValue ) |
|
1047 |
|
bool DeviceParamModel::setData ( |
1048 |
|
const QModelIndex& index, const QVariant& value, int /*role*/) |
1049 |
{ |
{ |
1050 |
m_iMinValue = iMinValue; |
if (!index.isValid()) |
1051 |
|
return false; |
1052 |
|
|
1053 |
|
QString key = m_pParams->keys()[index.row()]; |
1054 |
|
//m_pParams[key].value = value.toString(); |
1055 |
|
m_pDevice->setParam(key, value.toString()); |
1056 |
|
emit dataChanged(index, index); |
1057 |
|
return true; |
1058 |
} |
} |
1059 |
|
|
1060 |
void qsamplerDeviceParamTableSpinBox::setMaxValue ( int iMaxValue ) |
|
1061 |
|
void DeviceParamModel::refresh ( qsamplerDevice* pDevice, bool bEditable ) |
1062 |
{ |
{ |
1063 |
m_iMaxValue = iMaxValue; |
m_pDevice = pDevice; |
1064 |
|
AbstractDeviceParamModel::refresh(&pDevice->params(), bEditable); |
1065 |
} |
} |
1066 |
|
|
1067 |
// Virtual implemetations. |
|
1068 |
QWidget *qsamplerDeviceParamTableSpinBox::createEditor (void) const |
void DeviceParamModel::clear (void) |
1069 |
{ |
{ |
1070 |
QSpinBox *pSpinBox = new QSpinBox(QTableItem::table()->viewport()); |
AbstractDeviceParamModel::clear(); |
1071 |
QObject::connect(pSpinBox, SIGNAL(valueChanged(int)), |
m_pDevice = NULL; |
|
QTableItem::table(), SLOT(doValueChanged())); |
|
|
if (m_iValue >= m_iMinValue && m_iMaxValue >= m_iValue) { |
|
|
pSpinBox->setMinValue(m_iMinValue); |
|
|
pSpinBox->setMaxValue(m_iMaxValue); |
|
|
} |
|
|
pSpinBox->setValue(m_iValue); |
|
|
return pSpinBox; |
|
1072 |
} |
} |
1073 |
|
|
1074 |
void qsamplerDeviceParamTableSpinBox::setContentFromEditor ( QWidget *pWidget ) |
|
1075 |
|
//------------------------------------------------------------------------- |
1076 |
|
// PortParamModel - data model for port parameters (used for QTableView) |
1077 |
|
// |
1078 |
|
|
1079 |
|
PortParamModel::PortParamModel ( QObject *pParent) |
1080 |
|
: AbstractDeviceParamModel(pParent) |
1081 |
{ |
{ |
1082 |
if (pWidget->inherits("QSpinBox")) |
m_pPort = NULL; |
1083 |
QTableItem::setText(QString::number(((QSpinBox *) pWidget)->value())); |
} |
1084 |
else |
|
1085 |
QTableItem::setContentFromEditor(pWidget); |
QVariant PortParamModel::data ( const QModelIndex &index, int role ) const |
1086 |
|
{ |
1087 |
|
if (!index.isValid()) |
1088 |
|
return QVariant(); |
1089 |
|
|
1090 |
|
if (role != Qt::DisplayRole) |
1091 |
|
return QVariant(); |
1092 |
|
|
1093 |
|
DeviceParameterRow item; |
1094 |
|
item.name = m_pParams->keys()[index.row()]; |
1095 |
|
item.param = (*m_pParams)[item.name]; |
1096 |
|
item.alive = (m_pPort && m_pPort->portID() >= 0); |
1097 |
|
|
1098 |
|
return QVariant::fromValue(item); |
1099 |
|
} |
1100 |
|
|
1101 |
|
|
1102 |
|
bool PortParamModel::setData ( |
1103 |
|
const QModelIndex& index, const QVariant& value, int /*role*/) |
1104 |
|
{ |
1105 |
|
if (!index.isValid()) |
1106 |
|
return false; |
1107 |
|
|
1108 |
|
QString key = m_pParams->keys()[index.row()]; |
1109 |
|
//params[key].value = value.toString(); |
1110 |
|
m_pPort->setParam(key, value.toString()); |
1111 |
|
emit dataChanged(index, index); |
1112 |
|
return true; |
1113 |
|
} |
1114 |
|
|
1115 |
|
|
1116 |
|
void PortParamModel::refresh ( qsamplerDevicePort* pPort, bool bEditable ) |
1117 |
|
{ |
1118 |
|
m_pPort = pPort; |
1119 |
|
AbstractDeviceParamModel::refresh(&pPort->params(), bEditable); |
1120 |
|
} |
1121 |
|
|
1122 |
|
|
1123 |
|
void PortParamModel::clear (void) |
1124 |
|
{ |
1125 |
|
AbstractDeviceParamModel::clear(); |
1126 |
|
m_pPort = NULL; |
1127 |
} |
} |
1128 |
|
|
1129 |
|
|
1130 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
1131 |
// qsamplerDeviceParamTableEditBox - Custom edit box for parameter table. |
// DeviceParamDelegate - table cell renderer for device/port parameters |
1132 |
// |
// |
1133 |
|
|
1134 |
// Constructor. |
DeviceParamDelegate::DeviceParamDelegate ( QObject *pParent) |
1135 |
qsamplerDeviceParamTableEditBox::qsamplerDeviceParamTableEditBox ( |
: QItemDelegate(pParent) |
|
QTable *pTable, EditType editType, const QString& sText ) |
|
|
: QTableItem(pTable, editType, sText) |
|
1136 |
{ |
{ |
1137 |
} |
} |
1138 |
|
|
1139 |
// Virtual implemetations. |
|
1140 |
QWidget *qsamplerDeviceParamTableEditBox::createEditor (void) const |
QWidget* DeviceParamDelegate::createEditor ( QWidget *pParent, |
1141 |
|
const QStyleOptionViewItem& /* option */, const QModelIndex& index ) const |
1142 |
{ |
{ |
1143 |
QLineEdit *pEditBox = new QLineEdit(QTableItem::table()->viewport()); |
if (!index.isValid()) |
1144 |
QObject::connect(pEditBox, SIGNAL(returnPressed()), |
return NULL; |
1145 |
QTableItem::table(), SLOT(doValueChanged())); |
|
1146 |
pEditBox->setText(QTableItem::text()); |
DeviceParameterRow r = index.model()->data(index, |
1147 |
return pEditBox; |
Qt::DisplayRole).value<DeviceParameterRow>(); |
1148 |
|
|
1149 |
|
const bool bEnabled = (r.alive) ? !r.param.fix : true; |
1150 |
|
|
1151 |
|
QString val = (r.alive) ? r.param.value : r.param.defaultv; |
1152 |
|
|
1153 |
|
switch (index.column()) { |
1154 |
|
case 0: |
1155 |
|
return new QLabel(r.name, pParent); |
1156 |
|
case 1: { |
1157 |
|
if (r.param.type == LSCP_TYPE_BOOL) { |
1158 |
|
QCheckBox *pCheckBox = new QCheckBox(pParent); |
1159 |
|
if (val != QString::null) |
1160 |
|
pCheckBox->setChecked(val.toLower() == "true"); |
1161 |
|
pCheckBox->setEnabled(bEnabled); |
1162 |
|
return pCheckBox; |
1163 |
|
} else if (r.param.possibilities.count() > 0) { |
1164 |
|
QStringList opts = r.param.possibilities; |
1165 |
|
if (r.param.multiplicity) |
1166 |
|
opts.prepend(tr("(none)")); |
1167 |
|
QComboBox *pComboBox = new QComboBox(pParent); |
1168 |
|
pComboBox->addItems(opts); |
1169 |
|
if (r.param.value.isEmpty()) |
1170 |
|
pComboBox->setCurrentIndex(0); |
1171 |
|
else |
1172 |
|
pComboBox->setCurrentIndex(pComboBox->findText(val)); |
1173 |
|
pComboBox->setEnabled(bEnabled); |
1174 |
|
return pComboBox; |
1175 |
|
} else if (r.param.type == LSCP_TYPE_INT && bEnabled) { |
1176 |
|
QSpinBox *pSpinBox = new QSpinBox(pParent); |
1177 |
|
pSpinBox->setMinimum( |
1178 |
|
(!r.param.range_min.isEmpty()) ? |
1179 |
|
r.param.range_min.toInt() : 0 // or better a negative default min value ? |
1180 |
|
); |
1181 |
|
pSpinBox->setMaximum( |
1182 |
|
(!r.param.range_max.isEmpty()) ? |
1183 |
|
r.param.range_max.toInt() : (1 << 16) // or better a nigher default max value ? |
1184 |
|
); |
1185 |
|
pSpinBox->setValue(val.toInt()); |
1186 |
|
return pSpinBox; |
1187 |
|
} else if (bEnabled) { |
1188 |
|
QLineEdit *pLineEdit = new QLineEdit(val, pParent); |
1189 |
|
return pLineEdit; |
1190 |
|
} else { |
1191 |
|
QLabel *pLabel = new QLabel(val, pParent); |
1192 |
|
return pLabel; |
1193 |
|
} |
1194 |
|
} |
1195 |
|
case 2: |
1196 |
|
return new QLabel(r.param.description, pParent); |
1197 |
|
default: |
1198 |
|
return NULL; |
1199 |
|
} |
1200 |
} |
} |
1201 |
|
|
1202 |
void qsamplerDeviceParamTableEditBox::setContentFromEditor ( QWidget *pWidget ) |
|
1203 |
{ |
void DeviceParamDelegate::setEditorData ( |
1204 |
if (pWidget->inherits("QLineEdit")) |
QWidget* /*pEditor*/, const QModelIndex& /*index*/) const |
1205 |
QTableItem::setText(((QLineEdit *) pWidget)->text()); |
{ |
1206 |
else |
// Unused, since we set the editor data already in createEditor() |
1207 |
QTableItem::setContentFromEditor(pWidget); |
} |
1208 |
|
|
1209 |
|
|
1210 |
|
void DeviceParamDelegate::setModelData ( QWidget *pEditor, |
1211 |
|
QAbstractItemModel *pModel, const QModelIndex& index ) const |
1212 |
|
{ |
1213 |
|
if (index.column() == 1) { |
1214 |
|
DeviceParameterRow r = index.model()->data(index, |
1215 |
|
Qt::DisplayRole).value<DeviceParameterRow> (); |
1216 |
|
if (pEditor->metaObject()->className() == QString("QCheckBox")) { |
1217 |
|
QCheckBox* pCheckBox = static_cast<QCheckBox*> (pEditor); |
1218 |
|
pModel->setData(index, QVariant(pCheckBox->checkState() == Qt::Checked)); |
1219 |
|
} else if (pEditor->metaObject()->className() == QString("QComboBox")) { |
1220 |
|
QComboBox* pComboBox = static_cast<QComboBox*> (pEditor); |
1221 |
|
pModel->setData(index, pComboBox->currentText()); |
1222 |
|
} else if (pEditor->metaObject()->className() == QString("QSpinBox")) { |
1223 |
|
QSpinBox* pSpinBox = static_cast<QSpinBox*> (pEditor); |
1224 |
|
pModel->setData(index, pSpinBox->value()); |
1225 |
|
} else if (pEditor->metaObject()->className() == QString("QLineEdit")) { |
1226 |
|
QLineEdit* pLineEdit = static_cast<QLineEdit*> (pEditor); |
1227 |
|
pModel->setData(index, pLineEdit->text()); |
1228 |
|
} else if (pEditor->metaObject()->className() == QString("QLabel")) { |
1229 |
|
QLabel* pLabel = static_cast<QLabel*> (pEditor); |
1230 |
|
pModel->setData(index, pLabel->text()); |
1231 |
|
} |
1232 |
|
} |
1233 |
} |
} |
1234 |
|
|
1235 |
|
void DeviceParamDelegate::updateEditorGeometry ( QWidget *pEditor, |
1236 |
|
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
1237 |
|
{ |
1238 |
|
if (pEditor) |
1239 |
|
pEditor->setGeometry(option.rect); |
1240 |
|
} |
1241 |
|
|
1242 |
// end of qsamplerDevice.cpp |
// end of qsamplerDevice.cpp |