/[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 3049 by capela, Sat Dec 3 09:47:38 2016 UTC revision 3437 by capela, Mon Dec 3 16:30:53 2018 UTC
# Line 1  Line 1 
1  // qsamplerMainForm.cpp  // qsamplerMainForm.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2016, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2018, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007,2008,2015 Christian Schoenebeck     Copyright (C) 2007,2008,2015 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
# Line 91  static inline long lroundf ( float x ) Line 91  static inline long lroundf ( float x )
91    
92    
93  // All winsock apps needs this.  // All winsock apps needs this.
94  #if defined(WIN32)  #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
95  static WSADATA _wsaData;  static WSADATA _wsaData;
96  #endif  #endif
97    
# Line 324  MainForm::MainForm ( QWidget *pParent ) Line 324  MainForm::MainForm ( QWidget *pParent )
324          m_statusItem[QSAMPLER_STATUS_SESSION] = pLabel;          m_statusItem[QSAMPLER_STATUS_SESSION] = pLabel;
325          statusBar()->addWidget(pLabel);          statusBar()->addWidget(pLabel);
326    
327  #if defined(WIN32)  #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
328          WSAStartup(MAKEWORD(1, 1), &_wsaData);          WSAStartup(MAKEWORD(1, 1), &_wsaData);
329  #endif  #endif
330    
# Line 425  MainForm::~MainForm() Line 425  MainForm::~MainForm()
425          // Do final processing anyway.          // Do final processing anyway.
426          processServerExit();          processServerExit();
427    
428  #if defined(WIN32)  #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
429          WSACleanup();          WSACleanup();
430  #endif  #endif
431    
# Line 866  bool MainForm::saveSession ( bool bPromp Line 866  bool MainForm::saveSession ( bool bPromp
866                  // Enforce .lscp extension...                  // Enforce .lscp extension...
867                  if (QFileInfo(sFilename).suffix().isEmpty())                  if (QFileInfo(sFilename).suffix().isEmpty())
868                          sFilename += ".lscp";                          sFilename += ".lscp";
869            #if 0
870                  // Check if already exists...                  // Check if already exists...
871                  if (sFilename != m_sFilename && QFileInfo(sFilename).exists()) {                  if (sFilename != m_sFilename && QFileInfo(sFilename).exists()) {
872                          if (QMessageBox::warning(this,                          if (QMessageBox::warning(this,
# Line 878  bool MainForm::saveSession ( bool bPromp Line 879  bool MainForm::saveSession ( bool bPromp
879                                  == QMessageBox::No)                                  == QMessageBox::No)
880                                  return false;                                  return false;
881                  }                  }
882            #endif
883          }          }
884    
885          // Save it right away.          // Save it right away.
# Line 1060  bool MainForm::saveSessionFile ( const Q Line 1062  bool MainForm::saveSessionFile ( const Q
1062          // It is assumed that this new kind of device+session file          // It is assumed that this new kind of device+session file
1063          // will be loaded from a complete initialized server...          // will be loaded from a complete initialized server...
1064          int *piDeviceIDs;          int *piDeviceIDs;
1065          int  iDevice;          int  i, iDevice;
1066          ts << "RESET" << endl;          ts << "RESET" << endl;
1067    
1068          // Audio device mapping.          // Audio device mapping.
1069          QMap<int, int> audioDeviceMap;          QMap<int, int> audioDeviceMap; iDevice = 0;
1070          piDeviceIDs = Device::getDevices(m_pClient, Device::Audio);          piDeviceIDs = Device::getDevices(m_pClient, Device::Audio);
1071          for (iDevice = 0; piDeviceIDs && piDeviceIDs[iDevice] >= 0; iDevice++) {          for (i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; ++i) {
1072                  ts << endl;                  Device device(Device::Audio, piDeviceIDs[i]);
1073                  Device device(Device::Audio, piDeviceIDs[iDevice]);                  // Avoid plug-in driver devices...
1074                    if (device.driverName().toUpper() == "PLUGIN")
1075                            continue;
1076                  // Audio device specification...                  // Audio device specification...
1077                    ts << endl;
1078                  ts << "# " << device.deviceTypeName() << " " << device.driverName()                  ts << "# " << device.deviceTypeName() << " " << device.driverName()
1079                          << " " << tr("Device") << " " << iDevice << endl;                          << " " << tr("Device") << " " << iDevice << endl;
1080                  ts << "CREATE AUDIO_OUTPUT_DEVICE " << device.driverName();                  ts << "CREATE AUDIO_OUTPUT_DEVICE " << device.driverName();
# Line 1100  bool MainForm::saveSessionFile ( const Q Line 1105  bool MainForm::saveSessionFile ( const Q
1105                          iPort++;                          iPort++;
1106                  }                  }
1107                  // Audio device index/id mapping.                  // Audio device index/id mapping.
1108                  audioDeviceMap[device.deviceID()] = iDevice;                  audioDeviceMap.insert(device.deviceID(), iDevice++);
1109                  // Try to keep it snappy :)                  // Try to keep it snappy :)
1110                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
1111          }          }
1112    
1113          // MIDI device mapping.          // MIDI device mapping.
1114          QMap<int, int> midiDeviceMap;          QMap<int, int> midiDeviceMap; iDevice = 0;
1115          piDeviceIDs = Device::getDevices(m_pClient, Device::Midi);          piDeviceIDs = Device::getDevices(m_pClient, Device::Midi);
1116          for (iDevice = 0; piDeviceIDs && piDeviceIDs[iDevice] >= 0; iDevice++) {          for (i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; ++i) {
1117                  ts << endl;                  Device device(Device::Midi, piDeviceIDs[i]);
1118                  Device device(Device::Midi, piDeviceIDs[iDevice]);                  // Avoid plug-in driver devices...
1119                    if (device.driverName().toUpper() == "PLUGIN")
1120                            continue;
1121                  // MIDI device specification...                  // MIDI device specification...
1122                    ts << endl;
1123                  ts << "# " << device.deviceTypeName() << " " << device.driverName()                  ts << "# " << device.deviceTypeName() << " " << device.driverName()
1124                          << " " << tr("Device") << " " << iDevice << endl;                          << " " << tr("Device") << " " << iDevice << endl;
1125                  ts << "CREATE MIDI_INPUT_DEVICE " << device.driverName();                  ts << "CREATE MIDI_INPUT_DEVICE " << device.driverName();
# Line 1142  bool MainForm::saveSessionFile ( const Q Line 1150  bool MainForm::saveSessionFile ( const Q
1150                          iPort++;                          iPort++;
1151                  }                  }
1152                  // MIDI device index/id mapping.                  // MIDI device index/id mapping.
1153                  midiDeviceMap[device.deviceID()] = iDevice;                  midiDeviceMap.insert(device.deviceID(), iDevice++);
1154                  // Try to keep it snappy :)                  // Try to keep it snappy :)
1155                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
1156          }          }
# Line 1210  bool MainForm::saveSessionFile ( const Q Line 1218  bool MainForm::saveSessionFile ( const Q
1218                          iErrors++;                          iErrors++;
1219                  }                  }
1220                  // MIDI strument index/id mapping.                  // MIDI strument index/id mapping.
1221                  midiInstrumentMap[iMidiMap] = iMap;                  midiInstrumentMap.insert(iMidiMap, iMap);
1222          }          }
1223          // Check for errors...          // Check for errors...
1224          if (piMaps == NULL && ::lscp_client_get_errno(m_pClient)) {          if (piMaps == NULL && ::lscp_client_get_errno(m_pClient)) {
# Line 1219  bool MainForm::saveSessionFile ( const Q Line 1227  bool MainForm::saveSessionFile ( const Q
1227          }          }
1228  #endif  // CONFIG_MIDI_INSTRUMENT  #endif  // CONFIG_MIDI_INSTRUMENT
1229    
1230          // Sampler channel mapping.          // Sampler channel mapping...
1231            int iChannelID = 0;
1232          const QList<QMdiSubWindow *>& wlist          const QList<QMdiSubWindow *>& wlist
1233                  = m_pWorkspace->subWindowList();                  = m_pWorkspace->subWindowList();
1234          const int iStripCount = wlist.count();          const int iStripCount = wlist.count();
# Line 1231  bool MainForm::saveSessionFile ( const Q Line 1240  bool MainForm::saveSessionFile ( const Q
1240                  if (pChannelStrip) {                  if (pChannelStrip) {
1241                          Channel *pChannel = pChannelStrip->channel();                          Channel *pChannel = pChannelStrip->channel();
1242                          if (pChannel) {                          if (pChannel) {
1243                                  const int iChannelID = pChannel->channelID();                                  // Avoid "artifial" plug-in devices...
1244                                    const int iAudioDevice = pChannel->audioDevice();
1245                                    if (!audioDeviceMap.contains(iAudioDevice))
1246                                            continue;
1247                                    const int iMidiDevice = pChannel->midiDevice();
1248                                    if (!midiDeviceMap.contains(iMidiDevice))
1249                                            continue;
1250                                    // Go for regular, canonical devices...
1251                                  ts << "# " << tr("Channel") << " " << iChannelID << endl;                                  ts << "# " << tr("Channel") << " " << iChannelID << endl;
1252                                  ts << "ADD CHANNEL" << endl;                                  ts << "ADD CHANNEL" << endl;
1253                                  if (audioDeviceMap.isEmpty()) {                                  if (audioDeviceMap.isEmpty()) {
# Line 1239  bool MainForm::saveSessionFile ( const Q Line 1255  bool MainForm::saveSessionFile ( const Q
1255                                                  << " " << pChannel->audioDriver() << endl;                                                  << " " << pChannel->audioDriver() << endl;
1256                                  } else {                                  } else {
1257                                          ts << "SET CHANNEL AUDIO_OUTPUT_DEVICE " << iChannelID                                          ts << "SET CHANNEL AUDIO_OUTPUT_DEVICE " << iChannelID
1258                                                  << " " << audioDeviceMap[pChannel->audioDevice()] << endl;                                                  << " " << audioDeviceMap.value(iAudioDevice) << endl;
1259                                  }                                  }
1260                                  if (midiDeviceMap.isEmpty()) {                                  if (midiDeviceMap.isEmpty()) {
1261                                          ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannelID                                          ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannelID
1262                                                  << " " << pChannel->midiDriver() << endl;                                                  << " " << pChannel->midiDriver() << endl;
1263                                  } else {                                  } else {
1264                                          ts << "SET CHANNEL MIDI_INPUT_DEVICE " << iChannelID                                          ts << "SET CHANNEL MIDI_INPUT_DEVICE " << iChannelID
1265                                                  << " " << midiDeviceMap[pChannel->midiDevice()] << endl;                                                  << " " << midiDeviceMap.value(iMidiDevice) << endl;
1266                                  }                                  }
1267                                  ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannelID                                  ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannelID
1268                                          << " " << pChannel->midiPort() << endl;                                          << " " << pChannel->midiPort() << endl;
# Line 1277  bool MainForm::saveSessionFile ( const Q Line 1293  bool MainForm::saveSessionFile ( const Q
1293                                  if (pChannel->channelSolo())                                  if (pChannel->channelSolo())
1294                                          ts << "SET CHANNEL SOLO " << iChannelID << " 1" << endl;                                          ts << "SET CHANNEL SOLO " << iChannelID << " 1" << endl;
1295                          #ifdef CONFIG_MIDI_INSTRUMENT                          #ifdef CONFIG_MIDI_INSTRUMENT
1296                                  if (pChannel->midiMap() >= 0) {                                  const int iMidiMap = pChannel->midiMap();
1297                                    if (midiInstrumentMap.contains(iMidiMap)) {
1298                                          ts << "SET CHANNEL MIDI_INSTRUMENT_MAP " << iChannelID                                          ts << "SET CHANNEL MIDI_INSTRUMENT_MAP " << iChannelID
1299                                                  << " " << midiInstrumentMap[pChannel->midiMap()] << endl;                                                  << " " << midiInstrumentMap.value(iMidiMap) << endl;
1300                                  }                                  }
1301                          #endif                          #endif
1302                          #ifdef CONFIG_FXSEND                          #ifdef CONFIG_FXSEND
# Line 1318  bool MainForm::saveSessionFile ( const Q Line 1335  bool MainForm::saveSessionFile ( const Q
1335                                  }                                  }
1336                          #endif                          #endif
1337                                  ts << endl;                                  ts << endl;
1338                                    // Go for next channel...
1339                                    ++iChannelID;
1340                          }                          }
1341                  }                  }
1342                  // Try to keep it snappy :)                  // Try to keep it snappy :)
# Line 2801  void MainForm::startServer (void) Line 2820  void MainForm::startServer (void)
2820    
2821          // OK. Let's build the startup process...          // OK. Let's build the startup process...
2822          m_pServer = new QProcess();          m_pServer = new QProcess();
2823          bForceServerStop = true;          m_bForceServerStop = true;
2824    
2825          // Setup stdout/stderr capture...          // Setup stdout/stderr capture...
2826          m_pServer->setProcessChannelMode(QProcess::ForwardedChannels);          m_pServer->setProcessChannelMode(QProcess::ForwardedChannels);
# Line 2845  void MainForm::startServer (void) Line 2864  void MainForm::startServer (void)
2864    
2865    
2866  // Stop linuxsampler server...  // Stop linuxsampler server...
2867  void MainForm::stopServer (bool bInteractive)  void MainForm::stopServer ( bool bInteractive )
2868  {  {
2869          // Stop client code.          // Stop client code.
2870          stopClient();          stopClient();
# Line 2859  void MainForm::stopServer (bool bInterac Line 2878  void MainForm::stopServer (bool bInterac
2878                          "sampler session at any time by relaunching QSampler.\n\n"                          "sampler session at any time by relaunching QSampler.\n\n"
2879                          "Do you want LinuxSampler to stop?"),                          "Do you want LinuxSampler to stop?"),
2880                          QMessageBox::Yes | QMessageBox::No,                          QMessageBox::Yes | QMessageBox::No,
2881                          QMessageBox::Yes) == QMessageBox::No)                          QMessageBox::Yes) == QMessageBox::No) {
2882                  {                          m_bForceServerStop = false;
                         bForceServerStop = false;  
2883                  }                  }
2884          }          }
2885    
2886            bool bGraceWait = true;
2887    
2888          // And try to stop server.          // And try to stop server.
2889          if (m_pServer && bForceServerStop) {          if (m_pServer && m_bForceServerStop) {
2890                  appendMessages(tr("Server is stopping..."));                  appendMessages(tr("Server is stopping..."));
2891                  if (m_pServer->state() == QProcess::Running) {                  if (m_pServer->state() == QProcess::Running) {
2892                  #if defined(WIN32)                  #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
2893                          // Try harder...                          // Try harder...
2894                          m_pServer->kill();                          m_pServer->kill();
2895                  #else                  #else
2896                          // Try softly...                          // Try softly...
2897                          m_pServer->terminate();                          m_pServer->terminate();
2898                            bool bFinished = m_pServer->waitForFinished(QSAMPLER_TIMER_MSECS * 1000);
2899                            if (bFinished) bGraceWait = false;
2900                  #endif                  #endif
2901                  }                  }
2902          }       // Do final processing anyway.          }       // Do final processing anyway.
2903          else processServerExit();          else processServerExit();
2904    
2905          // Give it some time to terminate gracefully and stabilize...          // Give it some time to terminate gracefully and stabilize...
2906          QTime t;          if (bGraceWait) {
2907          t.start();                  QTime t;
2908          while (t.elapsed() < QSAMPLER_TIMER_MSECS)                  t.start();
2909                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                  while (t.elapsed() < QSAMPLER_TIMER_MSECS)
2910                            QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
2911            }
2912  }  }
2913    
2914    
# Line 2906  void MainForm::processServerExit (void) Line 2930  void MainForm::processServerExit (void)
2930          if (m_pMessages)          if (m_pMessages)
2931                  m_pMessages->flushStdoutBuffer();                  m_pMessages->flushStdoutBuffer();
2932    
2933          if (m_pServer && bForceServerStop) {          if (m_pServer && m_bForceServerStop) {
2934                  if (m_pServer->state() != QProcess::NotRunning) {                  if (m_pServer->state() != QProcess::NotRunning) {
2935                          appendMessages(tr("Server is being forced..."));                          appendMessages(tr("Server is being forced..."));
2936                          // Force final server shutdown...                          // Force final server shutdown...
# Line 2983  bool MainForm::startClient (void) Line 3007  bool MainForm::startClient (void)
3007                  stabilizeForm();                  stabilizeForm();
3008                  return false;                  return false;
3009          }          }
3010    
3011          // Just set receive timeout value, blindly.          // Just set receive timeout value, blindly.
3012          ::lscp_client_set_timeout(m_pClient, m_pOptions->iServerTimeout);          ::lscp_client_set_timeout(m_pClient, m_pOptions->iServerTimeout);
3013          appendMessages(          appendMessages(

Legend:
Removed from v.3049  
changed lines
  Added in v.3437

  ViewVC Help
Powered by ViewVC