1 |
// qsamplerChannel.cpp |
// qsamplerChannel.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2019, 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_SF2 |
36 |
|
#include "SF.h" |
37 |
|
#endif |
38 |
#endif |
#endif |
39 |
|
|
40 |
namespace QSampler { |
namespace QSampler { |
41 |
|
|
42 |
#define QSAMPLER_INSTRUMENT_MAX 100 |
#define QSAMPLER_INSTRUMENT_MAX 128 |
43 |
|
|
44 |
#define UNICODE_RIGHT_ARROW QChar(char(0x92), char(0x21)) |
#define UNICODE_RIGHT_ARROW QChar(char(0x92), char(0x21)) |
45 |
|
|
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 |
} |
} |
237 |
m_sInstrumentFile = sInstrumentFile; |
m_sInstrumentFile = sInstrumentFile; |
238 |
m_iInstrumentNr = iInstrumentNr; |
m_iInstrumentNr = iInstrumentNr; |
239 |
#ifdef CONFIG_INSTRUMENT_NAME |
#ifdef CONFIG_INSTRUMENT_NAME |
240 |
m_sInstrumentName = QString::null; // We'll get it, maybe later, on channel_info... |
m_sInstrumentName.clear(); // We'll get it, maybe later, on channel_info... |
241 |
#else |
#else |
242 |
m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true); |
m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true); |
243 |
#endif |
#endif |
632 |
#endif |
#endif |
633 |
// Some sanity checks. |
// Some sanity checks. |
634 |
if (m_sEngineName == "NONE" || m_sEngineName.isEmpty()) |
if (m_sEngineName == "NONE" || m_sEngineName.isEmpty()) |
635 |
m_sEngineName = QString::null; |
m_sEngineName.clear(); |
636 |
if (m_sInstrumentFile == "NONE" || m_sInstrumentFile.isEmpty()) { |
if (m_sInstrumentFile == "NONE" || m_sInstrumentFile.isEmpty()) { |
637 |
m_sInstrumentFile = QString::null; |
m_sInstrumentFile.clear(); |
638 |
m_sInstrumentName = QString::null; |
m_sInstrumentName.clear(); |
639 |
} |
} |
640 |
|
|
641 |
// Time for device info grabbing... |
// Time for device info grabbing... |
760 |
|
|
761 |
|
|
762 |
// Redirected messages output methods. |
// Redirected messages output methods. |
763 |
void Channel::appendMessages( const QString& s ) const |
void Channel::appendMessages ( const QString& sText ) const |
764 |
{ |
{ |
765 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
766 |
if (pMainForm) |
if (pMainForm) |
767 |
pMainForm->appendMessages(channelName() + ' ' + s); |
pMainForm->appendMessages(channelName() + ' ' + sText); |
768 |
} |
} |
769 |
|
|
770 |
void Channel::appendMessagesColor( const QString& s, |
void Channel::appendMessagesColor ( |
771 |
const QString& c ) const |
const QString& sText, const QString& sColor ) const |
772 |
{ |
{ |
773 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
774 |
if (pMainForm) |
if (pMainForm) |
775 |
pMainForm->appendMessagesColor(channelName() + ' ' + s, c); |
pMainForm->appendMessagesColor(channelName() + ' ' + sText, sColor); |
776 |
} |
} |
777 |
|
|
778 |
void Channel::appendMessagesText( const QString& s ) const |
void Channel::appendMessagesText ( const QString& sText ) const |
779 |
{ |
{ |
780 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
781 |
if (pMainForm) |
if (pMainForm) |
782 |
pMainForm->appendMessagesText(channelName() + ' ' + s); |
pMainForm->appendMessagesText(channelName() + ' ' + sText); |
783 |
} |
} |
784 |
|
|
785 |
void Channel::appendMessagesError( const QString& s ) const |
void Channel::appendMessagesError ( const QString& sText ) 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" + sText); |
790 |
} |
} |
791 |
|
|
792 |
void Channel::appendMessagesClient( const QString& s ) const |
void Channel::appendMessagesClient ( const QString& sText ) const |
793 |
{ |
{ |
794 |
MainForm *pMainForm = MainForm::getInstance(); |
MainForm *pMainForm = MainForm::getInstance(); |
795 |
if (pMainForm) |
if (pMainForm) |
796 |
pMainForm->appendMessagesClient(channelName() + ' ' + s); |
pMainForm->appendMessagesClient(channelName() + ' ' + sText); |
797 |
} |
} |
798 |
|
|
799 |
|
|
800 |
// Context menu event handler. |
// Context menu event handler. |
801 |
void Channel::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 Channel::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 Channel::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 Channel::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 |
} |
} |
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 |
|
|
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(); |
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 < QT_VERSION_CHECK(5, 0, 0) |
1080 |
QAbstractTableModel::reset(); |
QAbstractTableModel::reset(); |
1081 |
|
#else |
1082 |
|
QAbstractTableModel::beginResetModel(); |
1083 |
|
QAbstractTableModel::endResetModel(); |
1084 |
|
#endif |
1085 |
} |
} |
1086 |
|
|
1087 |
|
|
1110 |
pComboBox->addItems(item.options); |
pComboBox->addItems(item.options); |
1111 |
pComboBox->setCurrentIndex(item.selection); |
pComboBox->setCurrentIndex(item.selection); |
1112 |
pComboBox->setEnabled(true); |
pComboBox->setEnabled(true); |
1113 |
|
pComboBox->setEditable(true); |
1114 |
pComboBox->setGeometry(option.rect); |
pComboBox->setGeometry(option.rect); |
1115 |
return pComboBox; |
return pComboBox; |
1116 |
} |
} |