404 |
m_iDirtyCount++; |
m_iDirtyCount++; |
405 |
stabilizeForm(); |
stabilizeForm(); |
406 |
} // Otherwise, load an usual session file (LSCP script)... |
} // Otherwise, load an usual session file (LSCP script)... |
407 |
else if (closeSession(true)) |
else if (closeSession(true)) { |
408 |
loadSessionFile(sPath); |
loadSessionFile(sPath); |
409 |
|
break; |
410 |
|
} |
411 |
// Make it look responsive...:) |
// Make it look responsive...:) |
412 |
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
413 |
} |
} |
638 |
return false; |
return false; |
639 |
} |
} |
640 |
|
|
641 |
|
// Tell the world we'll take some time... |
642 |
|
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
643 |
|
|
644 |
// Read the file. |
// Read the file. |
645 |
|
int iLine = 0; |
646 |
int iErrors = 0; |
int iErrors = 0; |
647 |
QTextStream ts(&file); |
QTextStream ts(&file); |
648 |
while (!ts.atEnd()) { |
while (!ts.atEnd()) { |
649 |
// Read the line. |
// Read the line. |
650 |
QString sCommand = ts.readLine().stripWhiteSpace(); |
QString sCommand = ts.readLine().stripWhiteSpace(); |
651 |
|
iLine++; |
652 |
// If not empty, nor a comment, call the server... |
// If not empty, nor a comment, call the server... |
653 |
if (!sCommand.isEmpty() && sCommand[0] != '#') { |
if (!sCommand.isEmpty() && sCommand[0] != '#') { |
|
appendMessagesColor(sCommand, "#996633"); |
|
654 |
// Remember that, no matter what, |
// Remember that, no matter what, |
655 |
// all LSCP commands are CR/LF terminated. |
// all LSCP commands are CR/LF terminated. |
656 |
sCommand += "\r\n"; |
sCommand += "\r\n"; |
657 |
if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) { |
if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) { |
658 |
|
appendMessagesColor(QString("%1(%2): %3") |
659 |
|
.arg(QFileInfo(sFilename).fileName()).arg(iLine) |
660 |
|
.arg(sCommand.simplifyWhiteSpace()), "#996633"); |
661 |
appendMessagesClient("lscp_client_query"); |
appendMessagesClient("lscp_client_query"); |
662 |
iErrors++; |
iErrors++; |
663 |
} |
} |
672 |
// Now we'll try to create (update) the whole GUI session. |
// Now we'll try to create (update) the whole GUI session. |
673 |
updateSession(); |
updateSession(); |
674 |
|
|
675 |
|
// We're fornerly done. |
676 |
|
QApplication::restoreOverrideCursor(); |
677 |
|
|
678 |
// Have we any errors? |
// Have we any errors? |
679 |
if (iErrors > 0) |
if (iErrors > 0) |
680 |
appendMessagesError(tr("Session loaded with errors\nfrom \"%1\".\n\nSorry.").arg(sFilename)); |
appendMessagesError(tr("Session loaded with errors\nfrom \"%1\".\n\nSorry.").arg(sFilename)); |
698 |
// Save current session to specific file path. |
// Save current session to specific file path. |
699 |
bool qsamplerMainForm::saveSessionFile ( const QString& sFilename ) |
bool qsamplerMainForm::saveSessionFile ( const QString& sFilename ) |
700 |
{ |
{ |
701 |
|
if (m_pClient == NULL) |
702 |
|
return false; |
703 |
|
|
704 |
|
// Check whether server is apparently OK... |
705 |
|
if (::lscp_get_channels(m_pClient) < 0) { |
706 |
|
appendMessagesClient("lscp_get_channels"); |
707 |
|
return false; |
708 |
|
} |
709 |
|
|
710 |
// Open and write into real file. |
// Open and write into real file. |
711 |
QFile file(sFilename); |
QFile file(sFilename); |
712 |
if (!file.open(IO_WriteOnly | IO_Truncate)) { |
if (!file.open(IO_WriteOnly | IO_Truncate)) { |
714 |
return false; |
return false; |
715 |
} |
} |
716 |
|
|
717 |
|
// Tell the world we'll take some time... |
718 |
|
QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
719 |
|
|
720 |
// Write the file. |
// Write the file. |
721 |
int iErrors = 0; |
int iErrors = 0; |
722 |
QTextStream ts(&file); |
QTextStream ts(&file); |
733 |
<< " " << QTime::currentTime().toString("hh:mm:ss") << endl; |
<< " " << QTime::currentTime().toString("hh:mm:ss") << endl; |
734 |
ts << "#" << endl; |
ts << "#" << endl; |
735 |
ts << endl; |
ts << endl; |
736 |
|
|
737 |
// It is assumed that this new kind of device+session file |
// It is assumed that this new kind of device+session file |
738 |
// will be loaded from a complete |
// will be loaded from a complete initialized server... |
739 |
int *piDeviceIDs; |
int *piDeviceIDs; |
740 |
int iDevice; |
int iDevice; |
741 |
ts << "RESET" << endl; |
ts << "RESET" << endl; |
742 |
|
|
743 |
// Audio device mapping. |
// Audio device mapping. |
744 |
QMap<int, int> audioDeviceMap; |
QMap<int, int> audioDeviceMap; |
745 |
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio); |
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio); |
777 |
} |
} |
778 |
// Audio device index/id mapping. |
// Audio device index/id mapping. |
779 |
audioDeviceMap[device.deviceID()] = iDevice; |
audioDeviceMap[device.deviceID()] = iDevice; |
780 |
// Try to keep it snappy :) |
// Try to keep it snappy :) |
781 |
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
782 |
} |
} |
783 |
|
|
784 |
// MIDI device mapping. |
// MIDI device mapping. |
785 |
QMap<int, int> midiDeviceMap; |
QMap<int, int> midiDeviceMap; |
786 |
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi); |
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi); |
818 |
} |
} |
819 |
// MIDI device index/id mapping. |
// MIDI device index/id mapping. |
820 |
midiDeviceMap[device.deviceID()] = iDevice; |
midiDeviceMap[device.deviceID()] = iDevice; |
821 |
// Try to keep it snappy :) |
// Try to keep it snappy :) |
822 |
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
823 |
} |
} |
824 |
ts << endl; |
ts << endl; |
825 |
|
|
826 |
|
#ifdef CONFIG_MIDI_INSTRUMENT |
827 |
|
// MIDI instrument mapping... |
828 |
|
QMap<int, int> midiInstrumentMap; |
829 |
|
int *piMaps = ::lscp_list_midi_instrument_maps(m_pClient); |
830 |
|
for (int iMap = 0; piMaps && piMaps[iMap] >= 0; iMap++) { |
831 |
|
int iMidiMap = piMaps[iMap]; |
832 |
|
const char *pszMapName |
833 |
|
= ::lscp_get_midi_instrument_map_name(m_pClient, iMidiMap); |
834 |
|
ts << "# " << tr("MIDI instrument map") << " " << iMap; |
835 |
|
if (pszMapName) |
836 |
|
ts << " - " << pszMapName; |
837 |
|
ts << endl; |
838 |
|
ts << "ADD MIDI_INSTRUMENT_MAP"; |
839 |
|
if (pszMapName) |
840 |
|
ts << " '" << pszMapName << "'"; |
841 |
|
ts << endl; |
842 |
|
// MIDI instrument mapping... |
843 |
|
lscp_midi_instrument_t *pInstrs |
844 |
|
= ::lscp_list_midi_instruments(m_pClient, iMidiMap); |
845 |
|
for (int iInstr = 0; pInstrs && pInstrs[iInstr].map >= 0; iInstr++) { |
846 |
|
lscp_midi_instrument_info_t *pInstrInfo |
847 |
|
= ::lscp_get_midi_instrument_info(m_pClient, &pInstrs[iInstr]); |
848 |
|
if (pInstrInfo) { |
849 |
|
ts << "MAP MIDI_INSTRUMENT " |
850 |
|
<< iMap << " " |
851 |
|
<< pInstrs[iInstr].bank << " " |
852 |
|
<< pInstrs[iInstr].prog << " " |
853 |
|
<< pInstrInfo->engine_name << " '" |
854 |
|
<< pInstrInfo->instrument_file << "' " |
855 |
|
<< pInstrInfo->instrument_nr << " " |
856 |
|
<< pInstrInfo->volume << " "; |
857 |
|
switch (pInstrInfo->load_mode) { |
858 |
|
case LSCP_LOAD_PERSISTENT: |
859 |
|
ts << "PERSISTENT"; |
860 |
|
break; |
861 |
|
case LSCP_LOAD_ON_DEMAND_HOLD: |
862 |
|
ts << "ON_DEMAND_HOLD"; |
863 |
|
break; |
864 |
|
case LSCP_LOAD_ON_DEMAND: |
865 |
|
case LSCP_LOAD_DEFAULT: |
866 |
|
default: |
867 |
|
ts << "ON_DEMAND"; |
868 |
|
break; |
869 |
|
} |
870 |
|
if (pInstrInfo->name) |
871 |
|
ts << " '" << pInstrInfo->name << "'"; |
872 |
|
ts << endl; |
873 |
|
} // Check for errors... |
874 |
|
else if (::lscp_client_get_errno(m_pClient)) { |
875 |
|
appendMessagesClient("lscp_get_midi_instrument_info"); |
876 |
|
iErrors++; |
877 |
|
} |
878 |
|
// MIDI device index/id mapping. |
879 |
|
midiInstrumentMap[iMidiMap] = iMap; |
880 |
|
// Try to keep it snappy :) |
881 |
|
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
882 |
|
} |
883 |
|
// Check for errors... |
884 |
|
if (pInstrs) |
885 |
|
ts << endl; |
886 |
|
else if (::lscp_client_get_errno(m_pClient)) { |
887 |
|
appendMessagesClient("lscp_list_midi_instruments"); |
888 |
|
iErrors++; |
889 |
|
} |
890 |
|
} |
891 |
|
// Check for errors... |
892 |
|
if (piMaps == NULL && ::lscp_client_get_errno(m_pClient)) { |
893 |
|
appendMessagesClient("lscp_list_midi_instrument_maps"); |
894 |
|
iErrors++; |
895 |
|
} |
896 |
|
#endif // CONFIG_MIDI_INSTRUMENT |
897 |
|
|
898 |
// Sampler channel mapping. |
// Sampler channel mapping. |
899 |
QWidgetList wlist = m_pWorkspace->windowList(); |
QWidgetList wlist = m_pWorkspace->windowList(); |
900 |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
927 |
ts << pChannel->midiChannel(); |
ts << pChannel->midiChannel(); |
928 |
ts << endl; |
ts << endl; |
929 |
ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannel << endl; |
ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannel << endl; |
930 |
ts << "LOAD INSTRUMENT NON_MODAL '" << pChannel->instrumentFile() << "' " << pChannel->instrumentNr() << " " << iChannel << endl; |
if (pChannel->instrumentStatus() < 100) ts << "# "; |
931 |
|
ts << "LOAD INSTRUMENT NON_MODAL '" << pChannel->instrumentFile() << "' " |
932 |
|
<< pChannel->instrumentNr() << " " << iChannel << endl; |
933 |
qsamplerChannelRoutingMap::ConstIterator audioRoute; |
qsamplerChannelRoutingMap::ConstIterator audioRoute; |
934 |
for (audioRoute = pChannel->audioRouting().begin(); |
for (audioRoute = pChannel->audioRouting().begin(); |
935 |
audioRoute != pChannel->audioRouting().end(); |
audioRoute != pChannel->audioRouting().end(); |
938 |
<< " " << audioRoute.key() |
<< " " << audioRoute.key() |
939 |
<< " " << audioRoute.data() << endl; |
<< " " << audioRoute.data() << endl; |
940 |
} |
} |
941 |
ts << "SET CHANNEL VOLUME " << iChannel << " " << pChannel->volume() << endl; |
ts << "SET CHANNEL VOLUME " << iChannel |
942 |
|
<< " " << pChannel->volume() << endl; |
943 |
if (pChannel->channelMute()) |
if (pChannel->channelMute()) |
944 |
ts << "SET CHANNEL MUTE " << iChannel << " 1" << endl; |
ts << "SET CHANNEL MUTE " << iChannel << " 1" << endl; |
945 |
if (pChannel->channelSolo()) |
if (pChannel->channelSolo()) |
946 |
ts << "SET CHANNEL SOLO " << iChannel << " 1" << endl; |
ts << "SET CHANNEL SOLO " << iChannel << " 1" << endl; |
947 |
|
#ifdef CONFIG_MIDI_INSTRUMENT |
948 |
|
if (pChannel->midiMap() >= 0) { |
949 |
|
ts << "SET CHANNEL MIDI_INSTRUMENT_MAP " << iChannel |
950 |
|
<< " " << midiInstrumentMap[pChannel->midiMap()] << endl; |
951 |
|
} |
952 |
|
#endif |
953 |
ts << endl; |
ts << endl; |
954 |
} |
} |
955 |
} |
} |
957 |
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
958 |
} |
} |
959 |
|
|
|
#ifdef CONFIG_MIDI_INSTRUMENT |
|
|
// MIDI instrument mapping... |
|
|
lscp_midi_instrument_t *pInstrs = ::lscp_list_midi_instruments(m_pClient); |
|
|
if (pInstrs) |
|
|
ts << "# " << tr("MIDI instrument mapping") << endl; |
|
|
for (int iInstr = 0; pInstrs && pInstrs[iInstr].program >= 0; iInstr++) { |
|
|
lscp_midi_instrument_info_t *pInstrInfo |
|
|
= ::lscp_get_midi_instrument_info(m_pClient, &pInstrs[iInstr]); |
|
|
if (pInstrInfo) { |
|
|
ts << "MAP MIDI_INSTRUMENT " |
|
|
<< pInstrs[iInstr].bank_msb << " " |
|
|
<< pInstrs[iInstr].bank_lsb << " " |
|
|
<< pInstrs[iInstr].program << " " |
|
|
<< pInstrInfo->engine_name << " '" |
|
|
<< pInstrInfo->instrument_file << "' " |
|
|
<< pInstrInfo->instrument_nr << " " |
|
|
<< pInstrInfo->volume << " "; |
|
|
switch (pInstrInfo->load_mode) { |
|
|
case LSCP_LOAD_PERSISTENT: |
|
|
ts << "PERSISTENT"; |
|
|
break; |
|
|
case LSCP_LOAD_ON_DEMAND_HOLD: |
|
|
ts << "ON_DEMAND_HOLD"; |
|
|
break; |
|
|
case LSCP_LOAD_ON_DEMAND: |
|
|
case LSCP_LOAD_DEFAULT: |
|
|
default: |
|
|
ts << "ON_DEMAND"; |
|
|
break; |
|
|
} |
|
|
if (pInstrInfo->name) |
|
|
ts << " '" << pInstrInfo->name << "'"; |
|
|
ts << endl; |
|
|
} |
|
|
// Try to keep it snappy :) |
|
|
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
|
|
} |
|
|
if (pInstrs) |
|
|
ts << endl; |
|
|
#endif // CONFIG_MIDI_INSTRUMENT |
|
|
|
|
960 |
// Ok. we've wrote it. |
// Ok. we've wrote it. |
961 |
file.close(); |
file.close(); |
962 |
|
|
963 |
|
// We're fornerly done. |
964 |
|
QApplication::restoreOverrideCursor(); |
965 |
|
|
966 |
// Have we any errors? |
// Have we any errors? |
967 |
if (iErrors > 0) |
if (iErrors > 0) |
968 |
appendMessagesError(tr("Some settings could not be saved\nto \"%1\" session file.\n\nSorry.").arg(sFilename)); |
appendMessagesError(tr("Some settings could not be saved\nto \"%1\" session file.\n\nSorry.").arg(sFilename)); |
1055 |
return; |
return; |
1056 |
|
|
1057 |
// Just do the reset, after closing down current session... |
// Just do the reset, after closing down current session... |
1058 |
if (closeSession(true) && ::lscp_reset_sampler(m_pClient) != LSCP_OK) { |
if (closeSession(true)) { |
1059 |
appendMessagesClient("lscp_reset_sampler"); |
#ifdef CONFIG_MIDI_INSTRUMENT |
1060 |
appendMessagesError(tr("Could not reset sampler instance.\n\nSorry.")); |
// Reset all MIDI instrument mapping, if any. |
1061 |
return; |
int *piMaps = ::lscp_list_midi_instrument_maps(m_pClient); |
1062 |
|
for (int iMap = 0; piMaps && piMaps[iMap] >= 0; ++iMap) { |
1063 |
|
int iMidiMap = piMaps[iMap]; |
1064 |
|
if (::lscp_clear_midi_instruments(m_pClient, iMidiMap) != LSCP_OK) |
1065 |
|
appendMessagesClient("lscp_clear_midi_instruments"); |
1066 |
|
if (::lscp_remove_midi_instrument_map(m_pClient, iMidiMap) != LSCP_OK) |
1067 |
|
appendMessagesClient("lscp_remove_midi_instrument_map"); |
1068 |
|
} |
1069 |
|
// Check for errors... |
1070 |
|
if (piMaps == NULL && ::lscp_client_get_errno(m_pClient)) |
1071 |
|
appendMessagesClient("lscp_list_midi_instrument_maps"); |
1072 |
|
#endif // CONFIG_MIDI_INSTRUMENT |
1073 |
|
// actually do the sampler reset... |
1074 |
|
if (::lscp_reset_sampler(m_pClient) != LSCP_OK) { |
1075 |
|
appendMessagesClient("lscp_reset_sampler"); |
1076 |
|
appendMessagesError(tr("Could not reset sampler instance.\n\nSorry.")); |
1077 |
|
return; |
1078 |
|
} |
1079 |
} |
} |
1080 |
|
|
1081 |
// Log this. |
// Log this. |
1626 |
// Grab and restore current sampler channels session. |
// Grab and restore current sampler channels session. |
1627 |
void qsamplerMainForm::updateSession (void) |
void qsamplerMainForm::updateSession (void) |
1628 |
{ |
{ |
1629 |
|
#ifdef CONFIG_MIDI_INSTRUMENT |
1630 |
|
// FIXME Make some room for default instrument maps... |
1631 |
|
int iMaps = ::lscp_get_midi_instrument_maps(m_pClient); |
1632 |
|
if (iMaps < 0) |
1633 |
|
appendMessagesClient("lscp_get_midi_instrument_maps"); |
1634 |
|
else if (iMaps < 1) { |
1635 |
|
::lscp_add_midi_instrument_map(m_pClient, tr("Chromatic").latin1()); |
1636 |
|
::lscp_add_midi_instrument_map(m_pClient, tr("Drum Kits").latin1()); |
1637 |
|
} |
1638 |
|
#endif |
1639 |
|
|
1640 |
// Retrieve the current channel list. |
// Retrieve the current channel list. |
1641 |
int *piChannelIDs = ::lscp_list_channels(m_pClient); |
int *piChannelIDs = ::lscp_list_channels(m_pClient); |
1642 |
if (piChannelIDs == NULL) { |
if (piChannelIDs == NULL) { |
1644 |
appendMessagesClient("lscp_list_channels"); |
appendMessagesClient("lscp_list_channels"); |
1645 |
appendMessagesError(tr("Could not get current list of channels.\n\nSorry.")); |
appendMessagesError(tr("Could not get current list of channels.\n\nSorry.")); |
1646 |
} |
} |
1647 |
return; |
} else { |
1648 |
|
// Try to (re)create each channel. |
1649 |
|
m_pWorkspace->setUpdatesEnabled(false); |
1650 |
|
for (int iChannel = 0; piChannelIDs[iChannel] >= 0; iChannel++) { |
1651 |
|
// Check if theres already a channel strip for this one... |
1652 |
|
if (!channelStrip(piChannelIDs[iChannel])) |
1653 |
|
createChannelStrip(new qsamplerChannel(piChannelIDs[iChannel])); |
1654 |
|
} |
1655 |
|
m_pWorkspace->setUpdatesEnabled(true); |
1656 |
} |
} |
1657 |
|
|
1658 |
// Try to (re)create each channel. |
// Do we auto-arrange? |
1659 |
m_pWorkspace->setUpdatesEnabled(false); |
if (m_pOptions && m_pOptions->bAutoArrange) |
1660 |
for (int iChannel = 0; piChannelIDs[iChannel] >= 0; iChannel++) { |
channelsArrange(); |
1661 |
// Check if theres already a channel strip for this one... |
|
|
if (!channelStrip(piChannelIDs[iChannel])) |
|
|
createChannelStrip(new qsamplerChannel(piChannelIDs[iChannel])); |
|
|
// Make it visibly responsive... |
|
|
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
|
|
} |
|
|
m_pWorkspace->setUpdatesEnabled(true); |
|
|
|
|
1662 |
// Remember to refresh devices and instruments... |
// Remember to refresh devices and instruments... |
1663 |
if (m_pInstrumentListForm) |
if (m_pInstrumentListForm) |
1664 |
m_pInstrumentListForm->refreshInstruments(); |
m_pInstrumentListForm->refreshInstruments(); |
1834 |
|
|
1835 |
appendMessagesColor(s.simplifyWhiteSpace(), "#ff0000"); |
appendMessagesColor(s.simplifyWhiteSpace(), "#ff0000"); |
1836 |
|
|
1837 |
|
// Make it look responsive...:) |
1838 |
|
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
1839 |
|
|
1840 |
QMessageBox::critical(this, |
QMessageBox::critical(this, |
1841 |
QSAMPLER_TITLE ": " + tr("Error"), s, tr("Cancel")); |
QSAMPLER_TITLE ": " + tr("Error"), s, tr("Cancel")); |
1842 |
} |
} |
1851 |
appendMessagesColor(s + QString(": %1 (errno=%2)") |
appendMessagesColor(s + QString(": %1 (errno=%2)") |
1852 |
.arg(::lscp_client_get_result(m_pClient)) |
.arg(::lscp_client_get_result(m_pClient)) |
1853 |
.arg(::lscp_client_get_errno(m_pClient)), "#996666"); |
.arg(::lscp_client_get_errno(m_pClient)), "#996666"); |
1854 |
|
|
1855 |
|
// Make it look responsive...:) |
1856 |
|
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
1857 |
} |
} |
1858 |
|
|
1859 |
|
|