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

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

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

revision 1527 by schoenebeck, Mon Nov 26 16:00:21 2007 UTC revision 2028 by capela, Wed Nov 4 18:59:57 2009 UTC
# Line 1  Line 1 
1  // qsamplerOptions.cpp  // qsamplerOptions.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2009, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007, Christian Schoenebeck     Copyright (C) 2007, 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 22  Line 22 
22    
23  #include "qsamplerAbout.h"  #include "qsamplerAbout.h"
24  #include "qsamplerOptions.h"  #include "qsamplerOptions.h"
25    #include "qsamplerMainForm.h"
26    
27  #include <QTextStream>  #include <QTextStream>
28  #include <QComboBox>  #include <QComboBox>
# Line 33  Line 34 
34  #endif  #endif
35    
36    
37    namespace QSampler {
38    
39  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
40  // qsamplerOptions - Prototype settings structure.  // QSampler::Options - Prototype settings structure.
41  //  //
42    
43  // Constructor.  // Constructor.
44  qsamplerOptions::qsamplerOptions (void)  Options::Options (void)
45          : m_settings(QSAMPLER_DOMAIN, QSAMPLER_TITLE)          : m_settings(QSAMPLER_DOMAIN, QSAMPLER_TITLE)
46  {  {
47            loadOptions();
48    }
49    
50    
51    // Default Destructor.
52    Options::~Options (void)
53    {
54            saveOptions();
55    }
56    
57    
58    // Explicit load method.
59    void Options::loadOptions (void)
60    {
61          // Begin into general options group.          // Begin into general options group.
62          m_settings.beginGroup("/Options");          m_settings.beginGroup("/Options");
63    
# Line 48  qsamplerOptions::qsamplerOptions (void) Line 65  qsamplerOptions::qsamplerOptions (void)
65          m_settings.beginGroup("/Server");          m_settings.beginGroup("/Server");
66          sServerHost    = m_settings.value("/ServerHost", "localhost").toString();          sServerHost    = m_settings.value("/ServerHost", "localhost").toString();
67          iServerPort    = m_settings.value("/ServerPort", 8888).toInt();          iServerPort    = m_settings.value("/ServerPort", 8888).toInt();
68            #if defined(__APPLE__)  //  Toshi Nagata 20080105
69            //  TODO: Should this be a configure option?
70            iServerTimeout = m_settings.value("/ServerTimeout", 10000).toInt();
71            #else
72          iServerTimeout = m_settings.value("/ServerTimeout", 1000).toInt();          iServerTimeout = m_settings.value("/ServerTimeout", 1000).toInt();
73            #endif
74          bServerStart   = m_settings.value("/ServerStart", true).toBool();          bServerStart   = m_settings.value("/ServerStart", true).toBool();
75            #if defined(__APPLE__)  //  Toshi Nagata 20080113
76            sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler.starter").toString();
77            #else
78          sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler").toString();          sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler").toString();
79            #endif
80          iStartDelay    = m_settings.value("/StartDelay", 3).toInt();          iStartDelay    = m_settings.value("/StartDelay", 3).toInt();
81          m_settings.endGroup();          m_settings.endGroup();
82    
83            // Load logging options...
84            m_settings.beginGroup("/Logging");
85            bMessagesLog     = m_settings.value("/MessagesLog", false).toBool();
86            sMessagesLogPath = m_settings.value("/MessagesLogPath", "qsampler.log").toString();
87            m_settings.endGroup();
88    
89          // Load display options...          // Load display options...
90          m_settings.beginGroup("/Display");          m_settings.beginGroup("/Display");
91          sDisplayFont     = m_settings.value("/DisplayFont").toString();          sDisplayFont     = m_settings.value("/DisplayFont").toString();
# Line 69  qsamplerOptions::qsamplerOptions (void) Line 101  qsamplerOptions::qsamplerOptions (void)
101          bStdoutCapture   = m_settings.value("/StdoutCapture", true).toBool();          bStdoutCapture   = m_settings.value("/StdoutCapture", true).toBool();
102          bCompletePath    = m_settings.value("/CompletePath", true).toBool();          bCompletePath    = m_settings.value("/CompletePath", true).toBool();
103          iMaxRecentFiles  = m_settings.value("/MaxRecentFiles", 5).toInt();          iMaxRecentFiles  = m_settings.value("/MaxRecentFiles", 5).toInt();
104            iBaseFontSize    = m_settings.value("/BaseFontSize", 0).toInt();
105  // if libgig provides a fast way to retrieve instrument names even for large  // if libgig provides a fast way to retrieve instrument names even for large
106  // .gig files, then we enable this feature by default  // .gig files, then we enable this feature by default
107  #if HAVE_LIBGIG_SETAUTOLOAD  #if HAVE_LIBGIG_SETAUTOLOAD
# Line 99  qsamplerOptions::qsamplerOptions (void) Line 132  qsamplerOptions::qsamplerOptions (void)
132          }          }
133          m_settings.endGroup();          m_settings.endGroup();
134    
135            // Sampler fine tuning settings.
136            m_settings.beginGroup("/Tuning");
137            iMaxVoices  = m_settings.value("/MaxVoices",  -1).toInt();
138            iMaxStreams = m_settings.value("/MaxStreams",  -1).toInt();
139            m_settings.endGroup();
140    
141          // Last but not least, get the default directories.          // Last but not least, get the default directories.
142          m_settings.beginGroup("/Default");          m_settings.beginGroup("/Default");
143          sSessionDir    = m_settings.value("/SessionDir").toString();          sSessionDir    = m_settings.value("/SessionDir").toString();
# Line 115  qsamplerOptions::qsamplerOptions (void) Line 154  qsamplerOptions::qsamplerOptions (void)
154  }  }
155    
156    
157  // Default Destructor.  // Explicit save method.
158  qsamplerOptions::~qsamplerOptions (void)  void Options::saveOptions (void)
159  {  {
160          // Make program version available in the future.          // Make program version available in the future.
161          m_settings.beginGroup("/Program");          m_settings.beginGroup("/Program");
# Line 136  qsamplerOptions::~qsamplerOptions (void) Line 175  qsamplerOptions::~qsamplerOptions (void)
175          m_settings.setValue("/StartDelay", iStartDelay);          m_settings.setValue("/StartDelay", iStartDelay);
176          m_settings.endGroup();          m_settings.endGroup();
177    
178            // Save logging options...
179            m_settings.beginGroup("/Logging");
180            m_settings.setValue("/MessagesLog", bMessagesLog);
181            m_settings.setValue("/MessagesLogPath", sMessagesLogPath);
182            m_settings.endGroup();
183    
184          // Save display options.          // Save display options.
185          m_settings.beginGroup("/Display");          m_settings.beginGroup("/Display");
186          m_settings.setValue("/DisplayFont", sDisplayFont);          m_settings.setValue("/DisplayFont", sDisplayFont);
# Line 151  qsamplerOptions::~qsamplerOptions (void) Line 196  qsamplerOptions::~qsamplerOptions (void)
196          m_settings.setValue("/StdoutCapture", bStdoutCapture);          m_settings.setValue("/StdoutCapture", bStdoutCapture);
197          m_settings.setValue("/CompletePath", bCompletePath);          m_settings.setValue("/CompletePath", bCompletePath);
198          m_settings.setValue("/MaxRecentFiles", iMaxRecentFiles);          m_settings.setValue("/MaxRecentFiles", iMaxRecentFiles);
199            m_settings.setValue("/BaseFontSize", iBaseFontSize);
200          m_settings.setValue("/InstrumentNames", bInstrumentNames);          m_settings.setValue("/InstrumentNames", bInstrumentNames);
201          m_settings.endGroup();          m_settings.endGroup();
202    
# Line 172  qsamplerOptions::~qsamplerOptions (void) Line 218  qsamplerOptions::~qsamplerOptions (void)
218                  m_settings.setValue("/File" + QString::number(++iFile), iter.next());                  m_settings.setValue("/File" + QString::number(++iFile), iter.next());
219          m_settings.endGroup();          m_settings.endGroup();
220    
221            // Sampler fine tuning settings.
222            m_settings.beginGroup("/Tuning");
223            if (iMaxVoices > 0)
224                    m_settings.setValue("/MaxVoices", iMaxVoices);
225            if (iMaxStreams >= 0)
226                    m_settings.setValue("/MaxStreams", iMaxStreams);
227            m_settings.endGroup();
228    
229          // Default directories.          // Default directories.
230          m_settings.beginGroup("/Default");          m_settings.beginGroup("/Default");
231          m_settings.setValue("/SessionDir", sSessionDir);          m_settings.setValue("/SessionDir", sSessionDir);
# Line 185  qsamplerOptions::~qsamplerOptions (void) Line 239  qsamplerOptions::~qsamplerOptions (void)
239          m_settings.setValue("/Volume", iVolume);          m_settings.setValue("/Volume", iVolume);
240          m_settings.setValue("/Loadmode", iLoadMode);          m_settings.setValue("/Loadmode", iLoadMode);
241          m_settings.endGroup();          m_settings.endGroup();
242    
243            // Save/commit to disk.
244            m_settings.sync();
245  }  }
246    
247    
248  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
249  // Settings accessor.  // Settings accessor.
250  //  //
251    
252  QSettings& qsamplerOptions::settings (void)  QSettings& Options::settings (void)
253  {  {
254          return m_settings;          return m_settings;
255  }  }
# Line 202  QSettings& qsamplerOptions::settings (vo Line 260  QSettings& qsamplerOptions::settings (vo
260  //  //
261    
262  // Help about command line options.  // Help about command line options.
263  void qsamplerOptions::print_usage ( const char *arg0 )  void Options::print_usage ( const QString& arg0 )
264  {  {
265          QTextStream out(stderr);          QTextStream out(stderr);
266          out << QObject::tr("Usage: %1 [options] [session-file]\n\n"          out << QObject::tr("Usage: %1 [options] [session-file]\n\n"
# Line 218  void qsamplerOptions::print_usage ( cons Line 276  void qsamplerOptions::print_usage ( cons
276    
277    
278  // Parse command line arguments into m_settings.  // Parse command line arguments into m_settings.
279  bool qsamplerOptions::parse_args ( int argc, char **argv )  bool Options::parse_args ( const QStringList& args )
280  {  {
281          QTextStream out(stderr);          QTextStream out(stderr);
282          const QString sEol = "\n\n";          const QString sEol = "\n\n";
283          int iCmdArgs = 0;          int iCmdArgs = 0;
284            int argc = args.count();
285    
286          for (int i = 1; i < argc; i++) {          for (int i = 1; i < argc; i++) {
287    
288                  if (iCmdArgs > 0) {                  if (iCmdArgs > 0) {
289                          sSessionFile += " ";                          sSessionFile += " ";
290                          sSessionFile += argv[i];                          sSessionFile += args.at(i);
291                          iCmdArgs++;                          iCmdArgs++;
292                          continue;                          continue;
293                  }                  }
294    
295                  QString sArg = argv[i];                  QString sArg = args.at(i);
296                  QString sVal = QString::null;                  QString sVal = QString::null;
297                  int iEqual = sArg.indexOf("=");                  int iEqual = sArg.indexOf("=");
298                  if (iEqual >= 0) {                  if (iEqual >= 0) {
299                          sVal = sArg.right(sArg.length() - iEqual - 1);                          sVal = sArg.right(sArg.length() - iEqual - 1);
300                          sArg = sArg.left(iEqual);                          sArg = sArg.left(iEqual);
301                  }                  }
302                  else if (i < argc)                  else if (i < argc - 1)
303                          sVal = argv[i + 1];                          sVal = args.at(i + 1);
304    
305                  if (sArg == "-s" || sArg == "--start") {                  if (sArg == "-s" || sArg == "--start") {
306                          bServerStart = true;                          bServerStart = true;
# Line 265  bool qsamplerOptions::parse_args ( int a Line 324  bool qsamplerOptions::parse_args ( int a
324                                  i++;                                  i++;
325                  }                  }
326                  else if (sArg == "-?" || sArg == "--help") {                  else if (sArg == "-?" || sArg == "--help") {
327                          print_usage(argv[0]);                          print_usage(args.at(0));
328                          return false;                          return false;
329                  }                  }
330                  else if (sArg == "-v" || sArg == "--version") {                  else if (sArg == "-v" || sArg == "--version") {
# Line 297  bool qsamplerOptions::parse_args ( int a Line 356  bool qsamplerOptions::parse_args ( int a
356  //---------------------------------------------------------------------------  //---------------------------------------------------------------------------
357  // Widget geometry persistence helper methods.  // Widget geometry persistence helper methods.
358    
359  void qsamplerOptions::loadWidgetGeometry ( QWidget *pWidget )  void Options::loadWidgetGeometry ( QWidget *pWidget )
360  {  {
361          // Try to restore old form window positioning.          // Try to restore old form window positioning.
362          if (pWidget) {          if (pWidget) {
# Line 325  void qsamplerOptions::loadWidgetGeometry Line 384  void qsamplerOptions::loadWidgetGeometry
384  }  }
385    
386    
387  void qsamplerOptions::saveWidgetGeometry ( QWidget *pWidget )  void Options::saveWidgetGeometry ( QWidget *pWidget )
388  {  {
389          // Try to save form window position...          // Try to save form window position...
390          // (due to X11 window managers ideossincrasies, we better          // (due to X11 window managers ideossincrasies, we better
# Line 348  void qsamplerOptions::saveWidgetGeometry Line 407  void qsamplerOptions::saveWidgetGeometry
407  //---------------------------------------------------------------------------  //---------------------------------------------------------------------------
408  // Combo box history persistence helper implementation.  // Combo box history persistence helper implementation.
409    
410  void qsamplerOptions::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit )  void Options::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit )
411  {  {
412          // Load combobox list from configuration settings file...          // Load combobox list from configuration settings file...
413          m_settings.beginGroup("/History/" + pComboBox->objectName());          m_settings.beginGroup("/History/" + pComboBox->objectName());
# Line 371  void qsamplerOptions::loadComboBoxHistor Line 430  void qsamplerOptions::loadComboBoxHistor
430  }  }
431    
432    
433  void qsamplerOptions::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit )  void Options::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit )
434  {  {
435          // Add current text as latest item...          // Add current text as latest item...
436          const QString& sCurrentText = pComboBox->currentText();          const QString& sCurrentText = pComboBox->currentText();
# Line 400  void qsamplerOptions::saveComboBoxHistor Line 459  void qsamplerOptions::saveComboBoxHistor
459          m_settings.endGroup();          m_settings.endGroup();
460  }  }
461    
462    int Options::getMaxVoices() {
463    #ifndef CONFIG_MAX_VOICES
464            return -1;
465    #else
466            if (iMaxVoices > 0) return iMaxVoices;
467            return getEffectiveMaxVoices();
468    #endif // CONFIG_MAX_VOICES
469    }
470    
471    int Options::getEffectiveMaxVoices() {
472    #ifndef CONFIG_MAX_VOICES
473            return -1;
474    #else
475            MainForm *pMainForm = MainForm::getInstance();
476            if (!pMainForm || !pMainForm->client())
477                    return -1;
478    
479            return ::lscp_get_voices(pMainForm->client());
480    #endif // CONFIG_MAX_VOICES
481    }
482    
483    void Options::setMaxVoices(int iMaxVoices) {
484    #ifdef CONFIG_MAX_VOICES
485            if (iMaxVoices < 1) return;
486    
487            MainForm *pMainForm = MainForm::getInstance();
488            if (!pMainForm || !pMainForm->client())
489                    return;
490    
491            lscp_status_t result =
492                    ::lscp_set_voices(pMainForm->client(), iMaxVoices);
493    
494            if (result != LSCP_OK) {
495                    pMainForm->appendMessagesClient("lscp_set_voices");
496                    return;
497            }
498    
499            this->iMaxVoices = iMaxVoices;
500    #endif // CONFIG_MAX_VOICES
501    }
502    
503    int Options::getMaxStreams() {
504    #ifndef CONFIG_MAX_VOICES
505            return -1;
506    #else
507            if (iMaxStreams > 0) return iMaxStreams;
508            return getEffectiveMaxStreams();
509    #endif // CONFIG_MAX_VOICES
510    }
511    
512    int Options::getEffectiveMaxStreams() {
513    #ifndef CONFIG_MAX_VOICES
514            return -1;
515    #else
516            MainForm *pMainForm = MainForm::getInstance();
517            if (!pMainForm || !pMainForm->client())
518                    return -1;
519    
520            return ::lscp_get_streams(pMainForm->client());
521    #endif // CONFIG_MAX_VOICES
522    }
523    
524    void Options::setMaxStreams(int iMaxStreams) {
525    #ifdef CONFIG_MAX_VOICES
526            if (iMaxStreams < 0) return;
527    
528            MainForm *pMainForm = MainForm::getInstance();
529            if (!pMainForm || !pMainForm->client())
530                    return;
531    
532            lscp_status_t result =
533                    ::lscp_set_streams(pMainForm->client(), iMaxStreams);
534    
535            if (result != LSCP_OK) {
536                    pMainForm->appendMessagesClient("lscp_set_streams");
537                    return;
538            }
539    
540            this->iMaxStreams = iMaxStreams;
541    #endif // CONFIG_MAX_VOICES
542    }
543    
544    void Options::sendFineTuningSettings() {
545            setMaxVoices(iMaxVoices);
546            setMaxStreams(iMaxStreams);
547    
548            MainForm *pMainForm = MainForm::getInstance();
549            if (!pMainForm || !pMainForm->client())
550                    return;
551    
552            pMainForm->appendMessages(QObject::tr("Sent fine tuning settings."));
553    }
554    
555    } // namespace QSampler
556    
557    
558  // end of qsamplerOptions.cpp  // end of qsamplerOptions.cpp

Legend:
Removed from v.1527  
changed lines
  Added in v.2028

  ViewVC Help
Powered by ViewVC