/[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 1504 by capela, Wed Nov 21 11:46:40 2007 UTC revision 1738 by capela, Wed May 14 15:24:22 2008 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-2008, 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 33  Line 33 
33  #endif  #endif
34    
35    
36    namespace QSampler {
37    
38  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
39  // qsamplerOptions - Prototype settings structure.  // QSampler::Options - Prototype settings structure.
40  //  //
41    
42  // Constructor.  // Constructor.
43  qsamplerOptions::qsamplerOptions (void)  Options::Options (void)
44          : m_settings(QSAMPLER_DOMAIN, QSAMPLER_TITLE)          : m_settings(QSAMPLER_DOMAIN, QSAMPLER_TITLE)
45  {  {
46      // Begin into general options group.          // Begin into general options group.
47      m_settings.beginGroup("/Options");          m_settings.beginGroup("/Options");
48    
49            // Load server options...
50            m_settings.beginGroup("/Server");
51            sServerHost    = m_settings.value("/ServerHost", "localhost").toString();
52            iServerPort    = m_settings.value("/ServerPort", 8888).toInt();
53            #if defined(__APPLE__)  //  Toshi Nagata 20080105
54            //  TODO: Should this be a configure option?
55            iServerTimeout = m_settings.value("/ServerTimeout", 10000).toInt();
56            #else
57            iServerTimeout = m_settings.value("/ServerTimeout", 1000).toInt();
58            #endif
59            bServerStart   = m_settings.value("/ServerStart", true).toBool();
60            #if defined(__APPLE__)  //  Toshi Nagata 20080113
61            sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler.starter").toString();
62            #else
63            sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler").toString();
64            #endif
65            iStartDelay    = m_settings.value("/StartDelay", 3).toInt();
66            m_settings.endGroup();
67    
68            // Load logging options...
69            m_settings.beginGroup("/Logging");
70            bMessagesLog     = m_settings.value("/MessagesLog", false).toBool();
71            sMessagesLogPath = m_settings.value("/MessagesLogPath", "qsampler.log").toString();
72            m_settings.endGroup();
73    
74      // Load server options...          // Load display options...
75      m_settings.beginGroup("/Server");          m_settings.beginGroup("/Display");
76      sServerHost    = m_settings.value("/ServerHost", "localhost").toString();          sDisplayFont     = m_settings.value("/DisplayFont").toString();
77      iServerPort    = m_settings.value("/ServerPort", 8888).toInt();          bDisplayEffect   = m_settings.value("/DisplayEffect", true).toBool();
78      iServerTimeout = m_settings.value("/ServerTimeout", 1000).toInt();          bAutoRefresh     = m_settings.value("/AutoRefresh", true).toBool();
79      bServerStart   = m_settings.value("/ServerStart", true).toBool();          iAutoRefreshTime = m_settings.value("/AutoRefreshTime", 1000).toInt();
80      sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler").toString();          iMaxVolume       = m_settings.value("/MaxVolume", 100).toInt();
81      iStartDelay    = m_settings.value("/StartDelay", 3).toInt();          sMessagesFont    = m_settings.value("/MessagesFont").toString();
82      m_settings.endGroup();          bMessagesLimit   = m_settings.value("/MessagesLimit", true).toBool();
83            iMessagesLimitLines = m_settings.value("/MessagesLimitLines", 1000).toInt();
84      // Load display options...          bConfirmRemove   = m_settings.value("/ConfirmRemove", true).toBool();
85      m_settings.beginGroup("/Display");          bKeepOnTop       = m_settings.value("/KeepOnTop", true).toBool();
86      sDisplayFont     = m_settings.value("/DisplayFont").toString();          bStdoutCapture   = m_settings.value("/StdoutCapture", true).toBool();
87      bDisplayEffect   = m_settings.value("/DisplayEffect", true).toBool();          bCompletePath    = m_settings.value("/CompletePath", true).toBool();
88      bAutoRefresh     = m_settings.value("/AutoRefresh", true).toBool();          iMaxRecentFiles  = m_settings.value("/MaxRecentFiles", 5).toInt();
89      iAutoRefreshTime = m_settings.value("/AutoRefreshTime", 1000).toInt();  // if libgig provides a fast way to retrieve instrument names even for large
90      iMaxVolume       = m_settings.value("/MaxVolume", 100).toInt();  // .gig files, then we enable this feature by default
91      sMessagesFont    = m_settings.value("/MessagesFont").toString();  #if HAVE_LIBGIG_SETAUTOLOAD
92      bMessagesLimit   = m_settings.value("/MessagesLimit", true).toBool();          bInstrumentNames = m_settings.value("/InstrumentNames", true).toBool();
93      iMessagesLimitLines = m_settings.value("/MessagesLimitLines", 1000).toInt();  #else
94      bConfirmRemove   = m_settings.value("/ConfirmRemove", true).toBool();          bInstrumentNames = m_settings.value("/InstrumentNames", false).toBool();
95      bKeepOnTop       = m_settings.value("/KeepOnTop", true).toBool();  #endif
96      bStdoutCapture   = m_settings.value("/StdoutCapture", true).toBool();          m_settings.endGroup();
97      bCompletePath    = m_settings.value("/CompletePath", true).toBool();  
98      iMaxRecentFiles  = m_settings.value("/MaxRecentFiles", 5).toInt();          // And go into view options group.
99      bInstrumentNames = m_settings.value("/InstrumentNames", false).toBool();          m_settings.beginGroup("/View");
100      m_settings.endGroup();          bMenubar     = m_settings.value("/Menubar", true).toBool();
101            bToolbar     = m_settings.value("/Toolbar", true).toBool();
102      // And go into view options group.          bStatusbar   = m_settings.value("/Statusbar", true).toBool();
103      m_settings.beginGroup("/View");          bAutoArrange = m_settings.value("/AutoArrange", true).toBool();
104      bMenubar     = m_settings.value("/Menubar", true).toBool();          m_settings.endGroup();
     bToolbar     = m_settings.value("/Toolbar", true).toBool();  
     bStatusbar   = m_settings.value("/Statusbar", true).toBool();  
     bAutoArrange = m_settings.value("/AutoArrange", true).toBool();  
     m_settings.endGroup();  
105    
106      m_settings.endGroup(); // Options group.          m_settings.endGroup(); // Options group.
107    
108          // Recent file list.          // Recent file list.
109          recentFiles.clear();          recentFiles.clear();
# Line 93  qsamplerOptions::qsamplerOptions (void) Line 116  qsamplerOptions::qsamplerOptions (void)
116          }          }
117          m_settings.endGroup();          m_settings.endGroup();
118    
119      // Last but not least, get the default directories.          // Last but not least, get the default directories.
120      m_settings.beginGroup("/Default");          m_settings.beginGroup("/Default");
121      sSessionDir    = m_settings.value("/SessionDir").toString();          sSessionDir    = m_settings.value("/SessionDir").toString();
122      sInstrumentDir = m_settings.value("/InstrumentDir").toString();          sInstrumentDir = m_settings.value("/InstrumentDir").toString();
123      sEngineName    = m_settings.value("/EngineName").toString();          sEngineName    = m_settings.value("/EngineName").toString();
124      sAudioDriver   = m_settings.value("/AudioDriver").toString();          sAudioDriver   = m_settings.value("/AudioDriver").toString();
125      sMidiDriver    = m_settings.value("/MidiDriver").toString();          sMidiDriver    = m_settings.value("/MidiDriver").toString();
126      iMidiMap       = m_settings.value("/MidiMap",  0).toInt();          iMidiMap       = m_settings.value("/MidiMap",  0).toInt();
127      iMidiBank      = m_settings.value("/MidiBank", 0).toInt();          iMidiBank      = m_settings.value("/MidiBank", 0).toInt();
128      iMidiProg      = m_settings.value("/MidiProg", 0).toInt();          iMidiProg      = m_settings.value("/MidiProg", 0).toInt();
129      iVolume        = m_settings.value("/Volume", 100).toInt();          iVolume        = m_settings.value("/Volume", 100).toInt();
130      iLoadMode      = m_settings.value("/Loadmode", 0).toInt();          iLoadMode      = m_settings.value("/Loadmode", 0).toInt();
131      m_settings.endGroup();          m_settings.endGroup();
132  }  }
133    
134    
135  // Default Destructor.  // Default Destructor.
136  qsamplerOptions::~qsamplerOptions (void)  Options::~Options (void)
137  {  {
138      // Make program version available in the future.          // Make program version available in the future.
139      m_settings.beginGroup("/Program");          m_settings.beginGroup("/Program");
140      m_settings.setValue("/Version", QSAMPLER_VERSION);          m_settings.setValue("/Version", QSAMPLER_VERSION);
141      m_settings.endGroup();          m_settings.endGroup();
142    
143      // And go into general options group.          // And go into general options group.
144      m_settings.beginGroup("/Options");          m_settings.beginGroup("/Options");
145    
146      // Save server options.          // Save server options.
147      m_settings.beginGroup("/Server");          m_settings.beginGroup("/Server");
148      m_settings.setValue("/ServerHost", sServerHost);          m_settings.setValue("/ServerHost", sServerHost);
149      m_settings.setValue("/ServerPort", iServerPort);          m_settings.setValue("/ServerPort", iServerPort);
150      m_settings.setValue("/ServerTimeout", iServerTimeout);          m_settings.setValue("/ServerTimeout", iServerTimeout);
151      m_settings.setValue("/ServerStart", bServerStart);          m_settings.setValue("/ServerStart", bServerStart);
152      m_settings.setValue("/ServerCmdLine", sServerCmdLine);          m_settings.setValue("/ServerCmdLine", sServerCmdLine);
153      m_settings.setValue("/StartDelay", iStartDelay);          m_settings.setValue("/StartDelay", iStartDelay);
154      m_settings.endGroup();          m_settings.endGroup();
155    
156      // Save display options.          // Save logging options...
157      m_settings.beginGroup("/Display");          m_settings.beginGroup("/Logging");
158      m_settings.setValue("/DisplayFont", sDisplayFont);          m_settings.setValue("/MessagesLog", bMessagesLog);
159      m_settings.setValue("/DisplayEffect", bDisplayEffect);          m_settings.setValue("/MessagesLogPath", sMessagesLogPath);
160      m_settings.setValue("/AutoRefresh", bAutoRefresh);          m_settings.endGroup();
161      m_settings.setValue("/AutoRefreshTime", iAutoRefreshTime);  
162      m_settings.setValue("/MaxVolume", iMaxVolume);          // Save display options.
163      m_settings.setValue("/MessagesFont", sMessagesFont);          m_settings.beginGroup("/Display");
164      m_settings.setValue("/MessagesLimit", bMessagesLimit);          m_settings.setValue("/DisplayFont", sDisplayFont);
165      m_settings.setValue("/MessagesLimitLines", iMessagesLimitLines);          m_settings.setValue("/DisplayEffect", bDisplayEffect);
166      m_settings.setValue("/ConfirmRemove", bConfirmRemove);          m_settings.setValue("/AutoRefresh", bAutoRefresh);
167      m_settings.setValue("/KeepOnTop", bKeepOnTop);          m_settings.setValue("/AutoRefreshTime", iAutoRefreshTime);
168      m_settings.setValue("/StdoutCapture", bStdoutCapture);          m_settings.setValue("/MaxVolume", iMaxVolume);
169      m_settings.setValue("/CompletePath", bCompletePath);          m_settings.setValue("/MessagesFont", sMessagesFont);
170      m_settings.setValue("/MaxRecentFiles", iMaxRecentFiles);          m_settings.setValue("/MessagesLimit", bMessagesLimit);
171      m_settings.setValue("/InstrumentNames", bInstrumentNames);          m_settings.setValue("/MessagesLimitLines", iMessagesLimitLines);
172      m_settings.endGroup();          m_settings.setValue("/ConfirmRemove", bConfirmRemove);
173            m_settings.setValue("/KeepOnTop", bKeepOnTop);
174      // View options group.          m_settings.setValue("/StdoutCapture", bStdoutCapture);
175      m_settings.beginGroup("/View");          m_settings.setValue("/CompletePath", bCompletePath);
176      m_settings.setValue("/Menubar", bMenubar);          m_settings.setValue("/MaxRecentFiles", iMaxRecentFiles);
177      m_settings.setValue("/Toolbar", bToolbar);          m_settings.setValue("/InstrumentNames", bInstrumentNames);
178      m_settings.setValue("/Statusbar", bStatusbar);          m_settings.endGroup();
179      m_settings.setValue("/AutoArrange", bAutoArrange);  
180      m_settings.endGroup();          // View options group.
181            m_settings.beginGroup("/View");
182            m_settings.setValue("/Menubar", bMenubar);
183            m_settings.setValue("/Toolbar", bToolbar);
184            m_settings.setValue("/Statusbar", bStatusbar);
185            m_settings.setValue("/AutoArrange", bAutoArrange);
186            m_settings.endGroup();
187    
188      m_settings.endGroup(); // Options group.          m_settings.endGroup(); // Options group.
189    
190      // Recent file list.          // Recent file list.
191          int iFile = 0;          int iFile = 0;
192          m_settings.beginGroup("/RecentFiles");          m_settings.beginGroup("/RecentFiles");
193          QStringListIterator iter(recentFiles);          QStringListIterator iter(recentFiles);
# Line 166  qsamplerOptions::~qsamplerOptions (void) Line 195  qsamplerOptions::~qsamplerOptions (void)
195                  m_settings.setValue("/File" + QString::number(++iFile), iter.next());                  m_settings.setValue("/File" + QString::number(++iFile), iter.next());
196          m_settings.endGroup();          m_settings.endGroup();
197    
198      // Default directories.          // Default directories.
199      m_settings.beginGroup("/Default");          m_settings.beginGroup("/Default");
200      m_settings.setValue("/SessionDir", sSessionDir);          m_settings.setValue("/SessionDir", sSessionDir);
201      m_settings.setValue("/InstrumentDir", sInstrumentDir);          m_settings.setValue("/InstrumentDir", sInstrumentDir);
202      m_settings.setValue("/EngineName", sEngineName);          m_settings.setValue("/EngineName", sEngineName);
203      m_settings.setValue("/AudioDriver", sAudioDriver);          m_settings.setValue("/AudioDriver", sAudioDriver);
204      m_settings.setValue("/MidiDriver", sMidiDriver);          m_settings.setValue("/MidiDriver", sMidiDriver);
205      m_settings.setValue("/MidiMap", iMidiMap);          m_settings.setValue("/MidiMap", iMidiMap);
206      m_settings.setValue("/MidiBank", iMidiBank);          m_settings.setValue("/MidiBank", iMidiBank);
207      m_settings.setValue("/MidiProg", iMidiProg);          m_settings.setValue("/MidiProg", iMidiProg);
208      m_settings.setValue("/Volume", iVolume);          m_settings.setValue("/Volume", iVolume);
209      m_settings.setValue("/Loadmode", iLoadMode);          m_settings.setValue("/Loadmode", iLoadMode);
210      m_settings.endGroup();          m_settings.endGroup();
211  }  }
212    
213  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
214  // Settings accessor.  // Settings accessor.
215  //  //
216    
217  QSettings& qsamplerOptions::settings (void)  QSettings& Options::settings (void)
218  {  {
219      return m_settings;          return m_settings;
220  }  }
221    
222    
# Line 196  QSettings& qsamplerOptions::settings (vo Line 225  QSettings& qsamplerOptions::settings (vo
225  //  //
226    
227  // Help about command line options.  // Help about command line options.
228  void qsamplerOptions::print_usage ( const char *arg0 )  void Options::print_usage ( const char *arg0 )
229  {  {
230          QTextStream out(stderr);          QTextStream out(stderr);
231          out << QObject::tr("Usage: %1 [options] [session-file]\n\n"          out << QObject::tr("Usage: %1 [options] [session-file]\n\n"
# Line 212  void qsamplerOptions::print_usage ( cons Line 241  void qsamplerOptions::print_usage ( cons
241    
242    
243  // Parse command line arguments into m_settings.  // Parse command line arguments into m_settings.
244  bool qsamplerOptions::parse_args ( int argc, char **argv )  bool Options::parse_args ( int argc, char **argv )
245  {  {
246          QTextStream out(stderr);          QTextStream out(stderr);
247      const QString sEol = "\n\n";          const QString sEol = "\n\n";
248      int iCmdArgs = 0;          int iCmdArgs = 0;
249    
250      for (int i = 1; i < argc; i++) {          for (int i = 1; i < argc; i++) {
251    
252                    if (iCmdArgs > 0) {
253                            sSessionFile += " ";
254                            sSessionFile += argv[i];
255                            iCmdArgs++;
256                            continue;
257                    }
258    
259                    QString sArg = argv[i];
260                    QString sVal = QString::null;
261                    int iEqual = sArg.indexOf("=");
262                    if (iEqual >= 0) {
263                            sVal = sArg.right(sArg.length() - iEqual - 1);
264                            sArg = sArg.left(iEqual);
265                    }
266                    else if (i < argc)
267                            sVal = argv[i + 1];
268    
269          if (iCmdArgs > 0) {                  if (sArg == "-s" || sArg == "--start") {
270              sSessionFile += " ";                          bServerStart = true;
271              sSessionFile += argv[i];                  }
272              iCmdArgs++;                  else if (sArg == "-h" || sArg == "--hostname") {
273              continue;                          if (sVal.isNull()) {
274          }                                  out << QObject::tr("Option -h requires an argument (hostname).") + sEol;
275                                    return false;
276          QString sArg = argv[i];                          }
277          QString sVal = QString::null;                          sServerHost = sVal;
278          int iEqual = sArg.indexOf("=");                          if (iEqual < 0)
279          if (iEqual >= 0) {                                  i++;
280              sVal = sArg.right(sArg.length() - iEqual - 1);                  }
281              sArg = sArg.left(iEqual);                  else if (sArg == "-p" || sArg == "--port") {
282          }                          if (sVal.isNull()) {
283          else if (i < argc)                                  out << QObject::tr("Option -p requires an argument (port).") + sEol;
284              sVal = argv[i + 1];                                  return false;
285                            }
286          if (sArg == "-s" || sArg == "--start") {                          iServerPort = sVal.toInt();
287              bServerStart = true;                          if (iEqual < 0)
288          }                                  i++;
289          else if (sArg == "-h" || sArg == "--hostname") {                  }
290              if (sVal.isNull()) {                  else if (sArg == "-?" || sArg == "--help") {
291                  out << QObject::tr("Option -h requires an argument (hostname).") + sEol;                          print_usage(argv[0]);
292                  return false;                          return false;
293              }                  }
294              sServerHost = sVal;                  else if (sArg == "-v" || sArg == "--version") {
             if (iEqual < 0)  
                 i++;  
         }  
         else if (sArg == "-p" || sArg == "--port") {  
             if (sVal.isNull()) {  
                 out << QObject::tr("Option -p requires an argument (port).") + sEol;  
                 return false;  
             }  
             iServerPort = sVal.toInt();  
             if (iEqual < 0)  
                 i++;  
         }  
         else if (sArg == "-?" || sArg == "--help") {  
             print_usage(argv[0]);  
             return false;  
         }  
         else if (sArg == "-v" || sArg == "--version") {  
295                          out << QObject::tr("Qt: %1\n").arg(qVersion());                          out << QObject::tr("Qt: %1\n").arg(qVersion());
296  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
297                          out << QString("%1: %2\n")                          out << QString("%1: %2\n")
# Line 273  bool qsamplerOptions::parse_args ( int a Line 302  bool qsamplerOptions::parse_args ( int a
302                                  .arg(::lscp_client_package())                                  .arg(::lscp_client_package())
303                                  .arg(::lscp_client_version());                                  .arg(::lscp_client_version());
304                          out << QObject::tr(QSAMPLER_TITLE ": %1\n").arg(QSAMPLER_VERSION);                          out << QObject::tr(QSAMPLER_TITLE ": %1\n").arg(QSAMPLER_VERSION);
305              return false;                          return false;
306          }                  }
307          else {                  else {
308              // If we don't have one by now,                          // If we don't have one by now,
309              // this will be the startup sesion file...                          // this will be the startup sesion file...
310              sSessionFile += sArg;                          sSessionFile += sArg;
311              iCmdArgs++;                          iCmdArgs++;
312          }                  }
313      }          }
314    
315      // Alright with argument parsing.          // Alright with argument parsing.
316      return true;          return true;
317  }  }
318    
319    
320  //---------------------------------------------------------------------------  //---------------------------------------------------------------------------
321  // Widget geometry persistence helper methods.  // Widget geometry persistence helper methods.
322    
323  void qsamplerOptions::loadWidgetGeometry ( QWidget *pWidget )  void Options::loadWidgetGeometry ( QWidget *pWidget )
324  {  {
325          // Try to restore old form window positioning.          // Try to restore old form window positioning.
326          if (pWidget) {          if (pWidget) {
# Line 319  void qsamplerOptions::loadWidgetGeometry Line 348  void qsamplerOptions::loadWidgetGeometry
348  }  }
349    
350    
351  void qsamplerOptions::saveWidgetGeometry ( QWidget *pWidget )  void Options::saveWidgetGeometry ( QWidget *pWidget )
352  {  {
353          // Try to save form window position...          // Try to save form window position...
354          // (due to X11 window managers ideossincrasies, we better          // (due to X11 window managers ideossincrasies, we better
# Line 342  void qsamplerOptions::saveWidgetGeometry Line 371  void qsamplerOptions::saveWidgetGeometry
371  //---------------------------------------------------------------------------  //---------------------------------------------------------------------------
372  // Combo box history persistence helper implementation.  // Combo box history persistence helper implementation.
373    
374  void qsamplerOptions::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit )  void Options::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit )
375  {  {
376          // Load combobox list from configuration settings file...          // Load combobox list from configuration settings file...
377          m_settings.beginGroup("/History/" + pComboBox->objectName());          m_settings.beginGroup("/History/" + pComboBox->objectName());
# Line 365  void qsamplerOptions::loadComboBoxHistor Line 394  void qsamplerOptions::loadComboBoxHistor
394  }  }
395    
396    
397  void qsamplerOptions::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit )  void Options::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit )
398  {  {
399          // Add current text as latest item...          // Add current text as latest item...
400          const QString& sCurrentText = pComboBox->currentText();          const QString& sCurrentText = pComboBox->currentText();
# Line 394  void qsamplerOptions::saveComboBoxHistor Line 423  void qsamplerOptions::saveComboBoxHistor
423          m_settings.endGroup();          m_settings.endGroup();
424  }  }
425    
426    } // namespace QSampler
427    
428    
429  // end of qsamplerOptions.cpp  // end of qsamplerOptions.cpp

Legend:
Removed from v.1504  
changed lines
  Added in v.1738

  ViewVC Help
Powered by ViewVC