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