13
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
15
GNU General Public License for more details.
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
You should have received a copy of the GNU General Public License along
18
with this program; if not, write to the Free Software Foundation, Inc.,
19
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21
*****************************************************************************/
23
#include "qsamplerAbout.h"
22
24
#include "qsamplerChannel.h"
25
#include "qsamplerUtilities.h"
24
27
#include "qsamplerMainForm.h"
25
28
#include "qsamplerChannelForm.h"
29
#include <qfileinfo.h>
31
33
#ifdef CONFIG_LIBGIG
35
#define QSAMPLER_INSTRUMENT_MAX 8
39
#define QSAMPLER_INSTRUMENT_MAX 100
41
#define UNICODE_RIGHT_ARROW QChar(char(0x92), char(0x21))
38
44
//-------------------------------------------------------------------------
39
// qsamplerChannel - Sampler channel structure.
45
// QSampler::Channel - Sampler channel structure.
43
qsamplerChannel::qsamplerChannel ( qsamplerMainForm *pMainForm, int iChannelID )
49
Channel::Channel ( int iChannelID )
45
m_pMainForm = pMainForm;
46
51
m_iChannelID = iChannelID;
48
53
// m_sEngineName = noEngineName();
54
59
m_iMidiDevice = -1;
56
61
m_iMidiChannel = -1;
57
63
m_sAudioDriver = "ALSA";
58
64
m_iAudioDevice = -1;
63
70
// Default destructor.
64
qsamplerChannel::~qsamplerChannel (void)
69
// Main application form accessor.
70
qsamplerMainForm *qsamplerChannel::mainForm(void) const
76
// The global options settings delegated property.
77
qsamplerOptions *qsamplerChannel::options (void) const
79
if (m_pMainForm == NULL)
82
return m_pMainForm->options();
86
// The client descriptor delegated property.
87
lscp_client_t *qsamplerChannel::client (void) const
89
if (m_pMainForm == NULL)
92
return m_pMainForm->client();
71
Channel::~Channel (void)
96
76
// Create a new sampler channel, if not already.
97
bool qsamplerChannel::addChannel (void)
77
bool Channel::addChannel (void)
79
MainForm* pMainForm = MainForm::getInstance();
80
if (pMainForm == NULL)
82
if (pMainForm->client() == NULL)
102
85
// Are we a new channel?
103
86
if (m_iChannelID < 0) {
104
m_iChannelID = ::lscp_add_channel(client());
87
m_iChannelID = ::lscp_add_channel(pMainForm->client());
105
88
if (m_iChannelID < 0) {
106
89
appendMessagesClient("lscp_add_channel");
107
appendMessagesError(QObject::tr("Could not add channel.\n\nSorry."));
91
QObject::tr("Could not add channel.\n\nSorry."));
108
92
} // Otherwise it's created...
109
93
else appendMessages(QObject::tr("added."));
140
127
// Channel-ID (aka Sammpler-Channel) accessors.
141
int qsamplerChannel::channelID (void) const
128
int Channel::channelID (void) const
143
130
return m_iChannelID;
146
void qsamplerChannel::setChannelID ( int iChannelID )
133
void Channel::setChannelID ( int iChannelID )
148
135
m_iChannelID = iChannelID;
152
139
// Readable channel name.
153
QString qsamplerChannel::channelName (void) const
140
QString Channel::channelName (void) const
155
142
return (m_iChannelID < 0 ? QObject::tr("New Channel") : QObject::tr("Channel %1").arg(m_iChannelID));
159
146
// Engine name accessors.
160
const QString& qsamplerChannel::engineName (void) const
147
const QString& Channel::engineName (void) const
162
149
return m_sEngineName;
165
bool qsamplerChannel::loadEngine ( const QString& sEngineName )
152
bool Channel::loadEngine ( const QString& sEngineName )
167
if (client() == NULL || m_iChannelID < 0)
154
MainForm *pMainForm = MainForm::getInstance();
155
if (pMainForm == NULL)
157
if (pMainForm->client() == NULL || m_iChannelID < 0)
169
159
if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName)
172
if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {
162
if (::lscp_load_engine(pMainForm->client(),
163
sEngineName.toUtf8().constData(), m_iChannelID) != LSCP_OK) {
173
164
appendMessagesClient("lscp_load_engine");
176
168
appendMessages(QObject::tr("Engine: %1.").arg(sEngineName));
178
170
m_sEngineName = sEngineName;
183
175
// Instrument filename accessor.
184
const QString& qsamplerChannel::instrumentFile (void) const
176
const QString& Channel::instrumentFile (void) const
186
178
return m_sInstrumentFile;
189
181
// Instrument index accessor.
190
int qsamplerChannel::instrumentNr (void) const
182
int Channel::instrumentNr (void) const
192
184
return m_iInstrumentNr;
195
187
// Instrument name accessor.
196
const QString& qsamplerChannel::instrumentName (void) const
188
const QString& Channel::instrumentName (void) const
198
190
return m_sInstrumentName;
201
193
// Instrument status accessor.
202
int qsamplerChannel::instrumentStatus (void) const
194
int Channel::instrumentStatus (void) const
204
196
return m_iInstrumentStatus;
207
199
// Instrument file loader.
208
bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
200
bool Channel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
210
if (client() == NULL || m_iChannelID < 0)
202
MainForm *pMainForm = MainForm::getInstance();
203
if (pMainForm == NULL)
205
if (pMainForm->client() == NULL || m_iChannelID < 0)
212
207
if (!isInstrumentFile(sInstrumentFile))
214
209
if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr)
217
if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) {
213
::lscp_load_instrument_non_modal(
215
qsamplerUtilities::lscpEscapePath(
216
sInstrumentFile).toUtf8().constData(),
217
iInstrumentNr, m_iChannelID
218
220
appendMessagesClient("lscp_load_instrument");
245
247
// MIDI driver type accessors (DEPRECATED).
246
const QString& qsamplerChannel::midiDriver (void) const
248
const QString& Channel::midiDriver (void) const
248
250
return m_sMidiDriver;
251
bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )
253
bool Channel::setMidiDriver ( const QString& sMidiDriver )
253
if (client() == NULL || m_iChannelID < 0)
255
MainForm *pMainForm = MainForm::getInstance();
256
if (pMainForm == NULL)
258
if (pMainForm->client() == NULL || m_iChannelID < 0)
255
260
if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver)
258
if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) {
263
if (::lscp_set_channel_midi_type(pMainForm->client(),
264
m_iChannelID, sMidiDriver.toUtf8().constData()) != LSCP_OK) {
259
265
appendMessagesClient("lscp_set_channel_midi_type");
270
276
// MIDI device accessors.
271
int qsamplerChannel::midiDevice (void) const
277
int Channel::midiDevice (void) const
273
279
return m_iMidiDevice;
276
bool qsamplerChannel::setMidiDevice ( int iMidiDevice )
282
bool Channel::setMidiDevice ( int iMidiDevice )
278
if (client() == NULL || m_iChannelID < 0)
284
MainForm *pMainForm = MainForm::getInstance();
285
if (pMainForm == NULL)
287
if (pMainForm->client() == NULL || m_iChannelID < 0)
280
289
if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice)
283
if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) {
292
if (::lscp_set_channel_midi_device(pMainForm->client(), m_iChannelID, iMidiDevice) != LSCP_OK) {
284
293
appendMessagesClient("lscp_set_channel_midi_device");
295
304
// MIDI port number accessor.
296
int qsamplerChannel::midiPort (void) const
305
int Channel::midiPort (void) const
298
307
return m_iMidiPort;
301
bool qsamplerChannel::setMidiPort ( int iMidiPort )
310
bool Channel::setMidiPort ( int iMidiPort )
303
if (client() == NULL || m_iChannelID < 0)
312
MainForm *pMainForm = MainForm::getInstance();
313
if (pMainForm == NULL)
315
if (pMainForm->client() == NULL || m_iChannelID < 0)
305
317
if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort)
308
if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) {
320
if (::lscp_set_channel_midi_port(pMainForm->client(), m_iChannelID, iMidiPort) != LSCP_OK) {
309
321
appendMessagesClient("lscp_set_channel_midi_port");
320
332
// MIDI channel accessor.
321
int qsamplerChannel::midiChannel (void) const
333
int Channel::midiChannel (void) const
323
335
return m_iMidiChannel;
326
bool qsamplerChannel::setMidiChannel ( int iMidiChannel )
338
bool Channel::setMidiChannel ( int iMidiChannel )
328
if (client() == NULL || m_iChannelID < 0)
340
MainForm *pMainForm = MainForm::getInstance();
341
if (pMainForm == NULL)
343
if (pMainForm->client() == NULL || m_iChannelID < 0)
330
345
if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel)
333
if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) {
348
if (::lscp_set_channel_midi_channel(pMainForm->client(), m_iChannelID, iMidiChannel) != LSCP_OK) {
334
349
appendMessagesClient("lscp_set_channel_midi_channel");
360
// MIDI instrument map accessor.
361
int Channel::midiMap (void) const
366
bool Channel::setMidiMap ( int iMidiMap )
368
MainForm *pMainForm = MainForm::getInstance();
369
if (pMainForm == NULL)
371
if (pMainForm->client() == NULL || m_iChannelID < 0)
373
if (m_iInstrumentStatus == 100 && m_iMidiMap == iMidiMap)
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");
381
appendMessages(QObject::tr("MIDI map: %1.").arg(iMidiMap));
383
m_iMidiMap = iMidiMap;
345
388
// Audio device accessor.
346
int qsamplerChannel::audioDevice (void) const
389
int Channel::audioDevice (void) const
348
391
return m_iAudioDevice;
351
bool qsamplerChannel::setAudioDevice ( int iAudioDevice )
394
bool Channel::setAudioDevice ( int iAudioDevice )
353
if (client() == NULL || m_iChannelID < 0)
396
MainForm *pMainForm = MainForm::getInstance();
397
if (pMainForm == NULL)
399
if (pMainForm->client() == NULL || m_iChannelID < 0)
355
401
if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice)
358
if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) {
404
if (::lscp_set_channel_audio_device(pMainForm->client(), m_iChannelID, iAudioDevice) != LSCP_OK) {
359
405
appendMessagesClient("lscp_set_channel_audio_device");
370
416
// Audio driver type accessors (DEPRECATED).
371
const QString& qsamplerChannel::audioDriver (void) const
417
const QString& Channel::audioDriver (void) const
373
419
return m_sAudioDriver;
376
bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )
422
bool Channel::setAudioDriver ( const QString& sAudioDriver )
378
if (client() == NULL || m_iChannelID < 0)
424
MainForm *pMainForm = MainForm::getInstance();
425
if (pMainForm == NULL)
427
if (pMainForm->client() == NULL || m_iChannelID < 0)
380
429
if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver)
383
if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {
432
if (::lscp_set_channel_audio_type(pMainForm->client(),
433
m_iChannelID, sAudioDriver.toUtf8().constData()) != LSCP_OK) {
384
434
appendMessagesClient("lscp_set_channel_audio_type");
395
445
// Channel volume accessors.
396
float qsamplerChannel::volume (void) const
446
float Channel::volume (void) const
398
448
return m_fVolume;
401
bool qsamplerChannel::setVolume ( float fVolume )
451
bool Channel::setVolume ( float fVolume )
403
if (client() == NULL || m_iChannelID < 0)
453
MainForm *pMainForm = MainForm::getInstance();
454
if (pMainForm == NULL)
456
if (pMainForm->client() == NULL || m_iChannelID < 0)
405
458
if (m_iInstrumentStatus == 100 && m_fVolume == fVolume)
408
if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) {
461
if (::lscp_set_channel_volume(pMainForm->client(), m_iChannelID, fVolume) != LSCP_OK) {
409
462
appendMessagesClient("lscp_set_channel_volume");
473
// Sampler channel mute state.
474
bool Channel::channelMute (void) const
479
bool Channel::setChannelMute ( bool bMute )
481
MainForm *pMainForm = MainForm::getInstance();
482
if (pMainForm == NULL)
484
if (pMainForm->client() == NULL || m_iChannelID < 0)
486
if (m_iInstrumentStatus == 100 && ((m_bMute && bMute) || (!m_bMute && !bMute)))
489
#ifdef CONFIG_MUTE_SOLO
490
if (::lscp_set_channel_mute(pMainForm->client(), m_iChannelID, bMute) != LSCP_OK) {
491
appendMessagesClient("lscp_set_channel_mute");
494
appendMessages(QObject::tr("Mute: %1.").arg((int) bMute));
503
// Sampler channel solo state.
504
bool Channel::channelSolo (void) const
509
bool Channel::setChannelSolo ( bool bSolo )
511
MainForm *pMainForm = MainForm::getInstance();
512
if (pMainForm == NULL)
514
if (pMainForm->client() == NULL || m_iChannelID < 0)
516
if (m_iInstrumentStatus == 100 && ((m_bSolo && bSolo) || (!m_bSolo && !bSolo)))
519
#ifdef CONFIG_MUTE_SOLO
520
if (::lscp_set_channel_solo(pMainForm->client(), m_iChannelID, bSolo) != LSCP_OK) {
521
appendMessagesClient("lscp_set_channel_solo");
524
appendMessages(QObject::tr("Solo: %1.").arg((int) bSolo));
533
// Audio routing accessors.
534
int Channel::audioChannel ( int iAudioOut ) const
536
return m_audioRouting[iAudioOut];
539
bool Channel::setAudioChannel ( int iAudioOut, int iAudioIn )
541
MainForm *pMainForm = MainForm::getInstance();
542
if (pMainForm == NULL)
544
if (pMainForm->client() == NULL || m_iChannelID < 0)
546
if (m_iInstrumentStatus == 100 &&
547
m_audioRouting[iAudioOut] == iAudioIn)
550
if (::lscp_set_channel_audio_channel(pMainForm->client(),
551
m_iChannelID, iAudioOut, iAudioIn) != LSCP_OK) {
552
appendMessagesClient("lscp_set_channel_audio_channel");
556
appendMessages(QObject::tr("Audio Channel: %1 -> %2.")
557
.arg(iAudioOut).arg(iAudioIn));
559
m_audioRouting[iAudioOut] = iAudioIn;
563
// The audio routing map itself.
564
const ChannelRoutingMap& Channel::audioRouting (void) const
566
return m_audioRouting;
420
570
// Istrument name remapper.
421
void qsamplerChannel::updateInstrumentName (void)
571
void Channel::updateInstrumentName (void)
423
573
#ifndef CONFIG_INSTRUMENT_NAME
424
574
m_sInstrumentName = getInstrumentName(m_sInstrumentFile,
430
580
// Update whole channel info state.
431
bool qsamplerChannel::updateChannelInfo (void)
581
bool Channel::updateChannelInfo (void)
433
if (client() == NULL || m_iChannelID < 0)
583
MainForm *pMainForm = MainForm::getInstance();
584
if (pMainForm == NULL)
586
if (pMainForm->client() == NULL || m_iChannelID < 0)
436
589
// Read channel information.
437
lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID);
590
lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(pMainForm->client(), m_iChannelID);
438
591
if (pChannelInfo == NULL) {
439
592
appendMessagesClient("lscp_get_channel_info");
440
593
appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));
493
655
m_sMidiDriver = pDeviceInfo->driver;
658
// Set the audio routing map.
659
m_audioRouting.clear();
660
#ifdef CONFIG_AUDIO_ROUTING
661
int *piAudioRouting = pChannelInfo->audio_routing;
662
for (int i = 0; piAudioRouting && piAudioRouting[i] >= 0; i++)
663
m_audioRouting[i] = piAudioRouting[i];
665
char **ppszAudioRouting = pChannelInfo->audio_routing;
666
for (int i = 0; ppszAudioRouting && ppszAudioRouting[i]; i++)
667
m_audioRouting[i] = ::atoi(ppszAudioRouting[i]);
500
674
// Reset channel method.
501
bool qsamplerChannel::channelReset (void)
675
bool Channel::channelReset (void)
503
if (client() == NULL || m_iChannelID < 0)
677
MainForm *pMainForm = MainForm::getInstance();
678
if (pMainForm == NULL)
680
if (pMainForm->client() == NULL || m_iChannelID < 0)
506
if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK) {
683
if (::lscp_reset_channel(pMainForm->client(), m_iChannelID) != LSCP_OK) {
507
684
appendMessagesClient("lscp_reset_channel");
694
// Spawn instrument editor method.
695
bool Channel::editChannel (void)
697
#ifdef CONFIG_EDIT_INSTRUMENT
699
MainForm *pMainForm = MainForm::getInstance();
700
if (pMainForm == NULL)
702
if (pMainForm->client() == NULL || m_iChannelID < 0)
705
if (::lscp_edit_channel_instrument(pMainForm->client(), m_iChannelID)
707
appendMessagesClient("lscp_edit_channel_instrument");
708
appendMessagesError(QObject::tr(
709
"Could not launch an appropriate instrument editor "
710
"for the given instrument!\n\n"
711
"Make sure you have an appropriate "
712
"instrument editor like 'gigedit' installed "
713
"and that it placed its mandatory DLL file "
714
"into the sampler's plugin directory.")
719
appendMessages(QObject::tr("edit instrument."));
725
appendMessagesError(QObject::tr(
726
"Sorry, QSampler was compiled for a version of liblscp "
727
"which lacks this feature.\n\n"
728
"You may want to update liblscp and recompile QSampler afterwards.")
517
737
// Channel setup dialog form.
518
bool qsamplerChannel::channelSetup ( QWidget *pParent )
738
bool Channel::channelSetup ( QWidget *pParent )
740
MainForm *pMainForm = MainForm::getInstance();
741
if (pMainForm == NULL)
520
744
bool bResult = false;
522
746
appendMessages(QObject::tr("setup..."));
524
qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent);
748
ChannelForm *pChannelForm = new ChannelForm(pParent);
525
749
if (pChannelForm) {
526
750
pChannelForm->setup(this);
527
751
bResult = pChannelForm->exec();
535
759
// Redirected messages output methods.
536
void qsamplerChannel::appendMessages( const QString& s ) const
760
void Channel::appendMessages( const QString& s ) const
539
m_pMainForm->appendMessages(channelName() + ' ' + s);
762
MainForm *pMainForm = MainForm::getInstance();
764
pMainForm->appendMessages(channelName() + ' ' + s);
542
void qsamplerChannel::appendMessagesColor( const QString& s,
767
void Channel::appendMessagesColor( const QString& s,
543
768
const QString& c ) const
546
m_pMainForm->appendMessagesColor(channelName() + ' ' + s, c);
549
void qsamplerChannel::appendMessagesText( const QString& s ) const
552
m_pMainForm->appendMessagesText(channelName() + ' ' + s);
555
void qsamplerChannel::appendMessagesError( const QString& s ) const
558
m_pMainForm->appendMessagesError(channelName() + "\n\n" + s);
561
void qsamplerChannel::appendMessagesClient( const QString& s ) const
564
m_pMainForm->appendMessagesClient(channelName() + ' ' + s);
770
MainForm *pMainForm = MainForm::getInstance();
772
pMainForm->appendMessagesColor(channelName() + ' ' + s, c);
775
void Channel::appendMessagesText( const QString& s ) const
777
MainForm *pMainForm = MainForm::getInstance();
779
pMainForm->appendMessagesText(channelName() + ' ' + s);
782
void Channel::appendMessagesError( const QString& s ) const
784
MainForm *pMainForm = MainForm::getInstance();
786
pMainForm->appendMessagesError(channelName() + "\n\n" + s);
789
void Channel::appendMessagesClient( const QString& s ) const
791
MainForm *pMainForm = MainForm::getInstance();
793
pMainForm->appendMessagesClient(channelName() + ' ' + s);
568
797
// Context menu event handler.
569
void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent )
798
void Channel::contextMenuEvent( QContextMenuEvent *pEvent )
572
m_pMainForm->contextMenuEvent(pEvent);
800
MainForm *pMainForm = MainForm::getInstance();
802
pMainForm->contextMenuEvent(pEvent);
576
806
// FIXME: Check whether a given file is an instrument file.
577
bool qsamplerChannel::isInstrumentFile ( const QString& sInstrumentFile )
807
bool Channel::isInstrumentFile ( const QString& sInstrumentFile )
579
809
bool bResult = false;
581
811
QFile file(sInstrumentFile);
582
if (file.open(IO_ReadOnly)) {
812
if (file.open(QIODevice::ReadOnly)) {
583
813
char achHeader[16];
584
if (file.readBlock(achHeader, 16)) {
814
if (file.read(achHeader, 16) > 0) {
585
815
bResult = (::memcmp(&achHeader[0], "RIFF", 4) == 0
586
816
&& ::memcmp(&achHeader[8], "DLS LIST", 8) == 0);
661
901
// Common invalid name-helpers.
662
QString qsamplerChannel::noEngineName (void)
902
QString Channel::noEngineName (void)
664
904
return QObject::tr("(No engine)");
667
QString qsamplerChannel::noInstrumentName (void)
907
QString Channel::noInstrumentName (void)
669
909
return QObject::tr("(No instrument)");
672
QString qsamplerChannel::loadingInstrument (void) {
912
QString Channel::loadingInstrument (void) {
673
913
return QObject::tr("(Loading instrument...)");
917
//-------------------------------------------------------------------------
918
// QSampler::ChannelRoutingModel - data model for audio routing
919
// (used for QTableView)
921
ChannelRoutingModel::ChannelRoutingModel ( QObject *pParent )
922
: QAbstractTableModel(pParent), m_pDevice(NULL)
927
int ChannelRoutingModel::rowCount ( const QModelIndex& /*parent*/) const
929
return m_routing.size();
933
int ChannelRoutingModel::columnCount ( const QModelIndex& /*parent*/) const
939
Qt::ItemFlags ChannelRoutingModel::flags ( const QModelIndex& /*index*/) const
941
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
945
bool ChannelRoutingModel::setData ( const QModelIndex& index,
946
const QVariant& value, int /*role*/)
948
if (!index.isValid())
951
m_routing[index.row()] = value.toInt();
953
emit dataChanged(index, index);
958
QVariant ChannelRoutingModel::data ( const QModelIndex &index, int role ) const
960
if (!index.isValid())
962
if (role != Qt::DisplayRole)
964
if (index.column() != 0)
967
ChannelRoutingItem item;
969
// The common device port item list.
970
DevicePortList& ports = m_pDevice->ports();
971
QListIterator<DevicePort *> iter(ports);
972
while (iter.hasNext()) {
973
DevicePort *pPort = iter.next();
975
m_pDevice->deviceTypeName()
976
+ ' ' + m_pDevice->driverName()
977
+ ' ' + pPort->portName()
981
item.selection = m_routing[index.row()];
983
return QVariant::fromValue(item);
987
QVariant ChannelRoutingModel::headerData ( int section,
988
Qt::Orientation orientation, int role) const
990
if (role != Qt::DisplayRole)
993
switch (orientation) {
995
return UNICODE_RIGHT_ARROW + QObject::tr(" Device Channel");
997
return QObject::tr("Sampler Channel ") +
998
QString::number(section) + " " + UNICODE_RIGHT_ARROW;
1005
void ChannelRoutingModel::refresh ( Device *pDevice,
1006
const ChannelRoutingMap& routing )
1008
m_pDevice = pDevice;
1009
m_routing = routing;
1010
// inform the outer world (QTableView) that our data changed
1011
QAbstractTableModel::reset();
1015
//-------------------------------------------------------------------------
1016
// QSampler::ChannelRoutingDelegate - table cell renderer for audio routing
1019
ChannelRoutingDelegate::ChannelRoutingDelegate ( QObject *pParent )
1020
: QItemDelegate(pParent)
1025
QWidget* ChannelRoutingDelegate::createEditor ( QWidget *pParent,
1026
const QStyleOptionViewItem & option, const QModelIndex& index ) const
1028
if (!index.isValid())
1031
if (index.column() != 0)
1034
ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();
1036
QComboBox* pComboBox = new QComboBox(pParent);
1037
pComboBox->addItems(item.options);
1038
pComboBox->setCurrentIndex(item.selection);
1039
pComboBox->setEnabled(true);
1040
pComboBox->setGeometry(option.rect);
1045
void ChannelRoutingDelegate::setEditorData ( QWidget *pEditor,
1046
const QModelIndex &index) const
1048
ChannelRoutingItem item = index.model()->data(index,
1049
Qt::DisplayRole).value<ChannelRoutingItem> ();
1050
QComboBox* pComboBox = static_cast<QComboBox*> (pEditor);
1051
pComboBox->setCurrentIndex(item.selection);
1055
void ChannelRoutingDelegate::setModelData ( QWidget* pEditor,
1056
QAbstractItemModel *pModel, const QModelIndex& index ) const
1058
QComboBox *pComboBox = static_cast<QComboBox*> (pEditor);
1059
pModel->setData(index, pComboBox->currentIndex());
1063
void ChannelRoutingDelegate::updateEditorGeometry ( QWidget *pEditor,
1064
const QStyleOptionViewItem& option, const QModelIndex &/* index */) const
1066
pEditor->setGeometry(option.rect);
1069
} // namespace QSampler
677
1072
// end of qsamplerChannel.cpp