36 |
|
|
37 |
#include "qsamplerAbout.h" |
#include "qsamplerAbout.h" |
38 |
#include "qsamplerOptions.h" |
#include "qsamplerOptions.h" |
39 |
|
#include "qsamplerChannel.h" |
40 |
#include "qsamplerMessages.h" |
#include "qsamplerMessages.h" |
41 |
|
|
42 |
#include "qsamplerChannelStrip.h" |
#include "qsamplerChannelStrip.h" |
44 |
|
|
45 |
#include "config.h" |
#include "config.h" |
46 |
|
|
|
#if !defined(WIN32) |
|
|
#include <unistd.h> |
|
|
#endif |
|
47 |
|
|
48 |
// Timer constant stuff. |
// Timer constant stuff. |
49 |
#define QSAMPLER_TIMER_MSECS 200 |
#define QSAMPLER_TIMER_MSECS 200 |
55 |
#define QSAMPLER_STATUS_SESSION 3 // Current session modification state. |
#define QSAMPLER_STATUS_SESSION 3 // Current session modification state. |
56 |
|
|
57 |
|
|
58 |
|
// All winsock apps needs this. |
59 |
#if defined(WIN32) |
#if defined(WIN32) |
60 |
static WSADATA _wsaData; |
static WSADATA _wsaData; |
61 |
#endif |
#endif |
62 |
|
|
63 |
|
|
64 |
|
//------------------------------------------------------------------------- |
65 |
|
// qsamplerCustomEvent -- specialty for callback comunication. |
66 |
|
|
67 |
|
#define QSAMPLER_CUSTOM_EVENT 1000 |
68 |
|
|
69 |
|
class qsamplerCustomEvent : public QCustomEvent |
70 |
|
{ |
71 |
|
public: |
72 |
|
|
73 |
|
// Constructor. |
74 |
|
qsamplerCustomEvent(lscp_event_t event, const char *pchData, int cchData) |
75 |
|
: QCustomEvent(QSAMPLER_CUSTOM_EVENT) |
76 |
|
{ |
77 |
|
m_event = event; |
78 |
|
m_data.setLatin1(pchData, cchData); |
79 |
|
} |
80 |
|
|
81 |
|
// Accessors. |
82 |
|
lscp_event_t event() { return m_event; } |
83 |
|
QString& data() { return m_data; } |
84 |
|
|
85 |
|
private: |
86 |
|
|
87 |
|
// The proper event type. |
88 |
|
lscp_event_t m_event; |
89 |
|
// The event data as a string. |
90 |
|
QString m_data; |
91 |
|
}; |
92 |
|
|
93 |
|
|
94 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
95 |
// qsamplerMainForm -- Main window form implementation. |
// qsamplerMainForm -- Main window form implementation. |
96 |
|
|
104 |
m_pMessages = NULL; |
m_pMessages = NULL; |
105 |
|
|
106 |
// We'll start clean. |
// We'll start clean. |
107 |
m_iUntitled = 0; |
m_iUntitled = 0; |
108 |
m_iDirtyCount = 0; |
m_iDirtyCount = 0; |
109 |
|
m_iChangeCount = 0; |
110 |
|
|
111 |
m_pServer = NULL; |
m_pServer = NULL; |
112 |
m_pClient = NULL; |
m_pClient = NULL; |
286 |
} |
} |
287 |
|
|
288 |
|
|
289 |
|
// Window drag-n-drop event handlers. |
290 |
void qsamplerMainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent ) |
void qsamplerMainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent ) |
291 |
{ |
{ |
292 |
bool bAccept = false; |
bool bAccept = false; |
311 |
} |
} |
312 |
|
|
313 |
|
|
314 |
|
// Custome event handler. |
315 |
|
void qsamplerMainForm::customEvent ( QCustomEvent *pCustomEvent ) |
316 |
|
{ |
317 |
|
// For the time being, just pump it to messages. |
318 |
|
if (pCustomEvent->type() == QSAMPLER_CUSTOM_EVENT) { |
319 |
|
qsamplerCustomEvent *pEvent = (qsamplerCustomEvent *) pCustomEvent; |
320 |
|
appendMessagesColor(tr("Notify event: %1 data: %2") |
321 |
|
.arg(::lscp_event_to_text(pEvent->event())) |
322 |
|
.arg(pEvent->data()), "#996699"); |
323 |
|
} |
324 |
|
} |
325 |
|
|
326 |
|
|
327 |
|
// Context menu event handler. |
328 |
|
void qsamplerMainForm::contextMenuEvent( QContextMenuEvent *pEvent ) |
329 |
|
{ |
330 |
|
stabilizeForm(); |
331 |
|
|
332 |
|
editMenu->exec(pEvent->globalPos()); |
333 |
|
} |
334 |
|
|
335 |
|
|
336 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
337 |
// qsamplerMainForm -- Brainless public property accessors. |
// qsamplerMainForm -- Brainless public property accessors. |
338 |
|
|
485 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
486 |
QWidgetList wlist = m_pWorkspace->windowList(); |
QWidgetList wlist = m_pWorkspace->windowList(); |
487 |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
488 |
qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel); |
qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
489 |
if (bForce && ::lscp_remove_channel(m_pClient, pChannel->channelID()) != LSCP_OK) |
if (pChannelStrip) { |
490 |
appendMessagesClient("lscp_remove_channel"); |
qsamplerChannel *pChannel = pChannelStrip->channel(); |
491 |
delete pChannel; |
if (bForce && pChannel) |
492 |
|
pChannel->removeChannel(); |
493 |
|
delete pChannelStrip; |
494 |
|
} |
495 |
} |
} |
496 |
m_pWorkspace->setUpdatesEnabled(true); |
m_pWorkspace->setUpdatesEnabled(true); |
497 |
// We're now clean, for sure. |
// We're now clean, for sure. |
553 |
// Try to (re)create each channel. |
// Try to (re)create each channel. |
554 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
555 |
for (int iChannelID = 0; iChannelID < iChannels; iChannelID++) { |
for (int iChannelID = 0; iChannelID < iChannels; iChannelID++) { |
556 |
createChannel(iChannelID, false); |
createChannelStrip(iChannelID); |
557 |
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
558 |
} |
} |
559 |
m_pWorkspace->setUpdatesEnabled(true); |
m_pWorkspace->setUpdatesEnabled(true); |
567 |
m_sFilename = sFilename; |
m_sFilename = sFilename; |
568 |
updateRecentFiles(sFilename); |
updateRecentFiles(sFilename); |
569 |
appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename))); |
appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename))); |
570 |
|
|
571 |
|
// Make that an overall update. |
572 |
|
m_iChangeCount++; |
573 |
stabilizeForm(); |
stabilizeForm(); |
574 |
return true; |
return true; |
575 |
} |
} |
603 |
ts << endl; |
ts << endl; |
604 |
QWidgetList wlist = m_pWorkspace->windowList(); |
QWidgetList wlist = m_pWorkspace->windowList(); |
605 |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
606 |
qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel); |
qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
607 |
int iChannelID = pChannel->channelID(); |
if (pChannelStrip) { |
608 |
ts << "# " << pChannel->caption() << endl; |
qsamplerChannel *pChannel = pChannelStrip->channel(); |
609 |
ts << "ADD CHANNEL" << endl; |
if (pChannel) { |
610 |
ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannelID << endl; |
int iChannelID = pChannel->channelID(); |
611 |
ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannelID << " " << pChannel->midiDriver() << endl; |
ts << "# " << pChannelStrip->caption() << endl; |
612 |
ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannelID << " " << pChannel->midiPort() << endl; |
ts << "ADD CHANNEL" << endl; |
613 |
ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannelID << " " << pChannel->midiChannel() << endl; |
ts << "SET CHANNEL AUDIO_OUTPUT_TYPE " << iChannelID << " " << pChannel->audioDriver() << endl; |
614 |
ts << "SET CHANNEL AUDIO_OUTPUT_TYPE " << iChannelID << " " << pChannel->audioDriver() << endl; |
ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannelID << " " << pChannel->midiDriver() << endl; |
615 |
ts << "SET CHANNEL VOLUME " << iChannelID << " " << pChannel->volume() << endl; |
ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannelID << " " << pChannel->midiPort() << endl; |
616 |
ts << "LOAD INSTRUMENT " << pChannel->instrumentFile() << " " << pChannel->instrumentNr() << " " << iChannelID << endl; |
ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannelID << " "; |
617 |
ts << endl; |
if (pChannel->midiChannel() > 0) |
618 |
|
ts << pChannel->midiChannel(); |
619 |
|
else |
620 |
|
ts << "ALL"; |
621 |
|
ts << endl; |
622 |
|
ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannelID << endl; |
623 |
|
ts << "LOAD INSTRUMENT NON_MODAL '" << pChannel->instrumentFile() << "' " << pChannel->instrumentNr() << " " << iChannelID << endl; |
624 |
|
ts << "SET CHANNEL VOLUME " << iChannelID << " " << pChannel->volume() << endl; |
625 |
|
ts << endl; |
626 |
|
} |
627 |
|
} |
628 |
// Try to keep it snappy :) |
// Try to keep it snappy :) |
629 |
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
630 |
} |
} |
696 |
} |
} |
697 |
|
|
698 |
|
|
699 |
|
// Reset the sampler instance. |
700 |
|
void qsamplerMainForm::fileReset (void) |
701 |
|
{ |
702 |
|
if (m_pClient == NULL) |
703 |
|
return; |
704 |
|
|
705 |
|
// Ask user whether he/she want's an internal sampler reset... |
706 |
|
if (QMessageBox::warning(this, tr("Warning"), |
707 |
|
tr("Resetting the sampler instance will close\n" |
708 |
|
"all device and channel configurations.\n\n" |
709 |
|
"Please note that this operation may cause\n" |
710 |
|
"temporary MIDI and Audio disruption\n\n" |
711 |
|
"Do you want to reset the sampler engine now?"), |
712 |
|
tr("Reset"), tr("Cancel")) > 0) |
713 |
|
return; |
714 |
|
|
715 |
|
// Just do the reset, after closing down current session... |
716 |
|
if (closeSession(true) && ::lscp_reset_sampler(m_pClient) != LSCP_OK) { |
717 |
|
appendMessagesClient("lscp_reset_sampler"); |
718 |
|
appendMessagesError(tr("Could not reset sampler instance.\n\nSorry.")); |
719 |
|
return; |
720 |
|
} |
721 |
|
|
722 |
|
// Log this. |
723 |
|
appendMessages(tr("Sampler reset.")); |
724 |
|
} |
725 |
|
|
726 |
|
|
727 |
// Restart the client/server instance. |
// Restart the client/server instance. |
728 |
void qsamplerMainForm::fileRestart (void) |
void qsamplerMainForm::fileRestart (void) |
729 |
{ |
{ |
771 |
if (m_pClient == NULL) |
if (m_pClient == NULL) |
772 |
return; |
return; |
773 |
|
|
774 |
// Create the new sampler channel. |
// Just create the channel strip, |
775 |
int iChannelID = ::lscp_add_channel(m_pClient); |
// by giving an invalid channel id. |
776 |
if (iChannelID < 0) { |
createChannelStrip(-1); |
|
appendMessagesClient("lscp_add_channel"); |
|
|
appendMessagesError(tr("Could not create the new channel.\n\nSorry.")); |
|
|
return; |
|
|
} |
|
|
|
|
|
// Log this happening. |
|
|
appendMessages(tr("Channel %1 created.").arg(iChannelID)); |
|
|
|
|
|
// Just create the channel strip with given id. |
|
|
createChannel(iChannelID, true); |
|
|
|
|
|
// We'll be dirty, for sure... |
|
|
m_iDirtyCount++; |
|
|
// Stabilize form anyway. |
|
|
stabilizeForm(); |
|
777 |
} |
} |
778 |
|
|
779 |
|
|
783 |
if (m_pClient == NULL) |
if (m_pClient == NULL) |
784 |
return; |
return; |
785 |
|
|
786 |
qsamplerChannelStrip *pChannel = activeChannel(); |
qsamplerChannelStrip *pChannelStrip = activeChannelStrip(); |
787 |
|
if (pChannelStrip == NULL) |
788 |
|
return; |
789 |
|
|
790 |
|
qsamplerChannel *pChannel = pChannelStrip->channel(); |
791 |
if (pChannel == NULL) |
if (pChannel == NULL) |
792 |
return; |
return; |
793 |
|
|
797 |
tr("About to remove channel:\n\n" |
tr("About to remove channel:\n\n" |
798 |
"%1\n\n" |
"%1\n\n" |
799 |
"Are you sure?") |
"Are you sure?") |
800 |
.arg(pChannel->caption()), |
.arg(pChannelStrip->caption()), |
801 |
tr("OK"), tr("Cancel")) > 0) |
tr("OK"), tr("Cancel")) > 0) |
802 |
return; |
return; |
803 |
} |
} |
804 |
|
|
805 |
// Remove the existing sampler channel. |
// Remove the existing sampler channel. |
806 |
if (::lscp_remove_channel(m_pClient, pChannel->channelID()) != LSCP_OK) { |
if (!pChannel->removeChannel()) |
|
appendMessagesClient("lscp_remove_channel"); |
|
|
appendMessagesError(tr("Could not remove channel.\n\nSorry.")); |
|
807 |
return; |
return; |
|
} |
|
808 |
|
|
|
// Log this happening. |
|
|
appendMessages(tr("Channel %1 removed.").arg(pChannel->channelID())); |
|
|
|
|
809 |
// Just delete the channel strip. |
// Just delete the channel strip. |
810 |
delete pChannel; |
delete pChannelStrip; |
811 |
|
|
812 |
// Do we auto-arrange? |
// Do we auto-arrange? |
813 |
if (m_pOptions && m_pOptions->bAutoArrange) |
if (m_pOptions && m_pOptions->bAutoArrange) |
814 |
channelsArrange(); |
channelsArrange(); |
825 |
if (m_pClient == NULL) |
if (m_pClient == NULL) |
826 |
return; |
return; |
827 |
|
|
828 |
qsamplerChannelStrip *pChannel = activeChannel(); |
qsamplerChannelStrip *pChannelStrip = activeChannelStrip(); |
829 |
if (pChannel == NULL) |
if (pChannelStrip == NULL) |
830 |
return; |
return; |
831 |
|
|
832 |
// Just invoque the channel strip procedure. |
// Just invoque the channel strip procedure. |
833 |
pChannel->channelSetup(); |
pChannelStrip->channelSetup(); |
834 |
} |
} |
835 |
|
|
836 |
|
|
840 |
if (m_pClient == NULL) |
if (m_pClient == NULL) |
841 |
return; |
return; |
842 |
|
|
843 |
qsamplerChannelStrip *pChannel = activeChannel(); |
qsamplerChannelStrip *pChannelStrip = activeChannelStrip(); |
844 |
if (pChannel == NULL) |
if (pChannelStrip == NULL) |
845 |
return; |
return; |
846 |
|
|
847 |
// Remove the existing sampler channel. |
qsamplerChannel *pChannel = pChannelStrip->channel(); |
848 |
if (::lscp_reset_channel(m_pClient, pChannel->channelID()) != LSCP_OK) { |
if (pChannel == NULL) |
|
appendMessagesClient("lscp_reset_channel"); |
|
|
appendMessagesError(tr("Could not reset channel.\n\nSorry.")); |
|
849 |
return; |
return; |
|
} |
|
850 |
|
|
851 |
// Log this. |
// Reset the existing sampler channel. |
852 |
appendMessages(tr("Channel %1 reset.").arg(pChannel->channelID())); |
pChannel->resetChannel(); |
853 |
|
|
854 |
// Refresh channel strip info. |
// And force a deferred update. |
855 |
pChannel->updateChannelInfo(); |
m_iChangeCount++; |
856 |
} |
} |
857 |
|
|
858 |
|
|
913 |
qsamplerOptionsForm *pOptionsForm = new qsamplerOptionsForm(this); |
qsamplerOptionsForm *pOptionsForm = new qsamplerOptionsForm(this); |
914 |
if (pOptionsForm) { |
if (pOptionsForm) { |
915 |
// Check out some initial nullities(tm)... |
// Check out some initial nullities(tm)... |
916 |
qsamplerChannelStrip *pChannel = activeChannel(); |
qsamplerChannelStrip *pChannelStrip = activeChannelStrip(); |
917 |
if (m_pOptions->sDisplayFont.isEmpty() && pChannel) |
if (m_pOptions->sDisplayFont.isEmpty() && pChannelStrip) |
918 |
m_pOptions->sDisplayFont = pChannel->displayFont().toString(); |
m_pOptions->sDisplayFont = pChannelStrip->displayFont().toString(); |
919 |
if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages) |
if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages) |
920 |
m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString(); |
m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString(); |
921 |
// To track down deferred or immediate changes. |
// To track down deferred or immediate changes. |
925 |
bool bOldServerStart = m_pOptions->bServerStart; |
bool bOldServerStart = m_pOptions->bServerStart; |
926 |
QString sOldServerCmdLine = m_pOptions->sServerCmdLine; |
QString sOldServerCmdLine = m_pOptions->sServerCmdLine; |
927 |
QString sOldDisplayFont = m_pOptions->sDisplayFont; |
QString sOldDisplayFont = m_pOptions->sDisplayFont; |
928 |
|
bool bOldDisplayEffect = m_pOptions->bDisplayEffect; |
929 |
|
int iOldMaxVolume = m_pOptions->iMaxVolume; |
930 |
QString sOldMessagesFont = m_pOptions->sMessagesFont; |
QString sOldMessagesFont = m_pOptions->sMessagesFont; |
931 |
bool bOldStdoutCapture = m_pOptions->bStdoutCapture; |
bool bOldStdoutCapture = m_pOptions->bStdoutCapture; |
932 |
int bOldMessagesLimit = m_pOptions->bMessagesLimit; |
int bOldMessagesLimit = m_pOptions->bMessagesLimit; |
950 |
(!bOldCompletePath && m_pOptions->bCompletePath) || |
(!bOldCompletePath && m_pOptions->bCompletePath) || |
951 |
(iOldMaxRecentFiles != m_pOptions->iMaxRecentFiles)) |
(iOldMaxRecentFiles != m_pOptions->iMaxRecentFiles)) |
952 |
updateRecentFilesMenu(); |
updateRecentFilesMenu(); |
953 |
|
if (( bOldDisplayEffect && !m_pOptions->bDisplayEffect) || |
954 |
|
(!bOldDisplayEffect && m_pOptions->bDisplayEffect)) |
955 |
|
updateDisplayEffect(); |
956 |
if (sOldDisplayFont != m_pOptions->sDisplayFont) |
if (sOldDisplayFont != m_pOptions->sDisplayFont) |
957 |
updateDisplayFont(); |
updateDisplayFont(); |
958 |
|
if (iOldMaxVolume != m_pOptions->iMaxVolume) |
959 |
|
updateMaxVolume(); |
960 |
if (sOldMessagesFont != m_pOptions->sMessagesFont) |
if (sOldMessagesFont != m_pOptions->sMessagesFont) |
961 |
updateMessagesFont(); |
updateMessagesFont(); |
962 |
if (( bOldMessagesLimit && !m_pOptions->bMessagesLimit) || |
if (( bOldMessagesLimit && !m_pOptions->bMessagesLimit) || |
995 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
996 |
int y = 0; |
int y = 0; |
997 |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
998 |
qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel); |
qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
999 |
/* if (pChannel->testWState(WState_Maximized | WState_Minimized)) { |
/* if (pChannelStrip->testWState(WState_Maximized | WState_Minimized)) { |
1000 |
// Prevent flicker... |
// Prevent flicker... |
1001 |
pChannel->hide(); |
pChannelStrip->hide(); |
1002 |
pChannel->showNormal(); |
pChannelStrip->showNormal(); |
1003 |
} */ |
} */ |
1004 |
pChannel->adjustSize(); |
pChannelStrip->adjustSize(); |
1005 |
int iWidth = m_pWorkspace->width(); |
int iWidth = m_pWorkspace->width(); |
1006 |
if (iWidth < pChannel->width()) |
if (iWidth < pChannelStrip->width()) |
1007 |
iWidth = pChannel->width(); |
iWidth = pChannelStrip->width(); |
1008 |
// int iHeight = pChannel->height() + pChannel->parentWidget()->baseSize().height(); |
// int iHeight = pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height(); |
1009 |
int iHeight = pChannel->parentWidget()->frameGeometry().height(); |
int iHeight = pChannelStrip->parentWidget()->frameGeometry().height(); |
1010 |
pChannel->parentWidget()->setGeometry(0, y, iWidth, iHeight); |
pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight); |
1011 |
y += iHeight; |
y += iHeight; |
1012 |
} |
} |
1013 |
m_pWorkspace->setUpdatesEnabled(true); |
m_pWorkspace->setUpdatesEnabled(true); |
1055 |
sText += tr("Debugging option enabled."); |
sText += tr("Debugging option enabled."); |
1056 |
sText += "</font></small><br />"; |
sText += "</font></small><br />"; |
1057 |
#endif |
#endif |
1058 |
|
#ifndef CONFIG_LIBGIG |
1059 |
|
sText += "<small><font color=\"red\">"; |
1060 |
|
sText += tr("GIG (libgig) file support disabled."); |
1061 |
|
sText += "</font></small><br />"; |
1062 |
|
#endif |
1063 |
sText += "<br />\n"; |
sText += "<br />\n"; |
1064 |
sText += tr("Using") + ": "; |
sText += tr("Using") + ": "; |
1065 |
sText += ::lscp_client_package(); |
sText += ::lscp_client_package(); |
1093 |
setCaption(tr(QSAMPLER_TITLE " - [%1]").arg(sSessioName)); |
setCaption(tr(QSAMPLER_TITLE " - [%1]").arg(sSessioName)); |
1094 |
|
|
1095 |
// Update the main menu state... |
// Update the main menu state... |
1096 |
qsamplerChannelStrip *pChannel = activeChannel(); |
qsamplerChannelStrip *pChannelStrip = activeChannelStrip(); |
1097 |
bool bHasClient = (m_pOptions != NULL && m_pClient != NULL); |
bool bHasClient = (m_pOptions != NULL && m_pClient != NULL); |
1098 |
bool bHasChannel = (bHasClient && pChannel != NULL); |
bool bHasChannel = (bHasClient && pChannelStrip != NULL); |
1099 |
fileNewAction->setEnabled(bHasClient); |
fileNewAction->setEnabled(bHasClient); |
1100 |
fileOpenAction->setEnabled(bHasClient); |
fileOpenAction->setEnabled(bHasClient); |
1101 |
fileSaveAction->setEnabled(bHasClient && m_iDirtyCount > 0); |
fileSaveAction->setEnabled(bHasClient && m_iDirtyCount > 0); |
1102 |
fileSaveAsAction->setEnabled(bHasClient); |
fileSaveAsAction->setEnabled(bHasClient); |
1103 |
|
fileResetAction->setEnabled(bHasClient); |
1104 |
fileRestartAction->setEnabled(bHasClient || m_pServer == NULL); |
fileRestartAction->setEnabled(bHasClient || m_pServer == NULL); |
1105 |
editAddChannelAction->setEnabled(bHasClient); |
editAddChannelAction->setEnabled(bHasClient); |
1106 |
editRemoveChannelAction->setEnabled(bHasChannel); |
editRemoveChannelAction->setEnabled(bHasChannel); |
1119 |
} |
} |
1120 |
// Channel status... |
// Channel status... |
1121 |
if (bHasChannel) |
if (bHasChannel) |
1122 |
m_status[QSAMPLER_STATUS_CHANNEL]->setText(pChannel->caption()); |
m_status[QSAMPLER_STATUS_CHANNEL]->setText(pChannelStrip->caption()); |
1123 |
else |
else |
1124 |
m_status[QSAMPLER_STATUS_CHANNEL]->clear(); |
m_status[QSAMPLER_STATUS_CHANNEL]->clear(); |
1125 |
// Session status... |
// Session status... |
1138 |
|
|
1139 |
|
|
1140 |
// Channel change receiver slot. |
// Channel change receiver slot. |
1141 |
void qsamplerMainForm::channelChanged( qsamplerChannelStrip * ) |
void qsamplerMainForm::channelStripChanged( qsamplerChannelStrip * ) |
1142 |
{ |
{ |
1143 |
|
// Flag that we're update those channel strips. |
1144 |
|
m_iChangeCount++; |
1145 |
// Just mark the dirty form. |
// Just mark the dirty form. |
1146 |
m_iDirtyCount++; |
m_iDirtyCount++; |
1147 |
// and update the form status... |
// and update the form status... |
1214 |
|
|
1215 |
m_pWorkspace->setUpdatesEnabled(false); |
m_pWorkspace->setUpdatesEnabled(false); |
1216 |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
1217 |
qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel); |
qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
1218 |
pChannel->setDisplayFont(font); |
if (pChannelStrip) |
1219 |
|
pChannelStrip->setDisplayFont(font); |
1220 |
|
} |
1221 |
|
m_pWorkspace->setUpdatesEnabled(true); |
1222 |
|
} |
1223 |
|
|
1224 |
|
|
1225 |
|
// Update channel strips background effect. |
1226 |
|
void qsamplerMainForm::updateDisplayEffect (void) |
1227 |
|
{ |
1228 |
|
QPixmap pm; |
1229 |
|
if (m_pOptions->bDisplayEffect) |
1230 |
|
pm = QPixmap::fromMimeSource("displaybg1.png"); |
1231 |
|
|
1232 |
|
// Full channel list update... |
1233 |
|
QWidgetList wlist = m_pWorkspace->windowList(); |
1234 |
|
if (wlist.isEmpty()) |
1235 |
|
return; |
1236 |
|
|
1237 |
|
m_pWorkspace->setUpdatesEnabled(false); |
1238 |
|
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
1239 |
|
qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
1240 |
|
if (pChannelStrip) |
1241 |
|
pChannelStrip->setDisplayBackground(pm); |
1242 |
|
} |
1243 |
|
m_pWorkspace->setUpdatesEnabled(true); |
1244 |
|
} |
1245 |
|
|
1246 |
|
|
1247 |
|
// Force update of the channels maximum volume setting. |
1248 |
|
void qsamplerMainForm::updateMaxVolume (void) |
1249 |
|
{ |
1250 |
|
if (m_pOptions == NULL) |
1251 |
|
return; |
1252 |
|
|
1253 |
|
// Full channel list update... |
1254 |
|
QWidgetList wlist = m_pWorkspace->windowList(); |
1255 |
|
if (wlist.isEmpty()) |
1256 |
|
return; |
1257 |
|
|
1258 |
|
m_pWorkspace->setUpdatesEnabled(false); |
1259 |
|
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
1260 |
|
qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
1261 |
|
if (pChannelStrip) |
1262 |
|
pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume); |
1263 |
} |
} |
1264 |
m_pWorkspace->setUpdatesEnabled(true); |
m_pWorkspace->setUpdatesEnabled(true); |
1265 |
} |
} |
1358 |
// qsamplerMainForm -- MDI channel strip management. |
// qsamplerMainForm -- MDI channel strip management. |
1359 |
|
|
1360 |
// The channel strip creation executive. |
// The channel strip creation executive. |
1361 |
void qsamplerMainForm::createChannel ( int iChannelID, bool bPrompt ) |
qsamplerChannelStrip *qsamplerMainForm::createChannelStrip ( int iChannelID ) |
1362 |
{ |
{ |
1363 |
if (m_pClient == NULL) |
if (m_pClient == NULL) |
1364 |
return; |
return NULL; |
1365 |
|
|
1366 |
// Prepare for auto-arrange? |
// Prepare for auto-arrange? |
1367 |
qsamplerChannelStrip *pChannel = NULL; |
qsamplerChannelStrip *pChannelStrip = NULL; |
1368 |
int y = 0; |
int y = 0; |
1369 |
if (m_pOptions && m_pOptions->bAutoArrange) { |
if (m_pOptions && m_pOptions->bAutoArrange) { |
1370 |
QWidgetList wlist = m_pWorkspace->windowList(); |
QWidgetList wlist = m_pWorkspace->windowList(); |
1371 |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
1372 |
pChannel = (qsamplerChannelStrip *) wlist.at(iChannel); |
pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
1373 |
// y += pChannel->height() + pChannel->parentWidget()->baseSize().height(); |
// y += pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height(); |
1374 |
y += pChannel->parentWidget()->frameGeometry().height(); |
y += pChannelStrip->parentWidget()->frameGeometry().height(); |
1375 |
} |
} |
1376 |
} |
} |
1377 |
|
|
1378 |
// Add a new channel itema... |
// Add a new channel itema... |
1379 |
WFlags wflags = Qt::WStyle_Customize | Qt::WStyle_Tool | Qt::WStyle_Title | Qt::WStyle_NoBorder; |
WFlags wflags = Qt::WStyle_Customize | Qt::WStyle_Tool | Qt::WStyle_Title | Qt::WStyle_NoBorder; |
1380 |
pChannel = new qsamplerChannelStrip(m_pWorkspace, 0, wflags); |
pChannelStrip = new qsamplerChannelStrip(m_pWorkspace, 0, wflags); |
1381 |
pChannel->setup(this, iChannelID); |
// Actual channel setup. |
1382 |
// We'll need a display font. |
pChannelStrip->setup(this, iChannelID); |
1383 |
QFont font; |
QObject::connect(pChannelStrip, SIGNAL(channelChanged(qsamplerChannelStrip *)), this, SLOT(channelStripChanged(qsamplerChannelStrip *))); |
|
if (m_pOptions && font.fromString(m_pOptions->sDisplayFont)) |
|
|
pChannel->setDisplayFont(font); |
|
|
// Track channel setup changes. |
|
|
QObject::connect(pChannel, SIGNAL(channelChanged(qsamplerChannelStrip *)), this, SLOT(channelChanged(qsamplerChannelStrip *))); |
|
1384 |
// Before we show it up, may be we'll |
// Before we show it up, may be we'll |
1385 |
// better ask for some initial values? |
// better ask for some initial values? |
1386 |
if (bPrompt) |
if (iChannelID < 0 && !pChannelStrip->channelSetup()) { |
1387 |
pChannel->channelSetup(); |
// No luck, bail out... |
1388 |
|
delete pChannelStrip; |
1389 |
|
return NULL; |
1390 |
|
} |
1391 |
|
|
1392 |
|
// Set some initial aesthetic options... |
1393 |
|
if (m_pOptions) { |
1394 |
|
// Background display effect... |
1395 |
|
pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect); |
1396 |
|
// We'll need a display font. |
1397 |
|
QFont font; |
1398 |
|
if (font.fromString(m_pOptions->sDisplayFont)) |
1399 |
|
pChannelStrip->setDisplayFont(font); |
1400 |
|
// Maximum allowed volume setting. |
1401 |
|
pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume); |
1402 |
|
} |
1403 |
|
|
1404 |
// Now we show up us to the world. |
// Now we show up us to the world. |
1405 |
pChannel->show(); |
pChannelStrip->show(); |
1406 |
// Only then, we'll auto-arrange... |
// Only then, we'll auto-arrange... |
1407 |
if (m_pOptions && m_pOptions->bAutoArrange) { |
if (m_pOptions && m_pOptions->bAutoArrange) { |
1408 |
int iWidth = m_pWorkspace->width(); |
int iWidth = m_pWorkspace->width(); |
1409 |
// int iHeight = pChannel->height() + pChannel->parentWidget()->baseSize().height(); |
// int iHeight = pChannel->height() + pChannel->parentWidget()->baseSize().height(); |
1410 |
int iHeight = pChannel->parentWidget()->frameGeometry().height(); |
int iHeight = pChannelStrip->parentWidget()->frameGeometry().height(); |
1411 |
pChannel->parentWidget()->setGeometry(0, y, iWidth, iHeight); |
pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight); |
1412 |
} |
} |
1413 |
|
|
1414 |
|
// Return our successful reference... |
1415 |
|
return pChannelStrip; |
1416 |
} |
} |
1417 |
|
|
1418 |
|
|
1419 |
// Retrieve the active channel strip. |
// Retrieve the active channel strip. |
1420 |
qsamplerChannelStrip *qsamplerMainForm::activeChannel (void) |
qsamplerChannelStrip *qsamplerMainForm::activeChannelStrip (void) |
1421 |
{ |
{ |
1422 |
return (qsamplerChannelStrip *) m_pWorkspace->activeWindow(); |
return (qsamplerChannelStrip *) m_pWorkspace->activeWindow(); |
1423 |
} |
} |
1424 |
|
|
1425 |
|
|
1426 |
// Retrieve a channel strip by index. |
// Retrieve a channel strip by index. |
1427 |
qsamplerChannelStrip *qsamplerMainForm::channelAt ( int iChannel ) |
qsamplerChannelStrip *qsamplerMainForm::channelStripAt ( int iChannel ) |
1428 |
{ |
{ |
1429 |
QWidgetList wlist = m_pWorkspace->windowList(); |
QWidgetList wlist = m_pWorkspace->windowList(); |
1430 |
if (wlist.isEmpty()) |
if (wlist.isEmpty()) |
1445 |
if (!wlist.isEmpty()) { |
if (!wlist.isEmpty()) { |
1446 |
channelsMenu->insertSeparator(); |
channelsMenu->insertSeparator(); |
1447 |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
1448 |
qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel); |
qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
1449 |
int iItemID = channelsMenu->insertItem(pChannel->caption(), this, SLOT(channelsMenuActivated(int))); |
if (pChannelStrip) { |
1450 |
channelsMenu->setItemParameter(iItemID, iChannel); |
int iItemID = channelsMenu->insertItem(pChannelStrip->caption(), this, SLOT(channelsMenuActivated(int))); |
1451 |
channelsMenu->setItemChecked(iItemID, activeChannel() == pChannel); |
channelsMenu->setItemParameter(iItemID, iChannel); |
1452 |
|
channelsMenu->setItemChecked(iItemID, activeChannelStrip() == pChannelStrip); |
1453 |
|
} |
1454 |
} |
} |
1455 |
} |
} |
1456 |
} |
} |
1459 |
// Windows menu activation slot |
// Windows menu activation slot |
1460 |
void qsamplerMainForm::channelsMenuActivated ( int iChannel ) |
void qsamplerMainForm::channelsMenuActivated ( int iChannel ) |
1461 |
{ |
{ |
1462 |
qsamplerChannelStrip *pChannel = channelAt(iChannel); |
qsamplerChannelStrip *pChannelStrip = channelStripAt(iChannel); |
1463 |
if (pChannel) |
if (pChannelStrip) |
1464 |
pChannel->showNormal(); |
pChannelStrip->showNormal(); |
1465 |
pChannel->setFocus(); |
pChannelStrip->setFocus(); |
1466 |
} |
} |
1467 |
|
|
1468 |
|
|
1502 |
} |
} |
1503 |
|
|
1504 |
// Refresh each channel usage, on each period... |
// Refresh each channel usage, on each period... |
1505 |
if (m_pClient && m_pOptions->bAutoRefresh && m_pWorkspace->isUpdatesEnabled()) { |
if (m_pClient && (m_iChangeCount > 0 || m_pOptions->bAutoRefresh)) { |
1506 |
m_iTimerSlot += QSAMPLER_TIMER_MSECS; |
m_iTimerSlot += QSAMPLER_TIMER_MSECS; |
1507 |
if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime) { |
if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime && m_pWorkspace->isUpdatesEnabled()) { |
1508 |
m_iTimerSlot = 0; |
m_iTimerSlot = 0; |
1509 |
|
m_iChangeCount = 0; |
1510 |
QWidgetList wlist = m_pWorkspace->windowList(); |
QWidgetList wlist = m_pWorkspace->windowList(); |
1511 |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) { |
1512 |
qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel); |
qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel); |
1513 |
if (pChannel->isVisible()) |
if (pChannelStrip && pChannelStrip->isVisible()) { |
1514 |
pChannel->updateChannelUsage(); |
// If we can't make it clean, try next time. |
1515 |
|
if (!pChannelStrip->updateChannelUsage()) |
1516 |
|
m_iChangeCount++; |
1517 |
|
} |
1518 |
} |
} |
1519 |
} |
} |
1520 |
} |
} |
1600 |
// And try to stop server. |
// And try to stop server. |
1601 |
if (m_pServer) { |
if (m_pServer) { |
1602 |
appendMessages(tr("Server is stopping...")); |
appendMessages(tr("Server is stopping...")); |
1603 |
if (m_pServer->isRunning()) { |
if (m_pServer->isRunning()) |
1604 |
m_pServer->tryTerminate(); |
m_pServer->tryTerminate(); |
|
return; |
|
|
} |
|
1605 |
} |
} |
1606 |
|
|
1607 |
|
// Give it some time to terminate gracefully and stabilize... |
1608 |
|
QTime t; |
1609 |
|
t.start(); |
1610 |
|
while (t.elapsed() < QSAMPLER_TIMER_MSECS) |
1611 |
|
QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput); |
1612 |
|
|
1613 |
// Do final processing anyway. |
// Do final processing anyway. |
1614 |
processServerExit(); |
processServerExit(); |
1615 |
} |
} |
1651 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
1652 |
// qsamplerMainForm -- Client stuff. |
// qsamplerMainForm -- Client stuff. |
1653 |
|
|
|
|
|
1654 |
// The LSCP client callback procedure. |
// The LSCP client callback procedure. |
1655 |
lscp_status_t qsampler_client_callback ( lscp_client_t *pClient, const char *pchBuffer, int cchBuffer, void *pvData ) |
lscp_status_t qsampler_client_callback ( lscp_client_t */*pClient*/, lscp_event_t event, const char *pchData, int cchData, void *pvData ) |
1656 |
{ |
{ |
1657 |
qsamplerMainForm *pMainForm = (qsamplerMainForm *) pvData; |
qsamplerMainForm *pMainForm = (qsamplerMainForm *) pvData; |
1658 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
1659 |
return LSCP_FAILED; |
return LSCP_FAILED; |
1660 |
|
|
1661 |
char *pszBuffer = (char *) malloc(cchBuffer + 1); |
// ATTN: DO NOT EVER call any GUI code here, |
1662 |
if (pszBuffer == NULL) |
// as this is run under some other thread context. |
1663 |
return LSCP_FAILED; |
// A custom event must be posted here... |
1664 |
|
QApplication::postEvent(pMainForm, new qsamplerCustomEvent(event, pchData, cchData)); |
|
memcpy(pszBuffer, pchBuffer, cchBuffer); |
|
|
pszBuffer[cchBuffer] = (char) 0; |
|
|
pMainForm->appendMessagesColor(pszBuffer, "#996699"); |
|
|
free(pszBuffer); |
|
1665 |
|
|
1666 |
return LSCP_OK; |
return LSCP_OK; |
1667 |
} |
} |