/[svn]/qsampler/trunk/src/qsamplerMainForm.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerMainForm.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1559 by capela, Thu Dec 6 14:23:39 2007 UTC revision 1699 by schoenebeck, Sun Feb 17 10:46:17 2008 UTC
# Line 2  Line 2 
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
# Line 33  Line 33 
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>
# Line 471  bool MainForm::queryClose (void) Line 472  bool MainForm::queryClose (void)
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    
# Line 481  bool MainForm::queryClose (void) Line 482  bool MainForm::queryClose (void)
482    
483  void MainForm::closeEvent ( QCloseEvent *pCloseEvent )  void MainForm::closeEvent ( QCloseEvent *pCloseEvent )
484  {  {
485          if (queryClose())          if (queryClose()) {
486                    DeviceStatusForm::deleteAllInstances();
487                  pCloseEvent->accept();                  pCloseEvent->accept();
488          else          } else
489                  pCloseEvent->ignore();                  pCloseEvent->ignore();
490  }  }
491    
# Line 551  void MainForm::customEvent(QEvent* pCust Line 553  void MainForm::customEvent(QEvent* pCust
553          // For the time being, just pump it to messages.          // For the time being, just pump it to messages.
554          if (pCustomEvent->type() == QSAMPLER_CUSTOM_EVENT) {          if (pCustomEvent->type() == QSAMPLER_CUSTOM_EVENT) {
555                  CustomEvent *pEvent = static_cast<CustomEvent *> (pCustomEvent);                  CustomEvent *pEvent = static_cast<CustomEvent *> (pCustomEvent);
556                  if (pEvent->event() == LSCP_EVENT_CHANNEL_INFO) {                  switch (pEvent->event()) {
557                          int iChannelID = pEvent->data().toInt();                          case LSCP_EVENT_CHANNEL_INFO: {
558                          ChannelStrip *pChannelStrip = channelStrip(iChannelID);                                  int iChannelID = pEvent->data().toInt();
559                          if (pChannelStrip)                                  ChannelStrip *pChannelStrip = channelStrip(iChannelID);
560                                  channelStripChanged(pChannelStrip);                                  if (pChannelStrip)
561                  } else {                                          channelStripChanged(pChannelStrip);
562                          appendMessagesColor(tr("Notify event: %1 data: %2")                                  break;
563                                  .arg(::lscp_event_to_text(pEvent->event()))                          }
564                                  .arg(pEvent->data()), "#996699");                          case LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT:
565                                    if (m_pDeviceForm) m_pDeviceForm->refreshDevices();
566                                    DeviceStatusForm::onDevicesChanged();
567                                    updateViewMidiDeviceStatusMenu();
568                                    break;
569                            case LSCP_EVENT_MIDI_INPUT_DEVICE_INFO: {
570                                    if (m_pDeviceForm) m_pDeviceForm->refreshDevices();
571                                    const int iDeviceID = pEvent->data().section(' ', 0, 0).toInt();
572                                    DeviceStatusForm::onDeviceChanged(iDeviceID);
573                                    break;
574                            }
575    #if CONFIG_LSCP_CHANNEL_MIDI
576                            case LSCP_EVENT_CHANNEL_MIDI: {
577                                    const int iChannelID = pEvent->data().section(' ', 0, 0).toInt();
578                                    ChannelStrip *pChannelStrip = channelStrip(iChannelID);
579                                    if (pChannelStrip)
580                                            pChannelStrip->midiArrived();
581                                    break;
582                            }
583    #endif
584    #if CONFIG_LSCP_DEVICE_MIDI
585                            case LSCP_EVENT_DEVICE_MIDI: {
586                                    const int iDeviceID = pEvent->data().section(' ', 0, 0).toInt();
587                                    const int iPortID   = pEvent->data().section(' ', 1, 1).toInt();
588                                    DeviceStatusForm* pDeviceStatusForm =
589                                            DeviceStatusForm::getInstance(iDeviceID);
590                                    if (pDeviceStatusForm)
591                                            pDeviceStatusForm->midiArrived(iPortID);
592                                    break;
593                            }
594    #endif
595                            default:
596                                    appendMessagesColor(tr("Notify event: %1 data: %2")
597                                            .arg(::lscp_event_to_text(pEvent->event()))
598                                            .arg(pEvent->data()), "#996699");
599                  }                  }
600          }          }
601  }  }
602    
603    void MainForm::updateViewMidiDeviceStatusMenu() {
604            m_ui.viewMidiDeviceStatusMenu->clear();
605            const std::map<int, DeviceStatusForm*> statusForms =
606                    DeviceStatusForm::getInstances();
607            for (
608                    std::map<int, DeviceStatusForm*>::const_iterator iter = statusForms.begin();
609                    iter != statusForms.end(); ++iter
610            ) {
611                    DeviceStatusForm* pForm = iter->second;
612                    m_ui.viewMidiDeviceStatusMenu->addAction(
613                            pForm->visibleAction()
614                    );
615            }
616    }
617    
618  // Context menu event handler.  // Context menu event handler.
619  void MainForm::contextMenuEvent( QContextMenuEvent *pEvent )  void MainForm::contextMenuEvent( QContextMenuEvent *pEvent )
620  {  {
# Line 2390  void MainForm::startServer (void) Line 2441  void MainForm::startServer (void)
2441                  switch (QMessageBox::warning(this,                  switch (QMessageBox::warning(this,
2442                          QSAMPLER_TITLE ": " + tr("Warning"),                          QSAMPLER_TITLE ": " + tr("Warning"),
2443                          tr("Could not start the LinuxSampler server.\n\n"                          tr("Could not start the LinuxSampler server.\n\n"
2444                          "Maybe it ss already started."),                          "Maybe it is already started."),
2445                          tr("Stop"), tr("Kill"), tr("Cancel"))) {                          tr("Stop"), tr("Kill"), tr("Cancel"))) {
2446                  case 0:                  case 0:
2447                          m_pServer->terminate();                          m_pServer->terminate();
# Line 2410  void MainForm::startServer (void) Line 2461  void MainForm::startServer (void)
2461                  return;                  return;
2462    
2463          // OK. Let's build the startup process...          // OK. Let's build the startup process...
2464          m_pServer = new QProcess(this);          m_pServer = new QProcess();
2465            bForceServerStop = true;
2466    
2467          // Setup stdout/stderr capture...          // Setup stdout/stderr capture...
2468  //      if (m_pOptions->bStdoutCapture) {  //      if (m_pOptions->bStdoutCapture) {
# Line 2458  void MainForm::startServer (void) Line 2510  void MainForm::startServer (void)
2510    
2511    
2512  // Stop linuxsampler server...  // Stop linuxsampler server...
2513  void MainForm::stopServer (void)  void MainForm::stopServer (bool bInteractive)
2514  {  {
2515          // Stop client code.          // Stop client code.
2516          stopClient();          stopClient();
2517    
2518            if (m_pServer && bInteractive) {
2519                    if (QMessageBox::question(this,
2520                            QSAMPLER_TITLE ": " + tr("The backend's fate ..."),
2521                            tr("You have the option to keep the sampler backend (LinuxSampler)\n"
2522                            "running in the background. The sampler would continue to work\n"
2523                            "according to your current sampler session and you could alter the\n"
2524                            "sampler session at any time by relaunching QSampler.\n\n"
2525                            "Do you want LinuxSampler to stop or to keep running in\n"
2526                            "the background?"),
2527                            tr("Stop"), tr("Keep Running")) == 1)
2528                    {
2529                            bForceServerStop = false;
2530                    }
2531            }
2532    
2533          // And try to stop server.          // And try to stop server.
2534          if (m_pServer) {          if (m_pServer && bForceServerStop) {
2535                  appendMessages(tr("Server is stopping..."));                  appendMessages(tr("Server is stopping..."));
2536                  if (m_pServer->state() == QProcess::Running) {                  if (m_pServer->state() == QProcess::Running) {
2537  #if defined(WIN32)  #if defined(WIN32)
# Line 2504  void MainForm::processServerExit (void) Line 2571  void MainForm::processServerExit (void)
2571          if (m_pMessages)          if (m_pMessages)
2572                  m_pMessages->flushStdoutBuffer();                  m_pMessages->flushStdoutBuffer();
2573    
2574          if (m_pServer) {          if (m_pServer && bForceServerStop) {
2575                  if (m_pServer->state() != QProcess::NotRunning) {                  if (m_pServer->state() != QProcess::NotRunning) {
2576                          appendMessages(tr("Server is being forced..."));                          appendMessages(tr("Server is being forced..."));
2577                          // Force final server shutdown...                          // Force final server shutdown...
# Line 2589  bool MainForm::startClient (void) Line 2656  bool MainForm::startClient (void)
2656    
2657          // Subscribe to channel info change notifications...          // Subscribe to channel info change notifications...
2658          if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO) != LSCP_OK)          if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO) != LSCP_OK)
2659                  appendMessagesClient("lscp_client_subscribe");                  appendMessagesClient("lscp_client_subscribe(CHANNEL_INFO)");
2660    
2661            DeviceStatusForm::onDevicesChanged(); // initialize
2662            updateViewMidiDeviceStatusMenu();
2663            if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT) != LSCP_OK)
2664                    appendMessagesClient("lscp_client_subscribe(MIDI_INPUT_DEVICE_COUNT)");
2665            if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_MIDI_INPUT_DEVICE_INFO) != LSCP_OK)
2666                    appendMessagesClient("lscp_client_subscribe(MIDI_INPUT_DEVICE_INFO)");
2667    
2668    #if CONFIG_LSCP_CHANNEL_MIDI
2669            // Subscribe to channel MIDI data notifications...
2670            if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_CHANNEL_MIDI) != LSCP_OK)
2671                    appendMessagesClient("lscp_client_subscribe(CHANNEL_MIDI)");
2672    #endif
2673    
2674    #if CONFIG_LSCP_DEVICE_MIDI
2675            // Subscribe to channel MIDI data notifications...
2676            if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_DEVICE_MIDI) != LSCP_OK)
2677                    appendMessagesClient("lscp_client_subscribe(DEVICE_MIDI)");
2678    #endif
2679    
2680          // We may stop scheduling around.          // We may stop scheduling around.
2681          stopSchedule();          stopSchedule();
# Line 2643  void MainForm::stopClient (void) Line 2729  void MainForm::stopClient (void)
2729          closeSession(false);          closeSession(false);
2730    
2731          // Close us as a client...          // Close us as a client...
2732    #if CONFIG_LSCP_DEVICE_MIDI
2733            ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_DEVICE_MIDI);
2734    #endif
2735    #if CONFIG_LSCP_CHANNEL_MIDI
2736            ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_MIDI);
2737    #endif
2738            ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_MIDI_INPUT_DEVICE_INFO);
2739            ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT);
2740          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO);          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO);
2741          ::lscp_client_destroy(m_pClient);          ::lscp_client_destroy(m_pClient);
2742          m_pClient = NULL;          m_pClient = NULL;

Legend:
Removed from v.1559  
changed lines
  Added in v.1699

  ViewVC Help
Powered by ViewVC