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