1 |
// qsamplerChannel.cpp |
// qsamplerChannel.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2010, 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 |
20 |
|
|
21 |
*****************************************************************************/ |
*****************************************************************************/ |
22 |
|
|
|
#include "qsamplerUtilities.h" |
|
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 |
|
namespace QSampler { |
38 |
|
|
39 |
#define QSAMPLER_INSTRUMENT_MAX 100 |
#define QSAMPLER_INSTRUMENT_MAX 100 |
40 |
|
|
41 |
|
#define UNICODE_RIGHT_ARROW QChar(char(0x92), char(0x21)) |
42 |
|
|
43 |
|
|
44 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
45 |
// qsamplerChannel - Sampler channel structure. |
// QSampler::Channel - Sampler channel structure. |
46 |
// |
// |
47 |
|
|
48 |
// Constructor. |
// Constructor. |
49 |
qsamplerChannel::qsamplerChannel ( int iChannelID ) |
Channel::Channel ( int iChannelID ) |
50 |
{ |
{ |
51 |
m_iChannelID = iChannelID; |
m_iChannelID = iChannelID; |
52 |
|
|
62 |
m_iMidiMap = -1; |
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 |
} |
} |
69 |
|
|
70 |
// Default destructor. |
// Default destructor. |
71 |
qsamplerChannel::~qsamplerChannel (void) |
Channel::~Channel (void) |
72 |
{ |
{ |
73 |
} |
} |
74 |
|
|
75 |
|
|
76 |
// Create a new sampler channel, if not already. |
// Create a new sampler channel, if not already. |
77 |
bool qsamplerChannel::addChannel (void) |
bool Channel::addChannel (void) |
78 |
{ |
{ |
79 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm* pMainForm = MainForm::getInstance(); |
80 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
81 |
return false; |
return false; |
82 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
99 |
|
|
100 |
|
|
101 |
// Remove sampler channel. |
// Remove sampler channel. |
102 |
bool qsamplerChannel::removeChannel (void) |
bool Channel::removeChannel (void) |
103 |
{ |
{ |
104 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
105 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
106 |
return false; |
return false; |
107 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
125 |
|
|
126 |
|
|
127 |
// Channel-ID (aka Sammpler-Channel) accessors. |
// Channel-ID (aka Sammpler-Channel) accessors. |
128 |
int qsamplerChannel::channelID (void) const |
int Channel::channelID (void) const |
129 |
{ |
{ |
130 |
return m_iChannelID; |
return m_iChannelID; |
131 |
} |
} |
132 |
|
|
133 |
void qsamplerChannel::setChannelID ( int iChannelID ) |
void Channel::setChannelID ( int iChannelID ) |
134 |
{ |
{ |
135 |
m_iChannelID = iChannelID; |
m_iChannelID = iChannelID; |
136 |
} |
} |
137 |
|
|
138 |
|
|
139 |
// Readable channel name. |
// Readable channel name. |
140 |
QString qsamplerChannel::channelName (void) const |
QString Channel::channelName (void) const |
141 |
{ |
{ |
142 |
return (m_iChannelID < 0 ? QObject::tr("New Channel") : QObject::tr("Channel %1").arg(m_iChannelID)); |
return (m_iChannelID < 0 ? QObject::tr("New Channel") : QObject::tr("Channel %1").arg(m_iChannelID)); |
143 |
} |
} |
144 |
|
|
145 |
|
|
146 |
// Engine name accessors. |
// Engine name accessors. |
147 |
const QString& qsamplerChannel::engineName (void) const |
const QString& Channel::engineName (void) const |
148 |
{ |
{ |
149 |
return m_sEngineName; |
return m_sEngineName; |
150 |
} |
} |
151 |
|
|
152 |
bool qsamplerChannel::loadEngine ( const QString& sEngineName ) |
bool Channel::loadEngine ( const QString& sEngineName ) |
153 |
{ |
{ |
154 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
155 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
156 |
return false; |
return false; |
157 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
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(pMainForm->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 |
} |
} |
173 |
|
|
174 |
|
|
175 |
// Instrument filename accessor. |
// Instrument filename accessor. |
176 |
const QString& qsamplerChannel::instrumentFile (void) const |
const QString& Channel::instrumentFile (void) const |
177 |
{ |
{ |
178 |
return m_sInstrumentFile; |
return m_sInstrumentFile; |
179 |
} |
} |
180 |
|
|
181 |
// Instrument index accessor. |
// Instrument index accessor. |
182 |
int qsamplerChannel::instrumentNr (void) const |
int Channel::instrumentNr (void) const |
183 |
{ |
{ |
184 |
return m_iInstrumentNr; |
return m_iInstrumentNr; |
185 |
} |
} |
186 |
|
|
187 |
// Instrument name accessor. |
// Instrument name accessor. |
188 |
const QString& qsamplerChannel::instrumentName (void) const |
const QString& Channel::instrumentName (void) const |
189 |
{ |
{ |
190 |
return m_sInstrumentName; |
return m_sInstrumentName; |
191 |
} |
} |
192 |
|
|
193 |
// Instrument status accessor. |
// Instrument status accessor. |
194 |
int qsamplerChannel::instrumentStatus (void) const |
int Channel::instrumentStatus (void) const |
195 |
{ |
{ |
196 |
return m_iInstrumentStatus; |
return m_iInstrumentStatus; |
197 |
} |
} |
198 |
|
|
199 |
// Instrument file loader. |
// Instrument file loader. |
200 |
bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) |
bool Channel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) |
201 |
{ |
{ |
202 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
203 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
204 |
return false; |
return false; |
205 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
206 |
return false; |
return false; |
207 |
if (!isInstrumentFile(sInstrumentFile)) |
if (!QFileInfo(sInstrumentFile).exists()) |
208 |
return false; |
return false; |
209 |
if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr) |
if (m_iInstrumentStatus == 100 |
210 |
|
&& m_sInstrumentFile == sInstrumentFile |
211 |
|
&& m_iInstrumentNr == iInstrumentNr) |
212 |
return true; |
return true; |
213 |
|
|
214 |
if ( |
if (::lscp_load_instrument_non_modal( |
|
::lscp_load_instrument_non_modal( |
|
215 |
pMainForm->client(), |
pMainForm->client(), |
216 |
lscpEscapePath(sInstrumentFile).latin1(), |
qsamplerUtilities::lscpEscapePath( |
217 |
|
sInstrumentFile).toUtf8().constData(), |
218 |
iInstrumentNr, m_iChannelID |
iInstrumentNr, m_iChannelID |
219 |
) != LSCP_OK |
) != LSCP_OK) { |
|
) { |
|
220 |
appendMessagesClient("lscp_load_instrument"); |
appendMessagesClient("lscp_load_instrument"); |
221 |
return false; |
return false; |
222 |
} |
} |
229 |
|
|
230 |
|
|
231 |
// Special instrument file/name/number settler. |
// Special instrument file/name/number settler. |
232 |
bool qsamplerChannel::setInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) |
bool Channel::setInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) |
233 |
{ |
{ |
234 |
m_sInstrumentFile = sInstrumentFile; |
m_sInstrumentFile = sInstrumentFile; |
235 |
m_iInstrumentNr = iInstrumentNr; |
m_iInstrumentNr = iInstrumentNr; |
245 |
|
|
246 |
|
|
247 |
// MIDI driver type accessors (DEPRECATED). |
// MIDI driver type accessors (DEPRECATED). |
248 |
const QString& qsamplerChannel::midiDriver (void) const |
const QString& Channel::midiDriver (void) const |
249 |
{ |
{ |
250 |
return m_sMidiDriver; |
return m_sMidiDriver; |
251 |
} |
} |
252 |
|
|
253 |
bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver ) |
bool Channel::setMidiDriver ( const QString& sMidiDriver ) |
254 |
{ |
{ |
255 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
256 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
257 |
return false; |
return false; |
258 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
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(pMainForm->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 |
} |
} |
274 |
|
|
275 |
|
|
276 |
// MIDI device accessors. |
// MIDI device accessors. |
277 |
int qsamplerChannel::midiDevice (void) const |
int Channel::midiDevice (void) const |
278 |
{ |
{ |
279 |
return m_iMidiDevice; |
return m_iMidiDevice; |
280 |
} |
} |
281 |
|
|
282 |
bool qsamplerChannel::setMidiDevice ( int iMidiDevice ) |
bool Channel::setMidiDevice ( int iMidiDevice ) |
283 |
{ |
{ |
284 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
285 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
286 |
return false; |
return false; |
287 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
302 |
|
|
303 |
|
|
304 |
// MIDI port number accessor. |
// MIDI port number accessor. |
305 |
int qsamplerChannel::midiPort (void) const |
int Channel::midiPort (void) const |
306 |
{ |
{ |
307 |
return m_iMidiPort; |
return m_iMidiPort; |
308 |
} |
} |
309 |
|
|
310 |
bool qsamplerChannel::setMidiPort ( int iMidiPort ) |
bool Channel::setMidiPort ( int iMidiPort ) |
311 |
{ |
{ |
312 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
313 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
314 |
return false; |
return false; |
315 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
330 |
|
|
331 |
|
|
332 |
// MIDI channel accessor. |
// MIDI channel accessor. |
333 |
int qsamplerChannel::midiChannel (void) const |
int Channel::midiChannel (void) const |
334 |
{ |
{ |
335 |
return m_iMidiChannel; |
return m_iMidiChannel; |
336 |
} |
} |
337 |
|
|
338 |
bool qsamplerChannel::setMidiChannel ( int iMidiChannel ) |
bool Channel::setMidiChannel ( int iMidiChannel ) |
339 |
{ |
{ |
340 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
341 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
342 |
return false; |
return false; |
343 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
358 |
|
|
359 |
|
|
360 |
// MIDI instrument map accessor. |
// MIDI instrument map accessor. |
361 |
int qsamplerChannel::midiMap (void) const |
int Channel::midiMap (void) const |
362 |
{ |
{ |
363 |
return m_iMidiMap; |
return m_iMidiMap; |
364 |
} |
} |
365 |
|
|
366 |
bool qsamplerChannel::setMidiMap ( int iMidiMap ) |
bool Channel::setMidiMap ( int iMidiMap ) |
367 |
{ |
{ |
368 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
369 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
370 |
return false; |
return false; |
371 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
386 |
|
|
387 |
|
|
388 |
// Audio device accessor. |
// Audio device accessor. |
389 |
int qsamplerChannel::audioDevice (void) const |
int Channel::audioDevice (void) const |
390 |
{ |
{ |
391 |
return m_iAudioDevice; |
return m_iAudioDevice; |
392 |
} |
} |
393 |
|
|
394 |
bool qsamplerChannel::setAudioDevice ( int iAudioDevice ) |
bool Channel::setAudioDevice ( int iAudioDevice ) |
395 |
{ |
{ |
396 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
397 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
398 |
return false; |
return false; |
399 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
414 |
|
|
415 |
|
|
416 |
// Audio driver type accessors (DEPRECATED). |
// Audio driver type accessors (DEPRECATED). |
417 |
const QString& qsamplerChannel::audioDriver (void) const |
const QString& Channel::audioDriver (void) const |
418 |
{ |
{ |
419 |
return m_sAudioDriver; |
return m_sAudioDriver; |
420 |
} |
} |
421 |
|
|
422 |
bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver ) |
bool Channel::setAudioDriver ( const QString& sAudioDriver ) |
423 |
{ |
{ |
424 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
425 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
426 |
return false; |
return false; |
427 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
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(pMainForm->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 |
} |
} |
443 |
|
|
444 |
|
|
445 |
// Channel volume accessors. |
// Channel volume accessors. |
446 |
float qsamplerChannel::volume (void) const |
float Channel::volume (void) const |
447 |
{ |
{ |
448 |
return m_fVolume; |
return m_fVolume; |
449 |
} |
} |
450 |
|
|
451 |
bool qsamplerChannel::setVolume ( float fVolume ) |
bool Channel::setVolume ( float fVolume ) |
452 |
{ |
{ |
453 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
454 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
455 |
return false; |
return false; |
456 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
471 |
|
|
472 |
|
|
473 |
// Sampler channel mute state. |
// Sampler channel mute state. |
474 |
bool qsamplerChannel::channelMute (void) const |
bool Channel::channelMute (void) const |
475 |
{ |
{ |
476 |
return m_bMute; |
return m_bMute; |
477 |
} |
} |
478 |
|
|
479 |
bool qsamplerChannel::setChannelMute ( bool bMute ) |
bool Channel::setChannelMute ( bool bMute ) |
480 |
{ |
{ |
481 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
482 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
483 |
return false; |
return false; |
484 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
501 |
|
|
502 |
|
|
503 |
// Sampler channel solo state. |
// Sampler channel solo state. |
504 |
bool qsamplerChannel::channelSolo (void) const |
bool Channel::channelSolo (void) const |
505 |
{ |
{ |
506 |
return m_bSolo; |
return m_bSolo; |
507 |
} |
} |
508 |
|
|
509 |
bool qsamplerChannel::setChannelSolo ( bool bSolo ) |
bool Channel::setChannelSolo ( bool bSolo ) |
510 |
{ |
{ |
511 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
512 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
513 |
return false; |
return false; |
514 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
531 |
|
|
532 |
|
|
533 |
// Audio routing accessors. |
// Audio routing accessors. |
534 |
int qsamplerChannel::audioChannel ( int iAudioOut ) const |
int Channel::audioChannel ( int iAudioOut ) const |
535 |
{ |
{ |
536 |
return m_audioRouting[iAudioOut]; |
return m_audioRouting[iAudioOut]; |
537 |
} |
} |
538 |
|
|
539 |
bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn ) |
bool Channel::setAudioChannel ( int iAudioOut, int iAudioIn ) |
540 |
{ |
{ |
541 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
542 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
543 |
return false; |
return false; |
544 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
561 |
} |
} |
562 |
|
|
563 |
// The audio routing map itself. |
// The audio routing map itself. |
564 |
const qsamplerChannelRoutingMap& qsamplerChannel::audioRouting (void) const |
const ChannelRoutingMap& Channel::audioRouting (void) const |
565 |
{ |
{ |
566 |
return m_audioRouting; |
return m_audioRouting; |
567 |
} |
} |
568 |
|
|
569 |
|
|
570 |
// Istrument name remapper. |
// Istrument name remapper. |
571 |
void qsamplerChannel::updateInstrumentName (void) |
void Channel::updateInstrumentName (void) |
572 |
{ |
{ |
573 |
#ifndef CONFIG_INSTRUMENT_NAME |
#ifndef CONFIG_INSTRUMENT_NAME |
574 |
m_sInstrumentName = getInstrumentName(m_sInstrumentFile, |
m_sInstrumentName = getInstrumentName(m_sInstrumentFile, |
578 |
|
|
579 |
|
|
580 |
// Update whole channel info state. |
// Update whole channel info state. |
581 |
bool qsamplerChannel::updateChannelInfo (void) |
bool Channel::updateChannelInfo (void) |
582 |
{ |
{ |
583 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
584 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
585 |
return false; |
return false; |
586 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
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, |
672 |
|
|
673 |
|
|
674 |
// Reset channel method. |
// Reset channel method. |
675 |
bool qsamplerChannel::channelReset (void) |
bool Channel::channelReset (void) |
676 |
{ |
{ |
677 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
678 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
679 |
return false; |
return false; |
680 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
692 |
|
|
693 |
|
|
694 |
// Spawn instrument editor method. |
// Spawn instrument editor method. |
695 |
bool qsamplerChannel::editChannel (void) |
bool Channel::editChannel (void) |
696 |
{ |
{ |
697 |
#ifdef CONFIG_EDIT_INSTRUMENT |
#ifdef CONFIG_EDIT_INSTRUMENT |
698 |
|
|
699 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
700 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
701 |
return false; |
return false; |
702 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
703 |
return false; |
return false; |
704 |
|
|
705 |
if (::lscp_edit_instrument(pMainForm->client(), m_iChannelID) != LSCP_OK) { |
if (::lscp_edit_channel_instrument(pMainForm->client(), m_iChannelID) |
706 |
appendMessagesClient("lscp_edit_instrument"); |
!= LSCP_OK) { |
707 |
|
appendMessagesClient("lscp_edit_channel_instrument"); |
708 |
appendMessagesError(QObject::tr( |
appendMessagesError(QObject::tr( |
709 |
"Could not launch an appropriate instrument editor " |
"Could not launch an appropriate instrument editor " |
710 |
"for the given instrument!\n" |
"for the given instrument!\n\n" |
711 |
"Make sure you have an appropriate " |
"Make sure you have an appropriate " |
712 |
"instrument editor like 'gigedit' installed\n" |
"instrument editor like 'gigedit' installed " |
713 |
"and that it placed its mandatory DLL file " |
"and that it placed its mandatory DLL file " |
714 |
"into the sampler's plugin directory.") |
"into the sampler's plugin directory.") |
715 |
); |
); |
724 |
|
|
725 |
appendMessagesError(QObject::tr( |
appendMessagesError(QObject::tr( |
726 |
"Sorry, QSampler was compiled for a version of liblscp " |
"Sorry, QSampler was compiled for a version of liblscp " |
727 |
"which lacks this feature.\n" |
"which lacks this feature.\n\n" |
728 |
"You may want to update liblscp and recompile QSampler afterwards.") |
"You may want to update liblscp and recompile QSampler afterwards.") |
729 |
); |
); |
730 |
|
|
735 |
|
|
736 |
|
|
737 |
// Channel setup dialog form. |
// Channel setup dialog form. |
738 |
bool qsamplerChannel::channelSetup ( QWidget *pParent ) |
bool Channel::channelSetup ( QWidget *pParent ) |
739 |
{ |
{ |
740 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
741 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
742 |
return false; |
return false; |
743 |
|
|
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(); |
757 |
|
|
758 |
|
|
759 |
// Redirected messages output methods. |
// Redirected messages output methods. |
760 |
void qsamplerChannel::appendMessages( const QString& s ) const |
void Channel::appendMessages( const QString& s ) const |
761 |
{ |
{ |
762 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
763 |
if (pMainForm) |
if (pMainForm) |
764 |
pMainForm->appendMessages(channelName() + ' ' + s); |
pMainForm->appendMessages(channelName() + ' ' + s); |
765 |
} |
} |
766 |
|
|
767 |
void qsamplerChannel::appendMessagesColor( const QString& s, |
void Channel::appendMessagesColor( const QString& s, |
768 |
const QString& c ) const |
const QString& c ) const |
769 |
{ |
{ |
770 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
771 |
if (pMainForm) |
if (pMainForm) |
772 |
pMainForm->appendMessagesColor(channelName() + ' ' + s, c); |
pMainForm->appendMessagesColor(channelName() + ' ' + s, c); |
773 |
} |
} |
774 |
|
|
775 |
void qsamplerChannel::appendMessagesText( const QString& s ) const |
void Channel::appendMessagesText( const QString& s ) const |
776 |
{ |
{ |
777 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
778 |
if (pMainForm) |
if (pMainForm) |
779 |
pMainForm->appendMessagesText(channelName() + ' ' + s); |
pMainForm->appendMessagesText(channelName() + ' ' + s); |
780 |
} |
} |
781 |
|
|
782 |
void qsamplerChannel::appendMessagesError( const QString& s ) const |
void Channel::appendMessagesError( const QString& s ) const |
783 |
{ |
{ |
784 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
785 |
if (pMainForm) |
if (pMainForm) |
786 |
pMainForm->appendMessagesError(channelName() + "\n\n" + s); |
pMainForm->appendMessagesError(channelName() + "\n\n" + s); |
787 |
} |
} |
788 |
|
|
789 |
void qsamplerChannel::appendMessagesClient( const QString& s ) const |
void Channel::appendMessagesClient( const QString& s ) const |
790 |
{ |
{ |
791 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
792 |
if (pMainForm) |
if (pMainForm) |
793 |
pMainForm->appendMessagesClient(channelName() + ' ' + s); |
pMainForm->appendMessagesClient(channelName() + ' ' + s); |
794 |
} |
} |
795 |
|
|
796 |
|
|
797 |
// Context menu event handler. |
// Context menu event handler. |
798 |
void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent ) |
void Channel::contextMenuEvent( QContextMenuEvent *pEvent ) |
799 |
{ |
{ |
800 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
801 |
if (pMainForm) |
if (pMainForm) |
802 |
pMainForm->contextMenuEvent(pEvent); |
pMainForm->contextMenuEvent(pEvent); |
803 |
} |
} |
804 |
|
|
805 |
|
|
806 |
// FIXME: Check whether a given file is an instrument file. |
// FIXME: Check whether a given file is an instrument file (DLS only). |
807 |
bool qsamplerChannel::isInstrumentFile ( const QString& sInstrumentFile ) |
bool Channel::isDlsInstrumentFile ( const QString& sInstrumentFile ) |
808 |
{ |
{ |
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 |
} |
} |
823 |
|
|
824 |
|
|
825 |
// Retrieve the instrument list of a instrument file (.gig). |
// Retrieve the instrument list of a instrument file (.gig). |
826 |
QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile, |
QStringList Channel::getInstrumentList( const QString& sInstrumentFile, |
827 |
bool bInstrumentNames ) |
bool bInstrumentNames ) |
828 |
{ |
{ |
|
QString sInstrumentName = QFileInfo(sInstrumentFile).fileName(); |
|
829 |
QStringList instlist; |
QStringList instlist; |
830 |
|
|
831 |
if (isInstrumentFile(sInstrumentFile)) { |
if (isDlsInstrumentFile(sInstrumentFile)) { |
832 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
833 |
if (bInstrumentNames) { |
if (bInstrumentNames) { |
834 |
RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1()); |
RIFF::File *pRiff |
835 |
|
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
836 |
gig::File *pGig = new gig::File(pRiff); |
gig::File *pGig = new gig::File(pRiff); |
837 |
|
#if HAVE_LIBGIG_SETAUTOLOAD |
838 |
|
// prevent sleepy response time on large .gig files |
839 |
|
pGig->SetAutoLoad(false); |
840 |
|
#endif |
841 |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
842 |
while (pInstrument) { |
while (pInstrument) { |
843 |
instlist.append((pInstrument->pInfo)->Name.c_str()); |
instlist.append((pInstrument->pInfo)->Name.c_str()); |
846 |
delete pGig; |
delete pGig; |
847 |
delete pRiff; |
delete pRiff; |
848 |
} |
} |
849 |
else |
#endif |
850 |
#endif |
} |
851 |
for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++) |
|
852 |
instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]"); |
if (instlist.isEmpty()) { |
853 |
|
QFileInfo fi(sInstrumentFile); |
854 |
|
if (fi.exists()) { |
855 |
|
QString sInstrumentName = fi.fileName(); |
856 |
|
int iInstrumentNr = 0; |
857 |
|
while (iInstrumentNr < QSAMPLER_INSTRUMENT_MAX) { |
858 |
|
instlist.append(sInstrumentName |
859 |
|
+ " [" + QString::number(++iInstrumentNr) + "]"); |
860 |
|
} |
861 |
|
} |
862 |
|
else instlist.append(noInstrumentName()); |
863 |
} |
} |
|
else instlist.append(noInstrumentName()); |
|
864 |
|
|
865 |
return instlist; |
return instlist; |
866 |
} |
} |
867 |
|
|
868 |
|
|
869 |
// Retrieve the spacific instrument name of a instrument file (.gig), given its index. |
// Retrieve the spacific instrument name of a instrument file (.gig), given its index. |
870 |
QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile, |
QString Channel::getInstrumentName( const QString& sInstrumentFile, |
871 |
int iInstrumentNr, bool bInstrumentNames ) |
int iInstrumentNr, bool bInstrumentNames ) |
872 |
{ |
{ |
873 |
QString sInstrumentName; |
QString sInstrumentName; |
874 |
|
|
875 |
if (isInstrumentFile(sInstrumentFile)) { |
if (isDlsInstrumentFile(sInstrumentFile)) { |
876 |
sInstrumentName = QFileInfo(sInstrumentFile).fileName(); |
#ifdef CONFIG_LIBGIG |
|
#ifdef CONFIG_LIBGIG |
|
877 |
if (bInstrumentNames) { |
if (bInstrumentNames) { |
878 |
RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1()); |
RIFF::File *pRiff |
879 |
gig::File *pGig = new gig::File(pRiff); |
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
880 |
|
gig::File *pGig = new gig::File(pRiff); |
881 |
|
#if HAVE_LIBGIG_SETAUTOLOAD |
882 |
|
// prevent sleepy response time on large .gig files |
883 |
|
pGig->SetAutoLoad(false); |
884 |
|
#endif |
885 |
int iIndex = 0; |
int iIndex = 0; |
886 |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
887 |
while (pInstrument) { |
while (pInstrument) { |
895 |
delete pGig; |
delete pGig; |
896 |
delete pRiff; |
delete pRiff; |
897 |
} |
} |
898 |
else |
#endif |
899 |
#endif |
} |
900 |
sInstrumentName += " [" + QString::number(iInstrumentNr) + "]"; |
|
901 |
|
if (sInstrumentName.isEmpty()) { |
902 |
|
QFileInfo fi(sInstrumentFile); |
903 |
|
if (fi.exists()) { |
904 |
|
sInstrumentName = fi.fileName(); |
905 |
|
sInstrumentName += " [" + QString::number(iInstrumentNr) + "]"; |
906 |
|
} |
907 |
|
else sInstrumentName = noInstrumentName(); |
908 |
} |
} |
|
else sInstrumentName = noInstrumentName(); |
|
909 |
|
|
910 |
return sInstrumentName; |
return sInstrumentName; |
911 |
} |
} |
912 |
|
|
913 |
|
|
914 |
// Common invalid name-helpers. |
// Common invalid name-helpers. |
915 |
QString qsamplerChannel::noEngineName (void) |
QString Channel::noEngineName (void) |
916 |
{ |
{ |
917 |
return QObject::tr("(No engine)"); |
return QObject::tr("(No engine)"); |
918 |
} |
} |
919 |
|
|
920 |
QString qsamplerChannel::noInstrumentName (void) |
QString Channel::noInstrumentName (void) |
921 |
{ |
{ |
922 |
return QObject::tr("(No instrument)"); |
return QObject::tr("(No instrument)"); |
923 |
} |
} |
924 |
|
|
925 |
QString qsamplerChannel::loadingInstrument (void) { |
QString Channel::loadingInstrument (void) { |
926 |
return QObject::tr("(Loading instrument...)"); |
return QObject::tr("(Loading instrument...)"); |
927 |
} |
} |
928 |
|
|
929 |
|
|
|
|
|
930 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
931 |
// qsamplerChannelRoutingTable - Channel routing table. |
// QSampler::ChannelRoutingModel - data model for audio routing |
932 |
// |
// (used for QTableView) |
933 |
|
|
934 |
// Constructor. |
ChannelRoutingModel::ChannelRoutingModel ( QObject *pParent ) |
935 |
qsamplerChannelRoutingTable::qsamplerChannelRoutingTable ( |
: QAbstractTableModel(pParent), m_pDevice(NULL) |
936 |
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); |
|
937 |
} |
} |
938 |
|
|
939 |
// Default destructor. |
|
940 |
qsamplerChannelRoutingTable::~qsamplerChannelRoutingTable (void) |
int ChannelRoutingModel::rowCount ( const QModelIndex& /*parent*/) const |
941 |
|
{ |
942 |
|
return (m_pDevice) ? m_routing.size() : 0; |
943 |
|
} |
944 |
|
|
945 |
|
|
946 |
|
int ChannelRoutingModel::columnCount ( const QModelIndex& /*parent*/) const |
947 |
|
{ |
948 |
|
return 1; |
949 |
|
} |
950 |
|
|
951 |
|
|
952 |
|
Qt::ItemFlags ChannelRoutingModel::flags ( const QModelIndex& /*index*/) const |
953 |
{ |
{ |
954 |
|
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled; |
955 |
} |
} |
956 |
|
|
957 |
|
|
958 |
// Routing map table renderer. |
bool ChannelRoutingModel::setData ( const QModelIndex& index, |
959 |
void qsamplerChannelRoutingTable::refresh ( qsamplerDevice *pDevice, |
const QVariant& value, int /*role*/) |
|
const qsamplerChannelRoutingMap& routing ) |
|
960 |
{ |
{ |
961 |
if (pDevice == NULL) |
if (!index.isValid()) |
962 |
return; |
return false; |
963 |
|
|
964 |
|
m_routing[index.row()] = value.toInt(); |
965 |
|
|
966 |
|
emit dataChanged(index, index); |
967 |
|
return true; |
968 |
|
} |
969 |
|
|
970 |
|
|
971 |
|
QVariant ChannelRoutingModel::data ( const QModelIndex &index, int role ) const |
972 |
|
{ |
973 |
|
if (!index.isValid()) |
974 |
|
return QVariant(); |
975 |
|
if (role != Qt::DisplayRole) |
976 |
|
return QVariant(); |
977 |
|
if (index.column() != 0) |
978 |
|
return QVariant(); |
979 |
|
|
980 |
// Always (re)start it empty. |
ChannelRoutingItem item; |
|
QTable::setUpdatesEnabled(false); |
|
|
QTable::setNumRows(0); |
|
981 |
|
|
982 |
// The common device port item list. |
// The common device port item list. |
983 |
QStringList opts; |
DevicePortList& ports = m_pDevice->ports(); |
984 |
qsamplerDevicePortList& ports = pDevice->ports(); |
QListIterator<DevicePort *> iter(ports); |
985 |
qsamplerDevicePort *pPort; |
while (iter.hasNext()) { |
986 |
for (pPort = ports.first(); pPort; pPort = ports.next()) { |
DevicePort *pPort = iter.next(); |
987 |
opts.append(pDevice->deviceTypeName() |
item.options.append( |
988 |
+ ' ' + pDevice->driverName() |
m_pDevice->deviceTypeName() |
989 |
+ ' ' + pPort->portName()); |
+ ' ' + m_pDevice->driverName() |
990 |
} |
+ ' ' + pPort->portName() |
991 |
|
); |
992 |
// Those items shall have a proper pixmap... |
} |
993 |
QPixmap pmChannel = QPixmap::fromMimeSource("qsamplerChannel.png"); |
|
994 |
QPixmap pmDevice; |
item.selection = m_routing[index.row()]; |
995 |
switch (pDevice->deviceType()) { |
|
996 |
case qsamplerDevice::Audio: |
return QVariant::fromValue(item); |
997 |
pmDevice = QPixmap::fromMimeSource("audio2.png"); |
} |
998 |
break; |
|
999 |
case qsamplerDevice::Midi: |
|
1000 |
pmDevice = QPixmap::fromMimeSource("midi2.png"); |
QVariant ChannelRoutingModel::headerData ( int section, |
1001 |
break; |
Qt::Orientation orientation, int role) const |
1002 |
case qsamplerDevice::None: |
{ |
1003 |
break; |
if (role != Qt::DisplayRole) |
1004 |
} |
return QVariant(); |
1005 |
|
|
1006 |
// Fill the routing table... |
switch (orientation) { |
1007 |
QTable::insertRows(0, routing.count()); |
case Qt::Horizontal: |
1008 |
int iRow = 0; |
return UNICODE_RIGHT_ARROW + QObject::tr(" Device Channel"); |
1009 |
qsamplerChannelRoutingMap::ConstIterator iter; |
case Qt::Vertical: |
1010 |
for (iter = routing.begin(); iter != routing.end(); ++iter) { |
return QObject::tr("Audio Channel ") + |
1011 |
QTable::setPixmap(iRow, 0, pmChannel); |
QString::number(section) + " " + UNICODE_RIGHT_ARROW; |
1012 |
QTable::setText(iRow, 0, pDevice->deviceTypeName() |
default: |
1013 |
+ ' ' + QString::number(iter.key())); |
return QVariant(); |
1014 |
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); |
|
|
|
|
|
QTable::setUpdatesEnabled(true); |
|
|
QTable::updateContents(); |
|
1015 |
} |
} |
1016 |
|
|
1017 |
|
|
1018 |
// Commit any pending editing. |
void ChannelRoutingModel::refresh ( Device *pDevice, |
1019 |
void qsamplerChannelRoutingTable::flush (void) |
const ChannelRoutingMap& routing ) |
1020 |
{ |
{ |
1021 |
if (QTable::isEditing()) |
m_pDevice = pDevice; |
1022 |
QTable::endEdit(QTable::currEditRow(), QTable::currEditCol(), true, true); |
m_routing = routing; |
1023 |
|
// inform the outer world (QTableView) that our data changed |
1024 |
|
QAbstractTableModel::reset(); |
1025 |
} |
} |
1026 |
|
|
1027 |
|
|
1028 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
1029 |
// qsamplerChannelRoutingComboBox - Custom combo box for routing table. |
// QSampler::ChannelRoutingDelegate - table cell renderer for audio routing |
1030 |
// |
// |
1031 |
|
|
1032 |
// Constructor. |
ChannelRoutingDelegate::ChannelRoutingDelegate ( QObject *pParent ) |
1033 |
qsamplerChannelRoutingComboBox::qsamplerChannelRoutingComboBox ( |
: QItemDelegate(pParent) |
|
QTable *pTable, const QStringList& list, const QPixmap& pixmap ) |
|
|
: QTableItem(pTable, QTableItem::WhenCurrent, QString::null, pixmap), |
|
|
m_list(list) |
|
1034 |
{ |
{ |
|
m_iCurrentItem = 0; |
|
1035 |
} |
} |
1036 |
|
|
1037 |
// Public accessors. |
|
1038 |
void qsamplerChannelRoutingComboBox::setCurrentItem ( int iCurrentItem ) |
QWidget* ChannelRoutingDelegate::createEditor ( QWidget *pParent, |
1039 |
|
const QStyleOptionViewItem & option, const QModelIndex& index ) const |
1040 |
{ |
{ |
1041 |
m_iCurrentItem = iCurrentItem; |
if (!index.isValid()) |
1042 |
|
return NULL; |
1043 |
|
|
1044 |
|
if (index.column() != 0) |
1045 |
|
return NULL; |
1046 |
|
|
1047 |
QTableItem::setText(m_list[iCurrentItem]); |
ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>(); |
1048 |
|
|
1049 |
|
QComboBox* pComboBox = new QComboBox(pParent); |
1050 |
|
pComboBox->addItems(item.options); |
1051 |
|
pComboBox->setCurrentIndex(item.selection); |
1052 |
|
pComboBox->setEnabled(true); |
1053 |
|
pComboBox->setGeometry(option.rect); |
1054 |
|
return pComboBox; |
1055 |
} |
} |
1056 |
|
|
1057 |
int qsamplerChannelRoutingComboBox::currentItem (void) const |
|
1058 |
|
void ChannelRoutingDelegate::setEditorData ( QWidget *pEditor, |
1059 |
|
const QModelIndex &index) const |
1060 |
{ |
{ |
1061 |
return m_iCurrentItem; |
ChannelRoutingItem item = index.model()->data(index, |
1062 |
|
Qt::DisplayRole).value<ChannelRoutingItem> (); |
1063 |
|
QComboBox* pComboBox = static_cast<QComboBox*> (pEditor); |
1064 |
|
pComboBox->setCurrentIndex(item.selection); |
1065 |
} |
} |
1066 |
|
|
1067 |
// Virtual implemetations. |
|
1068 |
QWidget *qsamplerChannelRoutingComboBox::createEditor (void) const |
void ChannelRoutingDelegate::setModelData ( QWidget* pEditor, |
1069 |
|
QAbstractItemModel *pModel, const QModelIndex& index ) const |
1070 |
{ |
{ |
1071 |
QComboBox *pComboBox = new QComboBox(QTableItem::table()->viewport()); |
QComboBox *pComboBox = static_cast<QComboBox*> (pEditor); |
1072 |
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; |
|
1073 |
} |
} |
1074 |
|
|
1075 |
void qsamplerChannelRoutingComboBox::setContentFromEditor ( QWidget *pWidget ) |
|
1076 |
|
void ChannelRoutingDelegate::updateEditorGeometry ( QWidget *pEditor, |
1077 |
|
const QStyleOptionViewItem& option, const QModelIndex &/* index */) const |
1078 |
{ |
{ |
1079 |
if (pWidget->inherits("QComboBox")) { |
pEditor->setGeometry(option.rect); |
|
QComboBox *pComboBox = (QComboBox *) pWidget; |
|
|
m_iCurrentItem = pComboBox->currentItem(); |
|
|
QTableItem::setText(pComboBox->currentText()); |
|
|
} |
|
|
else QTableItem::setContentFromEditor(pWidget); |
|
1080 |
} |
} |
1081 |
|
|
1082 |
|
} // namespace QSampler |
1083 |
|
|
1084 |
|
|
1085 |
// end of qsamplerChannel.cpp |
// end of qsamplerChannel.cpp |