1 |
// qsamplerOptions.cpp |
// qsamplerOptions.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2008, 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 |
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 |
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 |
|
|
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"); |
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" |
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 |
|
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("="); |
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 |
|
|
305 |
if (sArg == "-s" || sArg == "--start") { |
if (sArg == "-s" || sArg == "--start") { |
306 |
bServerStart = true; |
bServerStart = true; |
324 |
i++; |
i++; |
325 |
} |
} |
326 |
else if (sArg == "-?" || sArg == "--help") { |
else if (sArg == "-?" || sArg == "--help") { |
327 |
print_usage(argv[0]); |
print_usage(args.at(0)); |
328 |
return false; |
return false; |
329 |
} |
} |
330 |
else if (sArg == "-v" || sArg == "--version") { |
else if (sArg == "-v" || sArg == "--version") { |
459 |
m_settings.endGroup(); |
m_settings.endGroup(); |
460 |
} |
} |
461 |
|
|
462 |
|
int Options::getMaxVoices() { |
463 |
|
#ifndef CONFIG_MAX_VOICES |
464 |
|
return -1; |
465 |
|
#else |
466 |
|
if (iMaxVoices > 0) return iMaxVoices; |
467 |
|
return getEffectiveMaxVoices(); |
468 |
|
#endif // CONFIG_MAX_VOICES |
469 |
|
} |
470 |
|
|
471 |
|
int Options::getEffectiveMaxVoices() { |
472 |
|
#ifndef CONFIG_MAX_VOICES |
473 |
|
return -1; |
474 |
|
#else |
475 |
|
MainForm *pMainForm = MainForm::getInstance(); |
476 |
|
if (!pMainForm || !pMainForm->client()) |
477 |
|
return -1; |
478 |
|
|
479 |
|
return ::lscp_get_voices(pMainForm->client()); |
480 |
|
#endif // CONFIG_MAX_VOICES |
481 |
|
} |
482 |
|
|
483 |
|
void Options::setMaxVoices(int iMaxVoices) { |
484 |
|
#ifdef CONFIG_MAX_VOICES |
485 |
|
if (iMaxVoices < 1) return; |
486 |
|
|
487 |
|
MainForm *pMainForm = MainForm::getInstance(); |
488 |
|
if (!pMainForm || !pMainForm->client()) |
489 |
|
return; |
490 |
|
|
491 |
|
lscp_status_t result = |
492 |
|
::lscp_set_voices(pMainForm->client(), iMaxVoices); |
493 |
|
|
494 |
|
if (result != LSCP_OK) { |
495 |
|
pMainForm->appendMessagesClient("lscp_set_voices"); |
496 |
|
return; |
497 |
|
} |
498 |
|
|
499 |
|
this->iMaxVoices = iMaxVoices; |
500 |
|
#endif // CONFIG_MAX_VOICES |
501 |
|
} |
502 |
|
|
503 |
|
int Options::getMaxStreams() { |
504 |
|
#ifndef CONFIG_MAX_VOICES |
505 |
|
return -1; |
506 |
|
#else |
507 |
|
if (iMaxStreams > 0) return iMaxStreams; |
508 |
|
return getEffectiveMaxStreams(); |
509 |
|
#endif // CONFIG_MAX_VOICES |
510 |
|
} |
511 |
|
|
512 |
|
int Options::getEffectiveMaxStreams() { |
513 |
|
#ifndef CONFIG_MAX_VOICES |
514 |
|
return -1; |
515 |
|
#else |
516 |
|
MainForm *pMainForm = MainForm::getInstance(); |
517 |
|
if (!pMainForm || !pMainForm->client()) |
518 |
|
return -1; |
519 |
|
|
520 |
|
return ::lscp_get_streams(pMainForm->client()); |
521 |
|
#endif // CONFIG_MAX_VOICES |
522 |
|
} |
523 |
|
|
524 |
|
void Options::setMaxStreams(int iMaxStreams) { |
525 |
|
#ifdef CONFIG_MAX_VOICES |
526 |
|
if (iMaxStreams < 0) return; |
527 |
|
|
528 |
|
MainForm *pMainForm = MainForm::getInstance(); |
529 |
|
if (!pMainForm || !pMainForm->client()) |
530 |
|
return; |
531 |
|
|
532 |
|
lscp_status_t result = |
533 |
|
::lscp_set_streams(pMainForm->client(), iMaxStreams); |
534 |
|
|
535 |
|
if (result != LSCP_OK) { |
536 |
|
pMainForm->appendMessagesClient("lscp_set_streams"); |
537 |
|
return; |
538 |
|
} |
539 |
|
|
540 |
|
this->iMaxStreams = iMaxStreams; |
541 |
|
#endif // CONFIG_MAX_VOICES |
542 |
|
} |
543 |
|
|
544 |
|
void Options::sendFineTuningSettings() { |
545 |
|
setMaxVoices(iMaxVoices); |
546 |
|
setMaxStreams(iMaxStreams); |
547 |
|
|
548 |
|
MainForm *pMainForm = MainForm::getInstance(); |
549 |
|
if (!pMainForm || !pMainForm->client()) |
550 |
|
return; |
551 |
|
|
552 |
|
pMainForm->appendMessages(QObject::tr("Sent fine tuning settings.")); |
553 |
|
} |
554 |
|
|
555 |
} // namespace QSampler |
} // namespace QSampler |
556 |
|
|
557 |
|
|