1 |
// qsamplerChannel.cpp |
// qsamplerChannel.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2003-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" |
#include "qsamplerAbout.h" |
24 |
#include "qsamplerChannel.h" |
#include "qsamplerChannel.h" |
25 |
|
#include "qsamplerUtilities.h" |
26 |
|
|
27 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
28 |
#include "qsamplerChannelForm.h" |
#include "qsamplerChannelForm.h" |
29 |
|
|
30 |
#include <qfileinfo.h> |
#include <QFileInfo> |
31 |
#include <qcombobox.h> |
#include <QComboBox> |
32 |
|
|
33 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
34 |
#include "gig.h" |
#include "gig.h" |
35 |
#endif |
#endif |
36 |
|
|
37 |
#define QSAMPLER_INSTRUMENT_MAX 8 |
#define QSAMPLER_INSTRUMENT_MAX 100 |
38 |
|
|
39 |
|
#define UNICODE_RIGHT_ARROW QChar(char(0x92), char(0x21)) |
40 |
|
|
41 |
|
|
42 |
|
using namespace QSampler; |
43 |
|
|
44 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
45 |
// qsamplerChannel - Sampler channel structure. |
// qsamplerChannel - Sampler channel structure. |
46 |
// |
// |
47 |
|
|
48 |
// Constructor. |
// Constructor. |
49 |
qsamplerChannel::qsamplerChannel ( qsamplerMainForm *pMainForm, int iChannelID ) |
qsamplerChannel::qsamplerChannel ( int iChannelID ) |
50 |
{ |
{ |
|
m_pMainForm = pMainForm; |
|
51 |
m_iChannelID = iChannelID; |
m_iChannelID = iChannelID; |
52 |
|
|
53 |
// m_sEngineName = noEngineName(); |
// m_sEngineName = noEngineName(); |
59 |
m_iMidiDevice = -1; |
m_iMidiDevice = -1; |
60 |
m_iMidiPort = -1; |
m_iMidiPort = -1; |
61 |
m_iMidiChannel = -1; |
m_iMidiChannel = -1; |
62 |
|
m_iMidiMap = -1; |
63 |
m_sAudioDriver = "ALSA"; |
m_sAudioDriver = "ALSA"; |
64 |
m_iAudioDevice = -1; |
m_iAudioDevice = -1; |
65 |
m_fVolume = 0.0; |
m_fVolume = 0.0f; |
66 |
m_bMute = false; |
m_bMute = false; |
67 |
m_bSolo = false; |
m_bSolo = false; |
68 |
} |
} |
73 |
} |
} |
74 |
|
|
75 |
|
|
|
// Main application form accessor. |
|
|
qsamplerMainForm *qsamplerChannel::mainForm(void) const |
|
|
{ |
|
|
return m_pMainForm; |
|
|
} |
|
|
|
|
|
|
|
|
// The global options settings delegated property. |
|
|
qsamplerOptions *qsamplerChannel::options (void) const |
|
|
{ |
|
|
if (m_pMainForm == NULL) |
|
|
return NULL; |
|
|
|
|
|
return m_pMainForm->options(); |
|
|
} |
|
|
|
|
|
|
|
|
// The client descriptor delegated property. |
|
|
lscp_client_t *qsamplerChannel::client (void) const |
|
|
{ |
|
|
if (m_pMainForm == NULL) |
|
|
return NULL; |
|
|
|
|
|
return m_pMainForm->client(); |
|
|
} |
|
|
|
|
|
|
|
76 |
// Create a new sampler channel, if not already. |
// Create a new sampler channel, if not already. |
77 |
bool qsamplerChannel::addChannel (void) |
bool qsamplerChannel::addChannel (void) |
78 |
{ |
{ |
79 |
if (client() == NULL) |
MainForm* pMainForm = MainForm::getInstance(); |
80 |
|
if (pMainForm == NULL) |
81 |
|
return false; |
82 |
|
if (pMainForm->client() == NULL) |
83 |
return false; |
return false; |
84 |
|
|
85 |
// Are we a new channel? |
// Are we a new channel? |
86 |
if (m_iChannelID < 0) { |
if (m_iChannelID < 0) { |
87 |
m_iChannelID = ::lscp_add_channel(client()); |
m_iChannelID = ::lscp_add_channel(pMainForm->client()); |
88 |
if (m_iChannelID < 0) { |
if (m_iChannelID < 0) { |
89 |
appendMessagesClient("lscp_add_channel"); |
appendMessagesClient("lscp_add_channel"); |
90 |
appendMessagesError(QObject::tr("Could not add channel.\n\nSorry.")); |
appendMessagesError( |
91 |
|
QObject::tr("Could not add channel.\n\nSorry.")); |
92 |
} // Otherwise it's created... |
} // Otherwise it's created... |
93 |
else appendMessages(QObject::tr("added.")); |
else appendMessages(QObject::tr("added.")); |
94 |
} |
} |
101 |
// Remove sampler channel. |
// Remove sampler channel. |
102 |
bool qsamplerChannel::removeChannel (void) |
bool qsamplerChannel::removeChannel (void) |
103 |
{ |
{ |
104 |
if (client() == NULL) |
MainForm *pMainForm = MainForm::getInstance(); |
105 |
|
if (pMainForm == NULL) |
106 |
|
return false; |
107 |
|
if (pMainForm->client() == NULL) |
108 |
return false; |
return false; |
109 |
|
|
110 |
// Are we an existing channel? |
// Are we an existing channel? |
111 |
if (m_iChannelID >= 0) { |
if (m_iChannelID >= 0) { |
112 |
if (::lscp_remove_channel(client(), m_iChannelID) != LSCP_OK) { |
if (::lscp_remove_channel(pMainForm->client(), m_iChannelID) != LSCP_OK) { |
113 |
appendMessagesClient("lscp_remove_channel"); |
appendMessagesClient("lscp_remove_channel"); |
114 |
appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry.")); |
appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry.")); |
115 |
} else { |
} else { |
151 |
|
|
152 |
bool qsamplerChannel::loadEngine ( const QString& sEngineName ) |
bool qsamplerChannel::loadEngine ( const QString& sEngineName ) |
153 |
{ |
{ |
154 |
if (client() == NULL || m_iChannelID < 0) |
MainForm *pMainForm = MainForm::getInstance(); |
155 |
|
if (pMainForm == NULL) |
156 |
|
return false; |
157 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
158 |
return false; |
return false; |
159 |
if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName) |
if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName) |
160 |
return true; |
return true; |
161 |
|
|
162 |
if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) { |
if (::lscp_load_engine(pMainForm->client(), |
163 |
|
sEngineName.toUtf8().constData(), m_iChannelID) != LSCP_OK) { |
164 |
appendMessagesClient("lscp_load_engine"); |
appendMessagesClient("lscp_load_engine"); |
165 |
return false; |
return false; |
166 |
} |
} |
167 |
|
|
168 |
appendMessages(QObject::tr("Engine: %1.").arg(sEngineName)); |
appendMessages(QObject::tr("Engine: %1.").arg(sEngineName)); |
169 |
|
|
170 |
m_sEngineName = sEngineName; |
m_sEngineName = sEngineName; |
199 |
// Instrument file loader. |
// Instrument file loader. |
200 |
bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) |
bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) |
201 |
{ |
{ |
202 |
if (client() == NULL || m_iChannelID < 0) |
MainForm *pMainForm = MainForm::getInstance(); |
203 |
|
if (pMainForm == NULL) |
204 |
|
return false; |
205 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
206 |
return false; |
return false; |
207 |
if (!isInstrumentFile(sInstrumentFile)) |
if (!isInstrumentFile(sInstrumentFile)) |
208 |
return false; |
return false; |
209 |
if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr) |
if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr) |
210 |
return true; |
return true; |
211 |
|
|
212 |
if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) { |
if ( |
213 |
|
::lscp_load_instrument_non_modal( |
214 |
|
pMainForm->client(), |
215 |
|
qsamplerUtilities::lscpEscapePath( |
216 |
|
sInstrumentFile).toUtf8().constData(), |
217 |
|
iInstrumentNr, m_iChannelID |
218 |
|
) != LSCP_OK |
219 |
|
) { |
220 |
appendMessagesClient("lscp_load_instrument"); |
appendMessagesClient("lscp_load_instrument"); |
221 |
return false; |
return false; |
222 |
} |
} |
252 |
|
|
253 |
bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver ) |
bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver ) |
254 |
{ |
{ |
255 |
if (client() == NULL || m_iChannelID < 0) |
MainForm *pMainForm = MainForm::getInstance(); |
256 |
|
if (pMainForm == NULL) |
257 |
|
return false; |
258 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
259 |
return false; |
return false; |
260 |
if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver) |
if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver) |
261 |
return true; |
return true; |
262 |
|
|
263 |
if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) { |
if (::lscp_set_channel_midi_type(pMainForm->client(), |
264 |
|
m_iChannelID, sMidiDriver.toUtf8().constData()) != LSCP_OK) { |
265 |
appendMessagesClient("lscp_set_channel_midi_type"); |
appendMessagesClient("lscp_set_channel_midi_type"); |
266 |
return false; |
return false; |
267 |
} |
} |
281 |
|
|
282 |
bool qsamplerChannel::setMidiDevice ( int iMidiDevice ) |
bool qsamplerChannel::setMidiDevice ( int iMidiDevice ) |
283 |
{ |
{ |
284 |
if (client() == NULL || m_iChannelID < 0) |
MainForm *pMainForm = MainForm::getInstance(); |
285 |
|
if (pMainForm == NULL) |
286 |
|
return false; |
287 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
288 |
return false; |
return false; |
289 |
if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice) |
if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice) |
290 |
return true; |
return true; |
291 |
|
|
292 |
if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) { |
if (::lscp_set_channel_midi_device(pMainForm->client(), m_iChannelID, iMidiDevice) != LSCP_OK) { |
293 |
appendMessagesClient("lscp_set_channel_midi_device"); |
appendMessagesClient("lscp_set_channel_midi_device"); |
294 |
return false; |
return false; |
295 |
} |
} |
309 |
|
|
310 |
bool qsamplerChannel::setMidiPort ( int iMidiPort ) |
bool qsamplerChannel::setMidiPort ( int iMidiPort ) |
311 |
{ |
{ |
312 |
if (client() == NULL || m_iChannelID < 0) |
MainForm *pMainForm = MainForm::getInstance(); |
313 |
|
if (pMainForm == NULL) |
314 |
|
return false; |
315 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
316 |
return false; |
return false; |
317 |
if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort) |
if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort) |
318 |
return true; |
return true; |
319 |
|
|
320 |
if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) { |
if (::lscp_set_channel_midi_port(pMainForm->client(), m_iChannelID, iMidiPort) != LSCP_OK) { |
321 |
appendMessagesClient("lscp_set_channel_midi_port"); |
appendMessagesClient("lscp_set_channel_midi_port"); |
322 |
return false; |
return false; |
323 |
} |
} |
337 |
|
|
338 |
bool qsamplerChannel::setMidiChannel ( int iMidiChannel ) |
bool qsamplerChannel::setMidiChannel ( int iMidiChannel ) |
339 |
{ |
{ |
340 |
if (client() == NULL || m_iChannelID < 0) |
MainForm *pMainForm = MainForm::getInstance(); |
341 |
|
if (pMainForm == NULL) |
342 |
|
return false; |
343 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
344 |
return false; |
return false; |
345 |
if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel) |
if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel) |
346 |
return true; |
return true; |
347 |
|
|
348 |
if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) { |
if (::lscp_set_channel_midi_channel(pMainForm->client(), m_iChannelID, iMidiChannel) != LSCP_OK) { |
349 |
appendMessagesClient("lscp_set_channel_midi_channel"); |
appendMessagesClient("lscp_set_channel_midi_channel"); |
350 |
return false; |
return false; |
351 |
} |
} |
357 |
} |
} |
358 |
|
|
359 |
|
|
360 |
|
// MIDI instrument map accessor. |
361 |
|
int qsamplerChannel::midiMap (void) const |
362 |
|
{ |
363 |
|
return m_iMidiMap; |
364 |
|
} |
365 |
|
|
366 |
|
bool qsamplerChannel::setMidiMap ( int iMidiMap ) |
367 |
|
{ |
368 |
|
MainForm *pMainForm = MainForm::getInstance(); |
369 |
|
if (pMainForm == NULL) |
370 |
|
return false; |
371 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
372 |
|
return false; |
373 |
|
if (m_iInstrumentStatus == 100 && m_iMidiMap == iMidiMap) |
374 |
|
return true; |
375 |
|
#ifdef CONFIG_MIDI_INSTRUMENT |
376 |
|
if (::lscp_set_channel_midi_map(pMainForm->client(), m_iChannelID, iMidiMap) != LSCP_OK) { |
377 |
|
appendMessagesClient("lscp_set_channel_midi_map"); |
378 |
|
return false; |
379 |
|
} |
380 |
|
#endif |
381 |
|
appendMessages(QObject::tr("MIDI map: %1.").arg(iMidiMap)); |
382 |
|
|
383 |
|
m_iMidiMap = iMidiMap; |
384 |
|
return true; |
385 |
|
} |
386 |
|
|
387 |
|
|
388 |
// Audio device accessor. |
// Audio device accessor. |
389 |
int qsamplerChannel::audioDevice (void) const |
int qsamplerChannel::audioDevice (void) const |
390 |
{ |
{ |
393 |
|
|
394 |
bool qsamplerChannel::setAudioDevice ( int iAudioDevice ) |
bool qsamplerChannel::setAudioDevice ( int iAudioDevice ) |
395 |
{ |
{ |
396 |
if (client() == NULL || m_iChannelID < 0) |
MainForm *pMainForm = MainForm::getInstance(); |
397 |
|
if (pMainForm == NULL) |
398 |
|
return false; |
399 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
400 |
return false; |
return false; |
401 |
if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice) |
if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice) |
402 |
return true; |
return true; |
403 |
|
|
404 |
if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) { |
if (::lscp_set_channel_audio_device(pMainForm->client(), m_iChannelID, iAudioDevice) != LSCP_OK) { |
405 |
appendMessagesClient("lscp_set_channel_audio_device"); |
appendMessagesClient("lscp_set_channel_audio_device"); |
406 |
return false; |
return false; |
407 |
} |
} |
421 |
|
|
422 |
bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver ) |
bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver ) |
423 |
{ |
{ |
424 |
if (client() == NULL || m_iChannelID < 0) |
MainForm *pMainForm = MainForm::getInstance(); |
425 |
|
if (pMainForm == NULL) |
426 |
|
return false; |
427 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
428 |
return false; |
return false; |
429 |
if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver) |
if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver) |
430 |
return true; |
return true; |
431 |
|
|
432 |
if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) { |
if (::lscp_set_channel_audio_type(pMainForm->client(), |
433 |
|
m_iChannelID, sAudioDriver.toUtf8().constData()) != LSCP_OK) { |
434 |
appendMessagesClient("lscp_set_channel_audio_type"); |
appendMessagesClient("lscp_set_channel_audio_type"); |
435 |
return false; |
return false; |
436 |
} |
} |
450 |
|
|
451 |
bool qsamplerChannel::setVolume ( float fVolume ) |
bool qsamplerChannel::setVolume ( float fVolume ) |
452 |
{ |
{ |
453 |
if (client() == NULL || m_iChannelID < 0) |
MainForm *pMainForm = MainForm::getInstance(); |
454 |
|
if (pMainForm == NULL) |
455 |
|
return false; |
456 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
457 |
return false; |
return false; |
458 |
if (m_iInstrumentStatus == 100 && m_fVolume == fVolume) |
if (m_iInstrumentStatus == 100 && m_fVolume == fVolume) |
459 |
return true; |
return true; |
460 |
|
|
461 |
if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) { |
if (::lscp_set_channel_volume(pMainForm->client(), m_iChannelID, fVolume) != LSCP_OK) { |
462 |
appendMessagesClient("lscp_set_channel_volume"); |
appendMessagesClient("lscp_set_channel_volume"); |
463 |
return false; |
return false; |
464 |
} |
} |
478 |
|
|
479 |
bool qsamplerChannel::setChannelMute ( bool bMute ) |
bool qsamplerChannel::setChannelMute ( bool bMute ) |
480 |
{ |
{ |
481 |
if (client() == NULL || m_iChannelID < 0) |
MainForm *pMainForm = MainForm::getInstance(); |
482 |
|
if (pMainForm == NULL) |
483 |
|
return false; |
484 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
485 |
return false; |
return false; |
486 |
if (m_iInstrumentStatus == 100 && ((m_bMute && bMute) || (!m_bMute && !bMute))) |
if (m_iInstrumentStatus == 100 && ((m_bMute && bMute) || (!m_bMute && !bMute))) |
487 |
return true; |
return true; |
488 |
|
|
489 |
#ifdef CONFIG_MUTE_SOLO |
#ifdef CONFIG_MUTE_SOLO |
490 |
if (::lscp_set_channel_mute(client(), m_iChannelID, bMute) != LSCP_OK) { |
if (::lscp_set_channel_mute(pMainForm->client(), m_iChannelID, bMute) != LSCP_OK) { |
491 |
appendMessagesClient("lscp_set_channel_mute"); |
appendMessagesClient("lscp_set_channel_mute"); |
492 |
return false; |
return false; |
493 |
} |
} |
508 |
|
|
509 |
bool qsamplerChannel::setChannelSolo ( bool bSolo ) |
bool qsamplerChannel::setChannelSolo ( bool bSolo ) |
510 |
{ |
{ |
511 |
if (client() == NULL || m_iChannelID < 0) |
MainForm *pMainForm = MainForm::getInstance(); |
512 |
|
if (pMainForm == NULL) |
513 |
|
return false; |
514 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
515 |
return false; |
return false; |
516 |
if (m_iInstrumentStatus == 100 && ((m_bSolo && bSolo) || (!m_bSolo && !bSolo))) |
if (m_iInstrumentStatus == 100 && ((m_bSolo && bSolo) || (!m_bSolo && !bSolo))) |
517 |
return true; |
return true; |
518 |
|
|
519 |
#ifdef CONFIG_MUTE_SOLO |
#ifdef CONFIG_MUTE_SOLO |
520 |
if (::lscp_set_channel_solo(client(), m_iChannelID, bSolo) != LSCP_OK) { |
if (::lscp_set_channel_solo(pMainForm->client(), m_iChannelID, bSolo) != LSCP_OK) { |
521 |
appendMessagesClient("lscp_set_channel_solo"); |
appendMessagesClient("lscp_set_channel_solo"); |
522 |
return false; |
return false; |
523 |
} |
} |
538 |
|
|
539 |
bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn ) |
bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn ) |
540 |
{ |
{ |
541 |
if (client() == NULL || m_iChannelID < 0) |
MainForm *pMainForm = MainForm::getInstance(); |
542 |
|
if (pMainForm == NULL) |
543 |
|
return false; |
544 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
545 |
return false; |
return false; |
546 |
if (m_iInstrumentStatus == 100 && |
if (m_iInstrumentStatus == 100 && |
547 |
m_audioRouting[iAudioOut] == iAudioIn) |
m_audioRouting[iAudioOut] == iAudioIn) |
548 |
return true; |
return true; |
549 |
|
|
550 |
if (::lscp_set_channel_audio_channel(client(), |
if (::lscp_set_channel_audio_channel(pMainForm->client(), |
551 |
m_iChannelID, iAudioOut, iAudioIn) != LSCP_OK) { |
m_iChannelID, iAudioOut, iAudioIn) != LSCP_OK) { |
552 |
appendMessagesClient("lscp_set_channel_audio_channel"); |
appendMessagesClient("lscp_set_channel_audio_channel"); |
553 |
return false; |
return false; |
580 |
// Update whole channel info state. |
// Update whole channel info state. |
581 |
bool qsamplerChannel::updateChannelInfo (void) |
bool qsamplerChannel::updateChannelInfo (void) |
582 |
{ |
{ |
583 |
if (client() == NULL || m_iChannelID < 0) |
MainForm *pMainForm = MainForm::getInstance(); |
584 |
|
if (pMainForm == NULL) |
585 |
|
return false; |
586 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
587 |
return false; |
return false; |
588 |
|
|
589 |
// Read channel information. |
// Read channel information. |
590 |
lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID); |
lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(pMainForm->client(), m_iChannelID); |
591 |
if (pChannelInfo == NULL) { |
if (pChannelInfo == NULL) { |
592 |
appendMessagesClient("lscp_get_channel_info"); |
appendMessagesClient("lscp_get_channel_info"); |
593 |
appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry.")); |
appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry.")); |
596 |
|
|
597 |
#ifdef CONFIG_INSTRUMENT_NAME |
#ifdef CONFIG_INSTRUMENT_NAME |
598 |
// We got all actual instrument datum... |
// We got all actual instrument datum... |
599 |
m_sInstrumentFile = pChannelInfo->instrument_file; |
m_sInstrumentFile = |
600 |
|
qsamplerUtilities::lscpEscapedPathToPosix(pChannelInfo->instrument_file); |
601 |
m_iInstrumentNr = pChannelInfo->instrument_nr; |
m_iInstrumentNr = pChannelInfo->instrument_nr; |
602 |
m_sInstrumentName = pChannelInfo->instrument_name; |
m_sInstrumentName = |
603 |
|
qsamplerUtilities::lscpEscapedTextToRaw(pChannelInfo->instrument_name); |
604 |
#else |
#else |
605 |
// First, check if intrument name has changed, |
// First, check if intrument name has changed, |
606 |
// taking care that instrument name lookup might be expensive, |
// taking care that instrument name lookup might be expensive, |
618 |
m_iMidiDevice = pChannelInfo->midi_device; |
m_iMidiDevice = pChannelInfo->midi_device; |
619 |
m_iMidiPort = pChannelInfo->midi_port; |
m_iMidiPort = pChannelInfo->midi_port; |
620 |
m_iMidiChannel = pChannelInfo->midi_channel; |
m_iMidiChannel = pChannelInfo->midi_channel; |
621 |
|
#ifdef CONFIG_MIDI_INSTRUMENT |
622 |
|
m_iMidiMap = pChannelInfo->midi_map; |
623 |
|
#endif |
624 |
m_iAudioDevice = pChannelInfo->audio_device; |
m_iAudioDevice = pChannelInfo->audio_device; |
625 |
m_fVolume = pChannelInfo->volume; |
m_fVolume = pChannelInfo->volume; |
626 |
#ifdef CONFIG_MUTE_SOLO |
#ifdef CONFIG_MUTE_SOLO |
639 |
lscp_device_info_t *pDeviceInfo; |
lscp_device_info_t *pDeviceInfo; |
640 |
const QString sNone = QObject::tr("(none)"); |
const QString sNone = QObject::tr("(none)"); |
641 |
// Audio device driver type. |
// Audio device driver type. |
642 |
pDeviceInfo = ::lscp_get_audio_device_info(client(), m_iAudioDevice); |
pDeviceInfo = ::lscp_get_audio_device_info(pMainForm->client(), m_iAudioDevice); |
643 |
if (pDeviceInfo == NULL) { |
if (pDeviceInfo == NULL) { |
644 |
appendMessagesClient("lscp_get_audio_device_info"); |
appendMessagesClient("lscp_get_audio_device_info"); |
645 |
m_sAudioDriver = sNone; |
m_sAudioDriver = sNone; |
647 |
m_sAudioDriver = pDeviceInfo->driver; |
m_sAudioDriver = pDeviceInfo->driver; |
648 |
} |
} |
649 |
// MIDI device driver type. |
// MIDI device driver type. |
650 |
pDeviceInfo = ::lscp_get_midi_device_info(client(), m_iMidiDevice); |
pDeviceInfo = ::lscp_get_midi_device_info(pMainForm->client(), m_iMidiDevice); |
651 |
if (pDeviceInfo == NULL) { |
if (pDeviceInfo == NULL) { |
652 |
appendMessagesClient("lscp_get_midi_device_info"); |
appendMessagesClient("lscp_get_midi_device_info"); |
653 |
m_sMidiDriver = sNone; |
m_sMidiDriver = sNone; |
657 |
|
|
658 |
// Set the audio routing map. |
// Set the audio routing map. |
659 |
m_audioRouting.clear(); |
m_audioRouting.clear(); |
660 |
char **ppszRouting = pChannelInfo->audio_routing; |
#ifdef CONFIG_AUDIO_ROUTING |
661 |
for (int i = 0; ppszRouting && ppszRouting[i]; i++) { |
int *piAudioRouting = pChannelInfo->audio_routing; |
662 |
m_audioRouting[i] = ::atoi(ppszRouting[i]); |
for (int i = 0; piAudioRouting && piAudioRouting[i] >= 0; i++) |
663 |
} |
m_audioRouting[i] = piAudioRouting[i]; |
664 |
|
#else |
665 |
|
char **ppszAudioRouting = pChannelInfo->audio_routing; |
666 |
|
for (int i = 0; ppszAudioRouting && ppszAudioRouting[i]; i++) |
667 |
|
m_audioRouting[i] = ::atoi(ppszAudioRouting[i]); |
668 |
|
#endif |
669 |
|
|
670 |
return true; |
return true; |
671 |
} |
} |
674 |
// Reset channel method. |
// Reset channel method. |
675 |
bool qsamplerChannel::channelReset (void) |
bool qsamplerChannel::channelReset (void) |
676 |
{ |
{ |
677 |
if (client() == NULL || m_iChannelID < 0) |
MainForm *pMainForm = MainForm::getInstance(); |
678 |
|
if (pMainForm == NULL) |
679 |
|
return false; |
680 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
681 |
return false; |
return false; |
682 |
|
|
683 |
if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK) { |
if (::lscp_reset_channel(pMainForm->client(), m_iChannelID) != LSCP_OK) { |
684 |
appendMessagesClient("lscp_reset_channel"); |
appendMessagesClient("lscp_reset_channel"); |
685 |
return false; |
return false; |
686 |
} |
} |
691 |
} |
} |
692 |
|
|
693 |
|
|
694 |
|
// Spawn instrument editor method. |
695 |
|
bool qsamplerChannel::editChannel (void) |
696 |
|
{ |
697 |
|
#ifdef CONFIG_EDIT_INSTRUMENT |
698 |
|
|
699 |
|
MainForm *pMainForm = MainForm::getInstance(); |
700 |
|
if (pMainForm == NULL) |
701 |
|
return false; |
702 |
|
if (pMainForm->client() == NULL || m_iChannelID < 0) |
703 |
|
return false; |
704 |
|
|
705 |
|
if (::lscp_edit_channel_instrument(pMainForm->client(), m_iChannelID) |
706 |
|
!= LSCP_OK) { |
707 |
|
appendMessagesClient("lscp_edit_channel_instrument"); |
708 |
|
appendMessagesError(QObject::tr( |
709 |
|
"Could not launch an appropriate instrument editor " |
710 |
|
"for the given instrument!\n" |
711 |
|
"Make sure you have an appropriate " |
712 |
|
"instrument editor like 'gigedit' installed\n" |
713 |
|
"and that it placed its mandatory DLL file " |
714 |
|
"into the sampler's plugin directory.") |
715 |
|
); |
716 |
|
return false; |
717 |
|
} |
718 |
|
|
719 |
|
appendMessages(QObject::tr("edit instrument.")); |
720 |
|
|
721 |
|
return true; |
722 |
|
|
723 |
|
#else |
724 |
|
|
725 |
|
appendMessagesError(QObject::tr( |
726 |
|
"Sorry, QSampler was compiled for a version of liblscp " |
727 |
|
"which lacks this feature.\n" |
728 |
|
"You may want to update liblscp and recompile QSampler afterwards.") |
729 |
|
); |
730 |
|
|
731 |
|
return false; |
732 |
|
|
733 |
|
#endif |
734 |
|
} |
735 |
|
|
736 |
|
|
737 |
// Channel setup dialog form. |
// Channel setup dialog form. |
738 |
bool qsamplerChannel::channelSetup ( QWidget *pParent ) |
bool qsamplerChannel::channelSetup ( QWidget *pParent ) |
739 |
{ |
{ |
740 |
|
MainForm *pMainForm = MainForm::getInstance(); |
741 |
|
if (pMainForm == NULL) |
742 |
|
return false; |
743 |
|
|
744 |
bool bResult = false; |
bool bResult = false; |
745 |
|
|
746 |
appendMessages(QObject::tr("setup...")); |
appendMessages(QObject::tr("setup...")); |
747 |
|
|
748 |
qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent); |
ChannelForm *pChannelForm = new ChannelForm(pParent); |
749 |
if (pChannelForm) { |
if (pChannelForm) { |
750 |
pChannelForm->setup(this); |
pChannelForm->setup(this); |
751 |
bResult = pChannelForm->exec(); |
bResult = pChannelForm->exec(); |
759 |
// Redirected messages output methods. |
// Redirected messages output methods. |
760 |
void qsamplerChannel::appendMessages( const QString& s ) const |
void qsamplerChannel::appendMessages( const QString& s ) const |
761 |
{ |
{ |
762 |
if (m_pMainForm) |
MainForm *pMainForm = MainForm::getInstance(); |
763 |
m_pMainForm->appendMessages(channelName() + ' ' + s); |
if (pMainForm) |
764 |
|
pMainForm->appendMessages(channelName() + ' ' + s); |
765 |
} |
} |
766 |
|
|
767 |
void qsamplerChannel::appendMessagesColor( const QString& s, |
void qsamplerChannel::appendMessagesColor( const QString& s, |
768 |
const QString& c ) const |
const QString& c ) const |
769 |
{ |
{ |
770 |
if (m_pMainForm) |
MainForm *pMainForm = MainForm::getInstance(); |
771 |
m_pMainForm->appendMessagesColor(channelName() + ' ' + s, c); |
if (pMainForm) |
772 |
|
pMainForm->appendMessagesColor(channelName() + ' ' + s, c); |
773 |
} |
} |
774 |
|
|
775 |
void qsamplerChannel::appendMessagesText( const QString& s ) const |
void qsamplerChannel::appendMessagesText( const QString& s ) const |
776 |
{ |
{ |
777 |
if (m_pMainForm) |
MainForm *pMainForm = MainForm::getInstance(); |
778 |
m_pMainForm->appendMessagesText(channelName() + ' ' + s); |
if (pMainForm) |
779 |
|
pMainForm->appendMessagesText(channelName() + ' ' + s); |
780 |
} |
} |
781 |
|
|
782 |
void qsamplerChannel::appendMessagesError( const QString& s ) const |
void qsamplerChannel::appendMessagesError( const QString& s ) const |
783 |
{ |
{ |
784 |
if (m_pMainForm) |
MainForm *pMainForm = MainForm::getInstance(); |
785 |
m_pMainForm->appendMessagesError(channelName() + "\n\n" + s); |
if (pMainForm) |
786 |
|
pMainForm->appendMessagesError(channelName() + "\n\n" + s); |
787 |
} |
} |
788 |
|
|
789 |
void qsamplerChannel::appendMessagesClient( const QString& s ) const |
void qsamplerChannel::appendMessagesClient( const QString& s ) const |
790 |
{ |
{ |
791 |
if (m_pMainForm) |
MainForm *pMainForm = MainForm::getInstance(); |
792 |
m_pMainForm->appendMessagesClient(channelName() + ' ' + s); |
if (pMainForm) |
793 |
|
pMainForm->appendMessagesClient(channelName() + ' ' + s); |
794 |
} |
} |
795 |
|
|
796 |
|
|
797 |
// Context menu event handler. |
// Context menu event handler. |
798 |
void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent ) |
void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent ) |
799 |
{ |
{ |
800 |
if (m_pMainForm) |
MainForm *pMainForm = MainForm::getInstance(); |
801 |
m_pMainForm->contextMenuEvent(pEvent); |
if (pMainForm) |
802 |
|
pMainForm->contextMenuEvent(pEvent); |
803 |
} |
} |
804 |
|
|
805 |
|
|
809 |
bool bResult = false; |
bool bResult = false; |
810 |
|
|
811 |
QFile file(sInstrumentFile); |
QFile file(sInstrumentFile); |
812 |
if (file.open(IO_ReadOnly)) { |
if (file.open(QIODevice::ReadOnly)) { |
813 |
char achHeader[16]; |
char achHeader[16]; |
814 |
if (file.readBlock(achHeader, 16)) { |
if (file.read(achHeader, 16) > 0) { |
815 |
bResult = (::memcmp(&achHeader[0], "RIFF", 4) == 0 |
bResult = (::memcmp(&achHeader[0], "RIFF", 4) == 0 |
816 |
&& ::memcmp(&achHeader[8], "DLS LIST", 8) == 0); |
&& ::memcmp(&achHeader[8], "DLS LIST", 8) == 0); |
817 |
} |
} |
832 |
if (isInstrumentFile(sInstrumentFile)) { |
if (isInstrumentFile(sInstrumentFile)) { |
833 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
834 |
if (bInstrumentNames) { |
if (bInstrumentNames) { |
835 |
RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1()); |
RIFF::File *pRiff |
836 |
|
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
837 |
gig::File *pGig = new gig::File(pRiff); |
gig::File *pGig = new gig::File(pRiff); |
838 |
|
#if HAVE_LIBGIG_SETAUTOLOAD |
839 |
|
// prevent sleepy response time on large .gig files |
840 |
|
pGig->SetAutoLoad(false); |
841 |
|
#endif |
842 |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
843 |
while (pInstrument) { |
while (pInstrument) { |
844 |
instlist.append((pInstrument->pInfo)->Name.c_str()); |
instlist.append((pInstrument->pInfo)->Name.c_str()); |
868 |
sInstrumentName = QFileInfo(sInstrumentFile).fileName(); |
sInstrumentName = QFileInfo(sInstrumentFile).fileName(); |
869 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
870 |
if (bInstrumentNames) { |
if (bInstrumentNames) { |
871 |
RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1()); |
RIFF::File *pRiff |
872 |
gig::File *pGig = new gig::File(pRiff); |
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
873 |
|
gig::File *pGig = new gig::File(pRiff); |
874 |
|
#if HAVE_LIBGIG_SETAUTOLOAD |
875 |
|
// prevent sleepy response time on large .gig files |
876 |
|
pGig->SetAutoLoad(false); |
877 |
|
#endif |
878 |
int iIndex = 0; |
int iIndex = 0; |
879 |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
880 |
while (pInstrument) { |
while (pInstrument) { |
914 |
} |
} |
915 |
|
|
916 |
|
|
|
|
|
917 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
918 |
// qsamplerChannelRoutingTable - Channel routing table. |
// ChannelRoutingModel - data model for audio routing (used for QTableView) |
919 |
// |
// |
920 |
|
|
921 |
// Constructor. |
ChannelRoutingModel::ChannelRoutingModel ( QObject *pParent ) |
922 |
qsamplerChannelRoutingTable::qsamplerChannelRoutingTable ( |
: QAbstractTableModel(pParent), m_pDevice(NULL) |
923 |
QWidget *pParent, const char *pszName ) |
{ |
|
: QTable(pParent, pszName) |
|
|
{ |
|
|
// Set fixed number of columns. |
|
|
QTable::setNumCols(2); |
|
|
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("Sampler Channel")); |
|
|
pHeader->setLabel(1, tr("Device Channel")); |
|
|
// Set read-onlyness of each column |
|
|
QTable::setColumnReadOnly(0, true); |
|
|
// QTable::setColumnReadOnly(1, false); -- of course not. |
|
|
QTable::setColumnStretchable(1, true); |
|
924 |
} |
} |
925 |
|
|
926 |
// Default destructor. |
|
927 |
qsamplerChannelRoutingTable::~qsamplerChannelRoutingTable (void) |
int ChannelRoutingModel::rowCount ( const QModelIndex& /*parent*/) const |
928 |
{ |
{ |
929 |
|
return m_routing.size(); |
930 |
} |
} |
931 |
|
|
932 |
|
|
933 |
// Routing map table renderer. |
int ChannelRoutingModel::columnCount ( const QModelIndex& /*parent*/) const |
934 |
void qsamplerChannelRoutingTable::refresh ( qsamplerDevice *pDevice, |
{ |
935 |
const qsamplerChannelRoutingMap& routing ) |
return 1; |
936 |
|
} |
937 |
|
|
938 |
|
|
939 |
|
Qt::ItemFlags ChannelRoutingModel::flags ( const QModelIndex& /*index*/) const |
940 |
|
{ |
941 |
|
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled; |
942 |
|
} |
943 |
|
|
944 |
|
|
945 |
|
bool ChannelRoutingModel::setData ( const QModelIndex& index, |
946 |
|
const QVariant& value, int /*role*/) |
947 |
{ |
{ |
948 |
if (pDevice == NULL) |
if (!index.isValid()) |
949 |
return; |
return false; |
950 |
|
|
951 |
// Always (re)start it empty. |
m_routing[index.row()] = value.toInt(); |
952 |
QTable::setUpdatesEnabled(false); |
|
953 |
QTable::setNumRows(0); |
emit dataChanged(index, index); |
954 |
|
return true; |
955 |
|
} |
956 |
|
|
957 |
|
|
958 |
|
QVariant ChannelRoutingModel::data ( const QModelIndex &index, int role ) const |
959 |
|
{ |
960 |
|
if (!index.isValid()) |
961 |
|
return QVariant(); |
962 |
|
if (role != Qt::DisplayRole) |
963 |
|
return QVariant(); |
964 |
|
if (index.column() != 0) |
965 |
|
return QVariant(); |
966 |
|
|
967 |
|
ChannelRoutingItem item; |
968 |
|
|
969 |
// The common device port item list. |
// The common device port item list. |
970 |
QStringList opts; |
qsamplerDevicePortList& ports = m_pDevice->ports(); |
971 |
qsamplerDevicePortList& ports = pDevice->ports(); |
QListIterator<qsamplerDevicePort *> iter(ports); |
972 |
qsamplerDevicePort *pPort; |
while (iter.hasNext()) { |
973 |
for (pPort = ports.first(); pPort; pPort = ports.next()) { |
qsamplerDevicePort *pPort = iter.next(); |
974 |
opts.append(pDevice->deviceTypeName() |
item.options.append( |
975 |
+ ' ' + pDevice->driverName() |
m_pDevice->deviceTypeName() |
976 |
+ ' ' + pPort->portName()); |
+ ' ' + m_pDevice->driverName() |
977 |
} |
+ ' ' + pPort->portName() |
978 |
|
); |
979 |
// Those items shall have a proper pixmap... |
} |
980 |
QPixmap pmChannel = QPixmap::fromMimeSource("qsamplerChannel.png"); |
|
981 |
QPixmap pmDevice; |
item.selection = m_routing[index.row()]; |
982 |
switch (pDevice->deviceType()) { |
|
983 |
case qsamplerDevice::Audio: |
return QVariant::fromValue(item); |
984 |
pmDevice = QPixmap::fromMimeSource("audio2.png"); |
} |
985 |
break; |
|
986 |
case qsamplerDevice::Midi: |
|
987 |
pmDevice = QPixmap::fromMimeSource("midi2.png"); |
QVariant ChannelRoutingModel::headerData ( int section, |
988 |
break; |
Qt::Orientation orientation, int role) const |
989 |
case qsamplerDevice::None: |
{ |
990 |
break; |
if (role != Qt::DisplayRole) |
991 |
} |
return QVariant(); |
|
|
|
|
// Fill the routing table... |
|
|
QTable::insertRows(0, routing.count()); |
|
|
int iRow = 0; |
|
|
qsamplerChannelRoutingMap::ConstIterator iter; |
|
|
for (iter = routing.begin(); iter != routing.end(); ++iter) { |
|
|
QTable::setPixmap(iRow, 0, pmChannel); |
|
|
QTable::setText(iRow, 0, pDevice->deviceTypeName() |
|
|
+ ' ' + QString::number(iter.key())); |
|
|
qsamplerChannelRoutingComboBox *pComboItem = |
|
|
new qsamplerChannelRoutingComboBox(this, opts, pmDevice); |
|
|
pComboItem->setCurrentItem(iter.data()); |
|
|
QTable::setItem(iRow, 1, pComboItem); |
|
|
++iRow; |
|
|
} |
|
|
|
|
|
// Adjust optimal column widths. |
|
|
QTable::adjustColumn(0); |
|
|
QTable::adjustColumn(1); |
|
992 |
|
|
993 |
QTable::setUpdatesEnabled(true); |
switch (orientation) { |
994 |
QTable::updateContents(); |
case Qt::Horizontal: |
995 |
|
return UNICODE_RIGHT_ARROW + QObject::tr(" Device Channel"); |
996 |
|
case Qt::Vertical: |
997 |
|
return QObject::tr("Sampler Channel ") + |
998 |
|
QString::number(section) + " " + UNICODE_RIGHT_ARROW; |
999 |
|
default: |
1000 |
|
return QVariant(); |
1001 |
|
} |
1002 |
|
} |
1003 |
|
|
1004 |
|
|
1005 |
|
void ChannelRoutingModel::refresh ( qsamplerDevice *pDevice, |
1006 |
|
const qsamplerChannelRoutingMap& routing ) |
1007 |
|
{ |
1008 |
|
m_pDevice = pDevice; |
1009 |
|
m_routing = routing; |
1010 |
|
// inform the outer world (QTableView) that our data changed |
1011 |
|
QAbstractTableModel::reset(); |
1012 |
} |
} |
1013 |
|
|
1014 |
|
|
1015 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
1016 |
// qsamplerChannelRoutingComboBox - Custom combo box for routing table. |
// ChannelRoutingDelegate - table cell renderer for audio routing |
1017 |
// |
// |
1018 |
|
|
1019 |
// Constructor. |
ChannelRoutingDelegate::ChannelRoutingDelegate ( QObject *pParent ) |
1020 |
qsamplerChannelRoutingComboBox::qsamplerChannelRoutingComboBox ( |
: QItemDelegate(pParent) |
|
QTable *pTable, const QStringList& list, const QPixmap& pixmap ) |
|
|
: QTableItem(pTable, QTableItem::WhenCurrent, QString::null, pixmap), |
|
|
m_list(list) |
|
1021 |
{ |
{ |
|
m_iCurrentItem = 0; |
|
1022 |
} |
} |
1023 |
|
|
1024 |
// Public accessors. |
|
1025 |
void qsamplerChannelRoutingComboBox::setCurrentItem ( int iCurrentItem ) |
QWidget* ChannelRoutingDelegate::createEditor ( QWidget *pParent, |
1026 |
|
const QStyleOptionViewItem & option, const QModelIndex& index ) const |
1027 |
{ |
{ |
1028 |
m_iCurrentItem = iCurrentItem; |
if (!index.isValid()) |
1029 |
|
return NULL; |
1030 |
|
|
1031 |
|
if (index.column() != 0) |
1032 |
|
return NULL; |
1033 |
|
|
1034 |
|
ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>(); |
1035 |
|
|
1036 |
QTableItem::setText(m_list[iCurrentItem]); |
QComboBox* pComboBox = new QComboBox(pParent); |
1037 |
|
pComboBox->addItems(item.options); |
1038 |
|
pComboBox->setCurrentIndex(item.selection); |
1039 |
|
pComboBox->setEnabled(true); |
1040 |
|
pComboBox->setGeometry(option.rect); |
1041 |
|
return pComboBox; |
1042 |
} |
} |
1043 |
|
|
1044 |
int qsamplerChannelRoutingComboBox::currentItem (void) const |
|
1045 |
|
void ChannelRoutingDelegate::setEditorData ( QWidget *pEditor, |
1046 |
|
const QModelIndex &index) const |
1047 |
{ |
{ |
1048 |
return m_iCurrentItem; |
ChannelRoutingItem item = index.model()->data(index, |
1049 |
|
Qt::DisplayRole).value<ChannelRoutingItem> (); |
1050 |
|
QComboBox* pComboBox = static_cast<QComboBox*> (pEditor); |
1051 |
|
pComboBox->setCurrentIndex(item.selection); |
1052 |
} |
} |
1053 |
|
|
1054 |
// Virtual implemetations. |
|
1055 |
QWidget *qsamplerChannelRoutingComboBox::createEditor (void) const |
void ChannelRoutingDelegate::setModelData ( QWidget* pEditor, |
1056 |
|
QAbstractItemModel *pModel, const QModelIndex& index ) const |
1057 |
{ |
{ |
1058 |
QComboBox *pComboBox = new QComboBox(QTableItem::table()->viewport()); |
QComboBox *pComboBox = static_cast<QComboBox*> (pEditor); |
1059 |
QObject::connect(pComboBox, SIGNAL(activated(int)), |
pModel->setData(index, pComboBox->currentIndex()); |
|
QTableItem::table(), SLOT(doValueChanged())); |
|
|
for (QStringList::ConstIterator iter = m_list.begin(); |
|
|
iter != m_list.end(); iter++) { |
|
|
pComboBox->insertItem(QTableItem::pixmap(), *iter); |
|
|
} |
|
|
pComboBox->setCurrentItem(m_iCurrentItem); |
|
|
return pComboBox; |
|
1060 |
} |
} |
1061 |
|
|
1062 |
void qsamplerChannelRoutingComboBox::setContentFromEditor ( QWidget *pWidget ) |
|
1063 |
|
void ChannelRoutingDelegate::updateEditorGeometry ( QWidget *pEditor, |
1064 |
|
const QStyleOptionViewItem& option, const QModelIndex &/* index */) const |
1065 |
{ |
{ |
1066 |
if (pWidget->inherits("QComboBox")) { |
pEditor->setGeometry(option.rect); |
|
QComboBox *pComboBox = (QComboBox *) pWidget; |
|
|
m_iCurrentItem = pComboBox->currentItem(); |
|
|
QTableItem::setText(pComboBox->currentText()); |
|
|
} |
|
|
else QTableItem::setContentFromEditor(pWidget); |
|
1067 |
} |
} |
1068 |
|
|
1069 |
|
|