2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2007, 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 |
33 |
#include "qsamplerInstrumentListForm.h" |
#include "qsamplerInstrumentListForm.h" |
34 |
#include "qsamplerDeviceForm.h" |
#include "qsamplerDeviceForm.h" |
35 |
#include "qsamplerOptionsForm.h" |
#include "qsamplerOptionsForm.h" |
36 |
|
#include "qsamplerDeviceStatusForm.h" |
37 |
|
|
38 |
#include <QApplication> |
#include <QApplication> |
39 |
#include <QWorkspace> |
#include <QWorkspace> |
472 |
if (m_pDeviceForm) |
if (m_pDeviceForm) |
473 |
m_pDeviceForm->close(); |
m_pDeviceForm->close(); |
474 |
// Stop client and/or server, gracefully. |
// Stop client and/or server, gracefully. |
475 |
stopServer(); |
stopServer(true /*interactive*/); |
476 |
} |
} |
477 |
} |
} |
478 |
|
|
552 |
// For the time being, just pump it to messages. |
// For the time being, just pump it to messages. |
553 |
if (pCustomEvent->type() == QSAMPLER_CUSTOM_EVENT) { |
if (pCustomEvent->type() == QSAMPLER_CUSTOM_EVENT) { |
554 |
CustomEvent *pEvent = static_cast<CustomEvent *> (pCustomEvent); |
CustomEvent *pEvent = static_cast<CustomEvent *> (pCustomEvent); |
555 |
if (pEvent->event() == LSCP_EVENT_CHANNEL_INFO) { |
switch (pEvent->event()) { |
556 |
int iChannelID = pEvent->data().toInt(); |
case LSCP_EVENT_CHANNEL_INFO: { |
557 |
ChannelStrip *pChannelStrip = channelStrip(iChannelID); |
int iChannelID = pEvent->data().toInt(); |
558 |
if (pChannelStrip) |
ChannelStrip *pChannelStrip = channelStrip(iChannelID); |
559 |
channelStripChanged(pChannelStrip); |
if (pChannelStrip) |
560 |
} else { |
channelStripChanged(pChannelStrip); |
561 |
appendMessagesColor(tr("Notify event: %1 data: %2") |
break; |
562 |
.arg(::lscp_event_to_text(pEvent->event())) |
} |
563 |
.arg(pEvent->data()), "#996699"); |
case LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT: |
564 |
|
DeviceStatusForm::onDevicesChanged(); |
565 |
|
updateViewMidiDeviceStatusMenu(); |
566 |
|
break; //TODO: refresh device dialog as well |
567 |
|
#if CONFIG_LSCP_CHANNEL_MIDI |
568 |
|
case LSCP_EVENT_CHANNEL_MIDI: { |
569 |
|
const int iChannelID = pEvent->data().section(' ', 0, 0).toInt(); |
570 |
|
ChannelStrip *pChannelStrip = channelStrip(iChannelID); |
571 |
|
if (pChannelStrip) |
572 |
|
pChannelStrip->midiArrived(); |
573 |
|
break; |
574 |
|
} |
575 |
|
#endif |
576 |
|
#if CONFIG_LSCP_DEVICE_MIDI |
577 |
|
case LSCP_EVENT_DEVICE_MIDI: { |
578 |
|
const int iDeviceID = pEvent->data().section(' ', 0, 0).toInt(); |
579 |
|
const int iPortID = pEvent->data().section(' ', 1, 1).toInt(); |
580 |
|
DeviceStatusForm* pDeviceStatusForm = |
581 |
|
DeviceStatusForm::getInstance(iDeviceID); |
582 |
|
if (pDeviceStatusForm) |
583 |
|
pDeviceStatusForm->midiArrived(iPortID); |
584 |
|
break; |
585 |
|
} |
586 |
|
#endif |
587 |
|
default: |
588 |
|
appendMessagesColor(tr("Notify event: %1 data: %2") |
589 |
|
.arg(::lscp_event_to_text(pEvent->event())) |
590 |
|
.arg(pEvent->data()), "#996699"); |
591 |
} |
} |
592 |
} |
} |
593 |
} |
} |
594 |
|
|
595 |
|
void MainForm::updateViewMidiDeviceStatusMenu() { |
596 |
|
m_ui.viewMidiDeviceStatusMenu->clear(); |
597 |
|
const std::map<int, DeviceStatusForm*> statusForms = |
598 |
|
DeviceStatusForm::getInstances(); |
599 |
|
for ( |
600 |
|
std::map<int, DeviceStatusForm*>::const_iterator iter = statusForms.begin(); |
601 |
|
iter != statusForms.end(); ++iter |
602 |
|
) { |
603 |
|
DeviceStatusForm* pForm = iter->second; |
604 |
|
m_ui.viewMidiDeviceStatusMenu->addAction( |
605 |
|
pForm->visibleAction() |
606 |
|
); |
607 |
|
} |
608 |
|
} |
609 |
|
|
610 |
// Context menu event handler. |
// Context menu event handler. |
611 |
void MainForm::contextMenuEvent( QContextMenuEvent *pEvent ) |
void MainForm::contextMenuEvent( QContextMenuEvent *pEvent ) |
612 |
{ |
{ |
2433 |
switch (QMessageBox::warning(this, |
switch (QMessageBox::warning(this, |
2434 |
QSAMPLER_TITLE ": " + tr("Warning"), |
QSAMPLER_TITLE ": " + tr("Warning"), |
2435 |
tr("Could not start the LinuxSampler server.\n\n" |
tr("Could not start the LinuxSampler server.\n\n" |
2436 |
"Maybe it ss already started."), |
"Maybe it is already started."), |
2437 |
tr("Stop"), tr("Kill"), tr("Cancel"))) { |
tr("Stop"), tr("Kill"), tr("Cancel"))) { |
2438 |
case 0: |
case 0: |
2439 |
m_pServer->terminate(); |
m_pServer->terminate(); |
2453 |
return; |
return; |
2454 |
|
|
2455 |
// OK. Let's build the startup process... |
// OK. Let's build the startup process... |
2456 |
m_pServer = new QProcess(this); |
m_pServer = new QProcess(); |
2457 |
|
bForceServerStop = true; |
2458 |
|
|
2459 |
// Setup stdout/stderr capture... |
// Setup stdout/stderr capture... |
2460 |
// if (m_pOptions->bStdoutCapture) { |
// if (m_pOptions->bStdoutCapture) { |
2461 |
//m_pServer->setProcessChannelMode( |
#if QT_VERSION >= 0x040200 |
2462 |
// QProcess::StandardOutput); |
m_pServer->setProcessChannelMode(QProcess::ForwardedChannels); |
2463 |
|
#endif |
2464 |
QObject::connect(m_pServer, |
QObject::connect(m_pServer, |
2465 |
SIGNAL(readyReadStandardOutput()), |
SIGNAL(readyReadStandardOutput()), |
2466 |
SLOT(readServerStdout())); |
SLOT(readServerStdout())); |
2471 |
|
|
2472 |
// The unforgiveable signal communication... |
// The unforgiveable signal communication... |
2473 |
QObject::connect(m_pServer, |
QObject::connect(m_pServer, |
2474 |
SIGNAL(finished(int,QProcess::ExitStatus)), |
SIGNAL(finished(int, QProcess::ExitStatus)), |
2475 |
SLOT(processServerExit())); |
SLOT(processServerExit())); |
2476 |
|
|
2477 |
// Build process arguments... |
// Build process arguments... |
2502 |
|
|
2503 |
|
|
2504 |
// Stop linuxsampler server... |
// Stop linuxsampler server... |
2505 |
void MainForm::stopServer (void) |
void MainForm::stopServer (bool bInteractive) |
2506 |
{ |
{ |
2507 |
// Stop client code. |
// Stop client code. |
2508 |
stopClient(); |
stopClient(); |
2509 |
|
|
2510 |
|
if (m_pServer && bInteractive) { |
2511 |
|
if (QMessageBox::question(this, |
2512 |
|
QSAMPLER_TITLE ": " + tr("The backend's fate ..."), |
2513 |
|
tr("You have the option to keep the sampler backend (LinuxSampler)\n" |
2514 |
|
"running in the background. The sampler would continue to work\n" |
2515 |
|
"according to your current sampler session and you could alter the\n" |
2516 |
|
"sampler session at any time by relaunching QSampler.\n\n" |
2517 |
|
"Do you want LinuxSampler to stop or to keep running in\n" |
2518 |
|
"the background?"), |
2519 |
|
tr("Stop"), tr("Keep Running")) == 1) |
2520 |
|
{ |
2521 |
|
bForceServerStop = false; |
2522 |
|
} |
2523 |
|
} |
2524 |
|
|
2525 |
// And try to stop server. |
// And try to stop server. |
2526 |
if (m_pServer) { |
if (m_pServer && bForceServerStop) { |
2527 |
appendMessages(tr("Server is stopping...")); |
appendMessages(tr("Server is stopping...")); |
2528 |
if (m_pServer->state() == QProcess::Running) |
if (m_pServer->state() == QProcess::Running) { |
2529 |
|
#if defined(WIN32) |
2530 |
|
// Try harder... |
2531 |
|
m_pServer->kill(); |
2532 |
|
#else |
2533 |
|
// Try softly... |
2534 |
m_pServer->terminate(); |
m_pServer->terminate(); |
2535 |
} |
#endif |
2536 |
|
} |
2537 |
|
} // Do final processing anyway. |
2538 |
|
else processServerExit(); |
2539 |
|
|
2540 |
// Give it some time to terminate gracefully and stabilize... |
// Give it some time to terminate gracefully and stabilize... |
2541 |
QTime t; |
QTime t; |
2542 |
t.start(); |
t.start(); |
2543 |
while (t.elapsed() < QSAMPLER_TIMER_MSECS) |
while (t.elapsed() < QSAMPLER_TIMER_MSECS) |
2544 |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
|
|
|
|
// Do final processing anyway. |
|
|
processServerExit(); |
|
2545 |
} |
} |
2546 |
|
|
2547 |
|
|
2563 |
if (m_pMessages) |
if (m_pMessages) |
2564 |
m_pMessages->flushStdoutBuffer(); |
m_pMessages->flushStdoutBuffer(); |
2565 |
|
|
2566 |
if (m_pServer) { |
if (m_pServer && bForceServerStop) { |
2567 |
|
if (m_pServer->state() != QProcess::NotRunning) { |
2568 |
|
appendMessages(tr("Server is being forced...")); |
2569 |
|
// Force final server shutdown... |
2570 |
|
m_pServer->kill(); |
2571 |
|
// Give it some time to terminate gracefully and stabilize... |
2572 |
|
QTime t; |
2573 |
|
t.start(); |
2574 |
|
while (t.elapsed() < QSAMPLER_TIMER_MSECS) |
2575 |
|
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
2576 |
|
} |
2577 |
// Force final server shutdown... |
// Force final server shutdown... |
2578 |
appendMessages( |
appendMessages( |
2579 |
tr("Server was stopped with exit status %1.") |
tr("Server was stopped with exit status %1.") |
2580 |
.arg(m_pServer->exitStatus())); |
.arg(m_pServer->exitStatus())); |
|
m_pServer->terminate(); |
|
|
if (!m_pServer->waitForFinished(2000)) |
|
|
m_pServer->kill(); |
|
|
// Destroy it. |
|
2581 |
delete m_pServer; |
delete m_pServer; |
2582 |
m_pServer = NULL; |
m_pServer = NULL; |
2583 |
} |
} |
2648 |
|
|
2649 |
// Subscribe to channel info change notifications... |
// Subscribe to channel info change notifications... |
2650 |
if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO) != LSCP_OK) |
if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO) != LSCP_OK) |
2651 |
appendMessagesClient("lscp_client_subscribe"); |
appendMessagesClient("lscp_client_subscribe(CHANNEL_INFO)"); |
2652 |
|
|
2653 |
|
DeviceStatusForm::onDevicesChanged(); // initialize |
2654 |
|
updateViewMidiDeviceStatusMenu(); |
2655 |
|
if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT) != LSCP_OK) |
2656 |
|
appendMessagesClient("lscp_client_subscribe(MIDI_INPUT_DEVICE_COUNT)"); |
2657 |
|
|
2658 |
|
#if CONFIG_LSCP_CHANNEL_MIDI |
2659 |
|
// Subscribe to channel MIDI data notifications... |
2660 |
|
if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_CHANNEL_MIDI) != LSCP_OK) |
2661 |
|
appendMessagesClient("lscp_client_subscribe(CHANNEL_MIDI)"); |
2662 |
|
#endif |
2663 |
|
|
2664 |
|
#if CONFIG_LSCP_DEVICE_MIDI |
2665 |
|
// Subscribe to channel MIDI data notifications... |
2666 |
|
if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_DEVICE_MIDI) != LSCP_OK) |
2667 |
|
appendMessagesClient("lscp_client_subscribe(DEVICE_MIDI)"); |
2668 |
|
#endif |
2669 |
|
|
2670 |
// We may stop scheduling around. |
// We may stop scheduling around. |
2671 |
stopSchedule(); |
stopSchedule(); |
2719 |
closeSession(false); |
closeSession(false); |
2720 |
|
|
2721 |
// Close us as a client... |
// Close us as a client... |
2722 |
|
#if CONFIG_LSCP_DEVICE_MIDI |
2723 |
|
::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_DEVICE_MIDI); |
2724 |
|
#endif |
2725 |
|
#if CONFIG_LSCP_CHANNEL_MIDI |
2726 |
|
::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_MIDI); |
2727 |
|
#endif |
2728 |
|
::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT); |
2729 |
::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO); |
::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO); |
2730 |
::lscp_client_destroy(m_pClient); |
::lscp_client_destroy(m_pClient); |
2731 |
m_pClient = NULL; |
m_pClient = NULL; |