1 |
capela |
106 |
// qsamplerOptions.cpp |
2 |
|
|
// |
3 |
|
|
/**************************************************************************** |
4 |
capela |
4070 |
Copyright (C) 2004-2024, 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 |
4067 |
#include <QFileInfo> |
28 |
capela |
1499 |
#include <QTextStream> |
29 |
capela |
4067 |
|
30 |
capela |
1499 |
#include <QComboBox> |
31 |
capela |
106 |
|
32 |
capela |
4024 |
#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 |
capela |
3558 |
#include <QApplication> |
41 |
capela |
3796 |
|
42 |
|
|
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
43 |
capela |
3558 |
#include <QDesktopWidget> |
44 |
capela |
3796 |
#endif |
45 |
capela |
3558 |
|
46 |
capela |
106 |
|
47 |
capela |
1558 |
namespace QSampler { |
48 |
|
|
|
49 |
capela |
106 |
//------------------------------------------------------------------------- |
50 |
capela |
1558 |
// QSampler::Options - Prototype settings structure. |
51 |
capela |
106 |
// |
52 |
|
|
|
53 |
|
|
// Constructor. |
54 |
capela |
1558 |
Options::Options (void) |
55 |
capela |
1504 |
: m_settings(QSAMPLER_DOMAIN, QSAMPLER_TITLE) |
56 |
capela |
106 |
{ |
57 |
capela |
2028 |
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 |
capela |
1509 |
// Begin into general options group. |
72 |
|
|
m_settings.beginGroup("/Options"); |
73 |
capela |
106 |
|
74 |
capela |
1509 |
// 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 |
capela |
2642 |
#if defined(__APPLE__) // Toshi Nagata 20080105 |
79 |
nagata |
1643 |
// TODO: Should this be a configure option? |
80 |
|
|
iServerTimeout = m_settings.value("/ServerTimeout", 10000).toInt(); |
81 |
capela |
2642 |
#else |
82 |
capela |
1509 |
iServerTimeout = m_settings.value("/ServerTimeout", 1000).toInt(); |
83 |
capela |
2642 |
#endif |
84 |
capela |
1509 |
bServerStart = m_settings.value("/ServerStart", true).toBool(); |
85 |
schoenebeck |
2712 |
#if defined(__APPLE__) |
86 |
|
|
sServerCmdLine = m_settings.value("/ServerCmdLine", "/usr/local/bin/linuxsampler").toString(); |
87 |
capela |
2642 |
#else |
88 |
capela |
1509 |
sServerCmdLine = m_settings.value("/ServerCmdLine", "linuxsampler").toString(); |
89 |
capela |
2642 |
#endif |
90 |
capela |
1509 |
iStartDelay = m_settings.value("/StartDelay", 3).toInt(); |
91 |
|
|
m_settings.endGroup(); |
92 |
capela |
106 |
|
93 |
capela |
1738 |
// 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 |
capela |
1509 |
// 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 |
capela |
2722 |
bConfirmReset = m_settings.value("/ConfirmReset", true).toBool(); |
111 |
|
|
bConfirmRestart = m_settings.value("/ConfirmRestart", true).toBool(); |
112 |
|
|
bConfirmError = m_settings.value("/ConfirmError", true).toBool(); |
113 |
capela |
1509 |
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 |
capela |
1749 |
iBaseFontSize = m_settings.value("/BaseFontSize", 0).toInt(); |
118 |
schoenebeck |
1527 |
// if libgig provides a fast way to retrieve instrument names even for large |
119 |
|
|
// .gig files, then we enable this feature by default |
120 |
capela |
2646 |
#ifdef CONFIG_LIBGIG_SETAUTOLOAD |
121 |
schoenebeck |
1527 |
bInstrumentNames = m_settings.value("/InstrumentNames", true).toBool(); |
122 |
|
|
#else |
123 |
capela |
1509 |
bInstrumentNames = m_settings.value("/InstrumentNames", false).toBool(); |
124 |
schoenebeck |
1527 |
#endif |
125 |
capela |
1509 |
m_settings.endGroup(); |
126 |
capela |
106 |
|
127 |
capela |
3648 |
// 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 |
capela |
1509 |
// 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 |
capela |
106 |
|
141 |
capela |
1509 |
m_settings.endGroup(); // Options group. |
142 |
capela |
106 |
|
143 |
capela |
1499 |
// 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 |
capela |
106 |
|
154 |
schoenebeck |
1803 |
// 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 |
capela |
1509 |
// 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 |
capela |
106 |
} |
174 |
|
|
|
175 |
|
|
|
176 |
capela |
2028 |
// Explicit save method. |
177 |
|
|
void Options::saveOptions (void) |
178 |
capela |
106 |
{ |
179 |
capela |
1509 |
// Make program version available in the future. |
180 |
|
|
m_settings.beginGroup("/Program"); |
181 |
capela |
4070 |
m_settings.setValue("/Version", PROJECT_VERSION); |
182 |
capela |
1509 |
m_settings.endGroup(); |
183 |
capela |
106 |
|
184 |
capela |
1509 |
// And go into general options group. |
185 |
|
|
m_settings.beginGroup("/Options"); |
186 |
capela |
106 |
|
187 |
capela |
1509 |
// 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 |
capela |
106 |
|
197 |
capela |
1738 |
// 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 |
capela |
1509 |
// 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 |
capela |
2722 |
m_settings.setValue("/ConfirmReset", bConfirmReset); |
215 |
|
|
m_settings.setValue("/ConfirmRestart", bConfirmRestart); |
216 |
|
|
m_settings.setValue("/ConfirmError", bConfirmError); |
217 |
capela |
1509 |
m_settings.setValue("/KeepOnTop", bKeepOnTop); |
218 |
|
|
m_settings.setValue("/StdoutCapture", bStdoutCapture); |
219 |
|
|
m_settings.setValue("/CompletePath", bCompletePath); |
220 |
|
|
m_settings.setValue("/MaxRecentFiles", iMaxRecentFiles); |
221 |
capela |
1749 |
m_settings.setValue("/BaseFontSize", iBaseFontSize); |
222 |
capela |
1509 |
m_settings.setValue("/InstrumentNames", bInstrumentNames); |
223 |
|
|
m_settings.endGroup(); |
224 |
capela |
106 |
|
225 |
capela |
3648 |
// 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 |
capela |
1509 |
// 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 |
capela |
106 |
|
239 |
capela |
1509 |
m_settings.endGroup(); // Options group. |
240 |
capela |
106 |
|
241 |
capela |
1509 |
// Recent file list. |
242 |
capela |
1499 |
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 |
capela |
106 |
|
249 |
schoenebeck |
1803 |
// 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 |
capela |
1509 |
// 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 |
capela |
2028 |
|
271 |
|
|
// Save/commit to disk. |
272 |
|
|
m_settings.sync(); |
273 |
capela |
106 |
} |
274 |
|
|
|
275 |
capela |
2028 |
|
276 |
capela |
106 |
//------------------------------------------------------------------------- |
277 |
|
|
// Settings accessor. |
278 |
|
|
// |
279 |
|
|
|
280 |
capela |
1558 |
QSettings& Options::settings (void) |
281 |
capela |
106 |
{ |
282 |
capela |
1509 |
return m_settings; |
283 |
capela |
106 |
} |
284 |
|
|
|
285 |
|
|
|
286 |
|
|
//------------------------------------------------------------------------- |
287 |
|
|
// Command-line argument stuff. |
288 |
|
|
// |
289 |
|
|
|
290 |
capela |
4024 |
#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 |
capela |
106 |
// Help about command line options. |
305 |
capela |
1890 |
void Options::print_usage ( const QString& arg0 ) |
306 |
capela |
106 |
{ |
307 |
capela |
1499 |
QTextStream out(stderr); |
308 |
capela |
4024 |
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 |
capela |
106 |
} |
325 |
|
|
|
326 |
capela |
4024 |
#endif |
327 |
capela |
106 |
|
328 |
capela |
4024 |
|
329 |
capela |
106 |
// Parse command line arguments into m_settings. |
330 |
capela |
1890 |
bool Options::parse_args ( const QStringList& args ) |
331 |
capela |
106 |
{ |
332 |
capela |
4024 |
#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 |
capela |
4068 |
foreach (const QString& sArg, parser.positionalArguments()) { |
375 |
capela |
4067 |
sessionFiles.append(QFileInfo(sArg).absoluteFilePath()); |
376 |
capela |
4024 |
} |
377 |
|
|
|
378 |
|
|
#else |
379 |
|
|
|
380 |
capela |
4067 |
int iCmdArgs = 0; |
381 |
|
|
|
382 |
capela |
1499 |
QTextStream out(stderr); |
383 |
capela |
1509 |
const QString sEol = "\n\n"; |
384 |
capela |
3556 |
const int argc = args.count(); |
385 |
capela |
106 |
|
386 |
capela |
3556 |
for (int i = 1; i < argc; ++i) { |
387 |
capela |
106 |
|
388 |
capela |
4067 |
QString sArg = args.at(i); |
389 |
|
|
|
390 |
capela |
1509 |
if (iCmdArgs > 0) { |
391 |
capela |
4067 |
sessionFiles.append(QFileInfo(sArg).absoluteFilePath()); |
392 |
capela |
3556 |
++iCmdArgs; |
393 |
capela |
1509 |
continue; |
394 |
|
|
} |
395 |
capela |
106 |
|
396 |
capela |
3518 |
QString sVal; |
397 |
capela |
2642 |
const int iEqual = sArg.indexOf("="); |
398 |
capela |
1509 |
if (iEqual >= 0) { |
399 |
|
|
sVal = sArg.right(sArg.length() - iEqual - 1); |
400 |
|
|
sArg = sArg.left(iEqual); |
401 |
|
|
} |
402 |
capela |
2642 |
else if (i < argc - 1) { |
403 |
capela |
1890 |
sVal = args.at(i + 1); |
404 |
capela |
2642 |
if (sVal[0] == '-') |
405 |
|
|
sVal.clear(); |
406 |
|
|
} |
407 |
capela |
106 |
|
408 |
capela |
1509 |
if (sArg == "-s" || sArg == "--start") { |
409 |
|
|
bServerStart = true; |
410 |
|
|
} |
411 |
capela |
4024 |
else if (sArg == "-n" || sArg == "--hostname") { |
412 |
capela |
1509 |
if (sVal.isNull()) { |
413 |
capela |
4024 |
out << QObject::tr("Option -n requires an argument (hostname).") + sEol; |
414 |
capela |
1509 |
return false; |
415 |
|
|
} |
416 |
|
|
sServerHost = sVal; |
417 |
|
|
if (iEqual < 0) |
418 |
capela |
3556 |
++i; |
419 |
capela |
1509 |
} |
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 |
capela |
3556 |
++i; |
428 |
capela |
1509 |
} |
429 |
capela |
4024 |
else if (sArg == "-h" || sArg == "--help") { |
430 |
capela |
1890 |
print_usage(args.at(0)); |
431 |
capela |
1509 |
return false; |
432 |
|
|
} |
433 |
|
|
else if (sArg == "-v" || sArg == "--version") { |
434 |
capela |
3837 |
out << QString("Qt: %1").arg(qVersion()); |
435 |
|
|
#if defined(QT_STATIC) |
436 |
|
|
out << "-static"; |
437 |
|
|
#endif |
438 |
|
|
out << '\n'; |
439 |
capela |
2642 |
#ifdef CONFIG_LIBGIG |
440 |
capela |
1499 |
out << QString("%1: %2\n") |
441 |
|
|
.arg(gig::libraryName().c_str()) |
442 |
|
|
.arg(gig::libraryVersion().c_str()); |
443 |
capela |
2642 |
#endif |
444 |
capela |
1499 |
out << QString("%1: %2\n") |
445 |
|
|
.arg(::lscp_client_package()) |
446 |
|
|
.arg(::lscp_client_version()); |
447 |
capela |
3849 |
out << QString("%1: %2\n") |
448 |
|
|
.arg(QSAMPLER_TITLE) |
449 |
capela |
4070 |
.arg(PROJECT_VERSION); |
450 |
capela |
1509 |
return false; |
451 |
capela |
4067 |
} else { |
452 |
capela |
1509 |
// If we don't have one by now, |
453 |
|
|
// this will be the startup sesion file... |
454 |
capela |
4067 |
sessionFiles.append(QFileInfo(sArg).absoluteFilePath()); |
455 |
capela |
3556 |
++iCmdArgs; |
456 |
capela |
1509 |
} |
457 |
|
|
} |
458 |
capela |
106 |
|
459 |
capela |
4024 |
#endif |
460 |
|
|
|
461 |
capela |
1509 |
// Alright with argument parsing. |
462 |
|
|
return true; |
463 |
capela |
106 |
} |
464 |
|
|
|
465 |
|
|
|
466 |
|
|
//--------------------------------------------------------------------------- |
467 |
|
|
// Widget geometry persistence helper methods. |
468 |
|
|
|
469 |
capela |
2077 |
void Options::loadWidgetGeometry ( QWidget *pWidget, bool bVisible ) |
470 |
capela |
106 |
{ |
471 |
capela |
1499 |
// Try to restore old form window positioning. |
472 |
|
|
if (pWidget) { |
473 |
capela |
2847 |
// if (bVisible) pWidget->show(); -- force initial exposure? |
474 |
capela |
1499 |
m_settings.beginGroup("/Geometry/" + pWidget->objectName()); |
475 |
capela |
3520 |
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) |
476 |
capela |
2779 |
const QByteArray& geometry |
477 |
|
|
= m_settings.value("/geometry").toByteArray(); |
478 |
capela |
3558 |
if (geometry.isEmpty()) { |
479 |
|
|
QWidget *pParent = pWidget->parentWidget(); |
480 |
|
|
if (pParent) |
481 |
|
|
pParent = pParent->window(); |
482 |
capela |
3796 |
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) |
483 |
capela |
3558 |
if (pParent == nullptr) |
484 |
|
|
pParent = QApplication::desktop(); |
485 |
capela |
3796 |
#endif |
486 |
capela |
3558 |
if (pParent) { |
487 |
|
|
QRect wrect(pWidget->geometry()); |
488 |
|
|
wrect.moveCenter(pParent->geometry().center()); |
489 |
|
|
pWidget->move(wrect.topLeft()); |
490 |
|
|
} |
491 |
|
|
} else { |
492 |
capela |
2779 |
pWidget->restoreGeometry(geometry); |
493 |
capela |
3558 |
} |
494 |
capela |
2843 |
#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 |
capela |
3067 |
// else |
507 |
|
|
// pWidget->adjustSize(); |
508 |
capela |
2779 |
if (!bVisible) |
509 |
|
|
bVisible = m_settings.value("/visible", false).toBool(); |
510 |
capela |
1499 |
if (bVisible) |
511 |
|
|
pWidget->show(); |
512 |
capela |
2779 |
else |
513 |
|
|
pWidget->hide(); |
514 |
|
|
m_settings.endGroup(); |
515 |
capela |
1499 |
} |
516 |
capela |
106 |
} |
517 |
|
|
|
518 |
|
|
|
519 |
capela |
2077 |
void Options::saveWidgetGeometry ( QWidget *pWidget, bool bVisible ) |
520 |
capela |
106 |
{ |
521 |
capela |
1499 |
// 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 |
capela |
3520 |
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) |
527 |
capela |
2843 |
m_settings.setValue("/geometry", pWidget->saveGeometry()); |
528 |
|
|
#else//--SAVE_OLD_GEOMETRY |
529 |
capela |
2077 |
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 |
capela |
2779 |
#endif |
536 |
|
|
if (!bVisible) bVisible = pWidget->isVisible(); |
537 |
capela |
1499 |
m_settings.setValue("/visible", bVisible); |
538 |
|
|
m_settings.endGroup(); |
539 |
|
|
} |
540 |
capela |
106 |
} |
541 |
|
|
|
542 |
|
|
|
543 |
|
|
//--------------------------------------------------------------------------- |
544 |
|
|
// Combo box history persistence helper implementation. |
545 |
|
|
|
546 |
capela |
1558 |
void Options::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit ) |
547 |
capela |
106 |
{ |
548 |
capela |
2723 |
const bool bBlockSignals = pComboBox->blockSignals(true); |
549 |
|
|
|
550 |
capela |
1499 |
// Load combobox list from configuration settings file... |
551 |
|
|
m_settings.beginGroup("/History/" + pComboBox->objectName()); |
552 |
capela |
106 |
|
553 |
capela |
1499 |
if (m_settings.childKeys().count() > 0) { |
554 |
|
|
pComboBox->setUpdatesEnabled(false); |
555 |
|
|
pComboBox->setDuplicatesEnabled(false); |
556 |
|
|
pComboBox->clear(); |
557 |
capela |
2723 |
for (int i = 0; i < iLimit; ++i) { |
558 |
capela |
1499 |
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 |
capela |
106 |
|
567 |
capela |
1499 |
m_settings.endGroup(); |
568 |
capela |
2723 |
|
569 |
|
|
pComboBox->blockSignals(bBlockSignals); |
570 |
capela |
106 |
} |
571 |
|
|
|
572 |
|
|
|
573 |
capela |
1558 |
void Options::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit ) |
574 |
capela |
106 |
{ |
575 |
capela |
2723 |
const bool bBlockSignals = pComboBox->blockSignals(true); |
576 |
|
|
|
577 |
capela |
1499 |
int iCount = pComboBox->count(); |
578 |
capela |
4043 |
|
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 |
capela |
1499 |
} |
590 |
capela |
4043 |
pComboBox->insertItem(0, sCurrentText); |
591 |
|
|
pComboBox->setCurrentIndex(0); |
592 |
|
|
++iCount; |
593 |
capela |
1499 |
} |
594 |
capela |
4043 |
|
595 |
capela |
1499 |
while (iCount >= iLimit) |
596 |
|
|
pComboBox->removeItem(--iCount); |
597 |
capela |
106 |
|
598 |
capela |
1499 |
// Save combobox list to configuration settings file... |
599 |
|
|
m_settings.beginGroup("/History/" + pComboBox->objectName()); |
600 |
capela |
2723 |
for (int i = 0; i < iCount; ++i) { |
601 |
capela |
1499 |
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 |
capela |
2723 |
|
608 |
|
|
pComboBox->blockSignals(bBlockSignals); |
609 |
capela |
106 |
} |
610 |
|
|
|
611 |
capela |
2723 |
|
612 |
schoenebeck |
1803 |
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 |
capela |
1558 |
} // namespace QSampler |
706 |
capela |
106 |
|
707 |
capela |
1558 |
|
708 |
capela |
106 |
// end of qsamplerOptions.cpp |
709 |
capela |
3067 |
|