1 |
// qsamplerChannel.cpp |
// qsamplerChannel.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2014, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
Copyright (C) 2007, Christian Schoenebeck |
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 |
32 |
|
|
33 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
34 |
#include "gig.h" |
#include "gig.h" |
35 |
|
#ifdef CONFIG_LIBGIG_SF_H |
36 |
|
#include "SF.h" |
37 |
|
#endif |
38 |
#endif |
#endif |
39 |
|
|
40 |
#define QSAMPLER_INSTRUMENT_MAX 100 |
namespace QSampler { |
41 |
|
|
42 |
#define UNICODE_RIGHT_ARROW QChar(char(0x92), char(0x21)) |
#define QSAMPLER_INSTRUMENT_MAX 128 |
43 |
|
|
44 |
|
#define UNICODE_RIGHT_ARROW QChar(char(0x92), char(0x21)) |
45 |
|
|
|
using namespace QSampler; |
|
46 |
|
|
47 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
48 |
// qsamplerChannel - Sampler channel structure. |
// QSampler::Channel - Sampler channel structure. |
49 |
// |
// |
50 |
|
|
51 |
// Constructor. |
// Constructor. |
52 |
qsamplerChannel::qsamplerChannel ( int iChannelID ) |
Channel::Channel ( int iChannelID ) |
53 |
{ |
{ |
54 |
m_iChannelID = iChannelID; |
m_iChannelID = iChannelID; |
55 |
|
|
71 |
} |
} |
72 |
|
|
73 |
// Default destructor. |
// Default destructor. |
74 |
qsamplerChannel::~qsamplerChannel (void) |
Channel::~Channel (void) |
75 |
{ |
{ |
76 |
} |
} |
77 |
|
|
78 |
|
|
79 |
// Create a new sampler channel, if not already. |
// Create a new sampler channel, if not already. |
80 |
bool qsamplerChannel::addChannel (void) |
bool Channel::addChannel (void) |
81 |
{ |
{ |
82 |
MainForm* pMainForm = MainForm::getInstance(); |
MainForm* pMainForm = MainForm::getInstance(); |
83 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
102 |
|
|
103 |
|
|
104 |
// Remove sampler channel. |
// Remove sampler channel. |
105 |
bool qsamplerChannel::removeChannel (void) |
bool Channel::removeChannel (void) |
106 |
{ |
{ |
107 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
108 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
128 |
|
|
129 |
|
|
130 |
// Channel-ID (aka Sammpler-Channel) accessors. |
// Channel-ID (aka Sammpler-Channel) accessors. |
131 |
int qsamplerChannel::channelID (void) const |
int Channel::channelID (void) const |
132 |
{ |
{ |
133 |
return m_iChannelID; |
return m_iChannelID; |
134 |
} |
} |
135 |
|
|
136 |
void qsamplerChannel::setChannelID ( int iChannelID ) |
void Channel::setChannelID ( int iChannelID ) |
137 |
{ |
{ |
138 |
m_iChannelID = iChannelID; |
m_iChannelID = iChannelID; |
139 |
} |
} |
140 |
|
|
141 |
|
|
142 |
// Readable channel name. |
// Readable channel name. |
143 |
QString qsamplerChannel::channelName (void) const |
QString Channel::channelName (void) const |
144 |
{ |
{ |
145 |
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)); |
146 |
} |
} |
147 |
|
|
148 |
|
|
149 |
// Engine name accessors. |
// Engine name accessors. |
150 |
const QString& qsamplerChannel::engineName (void) const |
const QString& Channel::engineName (void) const |
151 |
{ |
{ |
152 |
return m_sEngineName; |
return m_sEngineName; |
153 |
} |
} |
154 |
|
|
155 |
bool qsamplerChannel::loadEngine ( const QString& sEngineName ) |
bool Channel::loadEngine ( const QString& sEngineName ) |
156 |
{ |
{ |
157 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
158 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
176 |
|
|
177 |
|
|
178 |
// Instrument filename accessor. |
// Instrument filename accessor. |
179 |
const QString& qsamplerChannel::instrumentFile (void) const |
const QString& Channel::instrumentFile (void) const |
180 |
{ |
{ |
181 |
return m_sInstrumentFile; |
return m_sInstrumentFile; |
182 |
} |
} |
183 |
|
|
184 |
// Instrument index accessor. |
// Instrument index accessor. |
185 |
int qsamplerChannel::instrumentNr (void) const |
int Channel::instrumentNr (void) const |
186 |
{ |
{ |
187 |
return m_iInstrumentNr; |
return m_iInstrumentNr; |
188 |
} |
} |
189 |
|
|
190 |
// Instrument name accessor. |
// Instrument name accessor. |
191 |
const QString& qsamplerChannel::instrumentName (void) const |
const QString& Channel::instrumentName (void) const |
192 |
{ |
{ |
193 |
return m_sInstrumentName; |
return m_sInstrumentName; |
194 |
} |
} |
195 |
|
|
196 |
// Instrument status accessor. |
// Instrument status accessor. |
197 |
int qsamplerChannel::instrumentStatus (void) const |
int Channel::instrumentStatus (void) const |
198 |
{ |
{ |
199 |
return m_iInstrumentStatus; |
return m_iInstrumentStatus; |
200 |
} |
} |
201 |
|
|
202 |
// Instrument file loader. |
// Instrument file loader. |
203 |
bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) |
bool Channel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) |
204 |
{ |
{ |
205 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
206 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
207 |
return false; |
return false; |
208 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
209 |
return false; |
return false; |
210 |
if (!isInstrumentFile(sInstrumentFile)) |
if (!QFileInfo(sInstrumentFile).exists()) |
211 |
return false; |
return false; |
212 |
if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr) |
if (m_iInstrumentStatus == 100 |
213 |
|
&& m_sInstrumentFile == sInstrumentFile |
214 |
|
&& m_iInstrumentNr == iInstrumentNr) |
215 |
return true; |
return true; |
216 |
|
|
217 |
if ( |
if (::lscp_load_instrument_non_modal( |
|
::lscp_load_instrument_non_modal( |
|
218 |
pMainForm->client(), |
pMainForm->client(), |
219 |
qsamplerUtilities::lscpEscapePath( |
qsamplerUtilities::lscpEscapePath( |
220 |
sInstrumentFile).toUtf8().constData(), |
sInstrumentFile).toUtf8().constData(), |
221 |
iInstrumentNr, m_iChannelID |
iInstrumentNr, m_iChannelID |
222 |
) != LSCP_OK |
) != LSCP_OK) { |
|
) { |
|
223 |
appendMessagesClient("lscp_load_instrument"); |
appendMessagesClient("lscp_load_instrument"); |
224 |
return false; |
return false; |
225 |
} |
} |
232 |
|
|
233 |
|
|
234 |
// Special instrument file/name/number settler. |
// Special instrument file/name/number settler. |
235 |
bool qsamplerChannel::setInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) |
bool Channel::setInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) |
236 |
{ |
{ |
237 |
m_sInstrumentFile = sInstrumentFile; |
m_sInstrumentFile = sInstrumentFile; |
238 |
m_iInstrumentNr = iInstrumentNr; |
m_iInstrumentNr = iInstrumentNr; |
248 |
|
|
249 |
|
|
250 |
// MIDI driver type accessors (DEPRECATED). |
// MIDI driver type accessors (DEPRECATED). |
251 |
const QString& qsamplerChannel::midiDriver (void) const |
const QString& Channel::midiDriver (void) const |
252 |
{ |
{ |
253 |
return m_sMidiDriver; |
return m_sMidiDriver; |
254 |
} |
} |
255 |
|
|
256 |
bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver ) |
bool Channel::setMidiDriver ( const QString& sMidiDriver ) |
257 |
{ |
{ |
258 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
259 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
277 |
|
|
278 |
|
|
279 |
// MIDI device accessors. |
// MIDI device accessors. |
280 |
int qsamplerChannel::midiDevice (void) const |
int Channel::midiDevice (void) const |
281 |
{ |
{ |
282 |
return m_iMidiDevice; |
return m_iMidiDevice; |
283 |
} |
} |
284 |
|
|
285 |
bool qsamplerChannel::setMidiDevice ( int iMidiDevice ) |
bool Channel::setMidiDevice ( int iMidiDevice ) |
286 |
{ |
{ |
287 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
288 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
305 |
|
|
306 |
|
|
307 |
// MIDI port number accessor. |
// MIDI port number accessor. |
308 |
int qsamplerChannel::midiPort (void) const |
int Channel::midiPort (void) const |
309 |
{ |
{ |
310 |
return m_iMidiPort; |
return m_iMidiPort; |
311 |
} |
} |
312 |
|
|
313 |
bool qsamplerChannel::setMidiPort ( int iMidiPort ) |
bool Channel::setMidiPort ( int iMidiPort ) |
314 |
{ |
{ |
315 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
316 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
333 |
|
|
334 |
|
|
335 |
// MIDI channel accessor. |
// MIDI channel accessor. |
336 |
int qsamplerChannel::midiChannel (void) const |
int Channel::midiChannel (void) const |
337 |
{ |
{ |
338 |
return m_iMidiChannel; |
return m_iMidiChannel; |
339 |
} |
} |
340 |
|
|
341 |
bool qsamplerChannel::setMidiChannel ( int iMidiChannel ) |
bool Channel::setMidiChannel ( int iMidiChannel ) |
342 |
{ |
{ |
343 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
344 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
361 |
|
|
362 |
|
|
363 |
// MIDI instrument map accessor. |
// MIDI instrument map accessor. |
364 |
int qsamplerChannel::midiMap (void) const |
int Channel::midiMap (void) const |
365 |
{ |
{ |
366 |
return m_iMidiMap; |
return m_iMidiMap; |
367 |
} |
} |
368 |
|
|
369 |
bool qsamplerChannel::setMidiMap ( int iMidiMap ) |
bool Channel::setMidiMap ( int iMidiMap ) |
370 |
{ |
{ |
371 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
372 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
389 |
|
|
390 |
|
|
391 |
// Audio device accessor. |
// Audio device accessor. |
392 |
int qsamplerChannel::audioDevice (void) const |
int Channel::audioDevice (void) const |
393 |
{ |
{ |
394 |
return m_iAudioDevice; |
return m_iAudioDevice; |
395 |
} |
} |
396 |
|
|
397 |
bool qsamplerChannel::setAudioDevice ( int iAudioDevice ) |
bool Channel::setAudioDevice ( int iAudioDevice ) |
398 |
{ |
{ |
399 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
400 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
417 |
|
|
418 |
|
|
419 |
// Audio driver type accessors (DEPRECATED). |
// Audio driver type accessors (DEPRECATED). |
420 |
const QString& qsamplerChannel::audioDriver (void) const |
const QString& Channel::audioDriver (void) const |
421 |
{ |
{ |
422 |
return m_sAudioDriver; |
return m_sAudioDriver; |
423 |
} |
} |
424 |
|
|
425 |
bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver ) |
bool Channel::setAudioDriver ( const QString& sAudioDriver ) |
426 |
{ |
{ |
427 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
428 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
446 |
|
|
447 |
|
|
448 |
// Channel volume accessors. |
// Channel volume accessors. |
449 |
float qsamplerChannel::volume (void) const |
float Channel::volume (void) const |
450 |
{ |
{ |
451 |
return m_fVolume; |
return m_fVolume; |
452 |
} |
} |
453 |
|
|
454 |
bool qsamplerChannel::setVolume ( float fVolume ) |
bool Channel::setVolume ( float fVolume ) |
455 |
{ |
{ |
456 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
457 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
474 |
|
|
475 |
|
|
476 |
// Sampler channel mute state. |
// Sampler channel mute state. |
477 |
bool qsamplerChannel::channelMute (void) const |
bool Channel::channelMute (void) const |
478 |
{ |
{ |
479 |
return m_bMute; |
return m_bMute; |
480 |
} |
} |
481 |
|
|
482 |
bool qsamplerChannel::setChannelMute ( bool bMute ) |
bool Channel::setChannelMute ( bool bMute ) |
483 |
{ |
{ |
484 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
485 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
504 |
|
|
505 |
|
|
506 |
// Sampler channel solo state. |
// Sampler channel solo state. |
507 |
bool qsamplerChannel::channelSolo (void) const |
bool Channel::channelSolo (void) const |
508 |
{ |
{ |
509 |
return m_bSolo; |
return m_bSolo; |
510 |
} |
} |
511 |
|
|
512 |
bool qsamplerChannel::setChannelSolo ( bool bSolo ) |
bool Channel::setChannelSolo ( bool bSolo ) |
513 |
{ |
{ |
514 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
515 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
534 |
|
|
535 |
|
|
536 |
// Audio routing accessors. |
// Audio routing accessors. |
537 |
int qsamplerChannel::audioChannel ( int iAudioOut ) const |
int Channel::audioChannel ( int iAudioOut ) const |
538 |
{ |
{ |
539 |
return m_audioRouting[iAudioOut]; |
return m_audioRouting[iAudioOut]; |
540 |
} |
} |
541 |
|
|
542 |
bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn ) |
bool Channel::setAudioChannel ( int iAudioOut, int iAudioIn ) |
543 |
{ |
{ |
544 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
545 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
564 |
} |
} |
565 |
|
|
566 |
// The audio routing map itself. |
// The audio routing map itself. |
567 |
const qsamplerChannelRoutingMap& qsamplerChannel::audioRouting (void) const |
const ChannelRoutingMap& Channel::audioRouting (void) const |
568 |
{ |
{ |
569 |
return m_audioRouting; |
return m_audioRouting; |
570 |
} |
} |
571 |
|
|
572 |
|
|
573 |
// Istrument name remapper. |
// Istrument name remapper. |
574 |
void qsamplerChannel::updateInstrumentName (void) |
void Channel::updateInstrumentName (void) |
575 |
{ |
{ |
576 |
#ifndef CONFIG_INSTRUMENT_NAME |
#ifndef CONFIG_INSTRUMENT_NAME |
577 |
m_sInstrumentName = getInstrumentName(m_sInstrumentFile, |
m_sInstrumentName = getInstrumentName(m_sInstrumentFile, |
581 |
|
|
582 |
|
|
583 |
// Update whole channel info state. |
// Update whole channel info state. |
584 |
bool qsamplerChannel::updateChannelInfo (void) |
bool Channel::updateChannelInfo (void) |
585 |
{ |
{ |
586 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
587 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
675 |
|
|
676 |
|
|
677 |
// Reset channel method. |
// Reset channel method. |
678 |
bool qsamplerChannel::channelReset (void) |
bool Channel::channelReset (void) |
679 |
{ |
{ |
680 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
681 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
695 |
|
|
696 |
|
|
697 |
// Spawn instrument editor method. |
// Spawn instrument editor method. |
698 |
bool qsamplerChannel::editChannel (void) |
bool Channel::editChannel (void) |
699 |
{ |
{ |
700 |
#ifdef CONFIG_EDIT_INSTRUMENT |
#ifdef CONFIG_EDIT_INSTRUMENT |
701 |
|
|
710 |
appendMessagesClient("lscp_edit_channel_instrument"); |
appendMessagesClient("lscp_edit_channel_instrument"); |
711 |
appendMessagesError(QObject::tr( |
appendMessagesError(QObject::tr( |
712 |
"Could not launch an appropriate instrument editor " |
"Could not launch an appropriate instrument editor " |
713 |
"for the given instrument!\n" |
"for the given instrument!\n\n" |
714 |
"Make sure you have an appropriate " |
"Make sure you have an appropriate " |
715 |
"instrument editor like 'gigedit' installed\n" |
"instrument editor like 'gigedit' installed " |
716 |
"and that it placed its mandatory DLL file " |
"and that it placed its mandatory DLL file " |
717 |
"into the sampler's plugin directory.") |
"into the sampler's plugin directory.") |
718 |
); |
); |
727 |
|
|
728 |
appendMessagesError(QObject::tr( |
appendMessagesError(QObject::tr( |
729 |
"Sorry, QSampler was compiled for a version of liblscp " |
"Sorry, QSampler was compiled for a version of liblscp " |
730 |
"which lacks this feature.\n" |
"which lacks this feature.\n\n" |
731 |
"You may want to update liblscp and recompile QSampler afterwards.") |
"You may want to update liblscp and recompile QSampler afterwards.") |
732 |
); |
); |
733 |
|
|
738 |
|
|
739 |
|
|
740 |
// Channel setup dialog form. |
// Channel setup dialog form. |
741 |
bool qsamplerChannel::channelSetup ( QWidget *pParent ) |
bool Channel::channelSetup ( QWidget *pParent ) |
742 |
{ |
{ |
743 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
744 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
760 |
|
|
761 |
|
|
762 |
// Redirected messages output methods. |
// Redirected messages output methods. |
763 |
void qsamplerChannel::appendMessages( const QString& s ) const |
void Channel::appendMessages( const QString& s ) const |
764 |
{ |
{ |
765 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
766 |
if (pMainForm) |
if (pMainForm) |
767 |
pMainForm->appendMessages(channelName() + ' ' + s); |
pMainForm->appendMessages(channelName() + ' ' + s); |
768 |
} |
} |
769 |
|
|
770 |
void qsamplerChannel::appendMessagesColor( const QString& s, |
void Channel::appendMessagesColor( const QString& s, |
771 |
const QString& c ) const |
const QString& c ) const |
772 |
{ |
{ |
773 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
775 |
pMainForm->appendMessagesColor(channelName() + ' ' + s, c); |
pMainForm->appendMessagesColor(channelName() + ' ' + s, c); |
776 |
} |
} |
777 |
|
|
778 |
void qsamplerChannel::appendMessagesText( const QString& s ) const |
void Channel::appendMessagesText( const QString& s ) const |
779 |
{ |
{ |
780 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
781 |
if (pMainForm) |
if (pMainForm) |
782 |
pMainForm->appendMessagesText(channelName() + ' ' + s); |
pMainForm->appendMessagesText(channelName() + ' ' + s); |
783 |
} |
} |
784 |
|
|
785 |
void qsamplerChannel::appendMessagesError( const QString& s ) const |
void Channel::appendMessagesError( const QString& s ) const |
786 |
{ |
{ |
787 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
788 |
if (pMainForm) |
if (pMainForm) |
789 |
pMainForm->appendMessagesError(channelName() + "\n\n" + s); |
pMainForm->appendMessagesError(channelName() + "\n\n" + s); |
790 |
} |
} |
791 |
|
|
792 |
void qsamplerChannel::appendMessagesClient( const QString& s ) const |
void Channel::appendMessagesClient( const QString& s ) const |
793 |
{ |
{ |
794 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
795 |
if (pMainForm) |
if (pMainForm) |
798 |
|
|
799 |
|
|
800 |
// Context menu event handler. |
// Context menu event handler. |
801 |
void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent ) |
void Channel::contextMenuEvent( QContextMenuEvent *pEvent ) |
802 |
{ |
{ |
803 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
804 |
if (pMainForm) |
if (pMainForm) |
806 |
} |
} |
807 |
|
|
808 |
|
|
809 |
// FIXME: Check whether a given file is an instrument file. |
// FIXME: Check whether a given file is an instrument file (DLS only). |
810 |
bool qsamplerChannel::isInstrumentFile ( const QString& sInstrumentFile ) |
bool Channel::isDlsInstrumentFile ( const QString& sInstrumentFile ) |
811 |
{ |
{ |
812 |
bool bResult = false; |
bool bResult = false; |
813 |
|
|
825 |
} |
} |
826 |
|
|
827 |
|
|
828 |
|
// FIXME: Check whether a given file is an instrument file (SF2 only). |
829 |
|
bool Channel::isSf2InstrumentFile ( const QString& sInstrumentFile ) |
830 |
|
{ |
831 |
|
bool bResult = false; |
832 |
|
|
833 |
|
QFile file(sInstrumentFile); |
834 |
|
if (file.open(QIODevice::ReadOnly)) { |
835 |
|
char achHeader[12]; |
836 |
|
if (file.read(achHeader, 12) > 0) { |
837 |
|
bResult = (::memcmp(&achHeader[0], "RIFF", 4) == 0 |
838 |
|
&& ::memcmp(&achHeader[8], "sfbk", 4) == 0); |
839 |
|
} |
840 |
|
file.close(); |
841 |
|
} |
842 |
|
|
843 |
|
return bResult; |
844 |
|
} |
845 |
|
|
846 |
|
|
847 |
// Retrieve the instrument list of a instrument file (.gig). |
// Retrieve the instrument list of a instrument file (.gig). |
848 |
QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile, |
QStringList Channel::getInstrumentList ( |
849 |
bool bInstrumentNames ) |
const QString& sInstrumentFile, bool bInstrumentNames ) |
850 |
{ |
{ |
|
QString sInstrumentName = QFileInfo(sInstrumentFile).fileName(); |
|
851 |
QStringList instlist; |
QStringList instlist; |
852 |
|
|
853 |
if (isInstrumentFile(sInstrumentFile)) { |
const QFileInfo fi(sInstrumentFile); |
854 |
|
if (!fi.exists()) { |
855 |
|
instlist.append(noInstrumentName()); |
856 |
|
return instlist; |
857 |
|
} |
858 |
|
|
859 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
860 |
if (bInstrumentNames) { |
if (bInstrumentNames) { |
861 |
|
if (isDlsInstrumentFile(sInstrumentFile)) { |
862 |
RIFF::File *pRiff |
RIFF::File *pRiff |
863 |
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
864 |
gig::File *pGig = new gig::File(pRiff); |
gig::File *pGig = new gig::File(pRiff); |
865 |
#if HAVE_LIBGIG_SETAUTOLOAD |
#ifdef CONFIG_LIBGIG_SETAUTOLOAD |
866 |
// prevent sleepy response time on large .gig files |
// prevent sleepy response time on large .gig files |
867 |
pGig->SetAutoLoad(false); |
pGig->SetAutoLoad(false); |
868 |
#endif |
#endif |
869 |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
870 |
while (pInstrument) { |
while (pInstrument) { |
871 |
instlist.append((pInstrument->pInfo)->Name.c_str()); |
instlist.append((pInstrument->pInfo)->Name.c_str()); |
874 |
delete pGig; |
delete pGig; |
875 |
delete pRiff; |
delete pRiff; |
876 |
} |
} |
877 |
|
#ifdef CONFIG_LIBGIG_SF2 |
878 |
else |
else |
879 |
|
if (isSf2InstrumentFile(sInstrumentFile)) { |
880 |
|
RIFF::File *pRiff |
881 |
|
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
882 |
|
sf2::File *pSf2 = new sf2::File(pRiff); |
883 |
|
const int iPresetCount = pSf2->GetPresetCount(); |
884 |
|
for (int iIndex = 0; iIndex < iPresetCount; ++iIndex) { |
885 |
|
sf2::Preset *pPreset = pSf2->GetPreset(iIndex); |
886 |
|
if (pPreset) { |
887 |
|
instlist.append(pPreset->Name.c_str()); |
888 |
|
} else { |
889 |
|
instlist.append(fi.fileName() |
890 |
|
+ " [" + QString::number(iIndex) + "]"); |
891 |
|
} |
892 |
|
} |
893 |
|
delete pSf2; |
894 |
|
delete pRiff; |
895 |
|
} |
896 |
|
#endif |
897 |
|
} |
898 |
#endif |
#endif |
899 |
for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++) |
|
900 |
instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]"); |
if (instlist.isEmpty()) { |
901 |
|
for (int iIndex = 0; iIndex < QSAMPLER_INSTRUMENT_MAX; ++iIndex) { |
902 |
|
instlist.append(fi.fileName() |
903 |
|
+ " [" + QString::number(iIndex) + "]"); |
904 |
|
} |
905 |
} |
} |
|
else instlist.append(noInstrumentName()); |
|
906 |
|
|
907 |
return instlist; |
return instlist; |
908 |
} |
} |
909 |
|
|
910 |
|
|
911 |
// 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. |
912 |
QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile, |
QString Channel::getInstrumentName ( |
913 |
int iInstrumentNr, bool bInstrumentNames ) |
const QString& sInstrumentFile, int iInstrumentNr, bool bInstrumentNames ) |
914 |
{ |
{ |
915 |
|
const QFileInfo fi(sInstrumentFile); |
916 |
|
if (!fi.exists()) |
917 |
|
return noInstrumentName(); |
918 |
|
|
919 |
QString sInstrumentName; |
QString sInstrumentName; |
920 |
|
|
|
if (isInstrumentFile(sInstrumentFile)) { |
|
|
sInstrumentName = QFileInfo(sInstrumentFile).fileName(); |
|
921 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
922 |
if (bInstrumentNames) { |
if (bInstrumentNames) { |
923 |
|
if (isDlsInstrumentFile(sInstrumentFile)) { |
924 |
RIFF::File *pRiff |
RIFF::File *pRiff |
925 |
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
926 |
gig::File *pGig = new gig::File(pRiff); |
gig::File *pGig = new gig::File(pRiff); |
927 |
#if HAVE_LIBGIG_SETAUTOLOAD |
#ifdef CONFIG_LIBGIG_SETAUTOLOAD |
928 |
// prevent sleepy response time on large .gig files |
// prevent sleepy response time on large .gig files |
929 |
pGig->SetAutoLoad(false); |
pGig->SetAutoLoad(false); |
930 |
#endif |
#endif |
931 |
int iIndex = 0; |
int iIndex = 0; |
932 |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
933 |
while (pInstrument) { |
while (pInstrument) { |
941 |
delete pGig; |
delete pGig; |
942 |
delete pRiff; |
delete pRiff; |
943 |
} |
} |
944 |
|
#ifdef CONFIG_LIBGIG_SF2 |
945 |
else |
else |
946 |
|
if (isSf2InstrumentFile(sInstrumentFile)) { |
947 |
|
RIFF::File *pRiff |
948 |
|
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
949 |
|
sf2::File *pSf2 = new sf2::File(pRiff); |
950 |
|
sf2::Preset *pPreset = pSf2->GetPreset(iInstrumentNr); |
951 |
|
if (pPreset) |
952 |
|
sInstrumentName = pPreset->Name.c_str(); |
953 |
|
delete pSf2; |
954 |
|
delete pRiff; |
955 |
|
} |
956 |
|
#endif |
957 |
|
} |
958 |
#endif |
#endif |
959 |
|
|
960 |
|
if (sInstrumentName.isEmpty()) { |
961 |
|
sInstrumentName = fi.fileName(); |
962 |
sInstrumentName += " [" + QString::number(iInstrumentNr) + "]"; |
sInstrumentName += " [" + QString::number(iInstrumentNr) + "]"; |
963 |
} |
} |
|
else sInstrumentName = noInstrumentName(); |
|
964 |
|
|
965 |
return sInstrumentName; |
return sInstrumentName; |
966 |
} |
} |
967 |
|
|
968 |
|
|
969 |
// Common invalid name-helpers. |
// Common invalid name-helpers. |
970 |
QString qsamplerChannel::noEngineName (void) |
QString Channel::noEngineName (void) |
971 |
{ |
{ |
972 |
return QObject::tr("(No engine)"); |
return QObject::tr("(No engine)"); |
973 |
} |
} |
974 |
|
|
975 |
QString qsamplerChannel::noInstrumentName (void) |
QString Channel::noInstrumentName (void) |
976 |
{ |
{ |
977 |
return QObject::tr("(No instrument)"); |
return QObject::tr("(No instrument)"); |
978 |
} |
} |
979 |
|
|
980 |
QString qsamplerChannel::loadingInstrument (void) { |
QString Channel::loadingInstrument (void) { |
981 |
return QObject::tr("(Loading instrument...)"); |
return QObject::tr("(Loading instrument...)"); |
982 |
} |
} |
983 |
|
|
984 |
|
|
985 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
986 |
// ChannelRoutingModel - data model for audio routing (used for QTableView) |
// QSampler::ChannelRoutingModel - data model for audio routing |
987 |
// |
// (used for QTableView) |
988 |
|
|
989 |
ChannelRoutingModel::ChannelRoutingModel ( QObject *pParent ) |
ChannelRoutingModel::ChannelRoutingModel ( QObject *pParent ) |
990 |
: QAbstractTableModel(pParent), m_pDevice(NULL) |
: QAbstractTableModel(pParent), m_pDevice(NULL) |
994 |
|
|
995 |
int ChannelRoutingModel::rowCount ( const QModelIndex& /*parent*/) const |
int ChannelRoutingModel::rowCount ( const QModelIndex& /*parent*/) const |
996 |
{ |
{ |
997 |
return m_routing.size(); |
return (m_pDevice) ? m_routing.size() : 0; |
998 |
} |
} |
999 |
|
|
1000 |
|
|
1035 |
ChannelRoutingItem item; |
ChannelRoutingItem item; |
1036 |
|
|
1037 |
// The common device port item list. |
// The common device port item list. |
1038 |
qsamplerDevicePortList& ports = m_pDevice->ports(); |
DevicePortList& ports = m_pDevice->ports(); |
1039 |
QListIterator<qsamplerDevicePort *> iter(ports); |
QListIterator<DevicePort *> iter(ports); |
1040 |
while (iter.hasNext()) { |
while (iter.hasNext()) { |
1041 |
qsamplerDevicePort *pPort = iter.next(); |
DevicePort *pPort = iter.next(); |
1042 |
item.options.append( |
item.options.append( |
1043 |
m_pDevice->deviceTypeName() |
m_pDevice->deviceTypeName() |
1044 |
+ ' ' + m_pDevice->driverName() |
+ ' ' + m_pDevice->driverName() |
1062 |
case Qt::Horizontal: |
case Qt::Horizontal: |
1063 |
return UNICODE_RIGHT_ARROW + QObject::tr(" Device Channel"); |
return UNICODE_RIGHT_ARROW + QObject::tr(" Device Channel"); |
1064 |
case Qt::Vertical: |
case Qt::Vertical: |
1065 |
return QObject::tr("Sampler Channel ") + |
return QObject::tr("Audio Channel ") + |
1066 |
QString::number(section) + " " + UNICODE_RIGHT_ARROW; |
QString::number(section) + " " + UNICODE_RIGHT_ARROW; |
1067 |
default: |
default: |
1068 |
return QVariant(); |
return QVariant(); |
1070 |
} |
} |
1071 |
|
|
1072 |
|
|
1073 |
void ChannelRoutingModel::refresh ( qsamplerDevice *pDevice, |
void ChannelRoutingModel::refresh ( Device *pDevice, |
1074 |
const qsamplerChannelRoutingMap& routing ) |
const ChannelRoutingMap& routing ) |
1075 |
{ |
{ |
1076 |
m_pDevice = pDevice; |
m_pDevice = pDevice; |
1077 |
m_routing = routing; |
m_routing = routing; |
1078 |
// inform the outer world (QTableView) that our data changed |
// inform the outer world (QTableView) that our data changed |
1079 |
|
#if QT_VERSION < 0x050000 |
1080 |
QAbstractTableModel::reset(); |
QAbstractTableModel::reset(); |
1081 |
|
#else |
1082 |
|
QAbstractTableModel::beginResetModel(); |
1083 |
|
QAbstractTableModel::endResetModel(); |
1084 |
|
#endif |
1085 |
} |
} |
1086 |
|
|
1087 |
|
|
1088 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
1089 |
// ChannelRoutingDelegate - table cell renderer for audio routing |
// QSampler::ChannelRoutingDelegate - table cell renderer for audio routing |
1090 |
// |
// |
1091 |
|
|
1092 |
ChannelRoutingDelegate::ChannelRoutingDelegate ( QObject *pParent ) |
ChannelRoutingDelegate::ChannelRoutingDelegate ( QObject *pParent ) |
1139 |
pEditor->setGeometry(option.rect); |
pEditor->setGeometry(option.rect); |
1140 |
} |
} |
1141 |
|
|
1142 |
|
} // namespace QSampler |
1143 |
|
|
1144 |
|
|
1145 |
// end of qsamplerChannel.cpp |
// end of qsamplerChannel.cpp |