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

Legend:
Removed from v.267  
changed lines
  Added in v.3558

  ViewVC Help
Powered by ViewVC