1 |
// qsamplerOptions.cpp |
// qsamplerOptions.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2008, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2015, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
Copyright (C) 2007, Christian Schoenebeck |
Copyright (C) 2007,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 |
22 |
|
|
23 |
#include "qsamplerAbout.h" |
#include "qsamplerAbout.h" |
24 |
#include "qsamplerOptions.h" |
#include "qsamplerOptions.h" |
25 |
|
#include "qsamplerMainForm.h" |
26 |
|
|
27 |
#include <QTextStream> |
#include <QTextStream> |
28 |
#include <QComboBox> |
#include <QComboBox> |
44 |
Options::Options (void) |
Options::Options (void) |
45 |
: m_settings(QSAMPLER_DOMAIN, QSAMPLER_TITLE) |
: m_settings(QSAMPLER_DOMAIN, QSAMPLER_TITLE) |
46 |
{ |
{ |
47 |
|
loadOptions(); |
48 |
|
} |
49 |
|
|
50 |
|
|
51 |
|
// Default Destructor. |
52 |
|
Options::~Options (void) |
53 |
|
{ |
54 |
|
saveOptions(); |
55 |
|
} |
56 |
|
|
57 |
|
|
58 |
|
// Explicit load method. |
59 |
|
void Options::loadOptions (void) |
60 |
|
{ |
61 |
// Begin into general options group. |
// Begin into general options group. |
62 |
m_settings.beginGroup("/Options"); |
m_settings.beginGroup("/Options"); |
63 |
|
|
65 |
m_settings.beginGroup("/Server"); |
m_settings.beginGroup("/Server"); |
66 |
sServerHost = m_settings.value("/ServerHost", "localhost").toString(); |
sServerHost = m_settings.value("/ServerHost", "localhost").toString(); |
67 |
iServerPort = m_settings.value("/ServerPort", 8888).toInt(); |
iServerPort = m_settings.value("/ServerPort", 8888).toInt(); |
68 |
#if defined(__APPLE__) // Toshi Nagata 20080105 |
#if defined(__APPLE__) // Toshi Nagata 20080105 |
69 |
// TODO: Should this be a configure option? |
// TODO: Should this be a configure option? |
70 |
iServerTimeout = m_settings.value("/ServerTimeout", 10000).toInt(); |
iServerTimeout = m_settings.value("/ServerTimeout", 10000).toInt(); |
71 |
#else |
#else |
72 |
iServerTimeout = m_settings.value("/ServerTimeout", 1000).toInt(); |
iServerTimeout = m_settings.value("/ServerTimeout", 1000).toInt(); |
73 |
#endif |
#endif |
74 |
bServerStart = m_settings.value("/ServerStart", true).toBool(); |
bServerStart = m_settings.value("/ServerStart", true).toBool(); |
75 |
#if defined(__APPLE__) // Toshi Nagata 20080113 |
#if defined(__APPLE__) |
76 |
sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler.starter").toString(); |
sServerCmdLine = m_settings.value("/ServerCmdLine", "/usr/local/bin/linuxsampler").toString(); |
77 |
#else |
#else |
78 |
sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler").toString(); |
sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler").toString(); |
79 |
#endif |
#endif |
80 |
iStartDelay = m_settings.value("/StartDelay", 3).toInt(); |
iStartDelay = m_settings.value("/StartDelay", 3).toInt(); |
81 |
m_settings.endGroup(); |
m_settings.endGroup(); |
82 |
|
|
101 |
bStdoutCapture = m_settings.value("/StdoutCapture", true).toBool(); |
bStdoutCapture = m_settings.value("/StdoutCapture", true).toBool(); |
102 |
bCompletePath = m_settings.value("/CompletePath", true).toBool(); |
bCompletePath = m_settings.value("/CompletePath", true).toBool(); |
103 |
iMaxRecentFiles = m_settings.value("/MaxRecentFiles", 5).toInt(); |
iMaxRecentFiles = m_settings.value("/MaxRecentFiles", 5).toInt(); |
104 |
|
iBaseFontSize = m_settings.value("/BaseFontSize", 0).toInt(); |
105 |
// if libgig provides a fast way to retrieve instrument names even for large |
// if libgig provides a fast way to retrieve instrument names even for large |
106 |
// .gig files, then we enable this feature by default |
// .gig files, then we enable this feature by default |
107 |
#if HAVE_LIBGIG_SETAUTOLOAD |
#ifdef CONFIG_LIBGIG_SETAUTOLOAD |
108 |
bInstrumentNames = m_settings.value("/InstrumentNames", true).toBool(); |
bInstrumentNames = m_settings.value("/InstrumentNames", true).toBool(); |
109 |
#else |
#else |
110 |
bInstrumentNames = m_settings.value("/InstrumentNames", false).toBool(); |
bInstrumentNames = m_settings.value("/InstrumentNames", false).toBool(); |
132 |
} |
} |
133 |
m_settings.endGroup(); |
m_settings.endGroup(); |
134 |
|
|
135 |
|
// Sampler fine tuning settings. |
136 |
|
m_settings.beginGroup("/Tuning"); |
137 |
|
iMaxVoices = m_settings.value("/MaxVoices", -1).toInt(); |
138 |
|
iMaxStreams = m_settings.value("/MaxStreams", -1).toInt(); |
139 |
|
m_settings.endGroup(); |
140 |
|
|
141 |
// Last but not least, get the default directories. |
// Last but not least, get the default directories. |
142 |
m_settings.beginGroup("/Default"); |
m_settings.beginGroup("/Default"); |
143 |
sSessionDir = m_settings.value("/SessionDir").toString(); |
sSessionDir = m_settings.value("/SessionDir").toString(); |
154 |
} |
} |
155 |
|
|
156 |
|
|
157 |
// Default Destructor. |
// Explicit save method. |
158 |
Options::~Options (void) |
void Options::saveOptions (void) |
159 |
{ |
{ |
160 |
// Make program version available in the future. |
// Make program version available in the future. |
161 |
m_settings.beginGroup("/Program"); |
m_settings.beginGroup("/Program"); |
196 |
m_settings.setValue("/StdoutCapture", bStdoutCapture); |
m_settings.setValue("/StdoutCapture", bStdoutCapture); |
197 |
m_settings.setValue("/CompletePath", bCompletePath); |
m_settings.setValue("/CompletePath", bCompletePath); |
198 |
m_settings.setValue("/MaxRecentFiles", iMaxRecentFiles); |
m_settings.setValue("/MaxRecentFiles", iMaxRecentFiles); |
199 |
|
m_settings.setValue("/BaseFontSize", iBaseFontSize); |
200 |
m_settings.setValue("/InstrumentNames", bInstrumentNames); |
m_settings.setValue("/InstrumentNames", bInstrumentNames); |
201 |
m_settings.endGroup(); |
m_settings.endGroup(); |
202 |
|
|
218 |
m_settings.setValue("/File" + QString::number(++iFile), iter.next()); |
m_settings.setValue("/File" + QString::number(++iFile), iter.next()); |
219 |
m_settings.endGroup(); |
m_settings.endGroup(); |
220 |
|
|
221 |
|
// Sampler fine tuning settings. |
222 |
|
m_settings.beginGroup("/Tuning"); |
223 |
|
if (iMaxVoices > 0) |
224 |
|
m_settings.setValue("/MaxVoices", iMaxVoices); |
225 |
|
if (iMaxStreams >= 0) |
226 |
|
m_settings.setValue("/MaxStreams", iMaxStreams); |
227 |
|
m_settings.endGroup(); |
228 |
|
|
229 |
// Default directories. |
// Default directories. |
230 |
m_settings.beginGroup("/Default"); |
m_settings.beginGroup("/Default"); |
231 |
m_settings.setValue("/SessionDir", sSessionDir); |
m_settings.setValue("/SessionDir", sSessionDir); |
239 |
m_settings.setValue("/Volume", iVolume); |
m_settings.setValue("/Volume", iVolume); |
240 |
m_settings.setValue("/Loadmode", iLoadMode); |
m_settings.setValue("/Loadmode", iLoadMode); |
241 |
m_settings.endGroup(); |
m_settings.endGroup(); |
242 |
|
|
243 |
|
// Save/commit to disk. |
244 |
|
m_settings.sync(); |
245 |
} |
} |
246 |
|
|
247 |
|
|
248 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
249 |
// Settings accessor. |
// Settings accessor. |
250 |
// |
// |
260 |
// |
// |
261 |
|
|
262 |
// Help about command line options. |
// Help about command line options. |
263 |
void Options::print_usage ( const char *arg0 ) |
void Options::print_usage ( const QString& arg0 ) |
264 |
{ |
{ |
265 |
QTextStream out(stderr); |
QTextStream out(stderr); |
266 |
out << QObject::tr("Usage: %1 [options] [session-file]\n\n" |
out << QObject::tr("Usage: %1 [options] [session-file]\n\n" |
267 |
QSAMPLER_TITLE " - " QSAMPLER_SUBTITLE "\n\n" |
QSAMPLER_TITLE " - " QSAMPLER_SUBTITLE "\n\n" |
268 |
"Options:\n\n" |
"Options:\n\n" |
269 |
" -s, --start\n\tStart linuxsampler server locally\n\n" |
" -s, --start\n\tStart linuxsampler server locally\n\n" |
270 |
" -h, --hostname\n\tSpecify linuxsampler server hostname\n\n" |
" -h, --hostname\n\tSpecify linuxsampler server hostname (default = localhost)\n\n" |
271 |
" -p, --port\n\tSpecify linuxsampler server port number\n\n" |
" -p, --port\n\tSpecify linuxsampler server port number (default = 8888)\n\n" |
272 |
" -?, --help\n\tShow help about command line options\n\n" |
" -?, --help\n\tShow help about command line options\n\n" |
273 |
" -v, --version\n\tShow version information\n\n") |
" -v, --version\n\tShow version information\n\n") |
274 |
.arg(arg0); |
.arg(arg0); |
276 |
|
|
277 |
|
|
278 |
// Parse command line arguments into m_settings. |
// Parse command line arguments into m_settings. |
279 |
bool Options::parse_args ( int argc, char **argv ) |
bool Options::parse_args ( const QStringList& args ) |
280 |
{ |
{ |
281 |
QTextStream out(stderr); |
QTextStream out(stderr); |
282 |
const QString sEol = "\n\n"; |
const QString sEol = "\n\n"; |
283 |
int iCmdArgs = 0; |
int iCmdArgs = 0; |
284 |
|
const int argc = args.count(); |
285 |
|
|
286 |
for (int i = 1; i < argc; i++) { |
for (int i = 1; i < argc; i++) { |
287 |
|
|
288 |
if (iCmdArgs > 0) { |
if (iCmdArgs > 0) { |
289 |
sSessionFile += " "; |
sSessionFile += " "; |
290 |
sSessionFile += argv[i]; |
sSessionFile += args.at(i); |
291 |
iCmdArgs++; |
iCmdArgs++; |
292 |
continue; |
continue; |
293 |
} |
} |
294 |
|
|
295 |
QString sArg = argv[i]; |
QString sArg = args.at(i); |
296 |
QString sVal = QString::null; |
QString sVal = QString::null; |
297 |
int iEqual = sArg.indexOf("="); |
const int iEqual = sArg.indexOf("="); |
298 |
if (iEqual >= 0) { |
if (iEqual >= 0) { |
299 |
sVal = sArg.right(sArg.length() - iEqual - 1); |
sVal = sArg.right(sArg.length() - iEqual - 1); |
300 |
sArg = sArg.left(iEqual); |
sArg = sArg.left(iEqual); |
301 |
} |
} |
302 |
else if (i < argc) |
else if (i < argc - 1) { |
303 |
sVal = argv[i + 1]; |
sVal = args.at(i + 1); |
304 |
|
if (sVal[0] == '-') |
305 |
|
sVal.clear(); |
306 |
|
} |
307 |
|
|
308 |
if (sArg == "-s" || sArg == "--start") { |
if (sArg == "-s" || sArg == "--start") { |
309 |
bServerStart = true; |
bServerStart = true; |
310 |
} |
} |
311 |
else if (sArg == "-h" || sArg == "--hostname") { |
else if (sArg == "-h" || sArg == "--hostname") { |
312 |
if (sVal.isNull()) { |
if (sVal.isNull()) { |
313 |
out << QObject::tr("Option -h requires an argument (hostname).") + sEol; |
out << QObject::tr("Option -h requires an argument (host).") + sEol; |
314 |
return false; |
return false; |
315 |
} |
} |
316 |
sServerHost = sVal; |
sServerHost = sVal; |
327 |
i++; |
i++; |
328 |
} |
} |
329 |
else if (sArg == "-?" || sArg == "--help") { |
else if (sArg == "-?" || sArg == "--help") { |
330 |
print_usage(argv[0]); |
print_usage(args.at(0)); |
331 |
return false; |
return false; |
332 |
} |
} |
333 |
else if (sArg == "-v" || sArg == "--version") { |
else if (sArg == "-v" || sArg == "--version") { |
334 |
out << QObject::tr("Qt: %1\n").arg(qVersion()); |
out << QObject::tr("Qt: %1\n").arg(qVersion()); |
335 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
336 |
out << QString("%1: %2\n") |
out << QString("%1: %2\n") |
337 |
.arg(gig::libraryName().c_str()) |
.arg(gig::libraryName().c_str()) |
338 |
.arg(gig::libraryVersion().c_str()); |
.arg(gig::libraryVersion().c_str()); |
339 |
#endif |
#endif |
340 |
out << QString("%1: %2\n") |
out << QString("%1: %2\n") |
341 |
.arg(::lscp_client_package()) |
.arg(::lscp_client_package()) |
342 |
.arg(::lscp_client_version()); |
.arg(::lscp_client_version()); |
359 |
//--------------------------------------------------------------------------- |
//--------------------------------------------------------------------------- |
360 |
// Widget geometry persistence helper methods. |
// Widget geometry persistence helper methods. |
361 |
|
|
362 |
void Options::loadWidgetGeometry ( QWidget *pWidget ) |
void Options::loadWidgetGeometry ( QWidget *pWidget, bool bVisible ) |
363 |
{ |
{ |
364 |
// Try to restore old form window positioning. |
// Try to restore old form window positioning. |
365 |
if (pWidget) { |
if (pWidget) { |
366 |
QPoint fpos; |
QPoint wpos; |
367 |
QSize fsize; |
QSize wsize; |
|
bool bVisible; |
|
368 |
m_settings.beginGroup("/Geometry/" + pWidget->objectName()); |
m_settings.beginGroup("/Geometry/" + pWidget->objectName()); |
369 |
fpos.setX(m_settings.value("/x", -1).toInt()); |
wpos.setX(m_settings.value("/x", -1).toInt()); |
370 |
fpos.setY(m_settings.value("/y", -1).toInt()); |
wpos.setY(m_settings.value("/y", -1).toInt()); |
371 |
fsize.setWidth(m_settings.value("/width", -1).toInt()); |
wsize.setWidth(m_settings.value("/width", -1).toInt()); |
372 |
fsize.setHeight(m_settings.value("/height", -1).toInt()); |
wsize.setHeight(m_settings.value("/height", -1).toInt()); |
373 |
bVisible = m_settings.value("/visible", false).toBool(); |
if (!bVisible) bVisible = m_settings.value("/visible", false).toBool(); |
374 |
m_settings.endGroup(); |
m_settings.endGroup(); |
375 |
if (fpos.x() > 0 && fpos.y() > 0) |
if (wpos.x() > 0 && wpos.y() > 0) |
376 |
pWidget->move(fpos); |
pWidget->move(wpos); |
377 |
if (fsize.width() > 0 && fsize.height() > 0) |
if (wsize.width() > 0 && wsize.height() > 0) |
378 |
pWidget->resize(fsize); |
pWidget->resize(wsize); |
379 |
else |
// else |
380 |
pWidget->adjustSize(); |
// pWidget->adjustSize(); |
381 |
if (bVisible) |
if (bVisible) |
382 |
pWidget->show(); |
pWidget->show(); |
383 |
else |
// else |
384 |
pWidget->hide(); |
// pWidget->hide(); |
385 |
} |
} |
386 |
} |
} |
387 |
|
|
388 |
|
|
389 |
void Options::saveWidgetGeometry ( QWidget *pWidget ) |
void Options::saveWidgetGeometry ( QWidget *pWidget, bool bVisible ) |
390 |
{ |
{ |
391 |
// Try to save form window position... |
// Try to save form window position... |
392 |
// (due to X11 window managers ideossincrasies, we better |
// (due to X11 window managers ideossincrasies, we better |
393 |
// only save the form geometry while its up and visible) |
// only save the form geometry while its up and visible) |
394 |
if (pWidget) { |
if (pWidget) { |
395 |
m_settings.beginGroup("/Geometry/" + pWidget->objectName()); |
m_settings.beginGroup("/Geometry/" + pWidget->objectName()); |
396 |
bool bVisible = pWidget->isVisible(); |
const QPoint& wpos = pWidget->pos(); |
397 |
const QPoint& fpos = pWidget->pos(); |
const QSize& wsize = pWidget->size(); |
398 |
const QSize& fsize = pWidget->size(); |
if (!bVisible) bVisible = pWidget->isVisible(); |
399 |
m_settings.setValue("/x", fpos.x()); |
m_settings.setValue("/x", wpos.x()); |
400 |
m_settings.setValue("/y", fpos.y()); |
m_settings.setValue("/y", wpos.y()); |
401 |
m_settings.setValue("/width", fsize.width()); |
m_settings.setValue("/width", wsize.width()); |
402 |
m_settings.setValue("/height", fsize.height()); |
m_settings.setValue("/height", wsize.height()); |
403 |
m_settings.setValue("/visible", bVisible); |
m_settings.setValue("/visible", bVisible); |
404 |
m_settings.endGroup(); |
m_settings.endGroup(); |
405 |
} |
} |
461 |
m_settings.endGroup(); |
m_settings.endGroup(); |
462 |
} |
} |
463 |
|
|
464 |
|
int Options::getMaxVoices() { |
465 |
|
#ifndef CONFIG_MAX_VOICES |
466 |
|
return -1; |
467 |
|
#else |
468 |
|
if (iMaxVoices > 0) return iMaxVoices; |
469 |
|
return getEffectiveMaxVoices(); |
470 |
|
#endif // CONFIG_MAX_VOICES |
471 |
|
} |
472 |
|
|
473 |
|
int Options::getEffectiveMaxVoices() { |
474 |
|
#ifndef CONFIG_MAX_VOICES |
475 |
|
return -1; |
476 |
|
#else |
477 |
|
MainForm *pMainForm = MainForm::getInstance(); |
478 |
|
if (!pMainForm || !pMainForm->client()) |
479 |
|
return -1; |
480 |
|
|
481 |
|
return ::lscp_get_voices(pMainForm->client()); |
482 |
|
#endif // CONFIG_MAX_VOICES |
483 |
|
} |
484 |
|
|
485 |
|
void Options::setMaxVoices(int iMaxVoices) { |
486 |
|
#ifdef CONFIG_MAX_VOICES |
487 |
|
if (iMaxVoices < 1) return; |
488 |
|
|
489 |
|
MainForm *pMainForm = MainForm::getInstance(); |
490 |
|
if (!pMainForm || !pMainForm->client()) |
491 |
|
return; |
492 |
|
|
493 |
|
lscp_status_t result = |
494 |
|
::lscp_set_voices(pMainForm->client(), iMaxVoices); |
495 |
|
|
496 |
|
if (result != LSCP_OK) { |
497 |
|
pMainForm->appendMessagesClient("lscp_set_voices"); |
498 |
|
return; |
499 |
|
} |
500 |
|
|
501 |
|
this->iMaxVoices = iMaxVoices; |
502 |
|
#endif // CONFIG_MAX_VOICES |
503 |
|
} |
504 |
|
|
505 |
|
int Options::getMaxStreams() { |
506 |
|
#ifndef CONFIG_MAX_VOICES |
507 |
|
return -1; |
508 |
|
#else |
509 |
|
if (iMaxStreams > 0) return iMaxStreams; |
510 |
|
return getEffectiveMaxStreams(); |
511 |
|
#endif // CONFIG_MAX_VOICES |
512 |
|
} |
513 |
|
|
514 |
|
int Options::getEffectiveMaxStreams() { |
515 |
|
#ifndef CONFIG_MAX_VOICES |
516 |
|
return -1; |
517 |
|
#else |
518 |
|
MainForm *pMainForm = MainForm::getInstance(); |
519 |
|
if (!pMainForm || !pMainForm->client()) |
520 |
|
return -1; |
521 |
|
|
522 |
|
return ::lscp_get_streams(pMainForm->client()); |
523 |
|
#endif // CONFIG_MAX_VOICES |
524 |
|
} |
525 |
|
|
526 |
|
void Options::setMaxStreams(int iMaxStreams) { |
527 |
|
#ifdef CONFIG_MAX_VOICES |
528 |
|
if (iMaxStreams < 0) return; |
529 |
|
|
530 |
|
MainForm *pMainForm = MainForm::getInstance(); |
531 |
|
if (!pMainForm || !pMainForm->client()) |
532 |
|
return; |
533 |
|
|
534 |
|
lscp_status_t result = |
535 |
|
::lscp_set_streams(pMainForm->client(), iMaxStreams); |
536 |
|
|
537 |
|
if (result != LSCP_OK) { |
538 |
|
pMainForm->appendMessagesClient("lscp_set_streams"); |
539 |
|
return; |
540 |
|
} |
541 |
|
|
542 |
|
this->iMaxStreams = iMaxStreams; |
543 |
|
#endif // CONFIG_MAX_VOICES |
544 |
|
} |
545 |
|
|
546 |
|
void Options::sendFineTuningSettings() { |
547 |
|
setMaxVoices(iMaxVoices); |
548 |
|
setMaxStreams(iMaxStreams); |
549 |
|
|
550 |
|
MainForm *pMainForm = MainForm::getInstance(); |
551 |
|
if (!pMainForm || !pMainForm->client()) |
552 |
|
return; |
553 |
|
|
554 |
|
pMainForm->appendMessages(QObject::tr("Sent fine tuning settings.")); |
555 |
|
} |
556 |
|
|
557 |
} // namespace QSampler |
} // namespace QSampler |
558 |
|
|
559 |
|
|