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

Legend:
Removed from v.1499  
changed lines
  Added in v.1749

  ViewVC Help
Powered by ViewVC