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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1803 - (hide annotations) (download)
Sun Dec 7 13:58:16 2008 UTC (15 years, 3 months ago) by schoenebeck
File size: 16697 byte(s)
* Added support for runtime max. voices / disk streams setting (accessible
  from the "Options..." dialog). Those fine tuning settins will be saved
  in case the user modified them and automatically restored to the sampler
  when reconnecting to a sampler the next time.
* bumped version to 0.2.1.20

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

  ViewVC Help
Powered by ViewVC