1 |
// qsamplerDevice.cpp |
// qsamplerDevice.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2005, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2012, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
|
Copyright (C) 2007, 2008 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 |
|
namespace QSampler { |
35 |
|
|
36 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
37 |
// qsamplerDeviceParam - MIDI/Audio Device parameter structure. |
// QSampler::DeviceParam - MIDI/Audio Device parameter structure. |
38 |
// |
// |
39 |
|
|
40 |
// Constructors. |
// Constructors. |
41 |
qsamplerDeviceParam::qsamplerDeviceParam ( lscp_param_info_t *pParamInfo, |
DeviceParam::DeviceParam ( lscp_param_info_t *pParamInfo, |
42 |
const char *pszValue ) |
const char *pszValue ) |
43 |
{ |
{ |
44 |
setParam(pParamInfo, pszValue); |
setParam(pParamInfo, pszValue); |
46 |
|
|
47 |
|
|
48 |
// Default destructor. |
// Default destructor. |
49 |
qsamplerDeviceParam::~qsamplerDeviceParam (void) |
DeviceParam::~DeviceParam (void) |
50 |
{ |
{ |
51 |
} |
} |
52 |
|
|
53 |
|
|
54 |
// Initializer. |
// Initializer. |
55 |
void qsamplerDeviceParam::setParam ( lscp_param_info_t *pParamInfo, |
void DeviceParam::setParam ( lscp_param_info_t *pParamInfo, |
56 |
const char *pszValue ) |
const char *pszValue ) |
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->multiplicity; |
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; |
103 |
|
|
104 |
|
|
105 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
106 |
// qsamplerDevice - MIDI/Audio Device structure. |
// QSampler::Device - MIDI/Audio Device structure. |
107 |
// |
// |
108 |
|
|
109 |
// Constructor. |
// Constructor. |
110 |
qsamplerDevice::qsamplerDevice ( lscp_client_t *pClient, |
Device::Device ( DeviceType deviceType, int iDeviceID ) |
|
qsamplerDeviceType deviceType, int iDeviceID ) |
|
111 |
{ |
{ |
112 |
m_ports.setAutoDelete(true); |
// m_ports.setAutoDelete(true); |
113 |
|
|
114 |
setDevice(pClient, deviceType, iDeviceID); |
setDevice(deviceType, iDeviceID); |
115 |
} |
} |
116 |
|
|
117 |
// Default destructor. |
// Default destructor. |
118 |
qsamplerDevice::~qsamplerDevice (void) |
Device::~Device (void) |
119 |
{ |
{ |
120 |
|
qDeleteAll(m_ports); |
121 |
|
m_ports.clear(); |
122 |
|
} |
123 |
|
|
124 |
|
// Copy constructor. |
125 |
|
Device::Device ( const Device& device ) |
126 |
|
: m_params(device.m_params), m_ports(device.m_ports) |
127 |
|
{ |
128 |
|
m_iDeviceID = device.m_iDeviceID; |
129 |
|
m_deviceType = device.m_deviceType; |
130 |
|
m_sDeviceType = device.m_sDeviceType; |
131 |
|
m_sDriverName = device.m_sDriverName; |
132 |
|
m_sDeviceName = device.m_sDeviceName; |
133 |
} |
} |
134 |
|
|
135 |
|
|
136 |
// Initializer. |
// Initializer. |
137 |
void qsamplerDevice::setDevice ( lscp_client_t *pClient, |
void Device::setDevice ( DeviceType deviceType, int iDeviceID ) |
|
qsamplerDeviceType 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. |
155 |
lscp_device_info_t *pDeviceInfo = NULL; |
lscp_device_info_t *pDeviceInfo = NULL; |
156 |
switch (deviceType) { |
switch (deviceType) { |
157 |
case qsamplerDevice::Audio: |
case Device::Audio: |
158 |
m_sDeviceType = QObject::tr("Audio"); |
m_sDeviceType = QObject::tr("Audio"); |
159 |
pDeviceInfo = ::lscp_get_audio_device_info(pClient, iDeviceID); |
if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_audio_device_info( |
160 |
|
pMainForm->client(), m_iDeviceID)) == NULL) |
161 |
|
appendMessagesClient("lscp_get_audio_device_info"); |
162 |
break; |
break; |
163 |
case qsamplerDevice::Midi: |
case Device::Midi: |
164 |
m_sDeviceType = QObject::tr("MIDI"); |
m_sDeviceType = QObject::tr("MIDI"); |
165 |
pDeviceInfo = ::lscp_get_midi_device_info(pClient, iDeviceID); |
if (m_iDeviceID >= 0 && (pDeviceInfo = ::lscp_get_midi_device_info( |
166 |
|
pMainForm->client(), m_iDeviceID)) == NULL) |
167 |
|
appendMessagesClient("lscp_get_midi_device_info"); |
168 |
break; |
break; |
169 |
case qsamplerDevice::None: |
case Device::None: |
170 |
m_sDeviceType = QString::null; |
m_sDeviceType = QString::null; |
171 |
break; |
break; |
172 |
} |
} |
|
|
|
173 |
// If we're bogus, bail out... |
// If we're bogus, bail out... |
174 |
if (pDeviceInfo == NULL) { |
if (pDeviceInfo == NULL) { |
175 |
m_sDriverName = QString::null; |
m_sDriverName = QString::null; |
187 |
const QString sParam = pDeviceInfo->params[i].key; |
const QString sParam = pDeviceInfo->params[i].key; |
188 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
189 |
switch (deviceType) { |
switch (deviceType) { |
190 |
case qsamplerDevice::Audio: |
case Device::Audio: |
191 |
pParamInfo = ::lscp_get_audio_driver_param_info(pClient, |
if ((pParamInfo = ::lscp_get_audio_driver_param_info( |
192 |
m_sDriverName.latin1(), sParam.latin1(), NULL); |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
193 |
break; |
sParam.toUtf8().constData(), NULL)) == NULL) |
194 |
case qsamplerDevice::Midi: |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
|
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
|
|
m_sDriverName.latin1(), sParam.latin1(), NULL); |
|
195 |
break; |
break; |
196 |
case qsamplerDevice::None: |
case Device::Midi: |
197 |
|
if ((pParamInfo = ::lscp_get_midi_driver_param_info( |
198 |
|
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
199 |
|
sParam.toUtf8().constData(), NULL)) == NULL) |
200 |
|
appendMessagesClient("lscp_get_midi_driver_param_info"); |
201 |
|
break; |
202 |
|
case Device::None: |
203 |
break; |
break; |
204 |
} |
} |
205 |
if (pParamInfo) { |
if (pParamInfo) { |
206 |
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
m_params[sParam.toUpper()] = DeviceParam(pParamInfo, |
207 |
pDeviceInfo->params[i].value); |
pDeviceInfo->params[i].value); |
208 |
} |
} |
209 |
} |
} |
210 |
|
|
211 |
// Refresh parameter dependencies... |
// Refresh parameter dependencies... |
212 |
refreshParams(pClient); |
refreshParams(); |
213 |
// Set port/channel list... |
// Set port/channel list... |
214 |
refreshPorts(pClient); |
refreshPorts(); |
215 |
} |
} |
216 |
|
|
217 |
|
|
218 |
// Driver name initializer/settler. |
// Driver name initializer/settler. |
219 |
void qsamplerDevice::setDriver ( lscp_client_t *pClient, |
void Device::setDriver ( const QString& sDriverName ) |
|
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 Device::Audio: |
240 |
pDriverInfo = ::lscp_get_audio_driver_info(pClient, |
if ((pDriverInfo = ::lscp_get_audio_driver_info(pMainForm->client(), |
241 |
sDriverName.latin1()); |
sDriverName.toUtf8().constData())) == NULL) |
242 |
break; |
appendMessagesClient("lscp_get_audio_driver_info"); |
243 |
case qsamplerDevice::Midi: |
break; |
244 |
pDriverInfo = ::lscp_get_midi_driver_info(pClient, |
case Device::Midi: |
245 |
sDriverName.latin1()); |
if ((pDriverInfo = ::lscp_get_midi_driver_info(pMainForm->client(), |
246 |
|
sDriverName.toUtf8().constData())) == NULL) |
247 |
|
appendMessagesClient("lscp_get_midi_driver_info"); |
248 |
break; |
break; |
249 |
case qsamplerDevice::None: |
case Device::None: |
250 |
break; |
break; |
251 |
} |
} |
252 |
|
|
262 |
const QString sParam = pDriverInfo->parameters[i]; |
const QString sParam = pDriverInfo->parameters[i]; |
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 Device::Audio: |
266 |
pParamInfo = ::lscp_get_audio_driver_param_info(pClient, |
if ((pParamInfo = ::lscp_get_audio_driver_param_info( |
267 |
sDriverName.latin1(), sParam.latin1(), NULL); |
pMainForm->client(), sDriverName.toUtf8().constData(), |
268 |
break; |
sParam.toUtf8().constData(), NULL)) == NULL) |
269 |
case qsamplerDevice::Midi: |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
270 |
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
break; |
271 |
sDriverName.latin1(), sParam.latin1(), NULL); |
case Device::Midi: |
272 |
|
if ((pParamInfo = ::lscp_get_midi_driver_param_info( |
273 |
|
pMainForm->client(), sDriverName.toUtf8().constData(), |
274 |
|
sParam.toUtf8().constData(), NULL)) == NULL) |
275 |
|
appendMessagesClient("lscp_get_midi_driver_param_info"); |
276 |
break; |
break; |
277 |
case qsamplerDevice::None: |
case Device::None: |
278 |
break; |
break; |
279 |
} |
} |
280 |
if (pParamInfo) { |
if (pParamInfo) { |
281 |
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
m_params[sParam.toUpper()] = DeviceParam(pParamInfo, |
282 |
pParamInfo->defaultv); |
pParamInfo->defaultv); |
283 |
} |
} |
284 |
} |
} |
285 |
|
|
286 |
// Refresh parameter dependencies... |
// Refresh parameter dependencies... |
287 |
refreshParams(pClient); |
refreshParams(); |
288 |
// Set port/channel list... |
// Set port/channel list... |
289 |
refreshPorts(pClient); |
refreshPorts(); |
290 |
} |
} |
291 |
|
|
292 |
|
|
293 |
// Device property accessors. |
// Device property accessors. |
294 |
int qsamplerDevice::deviceID (void) const |
int Device::deviceID (void) const |
295 |
{ |
{ |
296 |
return m_iDeviceID; |
return m_iDeviceID; |
297 |
} |
} |
298 |
|
|
299 |
qsamplerDevice::qsamplerDeviceType qsamplerDevice::deviceType (void) const |
Device::DeviceType Device::deviceType (void) const |
300 |
{ |
{ |
301 |
return m_deviceType; |
return m_deviceType; |
302 |
} |
} |
303 |
|
|
304 |
const QString& qsamplerDevice::deviceTypeName (void) const |
const QString& Device::deviceTypeName (void) const |
305 |
{ |
{ |
306 |
return m_sDeviceType; |
return m_sDeviceType; |
307 |
} |
} |
308 |
|
|
309 |
const QString& qsamplerDevice::driverName (void) const |
const QString& Device::driverName (void) const |
310 |
{ |
{ |
311 |
return m_sDriverName; |
return m_sDriverName; |
312 |
} |
} |
313 |
|
|
314 |
const QString& qsamplerDevice::deviceName (void) const |
// Special device name formatter. |
315 |
|
QString Device::deviceName (void) const |
316 |
{ |
{ |
317 |
return m_sDeviceName; |
QString sPrefix; |
318 |
|
if (m_iDeviceID >= 0) |
319 |
|
sPrefix += m_sDeviceType + ' '; |
320 |
|
return sPrefix + m_sDeviceName; |
321 |
} |
} |
322 |
|
|
323 |
|
|
324 |
// Set the proper device parameter value. |
// Set the proper device parameter value. |
325 |
void qsamplerDevice::setParam ( const QString& sParam, |
bool Device::setParam ( const QString& sParam, |
326 |
const QString& sValue ) |
const QString& sValue ) |
327 |
{ |
{ |
328 |
m_params[sParam.upper()].value = sValue; |
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. |
335 |
|
m_params[sParam.toUpper()].value = sValue; |
336 |
|
|
337 |
|
// If the device already exists, things get immediate... |
338 |
|
int iRefresh = 0; |
339 |
|
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. |
348 |
|
lscp_param_t param; |
349 |
|
param.key = (char *) finalParamKey.constData(); |
350 |
|
param.value = (char *) finalParamVal.constData(); |
351 |
|
// Now it depends on the device type... |
352 |
|
lscp_status_t ret = LSCP_FAILED; |
353 |
|
switch (m_deviceType) { |
354 |
|
case Device::Audio: |
355 |
|
if (sParam == "CHANNELS") iRefresh++; |
356 |
|
if ((ret = ::lscp_set_audio_device_param(pMainForm->client(), |
357 |
|
m_iDeviceID, ¶m)) != LSCP_OK) |
358 |
|
appendMessagesClient("lscp_set_audio_device_param"); |
359 |
|
break; |
360 |
|
case Device::Midi: |
361 |
|
if (sParam == "PORTS") iRefresh++; |
362 |
|
if ((ret = ::lscp_set_midi_device_param(pMainForm->client(), |
363 |
|
m_iDeviceID, ¶m)) != LSCP_OK) |
364 |
|
appendMessagesClient("lscp_set_midi_device_param"); |
365 |
|
break; |
366 |
|
case Device::None: |
367 |
|
break; |
368 |
|
} |
369 |
|
// Show result. |
370 |
|
if (ret == LSCP_OK) { |
371 |
|
appendMessages(QString("%1: %2.").arg(sParam).arg(sValue)); |
372 |
|
// Special care for specific parameter changes... |
373 |
|
if (iRefresh > 0) |
374 |
|
iRefresh += refreshPorts(); |
375 |
|
iRefresh += refreshDepends(sParam); |
376 |
|
} else { |
377 |
|
// Oops... |
378 |
|
appendMessagesError( |
379 |
|
QObject::tr("Could not set device parameter value.\n\nSorry.")); |
380 |
|
} |
381 |
|
} |
382 |
|
|
383 |
|
// Return whether we're need a view refresh. |
384 |
|
return (iRefresh > 0); |
385 |
} |
} |
386 |
|
|
387 |
|
|
388 |
// Device parameter accessor. |
// Device parameter accessor. |
389 |
const qsamplerDeviceParamMap& qsamplerDevice::params (void) const |
const DeviceParamMap& Device::params (void) const |
390 |
{ |
{ |
391 |
return m_params; |
return m_params; |
392 |
} |
} |
393 |
|
|
394 |
|
|
395 |
// Device port/channel list accessor. |
// Device port/channel list accessor. |
396 |
qsamplerDevicePortList& qsamplerDevice::ports (void) |
DevicePortList& Device::ports (void) |
397 |
{ |
{ |
398 |
return m_ports; |
return m_ports; |
399 |
} |
} |
400 |
|
|
401 |
|
|
402 |
|
// Create a new device, as a copy of this current one. |
403 |
|
bool Device::createDevice (void) |
404 |
|
{ |
405 |
|
MainForm *pMainForm = MainForm::getInstance(); |
406 |
|
if (pMainForm == NULL) |
407 |
|
return false; |
408 |
|
if (pMainForm->client() == NULL) |
409 |
|
return false; |
410 |
|
|
411 |
|
// we need temporary lists with the final strings, because i.e. |
412 |
|
// QString::toUtf8() only returns a temporary object and the |
413 |
|
// C-style char* pointers for liblscp would immediately be invalidated |
414 |
|
QList<QByteArray> finalKeys; |
415 |
|
QList<QByteArray> finalVals; |
416 |
|
|
417 |
|
DeviceParamMap::ConstIterator iter; |
418 |
|
for (iter = m_params.begin(); iter != m_params.end(); ++iter) { |
419 |
|
if (iter.value().value == QString::null) continue; |
420 |
|
finalKeys.push_back(iter.key().toUtf8()); |
421 |
|
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. |
434 |
|
pParams[iParam].key = NULL; |
435 |
|
pParams[iParam].value = NULL; |
436 |
|
|
437 |
|
// Now it depends on the device type... |
438 |
|
switch (m_deviceType) { |
439 |
|
case Device::Audio: |
440 |
|
if ((m_iDeviceID = ::lscp_create_audio_device(pMainForm->client(), |
441 |
|
m_sDriverName.toUtf8().constData(), pParams)) < 0) |
442 |
|
appendMessagesClient("lscp_create_audio_device"); |
443 |
|
break; |
444 |
|
case Device::Midi: |
445 |
|
if ((m_iDeviceID = ::lscp_create_midi_device(pMainForm->client(), |
446 |
|
m_sDriverName.toUtf8().constData(), pParams)) < 0) |
447 |
|
appendMessagesClient("lscp_create_midi_device"); |
448 |
|
break; |
449 |
|
case Device::None: |
450 |
|
break; |
451 |
|
} |
452 |
|
|
453 |
|
// Free used parameter array. |
454 |
|
delete pParams; |
455 |
|
|
456 |
|
// Show result. |
457 |
|
if (m_iDeviceID >= 0) { |
458 |
|
// Refresh our own stuff... |
459 |
|
setDevice(m_deviceType, m_iDeviceID); |
460 |
|
appendMessages(QObject::tr("created.")); |
461 |
|
} else { |
462 |
|
appendMessagesError(QObject::tr("Could not create device.\n\nSorry.")); |
463 |
|
} |
464 |
|
|
465 |
|
// Return whether we're a valid device... |
466 |
|
return (m_iDeviceID >= 0); |
467 |
|
} |
468 |
|
|
469 |
|
|
470 |
|
// Destroy existing device. |
471 |
|
bool Device::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... |
480 |
|
lscp_status_t ret = LSCP_FAILED; |
481 |
|
switch (m_deviceType) { |
482 |
|
case Device::Audio: |
483 |
|
if ((ret = ::lscp_destroy_audio_device(pMainForm->client(), |
484 |
|
m_iDeviceID)) != LSCP_OK) |
485 |
|
appendMessagesClient("lscp_destroy_audio_device"); |
486 |
|
break; |
487 |
|
case Device::Midi: |
488 |
|
if ((ret = ::lscp_destroy_midi_device(pMainForm->client(), |
489 |
|
m_iDeviceID)) != LSCP_OK) |
490 |
|
appendMessagesClient("lscp_destroy_midi_device"); |
491 |
|
break; |
492 |
|
case Device::None: |
493 |
|
break; |
494 |
|
} |
495 |
|
|
496 |
|
// Show result. |
497 |
|
if (ret == LSCP_OK) { |
498 |
|
appendMessages(QObject::tr("deleted.")); |
499 |
|
m_iDeviceID = -1; |
500 |
|
} else { |
501 |
|
appendMessagesError(QObject::tr("Could not delete device.\n\nSorry.")); |
502 |
|
} |
503 |
|
|
504 |
|
// Return whether we've done it.. |
505 |
|
return (ret == LSCP_OK); |
506 |
|
} |
507 |
|
|
508 |
|
|
509 |
// Device parameter dependencies refreshner. |
// Device parameter dependencies refreshner. |
510 |
int qsamplerDevice::refreshParams ( lscp_client_t *pClient ) |
int Device::refreshParams (void) |
511 |
{ |
{ |
512 |
|
// This should only make sense for scratch devices... |
513 |
|
if (m_iDeviceID >= 0) |
514 |
|
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; |
DeviceParamMap::ConstIterator iter; |
518 |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) |
for (iter = m_params.begin(); iter != m_params.end(); ++iter) |
519 |
iParams += refreshParam(pClient, iter.key()); |
iParams += refreshParam(iter.key()); |
520 |
// Return how many parameters have been refreshed... |
// Return how many parameters have been refreshed... |
521 |
return iParams; |
return iParams; |
522 |
} |
} |
523 |
|
|
524 |
|
|
525 |
// Device port/channel list refreshner. |
// Device port/channel list refreshner. |
526 |
int qsamplerDevice::refreshPorts ( lscp_client_t *pClient ) |
int Device::refreshPorts (void) |
527 |
{ |
{ |
528 |
|
// This should only make sense for actual devices... |
529 |
|
if (m_iDeviceID < 0) |
530 |
|
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) { |
534 |
case qsamplerDevice::Audio: |
case Device::Audio: |
535 |
iPorts = m_params["CHANNELS"].value.toInt(); |
iPorts = m_params["CHANNELS"].value.toInt(); |
536 |
break; |
break; |
537 |
case qsamplerDevice::Midi: |
case Device::Midi: |
538 |
iPorts = m_params["PORTS"].value.toInt(); |
iPorts = m_params["PORTS"].value.toInt(); |
539 |
break; |
break; |
540 |
case qsamplerDevice::None: |
case Device::None: |
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(pClient, *this, iPort)); |
m_ports.append(new DevicePort(*this, iPort)); |
548 |
// Return how many ports have been refreshed... |
// Return how many ports have been refreshed... |
549 |
return iPorts; |
return iPorts; |
550 |
} |
} |
551 |
|
|
552 |
|
|
553 |
// Refresh/set dependencies given that some parameter has changed. |
// Refresh/set dependencies given that some parameter has changed. |
554 |
int qsamplerDevice::refreshDepends ( lscp_client_t *pClient, |
int Device::refreshDepends ( const QString& sParam ) |
|
const QString& sParam ) |
|
555 |
{ |
{ |
556 |
|
// This should only make sense for scratch devices... |
557 |
|
if (m_iDeviceID >= 0) |
558 |
|
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; |
DeviceParamMap::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(pClient, iter.key()); |
iDepends += refreshParam(iter.key()); |
566 |
} |
} |
567 |
// Return how many dependencies have been refreshed... |
// Return how many dependencies have been refreshed... |
568 |
return iDepends; |
return iDepends; |
570 |
|
|
571 |
|
|
572 |
// Refresh/set given parameter based on driver supplied dependencies. |
// Refresh/set given parameter based on driver supplied dependencies. |
573 |
int qsamplerDevice::refreshParam ( lscp_client_t *pClient, |
int Device::refreshParam ( const QString& sParam ) |
|
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()]; |
DeviceParam& 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. |
609 |
pDepends[iDepend].key = NULL; |
pDepends[iDepend].key = NULL; |
610 |
pDepends[iDepend].value = NULL; |
pDepends[iDepend].value = NULL; |
611 |
|
|
|
#if 0 |
|
612 |
// FIXME: Some parameter dependencies (e.g.ALSA CARD) |
// FIXME: Some parameter dependencies (e.g.ALSA CARD) |
613 |
// are blocking for no reason, causing timeout-crashes. |
// are blocking for no reason, causing potential timeout-crashes. |
614 |
|
// hopefully this gets mitigated if this dependency hell is only |
615 |
|
// carried out for scratch devices... |
616 |
|
|
617 |
// Retrieve some modern parameters... |
// Retrieve some modern parameters... |
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 Device::Audio: |
621 |
pParamInfo = ::lscp_get_audio_driver_param_info(pClient, |
if ((pParamInfo = ::lscp_get_audio_driver_param_info( |
622 |
m_sDriverName.latin1(), sParam.latin1(), pDepends); |
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
623 |
break; |
sParam.toUtf8().constData(), pDepends)) == NULL) |
624 |
case qsamplerDevice::Midi: |
appendMessagesClient("lscp_get_audio_driver_param_info"); |
625 |
pParamInfo = ::lscp_get_midi_driver_param_info(pClient, |
break; |
626 |
m_sDriverName.latin1(), sParam.latin1(), pDepends); |
case Device::Midi: |
627 |
|
if ((pParamInfo = ::lscp_get_midi_driver_param_info( |
628 |
|
pMainForm->client(), m_sDriverName.toUtf8().constData(), |
629 |
|
sParam.toUtf8().constData(), pDepends)) == NULL) |
630 |
|
appendMessagesClient("lscp_get_midi_driver_param_info"); |
631 |
break; |
break; |
632 |
case qsamplerDevice::None: |
case Device::None: |
633 |
break; |
break; |
634 |
} |
} |
635 |
if (pParamInfo) { |
if (pParamInfo) { |
636 |
param = qsamplerDeviceParam(pParamInfo, QString(param.value)); |
param = DeviceParam(pParamInfo, |
637 |
|
param.value.isEmpty() ? NULL : param.value.toUtf8().constData()); |
638 |
iRefresh++; |
iRefresh++; |
639 |
} |
} |
640 |
#endif |
|
641 |
// Free used parameter array. |
// Free used parameter array. |
642 |
delete pDepends; |
delete pDepends; |
643 |
|
|
646 |
} |
} |
647 |
|
|
648 |
|
|
649 |
|
// Redirected messages output methods. |
650 |
|
void Device::appendMessages( const QString& s ) const |
651 |
|
{ |
652 |
|
MainForm *pMainForm = MainForm::getInstance(); |
653 |
|
if (pMainForm) |
654 |
|
pMainForm->appendMessages(deviceName() + ' ' + s); |
655 |
|
} |
656 |
|
|
657 |
|
void Device::appendMessagesColor( const QString& s, |
658 |
|
const QString& c ) const |
659 |
|
{ |
660 |
|
MainForm *pMainForm = MainForm::getInstance(); |
661 |
|
if (pMainForm) |
662 |
|
pMainForm->appendMessagesColor(deviceName() + ' ' + s, c); |
663 |
|
} |
664 |
|
|
665 |
|
void Device::appendMessagesText( const QString& s ) const |
666 |
|
{ |
667 |
|
MainForm *pMainForm = MainForm::getInstance(); |
668 |
|
if (pMainForm) |
669 |
|
pMainForm->appendMessagesText(deviceName() + ' ' + s); |
670 |
|
} |
671 |
|
|
672 |
|
void Device::appendMessagesError( const QString& s ) const |
673 |
|
{ |
674 |
|
MainForm *pMainForm = MainForm::getInstance(); |
675 |
|
if (pMainForm) |
676 |
|
pMainForm->appendMessagesError(deviceName() + "\n\n" + s); |
677 |
|
} |
678 |
|
|
679 |
|
void Device::appendMessagesClient( const QString& s ) const |
680 |
|
{ |
681 |
|
MainForm *pMainForm = MainForm::getInstance(); |
682 |
|
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 *Device::getDevices ( lscp_client_t *pClient, |
689 |
qsamplerDeviceType deviceType ) |
DeviceType deviceType ) |
690 |
{ |
{ |
691 |
int *piDeviceIDs = NULL; |
int *piDeviceIDs = NULL; |
692 |
switch (deviceType) { |
switch (deviceType) { |
693 |
case qsamplerDevice::Audio: |
case Device::Audio: |
694 |
piDeviceIDs = ::lscp_list_audio_devices(pClient); |
piDeviceIDs = ::lscp_list_audio_devices(pClient); |
695 |
break; |
break; |
696 |
case qsamplerDevice::Midi: |
case Device::Midi: |
697 |
piDeviceIDs = ::lscp_list_midi_devices(pClient); |
piDeviceIDs = ::lscp_list_midi_devices(pClient); |
698 |
break; |
break; |
699 |
case qsamplerDevice::None: |
case Device::None: |
700 |
break; |
break; |
701 |
} |
} |
702 |
return piDeviceIDs; |
return piDeviceIDs; |
703 |
} |
} |
704 |
|
|
705 |
|
std::set<int> Device::getDeviceIDs(lscp_client_t *pClient, |
706 |
|
DeviceType deviceType) |
707 |
|
{ |
708 |
|
std::set<int> result; |
709 |
|
int* piDeviceIDs = getDevices(pClient, deviceType); |
710 |
|
if (!piDeviceIDs) return result; |
711 |
|
for (int i = 0; piDeviceIDs[i] != -1; ++i) |
712 |
|
result.insert(piDeviceIDs[i]); |
713 |
|
return result; |
714 |
|
} |
715 |
|
|
716 |
|
|
717 |
// Driver names enumerator. |
// Driver names enumerator. |
718 |
QStringList qsamplerDevice::getDrivers ( lscp_client_t *pClient, |
QStringList Device::getDrivers ( lscp_client_t *pClient, |
719 |
qsamplerDeviceType deviceType ) |
DeviceType deviceType ) |
720 |
{ |
{ |
721 |
QStringList drivers; |
QStringList drivers; |
722 |
|
|
723 |
const char **ppszDrivers = NULL; |
const char **ppszDrivers = NULL; |
724 |
switch (deviceType) { |
switch (deviceType) { |
725 |
case qsamplerDevice::Audio: |
case Device::Audio: |
726 |
ppszDrivers = ::lscp_get_available_audio_drivers(pClient); |
ppszDrivers = ::lscp_list_available_audio_drivers(pClient); |
727 |
break; |
break; |
728 |
case qsamplerDevice::Midi: |
case Device::Midi: |
729 |
ppszDrivers = ::lscp_get_available_midi_drivers(pClient); |
ppszDrivers = ::lscp_list_available_midi_drivers(pClient); |
730 |
break; |
break; |
731 |
case qsamplerDevice::None: |
case Device::None: |
732 |
break; |
break; |
733 |
} |
} |
734 |
|
|
735 |
for (int iDriver = 0; ppszDrivers[iDriver]; iDriver++) |
for (int iDriver = 0; ppszDrivers && ppszDrivers[iDriver]; iDriver++) |
736 |
drivers.append(ppszDrivers[iDriver]); |
drivers.append(ppszDrivers[iDriver]); |
737 |
|
|
738 |
return drivers; |
return drivers; |
740 |
|
|
741 |
|
|
742 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
743 |
// qsamplerDevicePort - MIDI/Audio Device port/channel structure. |
// QSampler::DevicePort - MIDI/Audio Device port/channel structure. |
744 |
// |
// |
745 |
|
|
746 |
// Constructor. |
// Constructor. |
747 |
qsamplerDevicePort::qsamplerDevicePort ( lscp_client_t *pClient, |
DevicePort::DevicePort ( Device& device, |
748 |
const qsamplerDevice& device, int iPortID ) |
int iPortID ) : m_device(device) |
749 |
{ |
{ |
750 |
setDevicePort(pClient, device, iPortID); |
setDevicePort(iPortID); |
751 |
} |
} |
752 |
|
|
753 |
// Default destructor. |
// Default destructor. |
754 |
qsamplerDevicePort::~qsamplerDevicePort (void) |
DevicePort::~DevicePort (void) |
755 |
{ |
{ |
756 |
} |
} |
757 |
|
|
758 |
|
|
759 |
// Initializer. |
// Initializer. |
760 |
void qsamplerDevicePort::setDevicePort ( lscp_client_t *pClient, |
void DevicePort::setDevicePort ( int iPortID ) |
|
const qsamplerDevice& device, int iPortID ) |
|
761 |
{ |
{ |
762 |
|
MainForm *pMainForm = MainForm::getInstance(); |
763 |
|
if (pMainForm == NULL) |
764 |
|
return; |
765 |
|
if (pMainForm->client() == NULL) |
766 |
|
return; |
767 |
|
|
768 |
// Device port id should be always set. |
// Device port id should be always set. |
769 |
m_iPortID = iPortID; |
m_iPortID = iPortID; |
770 |
|
|
772 |
m_params.clear(); |
m_params.clear(); |
773 |
|
|
774 |
// Retrieve device port/channel info, if any. |
// Retrieve device port/channel info, if any. |
|
QString sPrefix = device.driverName() + ' '; |
|
775 |
lscp_device_port_info_t *pPortInfo = NULL; |
lscp_device_port_info_t *pPortInfo = NULL; |
776 |
switch (device.deviceType()) { |
switch (m_device.deviceType()) { |
777 |
case qsamplerDevice::Audio: |
case Device::Audio: |
778 |
sPrefix += QObject::tr("Channel"); |
if ((pPortInfo = ::lscp_get_audio_channel_info(pMainForm->client(), |
779 |
pPortInfo = ::lscp_get_audio_channel_info(pClient, device.deviceID(), iPortID); |
m_device.deviceID(), m_iPortID)) == NULL) |
780 |
break; |
m_device.appendMessagesClient("lscp_get_audio_channel_info"); |
781 |
case qsamplerDevice::Midi: |
break; |
782 |
sPrefix += QObject::tr("Port"); |
case Device::Midi: |
783 |
pPortInfo = ::lscp_get_midi_port_info(pClient, device.deviceID(), iPortID); |
if ((pPortInfo = ::lscp_get_midi_port_info(pMainForm->client(), |
784 |
|
m_device.deviceID(), m_iPortID)) == NULL) |
785 |
|
m_device.appendMessagesClient("lscp_get_midi_port_info"); |
786 |
break; |
break; |
787 |
case qsamplerDevice::None: |
case Device::None: |
788 |
break; |
break; |
789 |
} |
} |
790 |
|
|
795 |
} |
} |
796 |
|
|
797 |
// Set device port/channel properties... |
// Set device port/channel properties... |
798 |
sPrefix += " %1:"; |
m_sPortName = pPortInfo->name; |
|
m_sPortName = sPrefix.arg(m_iPortID) + ' ' + pPortInfo->name; |
|
799 |
|
|
800 |
// Grab device port/channel parameters... |
// Grab device port/channel parameters... |
801 |
m_params.clear(); |
m_params.clear(); |
802 |
for (int i = 0; pPortInfo->params && pPortInfo->params[i].key; i++) { |
for (int i = 0; pPortInfo->params && pPortInfo->params[i].key; i++) { |
803 |
const QString sParam = pPortInfo->params[i].key; |
const QString sParam = pPortInfo->params[i].key; |
804 |
lscp_param_info_t *pParamInfo = NULL; |
lscp_param_info_t *pParamInfo = NULL; |
805 |
switch (device.deviceType()) { |
switch (m_device.deviceType()) { |
806 |
case qsamplerDevice::Audio: |
case Device::Audio: |
807 |
pParamInfo = ::lscp_get_audio_channel_param_info(pClient, |
if ((pParamInfo = ::lscp_get_audio_channel_param_info( |
808 |
device.deviceID(), iPortID, sParam.latin1()); |
pMainForm->client(), m_device.deviceID(), |
809 |
break; |
m_iPortID, sParam.toUtf8().constData())) == NULL) |
810 |
case qsamplerDevice::Midi: |
m_device.appendMessagesClient("lscp_get_audio_channel_param_info"); |
811 |
pParamInfo = ::lscp_get_midi_port_param_info(pClient, |
break; |
812 |
device.deviceID(), iPortID, sParam.latin1()); |
case Device::Midi: |
813 |
|
if ((pParamInfo = ::lscp_get_midi_port_param_info( |
814 |
|
pMainForm->client(), m_device.deviceID(), |
815 |
|
m_iPortID, sParam.toUtf8().constData())) == NULL) |
816 |
|
m_device.appendMessagesClient("lscp_get_midi_port_param_info"); |
817 |
break; |
break; |
818 |
case qsamplerDevice::None: |
case Device::None: |
819 |
break; |
break; |
820 |
} |
} |
821 |
if (pParamInfo) { |
if (pParamInfo) { |
822 |
m_params[sParam.upper()] = qsamplerDeviceParam(pParamInfo, |
m_params[sParam.toUpper()] = DeviceParam(pParamInfo, |
823 |
pPortInfo->params[i].value); |
pPortInfo->params[i].value); |
824 |
} |
} |
825 |
} |
} |
827 |
|
|
828 |
|
|
829 |
// Device port/channel property accessors. |
// Device port/channel property accessors. |
830 |
int qsamplerDevicePort::portID (void) const |
int DevicePort::portID (void) const |
831 |
{ |
{ |
832 |
return m_iPortID; |
return m_iPortID; |
833 |
} |
} |
834 |
|
|
835 |
const QString& qsamplerDevicePort::portName (void) const |
const QString& DevicePort::portName (void) const |
836 |
{ |
{ |
837 |
return m_sPortName; |
return m_sPortName; |
838 |
} |
} |
839 |
|
|
840 |
// Device port/channel parameter accessor. |
// Device port/channel parameter accessor. |
841 |
const qsamplerDeviceParamMap& qsamplerDevicePort::params (void) const |
const DeviceParamMap& DevicePort::params (void) const |
842 |
{ |
{ |
843 |
return m_params; |
return m_params; |
844 |
} |
} |
845 |
|
|
846 |
|
|
847 |
// Set the proper device port/channel parameter value. |
// Set the proper device port/channel parameter value. |
848 |
void qsamplerDevicePort::setParam ( const QString& sParam, |
bool DevicePort::setParam ( const QString& sParam, |
849 |
const QString& sValue ) |
const QString& sValue ) |
850 |
{ |
{ |
851 |
m_params[sParam.upper()].value = sValue; |
MainForm *pMainForm = MainForm::getInstance(); |
852 |
|
if (pMainForm == NULL) |
853 |
|
return false; |
854 |
|
if (pMainForm->client() == NULL) |
855 |
|
return false; |
856 |
|
|
857 |
|
// Set proper port/channel parameter. |
858 |
|
m_params[sParam.toUpper()].value = sValue; |
859 |
|
|
860 |
|
// If the device already exists, things get immediate... |
861 |
|
int iRefresh = 0; |
862 |
|
if (m_device.deviceID() >= 0 && m_iPortID >= 0) { |
863 |
|
|
864 |
|
// we need temporary byte arrrays with the final strings, because |
865 |
|
// i.e. QString::toUtf8() only returns a temporary object and the |
866 |
|
// C-style char* pointers for liblscp would immediately be invalidated |
867 |
|
QByteArray finalParamKey = sParam.toUtf8(); |
868 |
|
QByteArray finalParamVal = sValue.toUtf8(); |
869 |
|
|
870 |
|
// Prepare parameter struct. |
871 |
|
lscp_param_t param; |
872 |
|
param.key = (char *) finalParamKey.constData(); |
873 |
|
param.value = (char *) finalParamVal.constData(); |
874 |
|
// Now it depends on the device type... |
875 |
|
lscp_status_t ret = LSCP_FAILED; |
876 |
|
switch (m_device.deviceType()) { |
877 |
|
case Device::Audio: |
878 |
|
if ((ret = ::lscp_set_audio_channel_param(pMainForm->client(), |
879 |
|
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
880 |
|
m_device.appendMessagesClient("lscp_set_audio_channel_param"); |
881 |
|
break; |
882 |
|
case Device::Midi: |
883 |
|
if ((ret = ::lscp_set_midi_port_param(pMainForm->client(), |
884 |
|
m_device.deviceID(), m_iPortID, ¶m)) != LSCP_OK) |
885 |
|
m_device.appendMessagesClient("lscp_set_midi_port_param"); |
886 |
|
break; |
887 |
|
case Device::None: |
888 |
|
break; |
889 |
|
} |
890 |
|
// Show result. |
891 |
|
if (ret == LSCP_OK) { |
892 |
|
m_device.appendMessages(m_sPortName |
893 |
|
+ ' ' + QString("%1: %2.").arg(sParam).arg(sValue)); |
894 |
|
iRefresh++; |
895 |
|
} else { |
896 |
|
m_device.appendMessagesError( |
897 |
|
QObject::tr("Could not set %1 parameter value.\n\n" |
898 |
|
"Sorry.").arg(m_sPortName)); |
899 |
|
} |
900 |
|
} |
901 |
|
|
902 |
|
// Return whether we're need a view refresh. |
903 |
|
return (iRefresh > 0); |
904 |
} |
} |
905 |
|
|
906 |
|
|
907 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
908 |
// qsamplerDeviceItem - QListView device item. |
// QSampler::DeviceItem - QTreeWidget device item. |
909 |
// |
// |
910 |
|
|
911 |
// Constructors. |
// Constructors. |
912 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListView *pListView, |
DeviceItem::DeviceItem ( QTreeWidget* pTreeWidget, |
913 |
lscp_client_t *pClient, qsamplerDevice::qsamplerDeviceType deviceType ) |
Device::DeviceType deviceType ) |
914 |
: QListViewItem(pListView), m_device(pClient, deviceType) |
: QTreeWidgetItem(pTreeWidget, QSAMPLER_DEVICE_ITEM), |
915 |
|
m_device(deviceType) |
916 |
{ |
{ |
917 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
918 |
case qsamplerDevice::Audio: |
case Device::Audio: |
919 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio1.png")); |
setIcon(0, QPixmap(":/images/audio1.png")); |
920 |
QListViewItem::setText(0, QObject::tr("Audio devices")); |
setText(0, QObject::tr("Audio Devices")); |
921 |
break; |
break; |
922 |
case qsamplerDevice::Midi: |
case Device::Midi: |
923 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi1.png")); |
setIcon(0, QPixmap(":/images/midi1.png")); |
924 |
QListViewItem::setText(0, QObject::tr("MIDI devices")); |
setText(0, QObject::tr("MIDI Devices")); |
925 |
break; |
break; |
926 |
case qsamplerDevice::None: |
case Device::None: |
927 |
break; |
break; |
928 |
} |
} |
929 |
|
|
930 |
|
// Root items are not selectable... |
931 |
|
setFlags(flags() & ~Qt::ItemIsSelectable); |
932 |
} |
} |
933 |
|
|
934 |
qsamplerDeviceItem::qsamplerDeviceItem ( QListViewItem *pItem, |
DeviceItem::DeviceItem ( QTreeWidgetItem* pItem, |
935 |
lscp_client_t *pClient, qsamplerDevice::qsamplerDeviceType deviceType, |
Device::DeviceType deviceType, |
936 |
int iDeviceID ) |
int iDeviceID ) |
937 |
: QListViewItem(pItem), m_device(pClient, deviceType, iDeviceID) |
: QTreeWidgetItem(pItem, QSAMPLER_DEVICE_ITEM), |
938 |
|
m_device(deviceType, iDeviceID) |
939 |
{ |
{ |
940 |
switch(m_device.deviceType()) { |
switch(m_device.deviceType()) { |
941 |
case qsamplerDevice::Audio: |
case Device::Audio: |
942 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("audio2.png")); |
setIcon(0, QPixmap(":/images/audio2.png")); |
943 |
break; |
break; |
944 |
case qsamplerDevice::Midi: |
case Device::Midi: |
945 |
QListViewItem::setPixmap(0, QPixmap::fromMimeSource("midi2.png")); |
setIcon(0, QPixmap(":/images/midi2.png")); |
946 |
break; |
break; |
947 |
case qsamplerDevice::None: |
case Device::None: |
948 |
break; |
break; |
949 |
} |
} |
950 |
|
|
951 |
QListViewItem::setText(0, m_device.deviceName()); |
setText(0, m_device.deviceName()); |
952 |
} |
} |
953 |
|
|
954 |
// Default destructor. |
// Default destructor. |
955 |
qsamplerDeviceItem::~qsamplerDeviceItem (void) |
DeviceItem::~DeviceItem () |
956 |
{ |
{ |
957 |
} |
} |
958 |
|
|
959 |
// Instance accessors. |
// Instance accessors. |
960 |
qsamplerDevice& qsamplerDeviceItem::device (void) |
Device& DeviceItem::device () |
961 |
{ |
{ |
962 |
return m_device; |
return m_device; |
963 |
} |
} |
964 |
|
|
965 |
// To virtually distinguish between list view items. |
|
966 |
int qsamplerDeviceItem::rtti() const |
//------------------------------------------------------------------------- |
967 |
|
// QSampler::AbstractDeviceParamModel - data model base class for device parameters |
968 |
|
// |
969 |
|
|
970 |
|
AbstractDeviceParamModel::AbstractDeviceParamModel ( QObject* pParent ) |
971 |
|
: QAbstractTableModel(pParent), m_bEditable(false) |
972 |
{ |
{ |
973 |
return QSAMPLER_DEVICE_ITEM; |
m_pParams = NULL; |
974 |
} |
} |
975 |
|
|
976 |
|
|
977 |
|
int AbstractDeviceParamModel::rowCount ( const QModelIndex& /*parent*/) const |
978 |
|
{ |
979 |
|
//std::cout << "model size=" << params.size() << "\n" << std::flush; |
980 |
|
return (m_pParams ? m_pParams->size() : 0); |
981 |
|
} |
982 |
|
|
|
//------------------------------------------------------------------------- |
|
|
// qsamplerDeviceParamTable - Device parameter view table. |
|
|
// |
|
983 |
|
|
984 |
// Constructor. |
int AbstractDeviceParamModel::columnCount ( const QModelIndex& /*parent*/) const |
985 |
qsamplerDeviceParamTable::qsamplerDeviceParamTable ( QWidget *pParent, |
{ |
986 |
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, true); -- of course not. |
|
|
QTable::setColumnStretchable(1, true); |
|
987 |
} |
} |
988 |
|
|
989 |
// Default destructor. |
|
990 |
qsamplerDeviceParamTable::~qsamplerDeviceParamTable (void) |
Qt::ItemFlags AbstractDeviceParamModel::flags ( const QModelIndex& /*index*/) const |
991 |
{ |
{ |
992 |
|
return Qt::ItemIsEditable | Qt::ItemIsEnabled; |
993 |
} |
} |
994 |
|
|
995 |
|
|
996 |
// Common parameter table renderer. |
QVariant AbstractDeviceParamModel::headerData ( |
997 |
void qsamplerDeviceParamTable::refresh ( const qsamplerDeviceParamMap& params, |
int section, Qt::Orientation orientation, int role) const |
998 |
bool bEditable ) |
{ |
999 |
{ |
if (role != Qt::DisplayRole) |
1000 |
// Always (re)start it empty. |
return QVariant(); |
1001 |
QTable::setUpdatesEnabled(false); |
|
1002 |
QTable::setNumRows(0); |
if (orientation == Qt::Horizontal) { |
1003 |
|
switch (section) { |
1004 |
// Fill the parameter table... |
case 0: return tr("Parameter"); |
1005 |
QTable::insertRows(0, params.count()); |
case 1: return tr("Value"); |
1006 |
int iRow = 0; |
case 2: return tr("Description"); |
1007 |
qsamplerDeviceParamMap::ConstIterator iter; |
default: return QVariant(); |
|
for (iter = params.begin(); iter != params.end(); ++iter) { |
|
|
const qsamplerDeviceParam& param = iter.data(); |
|
|
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); |
|
1008 |
} |
} |
|
++iRow; |
|
1009 |
} |
} |
1010 |
|
|
1011 |
// Adjust optimal column widths. |
return QVariant(); |
1012 |
QTable::adjustColumn(0); |
} |
1013 |
QTable::adjustColumn(2); |
|
1014 |
|
|
1015 |
QTable::setUpdatesEnabled(true); |
void AbstractDeviceParamModel::refresh ( |
1016 |
QTable::updateContents(); |
const DeviceParamMap* pParams, bool bEditable ) |
1017 |
|
{ |
1018 |
|
m_pParams = pParams; |
1019 |
|
m_bEditable = bEditable; |
1020 |
|
// inform the outer world (QTableView) that our data changed |
1021 |
|
#if QT_VERSION < 0x050000 |
1022 |
|
QAbstractTableModel::reset(); |
1023 |
|
#else |
1024 |
|
QAbstractTableModel::beginResetModel(); |
1025 |
|
QAbstractTableModel::endResetModel(); |
1026 |
|
#endif |
1027 |
|
} |
1028 |
|
|
1029 |
|
|
1030 |
|
void AbstractDeviceParamModel::clear (void) |
1031 |
|
{ |
1032 |
|
m_pParams = NULL; |
1033 |
|
// inform the outer world (QTableView) that our data changed |
1034 |
|
#if QT_VERSION < 0x050000 |
1035 |
|
QAbstractTableModel::reset(); |
1036 |
|
#else |
1037 |
|
QAbstractTableModel::beginResetModel(); |
1038 |
|
QAbstractTableModel::endResetModel(); |
1039 |
|
#endif |
1040 |
} |
} |
1041 |
|
|
1042 |
|
|
1043 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
1044 |
// qsamplerDeviceParamTableSpinBox - Custom spin box for parameter table. |
// QSampler::DeviceParamModel - data model for device parameters |
1045 |
// |
// (used for QTableView) |
1046 |
|
|
1047 |
// Constructor. |
DeviceParamModel::DeviceParamModel ( QObject *pParent ) |
1048 |
qsamplerDeviceParamTableSpinBox::qsamplerDeviceParamTableSpinBox ( |
: AbstractDeviceParamModel(pParent) |
|
QTable *pTable, EditType editType, const QString& sText ) |
|
|
: QTableItem(pTable, editType, sText) |
|
1049 |
{ |
{ |
1050 |
m_iValue = sText.toInt(); |
m_pDevice = NULL; |
|
m_iMinValue = m_iMaxValue = 0; |
|
1051 |
} |
} |
1052 |
|
|
1053 |
// Public accessors. |
QVariant DeviceParamModel::data ( |
1054 |
void qsamplerDeviceParamTableSpinBox::setValue ( int iValue ) |
const QModelIndex &index, int role) const |
1055 |
{ |
{ |
1056 |
m_iValue = iValue; |
if (!index.isValid()) |
1057 |
QTableItem::setText(QString::number(m_iValue)); |
return QVariant(); |
1058 |
|
|
1059 |
|
if (role != Qt::DisplayRole) |
1060 |
|
return QVariant(); |
1061 |
|
|
1062 |
|
DeviceParameterRow item; |
1063 |
|
item.name = m_pParams->keys()[index.row()]; |
1064 |
|
item.param = (*m_pParams)[item.name]; |
1065 |
|
item.alive = (m_pDevice && m_pDevice->deviceID() >= 0); |
1066 |
|
|
1067 |
|
return QVariant::fromValue(item); |
1068 |
} |
} |
1069 |
|
|
1070 |
void qsamplerDeviceParamTableSpinBox::setMinValue ( int iMinValue ) |
|
1071 |
|
bool DeviceParamModel::setData ( |
1072 |
|
const QModelIndex& index, const QVariant& value, int /*role*/) |
1073 |
{ |
{ |
1074 |
m_iMinValue = iMinValue; |
if (!index.isValid()) |
1075 |
|
return false; |
1076 |
|
|
1077 |
|
QString key = m_pParams->keys()[index.row()]; |
1078 |
|
//m_pParams[key].value = value.toString(); |
1079 |
|
m_pDevice->setParam(key, value.toString()); |
1080 |
|
emit dataChanged(index, index); |
1081 |
|
return true; |
1082 |
} |
} |
1083 |
|
|
1084 |
void qsamplerDeviceParamTableSpinBox::setMaxValue ( int iMaxValue ) |
|
1085 |
|
void DeviceParamModel::refresh ( Device* pDevice, bool bEditable ) |
1086 |
{ |
{ |
1087 |
m_iMaxValue = iMaxValue; |
m_pDevice = pDevice; |
1088 |
|
AbstractDeviceParamModel::refresh(&pDevice->params(), bEditable); |
1089 |
} |
} |
1090 |
|
|
1091 |
// Virtual implemetations. |
|
1092 |
QWidget *qsamplerDeviceParamTableSpinBox::createEditor (void) const |
void DeviceParamModel::clear (void) |
1093 |
{ |
{ |
1094 |
QSpinBox *pSpinBox = new QSpinBox(QTableItem::table()->viewport()); |
AbstractDeviceParamModel::clear(); |
1095 |
QObject::connect(pSpinBox, SIGNAL(valueChanged(int)), |
m_pDevice = NULL; |
1096 |
QTableItem::table(), SLOT(doValueChanged())); |
} |
1097 |
if (m_iValue >= m_iMinValue && m_iMaxValue >= m_iValue) { |
|
1098 |
pSpinBox->setMinValue(m_iMinValue); |
|
1099 |
pSpinBox->setMaxValue(m_iMaxValue); |
//------------------------------------------------------------------------- |
1100 |
} |
// QSampler::PortParamModel - data model for port parameters |
1101 |
pSpinBox->setValue(m_iValue); |
// (used for QTableView) |
1102 |
return pSpinBox; |
|
1103 |
|
PortParamModel::PortParamModel ( QObject *pParent) |
1104 |
|
: AbstractDeviceParamModel(pParent) |
1105 |
|
{ |
1106 |
|
m_pPort = NULL; |
1107 |
} |
} |
1108 |
|
|
1109 |
void qsamplerDeviceParamTableSpinBox::setContentFromEditor ( QWidget *pWidget ) |
QVariant PortParamModel::data ( const QModelIndex &index, int role ) const |
1110 |
{ |
{ |
1111 |
if (pWidget->inherits("QSpinBox")) |
if (!index.isValid()) |
1112 |
QTableItem::setText(QString::number(((QSpinBox *) pWidget)->value())); |
return QVariant(); |
1113 |
else |
|
1114 |
QTableItem::setContentFromEditor(pWidget); |
if (role != Qt::DisplayRole) |
1115 |
|
return QVariant(); |
1116 |
|
|
1117 |
|
DeviceParameterRow item; |
1118 |
|
item.name = m_pParams->keys()[index.row()]; |
1119 |
|
item.param = (*m_pParams)[item.name]; |
1120 |
|
item.alive = (m_pPort && m_pPort->portID() >= 0); |
1121 |
|
|
1122 |
|
return QVariant::fromValue(item); |
1123 |
|
} |
1124 |
|
|
1125 |
|
|
1126 |
|
bool PortParamModel::setData ( |
1127 |
|
const QModelIndex& index, const QVariant& value, int /*role*/) |
1128 |
|
{ |
1129 |
|
if (!index.isValid()) |
1130 |
|
return false; |
1131 |
|
|
1132 |
|
QString key = m_pParams->keys()[index.row()]; |
1133 |
|
//params[key].value = value.toString(); |
1134 |
|
m_pPort->setParam(key, value.toString()); |
1135 |
|
emit dataChanged(index, index); |
1136 |
|
return true; |
1137 |
|
} |
1138 |
|
|
1139 |
|
|
1140 |
|
void PortParamModel::refresh ( DevicePort* pPort, bool bEditable ) |
1141 |
|
{ |
1142 |
|
m_pPort = pPort; |
1143 |
|
AbstractDeviceParamModel::refresh(&pPort->params(), bEditable); |
1144 |
|
} |
1145 |
|
|
1146 |
|
|
1147 |
|
void PortParamModel::clear (void) |
1148 |
|
{ |
1149 |
|
AbstractDeviceParamModel::clear(); |
1150 |
|
m_pPort = NULL; |
1151 |
} |
} |
1152 |
|
|
1153 |
|
|
1154 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
1155 |
// qsamplerDeviceParamTableEditBox - Custom edit box for parameter table. |
// QSampler::DeviceParamDelegate - table cell renderer for device/port parameters |
1156 |
// |
// |
1157 |
|
|
1158 |
// Constructor. |
DeviceParamDelegate::DeviceParamDelegate ( QObject *pParent) |
1159 |
qsamplerDeviceParamTableEditBox::qsamplerDeviceParamTableEditBox ( |
: QItemDelegate(pParent) |
1160 |
QTable *pTable, EditType editType, const QString& sText ) |
{ |
1161 |
: QTableItem(pTable, editType, sText) |
} |
1162 |
|
|
1163 |
|
|
1164 |
|
QWidget* DeviceParamDelegate::createEditor ( QWidget *pParent, |
1165 |
|
const QStyleOptionViewItem& /* option */, const QModelIndex& index ) const |
1166 |
{ |
{ |
1167 |
|
if (!index.isValid()) |
1168 |
|
return NULL; |
1169 |
|
|
1170 |
|
DeviceParameterRow r = index.model()->data(index, |
1171 |
|
Qt::DisplayRole).value<DeviceParameterRow>(); |
1172 |
|
|
1173 |
|
const bool bEnabled = (r.alive) ? !r.param.fix : true; |
1174 |
|
|
1175 |
|
QString val = (r.alive) ? r.param.value : r.param.defaultv; |
1176 |
|
|
1177 |
|
switch (index.column()) { |
1178 |
|
case 0: |
1179 |
|
return new QLabel(r.name, pParent); |
1180 |
|
case 1: { |
1181 |
|
if (r.param.type == LSCP_TYPE_BOOL) { |
1182 |
|
QCheckBox *pCheckBox = new QCheckBox(pParent); |
1183 |
|
if (val != QString::null) |
1184 |
|
pCheckBox->setChecked(val.toLower() == "true"); |
1185 |
|
pCheckBox->setEnabled(bEnabled); |
1186 |
|
return pCheckBox; |
1187 |
|
} else if (r.param.possibilities.count() > 0) { |
1188 |
|
QStringList opts = r.param.possibilities; |
1189 |
|
if (r.param.multiplicity) |
1190 |
|
opts.prepend(tr("(none)")); |
1191 |
|
QComboBox *pComboBox = new QComboBox(pParent); |
1192 |
|
pComboBox->addItems(opts); |
1193 |
|
if (r.param.value.isEmpty()) |
1194 |
|
pComboBox->setCurrentIndex(0); |
1195 |
|
else |
1196 |
|
pComboBox->setCurrentIndex(pComboBox->findText(val)); |
1197 |
|
pComboBox->setEnabled(bEnabled); |
1198 |
|
return pComboBox; |
1199 |
|
} else if (r.param.type == LSCP_TYPE_INT && bEnabled) { |
1200 |
|
QSpinBox *pSpinBox = new QSpinBox(pParent); |
1201 |
|
pSpinBox->setMinimum( |
1202 |
|
(!r.param.range_min.isEmpty()) ? |
1203 |
|
r.param.range_min.toInt() : 0 // or better a negative default min value ? |
1204 |
|
); |
1205 |
|
pSpinBox->setMaximum( |
1206 |
|
(!r.param.range_max.isEmpty()) ? |
1207 |
|
r.param.range_max.toInt() : (1 << 24) // or better a higher default max value ? |
1208 |
|
); |
1209 |
|
pSpinBox->setValue(val.toInt()); |
1210 |
|
return pSpinBox; |
1211 |
|
} else if (bEnabled) { |
1212 |
|
QLineEdit *pLineEdit = new QLineEdit(val, pParent); |
1213 |
|
return pLineEdit; |
1214 |
|
} else { |
1215 |
|
QLabel *pLabel = new QLabel(val, pParent); |
1216 |
|
return pLabel; |
1217 |
|
} |
1218 |
|
} |
1219 |
|
case 2: |
1220 |
|
return new QLabel(r.param.description, pParent); |
1221 |
|
default: |
1222 |
|
return NULL; |
1223 |
|
} |
1224 |
} |
} |
1225 |
|
|
1226 |
// Virtual implemetations. |
|
1227 |
QWidget *qsamplerDeviceParamTableEditBox::createEditor (void) const |
void DeviceParamDelegate::setEditorData ( |
1228 |
|
QWidget* /*pEditor*/, const QModelIndex& /*index*/) const |
1229 |
{ |
{ |
1230 |
QLineEdit *pEditBox = new QLineEdit(QTableItem::table()->viewport()); |
// Unused, since we set the editor data already in createEditor() |
|
QObject::connect(pEditBox, SIGNAL(returnPressed()), |
|
|
QTableItem::table(), SLOT(doValueChanged())); |
|
|
pEditBox->setText(QTableItem::text()); |
|
|
return pEditBox; |
|
1231 |
} |
} |
1232 |
|
|
1233 |
void qsamplerDeviceParamTableEditBox::setContentFromEditor ( QWidget *pWidget ) |
|
1234 |
|
void DeviceParamDelegate::setModelData ( QWidget *pEditor, |
1235 |
|
QAbstractItemModel *pModel, const QModelIndex& index ) const |
1236 |
|
{ |
1237 |
|
if (index.column() == 1) { |
1238 |
|
DeviceParameterRow r = index.model()->data(index, |
1239 |
|
Qt::DisplayRole).value<DeviceParameterRow> (); |
1240 |
|
if (pEditor->metaObject()->className() == QString("QCheckBox")) { |
1241 |
|
QCheckBox *pCheckBox = static_cast<QCheckBox *> (pEditor); |
1242 |
|
pModel->setData(index, QVariant(pCheckBox->checkState() == Qt::Checked)); |
1243 |
|
} else if (pEditor->metaObject()->className() == QString("QComboBox")) { |
1244 |
|
QComboBox *pComboBox = static_cast<QComboBox *> (pEditor); |
1245 |
|
pModel->setData(index, pComboBox->currentText()); |
1246 |
|
} else if (pEditor->metaObject()->className() == QString("QSpinBox")) { |
1247 |
|
QSpinBox *pSpinBox = static_cast<QSpinBox *> (pEditor); |
1248 |
|
pModel->setData(index, pSpinBox->value()); |
1249 |
|
} else if (pEditor->metaObject()->className() == QString("QLineEdit")) { |
1250 |
|
QLineEdit *pLineEdit = static_cast<QLineEdit *> (pEditor); |
1251 |
|
pModel->setData(index, pLineEdit->text()); |
1252 |
|
} else if (pEditor->metaObject()->className() == QString("QLabel")) { |
1253 |
|
QLabel *pLabel = static_cast<QLabel *> (pEditor); |
1254 |
|
pModel->setData(index, pLabel->text()); |
1255 |
|
} |
1256 |
|
} |
1257 |
|
} |
1258 |
|
|
1259 |
|
void DeviceParamDelegate::updateEditorGeometry ( QWidget *pEditor, |
1260 |
|
const QStyleOptionViewItem &option, const QModelIndex &/* index */) const |
1261 |
{ |
{ |
1262 |
if (pWidget->inherits("QLineEdit")) |
if (pEditor) |
1263 |
QTableItem::setText(((QLineEdit *) pWidget)->text()); |
pEditor->setGeometry(option.rect); |
|
else |
|
|
QTableItem::setContentFromEditor(pWidget); |
|
1264 |
} |
} |
1265 |
|
|
1266 |
|
} // namespace QSampler |
1267 |
|
|
1268 |
// end of qsamplerDevice.cpp |
// end of qsamplerDevice.cpp |