/[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 980 by capela, Sun Dec 17 22:29:29 2006 UTC revision 1890 by capela, Tue Apr 28 09:06:43 2009 UTC
# Line 1  Line 1 
1  // qsamplerOptions.cpp  // qsamplerOptions.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2006, 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
6    
7     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License     modify it under the terms of the GNU General Public License
# Line 21  Line 22 
22    
23  #include "qsamplerAbout.h"  #include "qsamplerAbout.h"
24  #include "qsamplerOptions.h"  #include "qsamplerOptions.h"
25    #include "qsamplerMainForm.h"
26    
27  #include <qcombobox.h>  #include <QTextStream>
28    #include <QComboBox>
29    
30  #include <lscp/client.h>  #include <lscp/client.h>
31    
# Line 31  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)
46  {  {
47      // Begin master key group.          // Begin into general options group.
48      m_settings.beginGroup("/qsampler");          m_settings.beginGroup("/Options");
49    
50      // And go into general options group.          // Load server options...
51      m_settings.beginGroup("/Options");          m_settings.beginGroup("/Server");
52            sServerHost    = m_settings.value("/ServerHost", "localhost").toString();
53            iServerPort    = m_settings.value("/ServerPort", 8888).toInt();
54            #if defined(__APPLE__)  //  Toshi Nagata 20080105
55            //  TODO: Should this be a configure option?
56            iServerTimeout = m_settings.value("/ServerTimeout", 10000).toInt();
57            #else
58            iServerTimeout = m_settings.value("/ServerTimeout", 1000).toInt();
59            #endif
60            bServerStart   = m_settings.value("/ServerStart", true).toBool();
61            #if defined(__APPLE__)  //  Toshi Nagata 20080113
62            sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler.starter").toString();
63            #else
64            sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler").toString();
65            #endif
66            iStartDelay    = m_settings.value("/StartDelay", 3).toInt();
67            m_settings.endGroup();
68    
69            // Load logging options...
70            m_settings.beginGroup("/Logging");
71            bMessagesLog     = m_settings.value("/MessagesLog", false).toBool();
72            sMessagesLogPath = m_settings.value("/MessagesLogPath", "qsampler.log").toString();
73            m_settings.endGroup();
74    
75            // Load display options...
76            m_settings.beginGroup("/Display");
77            sDisplayFont     = m_settings.value("/DisplayFont").toString();
78            bDisplayEffect   = m_settings.value("/DisplayEffect", true).toBool();
79            bAutoRefresh     = m_settings.value("/AutoRefresh", true).toBool();
80            iAutoRefreshTime = m_settings.value("/AutoRefreshTime", 1000).toInt();
81            iMaxVolume       = m_settings.value("/MaxVolume", 100).toInt();
82            sMessagesFont    = m_settings.value("/MessagesFont").toString();
83            bMessagesLimit   = m_settings.value("/MessagesLimit", true).toBool();
84            iMessagesLimitLines = m_settings.value("/MessagesLimitLines", 1000).toInt();
85            bConfirmRemove   = m_settings.value("/ConfirmRemove", true).toBool();
86            bKeepOnTop       = m_settings.value("/KeepOnTop", true).toBool();
87            bStdoutCapture   = m_settings.value("/StdoutCapture", true).toBool();
88            bCompletePath    = m_settings.value("/CompletePath", true).toBool();
89            iMaxRecentFiles  = m_settings.value("/MaxRecentFiles", 5).toInt();
90            iBaseFontSize    = m_settings.value("/BaseFontSize", 0).toInt();
91    // if libgig provides a fast way to retrieve instrument names even for large
92    // .gig files, then we enable this feature by default
93    #if HAVE_LIBGIG_SETAUTOLOAD
94            bInstrumentNames = m_settings.value("/InstrumentNames", true).toBool();
95    #else
96            bInstrumentNames = m_settings.value("/InstrumentNames", false).toBool();
97    #endif
98            m_settings.endGroup();
99    
100      // Load server options...          // And go into view options group.
101      m_settings.beginGroup("/Server");          m_settings.beginGroup("/View");
102      sServerHost    = m_settings.readEntry("/ServerHost", "localhost");          bMenubar     = m_settings.value("/Menubar", true).toBool();
103      iServerPort    = m_settings.readNumEntry("/ServerPort", 8888);          bToolbar     = m_settings.value("/Toolbar", true).toBool();
104      iServerTimeout = m_settings.readNumEntry("/ServerTimeout", 1000);          bStatusbar   = m_settings.value("/Statusbar", true).toBool();
105      bServerStart   = m_settings.readBoolEntry("/ServerStart", true);          bAutoArrange = m_settings.value("/AutoArrange", true).toBool();
106      sServerCmdLine = m_settings.readEntry("/ServerCmdLine", "linuxsampler");          m_settings.endGroup();
107      iStartDelay    = m_settings.readNumEntry("/StartDelay", 3);  
108      m_settings.endGroup();          m_settings.endGroup(); // Options group.
109    
110      // Load display options...          // Recent file list.
111      m_settings.beginGroup("/Display");          recentFiles.clear();
112      sDisplayFont     = m_settings.readEntry("/DisplayFont", QString::null);          m_settings.beginGroup("/RecentFiles");
113      bDisplayEffect   = m_settings.readBoolEntry("/DisplayEffect", true);          for (int iFile = 0; iFile < iMaxRecentFiles; iFile++) {
114      bAutoRefresh     = m_settings.readBoolEntry("/AutoRefresh", true);                  QString sFilename = m_settings.value(
115      iAutoRefreshTime = m_settings.readNumEntry("/AutoRefreshTime", 1000);                          "/File" + QString::number(iFile + 1)).toString();
116      iMaxVolume       = m_settings.readNumEntry("/MaxVolume", 100);                  if (!sFilename.isEmpty())
117      sMessagesFont    = m_settings.readEntry("/MessagesFont", QString::null);                          recentFiles.append(sFilename);
118      bMessagesLimit   = m_settings.readBoolEntry("/MessagesLimit", true);          }
119      iMessagesLimitLines = m_settings.readNumEntry("/MessagesLimitLines", 1000);          m_settings.endGroup();
120      bConfirmRemove   = m_settings.readBoolEntry("/ConfirmRemove", true);  
121      bKeepOnTop       = m_settings.readBoolEntry("/KeepOnTop", true);          // Sampler fine tuning settings.
122      bStdoutCapture   = m_settings.readBoolEntry("/StdoutCapture", true);          m_settings.beginGroup("/Tuning");
123      bCompletePath    = m_settings.readBoolEntry("/CompletePath", true);          iMaxVoices  = m_settings.value("/MaxVoices",  -1).toInt();
124      iMaxRecentFiles  = m_settings.readNumEntry("/MaxRecentFiles", 5);          iMaxStreams = m_settings.value("/MaxStreams",  -1).toInt();
125      bInstrumentNames = m_settings.readBoolEntry("/InstrumentNames", false);          m_settings.endGroup();
126      m_settings.endGroup();  
127            // Last but not least, get the default directories.
128      // And go into view options group.          m_settings.beginGroup("/Default");
129      m_settings.beginGroup("/View");          sSessionDir    = m_settings.value("/SessionDir").toString();
130      bMenubar     = m_settings.readBoolEntry("/Menubar", true);          sInstrumentDir = m_settings.value("/InstrumentDir").toString();
131      bToolbar     = m_settings.readBoolEntry("/Toolbar", true);          sEngineName    = m_settings.value("/EngineName").toString();
132      bStatusbar   = m_settings.readBoolEntry("/Statusbar", true);          sAudioDriver   = m_settings.value("/AudioDriver").toString();
133      bAutoArrange = m_settings.readBoolEntry("/AutoArrange", true);          sMidiDriver    = m_settings.value("/MidiDriver").toString();
134      m_settings.endGroup();          iMidiMap       = m_settings.value("/MidiMap",  0).toInt();
135            iMidiBank      = m_settings.value("/MidiBank", 0).toInt();
136      m_settings.endGroup(); // Options group.          iMidiProg      = m_settings.value("/MidiProg", 0).toInt();
137            iVolume        = m_settings.value("/Volume", 100).toInt();
138      // Recent file list.          iLoadMode      = m_settings.value("/Loadmode", 0).toInt();
139      m_settings.beginGroup("/RecentFiles");          m_settings.endGroup();
     recentFiles.clear();  
     for (int i = 0; i < iMaxRecentFiles; i++) {  
         QString sFilename = m_settings.readEntry("/File" + QString::number(i + 1), QString::null);  
         if (!sFilename.isEmpty())  
             recentFiles.append(sFilename);  
     }  
     m_settings.endGroup();  
   
     // Last but not least, get the default directories.  
     m_settings.beginGroup("/Default");  
     sSessionDir    = m_settings.readEntry("/SessionDir", QString::null);  
     sInstrumentDir = m_settings.readEntry("/InstrumentDir", QString::null);  
     sEngineName    = m_settings.readEntry("/EngineName", QString::null);  
     sAudioDriver   = m_settings.readEntry("/AudioDriver", QString::null);  
     sMidiDriver    = m_settings.readEntry("/MidiDriver", QString::null);  
     iMidiMap       = m_settings.readNumEntry("/MidiMap", 0);  
     iMidiBank      = m_settings.readNumEntry("/MidiBank", 0);  
     iMidiProg      = m_settings.readNumEntry("/MidiProg", 0);  
     iVolume        = m_settings.readNumEntry("/Volume", 100);  
     iLoadMode      = m_settings.readNumEntry("/Loadmode", 0);  
     m_settings.endGroup();  
140  }  }
141    
142    
143  // Default Destructor.  // Default Destructor.
144  qsamplerOptions::~qsamplerOptions (void)  Options::~Options (void)
145  {  {
146      // Make program version available in the future.          // Make program version available in the future.
147      m_settings.beginGroup("/Program");          m_settings.beginGroup("/Program");
148      m_settings.writeEntry("/Version", QSAMPLER_VERSION);          m_settings.setValue("/Version", QSAMPLER_VERSION);
149      m_settings.endGroup();          m_settings.endGroup();
150    
151      // And go into general options group.          // And go into general options group.
152      m_settings.beginGroup("/Options");          m_settings.beginGroup("/Options");
153    
154      // Save server options.          // Save server options.
155      m_settings.beginGroup("/Server");          m_settings.beginGroup("/Server");
156      m_settings.writeEntry("/ServerHost", sServerHost);          m_settings.setValue("/ServerHost", sServerHost);
157      m_settings.writeEntry("/ServerPort", iServerPort);          m_settings.setValue("/ServerPort", iServerPort);
158      m_settings.writeEntry("/ServerTimeout", iServerTimeout);          m_settings.setValue("/ServerTimeout", iServerTimeout);
159      m_settings.writeEntry("/ServerStart", bServerStart);          m_settings.setValue("/ServerStart", bServerStart);
160      m_settings.writeEntry("/ServerCmdLine", sServerCmdLine);          m_settings.setValue("/ServerCmdLine", sServerCmdLine);
161      m_settings.writeEntry("/StartDelay", iStartDelay);          m_settings.setValue("/StartDelay", iStartDelay);
162      m_settings.endGroup();          m_settings.endGroup();
163    
164      // Save display options.          // Save logging options...
165      m_settings.beginGroup("/Display");          m_settings.beginGroup("/Logging");
166      m_settings.writeEntry("/DisplayFont", sDisplayFont);          m_settings.setValue("/MessagesLog", bMessagesLog);
167      m_settings.writeEntry("/DisplayEffect", bDisplayEffect);          m_settings.setValue("/MessagesLogPath", sMessagesLogPath);
168      m_settings.writeEntry("/AutoRefresh", bAutoRefresh);          m_settings.endGroup();
169      m_settings.writeEntry("/AutoRefreshTime", iAutoRefreshTime);  
170      m_settings.writeEntry("/MaxVolume", iMaxVolume);          // Save display options.
171      m_settings.writeEntry("/MessagesFont", sMessagesFont);          m_settings.beginGroup("/Display");
172      m_settings.writeEntry("/MessagesLimit", bMessagesLimit);          m_settings.setValue("/DisplayFont", sDisplayFont);
173      m_settings.writeEntry("/MessagesLimitLines", iMessagesLimitLines);          m_settings.setValue("/DisplayEffect", bDisplayEffect);
174      m_settings.writeEntry("/ConfirmRemove", bConfirmRemove);          m_settings.setValue("/AutoRefresh", bAutoRefresh);
175      m_settings.writeEntry("/KeepOnTop", bKeepOnTop);          m_settings.setValue("/AutoRefreshTime", iAutoRefreshTime);
176      m_settings.writeEntry("/StdoutCapture", bStdoutCapture);          m_settings.setValue("/MaxVolume", iMaxVolume);
177      m_settings.writeEntry("/CompletePath", bCompletePath);          m_settings.setValue("/MessagesFont", sMessagesFont);
178      m_settings.writeEntry("/MaxRecentFiles", iMaxRecentFiles);          m_settings.setValue("/MessagesLimit", bMessagesLimit);
179      m_settings.writeEntry("/InstrumentNames", bInstrumentNames);          m_settings.setValue("/MessagesLimitLines", iMessagesLimitLines);
180      m_settings.endGroup();          m_settings.setValue("/ConfirmRemove", bConfirmRemove);
181            m_settings.setValue("/KeepOnTop", bKeepOnTop);
182      // View options group.          m_settings.setValue("/StdoutCapture", bStdoutCapture);
183      m_settings.beginGroup("/View");          m_settings.setValue("/CompletePath", bCompletePath);
184      m_settings.writeEntry("/Menubar", bMenubar);          m_settings.setValue("/MaxRecentFiles", iMaxRecentFiles);
185      m_settings.writeEntry("/Toolbar", bToolbar);          m_settings.setValue("/BaseFontSize", iBaseFontSize);
186      m_settings.writeEntry("/Statusbar", bStatusbar);          m_settings.setValue("/InstrumentNames", bInstrumentNames);
187      m_settings.writeEntry("/AutoArrange", bAutoArrange);          m_settings.endGroup();
188      m_settings.endGroup();  
189            // View options group.
190      m_settings.endGroup(); // Options group.          m_settings.beginGroup("/View");
191            m_settings.setValue("/Menubar", bMenubar);
192      // Recent file list.          m_settings.setValue("/Toolbar", bToolbar);
193      m_settings.beginGroup("/RecentFiles");          m_settings.setValue("/Statusbar", bStatusbar);
194      for (int i = 0; i < (int) recentFiles.count(); i++)          m_settings.setValue("/AutoArrange", bAutoArrange);
195          m_settings.writeEntry("/File" + QString::number(i + 1), recentFiles[i]);          m_settings.endGroup();
196      m_settings.endGroup();  
197            m_settings.endGroup(); // Options group.
198      // Default directories.  
199      m_settings.beginGroup("/Default");          // Recent file list.
200      m_settings.writeEntry("/SessionDir", sSessionDir);          int iFile = 0;
201      m_settings.writeEntry("/InstrumentDir", sInstrumentDir);          m_settings.beginGroup("/RecentFiles");
202      m_settings.writeEntry("/EngineName", sEngineName);          QStringListIterator iter(recentFiles);
203      m_settings.writeEntry("/AudioDriver", sAudioDriver);          while (iter.hasNext())
204      m_settings.writeEntry("/MidiDriver", sMidiDriver);                  m_settings.setValue("/File" + QString::number(++iFile), iter.next());
205      m_settings.writeEntry("/MidiMap", iMidiMap);          m_settings.endGroup();
206      m_settings.writeEntry("/MidiBank", iMidiBank);  
207      m_settings.writeEntry("/MidiProg", iMidiProg);          // Sampler fine tuning settings.
208      m_settings.writeEntry("/Volume", iVolume);          m_settings.beginGroup("/Tuning");
209      m_settings.writeEntry("/Loadmode", iLoadMode);          if (iMaxVoices > 0)
210      m_settings.endGroup();                  m_settings.setValue("/MaxVoices", iMaxVoices);
211            if (iMaxStreams >= 0)
212      m_settings.endGroup();                  m_settings.setValue("/MaxStreams", iMaxStreams);
213            m_settings.endGroup();
214    
215            // Default directories.
216            m_settings.beginGroup("/Default");
217            m_settings.setValue("/SessionDir", sSessionDir);
218            m_settings.setValue("/InstrumentDir", sInstrumentDir);
219            m_settings.setValue("/EngineName", sEngineName);
220            m_settings.setValue("/AudioDriver", sAudioDriver);
221            m_settings.setValue("/MidiDriver", sMidiDriver);
222            m_settings.setValue("/MidiMap", iMidiMap);
223            m_settings.setValue("/MidiBank", iMidiBank);
224            m_settings.setValue("/MidiProg", iMidiProg);
225            m_settings.setValue("/Volume", iVolume);
226            m_settings.setValue("/Loadmode", iLoadMode);
227            m_settings.endGroup();
228  }  }
229    
230  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
231  // Settings accessor.  // Settings accessor.
232  //  //
233    
234  QSettings& qsamplerOptions::settings (void)  QSettings& Options::settings (void)
235  {  {
236      return m_settings;          return m_settings;
237  }  }
238    
239    
# Line 195  QSettings& qsamplerOptions::settings (vo Line 242  QSettings& qsamplerOptions::settings (vo
242  //  //
243    
244  // Help about command line options.  // Help about command line options.
245  void qsamplerOptions::print_usage ( const char *arg0 )  void Options::print_usage ( const QString& arg0 )
246  {  {
247      const QString sEot = "\n\t";          QTextStream out(stderr);
248      const QString sEol = "\n\n";          out << QObject::tr("Usage: %1 [options] [session-file]\n\n"
249                    QSAMPLER_TITLE " - " QSAMPLER_SUBTITLE "\n\n"
250      fprintf(stderr, QObject::tr("Usage") + ": %s [" + QObject::tr("options") + "] [" +                  "Options:\n\n"
251          QObject::tr("session-file") + "]" + sEol, arg0);                  "  -s, --start\n\tStart linuxsampler server locally\n\n"
252      fprintf(stderr, QSAMPLER_TITLE " - " + QObject::tr(QSAMPLER_SUBTITLE) + sEol);                  "  -h, --hostname\n\tSpecify linuxsampler server hostname\n\n"
253      fprintf(stderr, QObject::tr("Options") + ":" + sEol);                  "  -p, --port\n\tSpecify linuxsampler server port number\n\n"
254      fprintf(stderr, "  -s, --start" + sEot +                  "  -?, --help\n\tShow help about command line options\n\n"
255          QObject::tr("Start linuxsampler server locally") + sEol);                  "  -v, --version\n\tShow version information\n\n")
256      fprintf(stderr, "  -h, --hostname" + sEot +                  .arg(arg0);
         QObject::tr("Specify linuxsampler server hostname") + sEol);  
     fprintf(stderr, "  -p, --port" + sEot +  
         QObject::tr("Specify linuxsampler server port number") + sEol);  
     fprintf(stderr, "  -?, --help" + sEot +  
         QObject::tr("Show help about command line options") + sEol);  
     fprintf(stderr, "  -v, --version" + sEot +  
         QObject::tr("Show version information") + sEol);  
257  }  }
258    
259    
260  // Parse command line arguments into m_settings.  // Parse command line arguments into m_settings.
261  bool qsamplerOptions::parse_args ( int argc, char **argv )  bool Options::parse_args ( const QStringList& args )
262  {  {
263      const QString sEol = "\n\n";          QTextStream out(stderr);
264      int iCmdArgs = 0;          const QString sEol = "\n\n";
265            int iCmdArgs = 0;
266      for (int i = 1; i < argc; i++) {          int argc = args.count();
267    
268          if (iCmdArgs > 0) {          for (int i = 1; i < argc; i++) {
269              sSessionFile += " ";  
270              sSessionFile += argv[i];                  if (iCmdArgs > 0) {
271              iCmdArgs++;                          sSessionFile += " ";
272              continue;                          sSessionFile += args.at(i);
273          }                          iCmdArgs++;
274                            continue;
275          QString sArg = argv[i];                  }
276          QString sVal = QString::null;  
277          int iEqual = sArg.find("=");                  QString sArg = args.at(i);
278          if (iEqual >= 0) {                  QString sVal = QString::null;
279              sVal = sArg.right(sArg.length() - iEqual - 1);                  int iEqual = sArg.indexOf("=");
280              sArg = sArg.left(iEqual);                  if (iEqual >= 0) {
281          }                          sVal = sArg.right(sArg.length() - iEqual - 1);
282          else if (i < argc)                          sArg = sArg.left(iEqual);
283              sVal = argv[i + 1];                  }
284                    else if (i < argc - 1)
285          if (sArg == "-s" || sArg == "--start") {                          sVal = args.at(i + 1);
286              bServerStart = true;  
287          }                  if (sArg == "-s" || sArg == "--start") {
288          else if (sArg == "-h" || sArg == "--hostname") {                          bServerStart = true;
289              if (sVal.isNull()) {                  }
290                  fprintf(stderr, QObject::tr("Option -h requires an argument (hostname).") + sEol);                  else if (sArg == "-h" || sArg == "--hostname") {
291                  return false;                          if (sVal.isNull()) {
292              }                                  out << QObject::tr("Option -h requires an argument (hostname).") + sEol;
293              sServerHost = sVal;                                  return false;
294              if (iEqual < 0)                          }
295                  i++;                          sServerHost = sVal;
296          }                          if (iEqual < 0)
297          else if (sArg == "-p" || sArg == "--port") {                                  i++;
298              if (sVal.isNull()) {                  }
299                  fprintf(stderr, QObject::tr("Option -p requires an argument (port).") + sEol);                  else if (sArg == "-p" || sArg == "--port") {
300                  return false;                          if (sVal.isNull()) {
301              }                                  out << QObject::tr("Option -p requires an argument (port).") + sEol;
302              iServerPort = sVal.toInt();                                  return false;
303              if (iEqual < 0)                          }
304                  i++;                          iServerPort = sVal.toInt();
305          }                          if (iEqual < 0)
306          else if (sArg == "-?" || sArg == "--help") {                                  i++;
307              print_usage(argv[0]);                  }
308              return false;                  else if (sArg == "-?" || sArg == "--help") {
309          }                          print_usage(args.at(0));
310          else if (sArg == "-v" || sArg == "--version") {                          return false;
311              fprintf(stderr, "Qt: %s\n", qVersion());                  }
312                    else if (sArg == "-v" || sArg == "--version") {
313                            out << QObject::tr("Qt: %1\n").arg(qVersion());
314  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
315                          fprintf(stderr, "%s: %s\n", gig::libraryName().c_str(), gig::libraryVersion().c_str());                          out << QString("%1: %2\n")
316  #endif                                              .arg(gig::libraryName().c_str())
317              fprintf(stderr, "%s: %s\n", ::lscp_client_package(), ::lscp_client_version());                                  .arg(gig::libraryVersion().c_str());
318              fprintf(stderr, "qsampler: %s\n", QSAMPLER_VERSION);  #endif
319              return false;                          out << QString("%1: %2\n")
320          }                                  .arg(::lscp_client_package())
321          else {                                  .arg(::lscp_client_version());
322              // If we don't have one by now,                          out << QObject::tr(QSAMPLER_TITLE ": %1\n").arg(QSAMPLER_VERSION);
323              // this will be the startup sesion file...                          return false;
324              sSessionFile += sArg;                  }
325              iCmdArgs++;                  else {
326          }                          // If we don't have one by now,
327      }                          // this will be the startup sesion file...
328                            sSessionFile += sArg;
329                            iCmdArgs++;
330                    }
331            }
332    
333      // Alright with argument parsing.          // Alright with argument parsing.
334      return true;          return true;
335  }  }
336    
337    
338  //---------------------------------------------------------------------------  //---------------------------------------------------------------------------
339  // Widget geometry persistence helper methods.  // Widget geometry persistence helper methods.
340    
341  void qsamplerOptions::loadWidgetGeometry ( QWidget *pWidget )  void Options::loadWidgetGeometry ( QWidget *pWidget )
342  {  {
343      // Try to restore old form window positioning.          // Try to restore old form window positioning.
344      if (pWidget) {          if (pWidget) {
345          QPoint fpos;                  QPoint fpos;
346          QSize  fsize;                  QSize  fsize;
347          bool bVisible;                  bool bVisible;
348          m_settings.beginGroup("/Geometry/" + QString(pWidget->name()));                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());
349          fpos.setX(m_settings.readNumEntry("/x", -1));                  fpos.setX(m_settings.value("/x", -1).toInt());
350          fpos.setY(m_settings.readNumEntry("/y", -1));                  fpos.setY(m_settings.value("/y", -1).toInt());
351          fsize.setWidth(m_settings.readNumEntry("/width", -1));                  fsize.setWidth(m_settings.value("/width", -1).toInt());
352          fsize.setHeight(m_settings.readNumEntry("/height", -1));                  fsize.setHeight(m_settings.value("/height", -1).toInt());
353          bVisible = m_settings.readBoolEntry("/visible", false);                  bVisible = m_settings.value("/visible", false).toBool();
354          m_settings.endGroup();                  m_settings.endGroup();
355          if (fpos.x() > 0 && fpos.y() > 0)                  if (fpos.x() > 0 && fpos.y() > 0)
356              pWidget->move(fpos);                          pWidget->move(fpos);
357          if (fsize.width() > 0 && fsize.height() > 0)                  if (fsize.width() > 0 && fsize.height() > 0)
358              pWidget->resize(fsize);                          pWidget->resize(fsize);
359          else                  else
360              pWidget->adjustSize();                          pWidget->adjustSize();
361          if (bVisible)                  if (bVisible)
362              pWidget->show();                          pWidget->show();
363          else                  else
364              pWidget->hide();                          pWidget->hide();
365      }          }
366  }  }
367    
368    
369  void qsamplerOptions::saveWidgetGeometry ( QWidget *pWidget )  void Options::saveWidgetGeometry ( QWidget *pWidget )
370  {  {
371      // Try to save form window position...          // Try to save form window position...
372      // (due to X11 window managers ideossincrasies, we better          // (due to X11 window managers ideossincrasies, we better
373      // only save the form geometry while its up and visible)          // only save the form geometry while its up and visible)
374      if (pWidget) {          if (pWidget) {
375          m_settings.beginGroup("/Geometry/" + QString(pWidget->name()));                  m_settings.beginGroup("/Geometry/" + pWidget->objectName());
376          bool bVisible = pWidget->isVisible();                  bool bVisible = pWidget->isVisible();
377          if (bVisible) {                  const QPoint& fpos  = pWidget->pos();
378              QPoint fpos  = pWidget->pos();                  const QSize&  fsize = pWidget->size();
379              QSize  fsize = pWidget->size();                  m_settings.setValue("/x", fpos.x());
380              m_settings.writeEntry("/x", fpos.x());                  m_settings.setValue("/y", fpos.y());
381              m_settings.writeEntry("/y", fpos.y());                  m_settings.setValue("/width", fsize.width());
382              m_settings.writeEntry("/width", fsize.width());                  m_settings.setValue("/height", fsize.height());
383              m_settings.writeEntry("/height", fsize.height());                  m_settings.setValue("/visible", bVisible);
384          }                  m_settings.endGroup();
385          m_settings.writeEntry("/visible", bVisible);          }
         m_settings.endGroup();  
     }  
386  }  }
387    
388    
389  //---------------------------------------------------------------------------  //---------------------------------------------------------------------------
390  // Combo box history persistence helper implementation.  // Combo box history persistence helper implementation.
391    
392  void qsamplerOptions::add2ComboBoxHistory ( QComboBox *pComboBox, const QString& sNewText, int iLimit, int iIndex )  void Options::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit )
393  {  {
394      int iCount = pComboBox->count();          // Load combobox list from configuration settings file...
395      for (int i = 0; i < iCount; i++) {          m_settings.beginGroup("/History/" + pComboBox->objectName());
396          QString sText = pComboBox->text(i);  
397          if (sText == sNewText) {          if (m_settings.childKeys().count() > 0) {
398              pComboBox->removeItem(i);                  pComboBox->setUpdatesEnabled(false);
399              iCount--;                  pComboBox->setDuplicatesEnabled(false);
400              break;                  pComboBox->clear();
401          }                  for (int i = 0; i < iLimit; i++) {
402      }                          const QString& sText = m_settings.value(
403      while (iCount >= iLimit)                                  "/Item" + QString::number(i + 1)).toString();
404          pComboBox->removeItem(--iCount);                          if (sText.isEmpty())
405      pComboBox->insertItem(sNewText, iIndex);                                  break;
406                            pComboBox->addItem(sText);
407                    }
408                    pComboBox->setUpdatesEnabled(true);
409            }
410    
411            m_settings.endGroup();
412  }  }
413    
414    
415  void qsamplerOptions::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit )  void Options::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit )
416  {  {
417      pComboBox->setUpdatesEnabled(false);          // Add current text as latest item...
418      pComboBox->setDuplicatesEnabled(false);          const QString& sCurrentText = pComboBox->currentText();
419            int iCount = pComboBox->count();
420            for (int i = 0; i < iCount; i++) {
421                    const QString& sText = pComboBox->itemText(i);
422                    if (sText == sCurrentText) {
423                            pComboBox->removeItem(i);
424                            iCount--;
425                            break;
426                    }
427            }
428            while (iCount >= iLimit)
429                    pComboBox->removeItem(--iCount);
430            pComboBox->insertItem(0, sCurrentText);
431            iCount++;
432    
433            // Save combobox list to configuration settings file...
434            m_settings.beginGroup("/History/" + pComboBox->objectName());
435            for (int i = 0; i < iCount; i++) {
436                    const QString& sText = pComboBox->itemText(i);
437                    if (sText.isEmpty())
438                            break;
439                    m_settings.setValue("/Item" + QString::number(i + 1), sText);
440            }
441            m_settings.endGroup();
442    }
443    
444    int Options::getMaxVoices() {
445    #ifndef CONFIG_MAX_VOICES
446            return -1;
447    #else
448            if (iMaxVoices > 0) return iMaxVoices;
449            return getEffectiveMaxVoices();
450    #endif // CONFIG_MAX_VOICES
451    }
452    
453      m_settings.beginGroup("/History/" + QString(pComboBox->name()));  int Options::getEffectiveMaxVoices() {
454      for (int i = 0; i < iLimit; i++) {  #ifndef CONFIG_MAX_VOICES
455          QString sText = m_settings.readEntry("/Item" + QString::number(i + 1), QString::null);          return -1;
456          if (sText.isEmpty())  #else
457              break;          MainForm *pMainForm = MainForm::getInstance();
458          add2ComboBoxHistory(pComboBox, sText, iLimit);          if (!pMainForm || !pMainForm->client())
459      }                  return -1;
     m_settings.endGroup();  
460    
461      pComboBox->setUpdatesEnabled(true);          return ::lscp_get_voices(pMainForm->client());
462    #endif // CONFIG_MAX_VOICES
463  }  }
464    
465    void Options::setMaxVoices(int iMaxVoices) {
466    #ifdef CONFIG_MAX_VOICES
467            if (iMaxVoices < 1) return;
468    
469            MainForm *pMainForm = MainForm::getInstance();
470            if (!pMainForm || !pMainForm->client())
471                    return;
472    
473            lscp_status_t result =
474                    ::lscp_set_voices(pMainForm->client(), iMaxVoices);
475    
476            if (result != LSCP_OK) {
477                    pMainForm->appendMessagesClient("lscp_set_voices");
478                    return;
479            }
480    
481  void qsamplerOptions::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit )          this->iMaxVoices = iMaxVoices;
482  {  #endif // CONFIG_MAX_VOICES
483      add2ComboBoxHistory(pComboBox, pComboBox->currentText(), iLimit, 0);  }
484    
485    int Options::getMaxStreams() {
486    #ifndef CONFIG_MAX_VOICES
487            return -1;
488    #else
489            if (iMaxStreams > 0) return iMaxStreams;
490            return getEffectiveMaxStreams();
491    #endif // CONFIG_MAX_VOICES
492    }
493    
494    int Options::getEffectiveMaxStreams() {
495    #ifndef CONFIG_MAX_VOICES
496            return -1;
497    #else
498            MainForm *pMainForm = MainForm::getInstance();
499            if (!pMainForm || !pMainForm->client())
500                    return -1;
501    
502            return ::lscp_get_streams(pMainForm->client());
503    #endif // CONFIG_MAX_VOICES
504    }
505    
506    void Options::setMaxStreams(int iMaxStreams) {
507    #ifdef CONFIG_MAX_VOICES
508            if (iMaxStreams < 0) return;
509    
510            MainForm *pMainForm = MainForm::getInstance();
511            if (!pMainForm || !pMainForm->client())
512                    return;
513    
514            lscp_status_t result =
515                    ::lscp_set_streams(pMainForm->client(), iMaxStreams);
516    
517            if (result != LSCP_OK) {
518                    pMainForm->appendMessagesClient("lscp_set_streams");
519                    return;
520            }
521    
522            this->iMaxStreams = iMaxStreams;
523    #endif // CONFIG_MAX_VOICES
524    }
525    
526    void Options::sendFineTuningSettings() {
527            setMaxVoices(iMaxVoices);
528            setMaxStreams(iMaxStreams);
529    
530            MainForm *pMainForm = MainForm::getInstance();
531            if (!pMainForm || !pMainForm->client())
532                    return;
533    
534      m_settings.beginGroup("/History/" + QString(pComboBox->name()));          pMainForm->appendMessages(QObject::tr("Sent fine tuning settings."));
     for (int i = 0; i < iLimit && i < pComboBox->count(); i++) {  
         QString sText = pComboBox->text(i);  
         if (sText.isEmpty())  
             break;  
         m_settings.writeEntry("/Item" + QString::number(i + 1), sText);  
     }  
     m_settings.endGroup();  
535  }  }
536    
537    } // namespace QSampler
538    
539    
540  // end of qsamplerOptions.cpp  // end of qsamplerOptions.cpp

Legend:
Removed from v.980  
changed lines
  Added in v.1890

  ViewVC Help
Powered by ViewVC