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