1 |
capela |
106 |
// qsamplerOptions.cpp |
2 |
|
|
// |
3 |
|
|
/**************************************************************************** |
4 |
capela |
1464 |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
|
|
Copyright (C) 2007, 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 |
|
|
|
26 |
|
|
#include <qcombobox.h> |
27 |
|
|
|
28 |
capela |
264 |
#include <lscp/client.h> |
29 |
capela |
106 |
|
30 |
capela |
605 |
#ifdef CONFIG_LIBGIG |
31 |
|
|
#include <gig.h> |
32 |
|
|
#endif |
33 |
capela |
106 |
|
34 |
capela |
605 |
|
35 |
capela |
106 |
//------------------------------------------------------------------------- |
36 |
|
|
// qsamplerOptions - Prototype settings structure. |
37 |
|
|
// |
38 |
|
|
|
39 |
|
|
// Constructor. |
40 |
|
|
qsamplerOptions::qsamplerOptions (void) |
41 |
|
|
{ |
42 |
|
|
// Begin master key group. |
43 |
|
|
m_settings.beginGroup("/qsampler"); |
44 |
|
|
|
45 |
|
|
// And go into general options group. |
46 |
|
|
m_settings.beginGroup("/Options"); |
47 |
|
|
|
48 |
|
|
// Load server options... |
49 |
|
|
m_settings.beginGroup("/Server"); |
50 |
|
|
sServerHost = m_settings.readEntry("/ServerHost", "localhost"); |
51 |
|
|
iServerPort = m_settings.readNumEntry("/ServerPort", 8888); |
52 |
capela |
395 |
iServerTimeout = m_settings.readNumEntry("/ServerTimeout", 1000); |
53 |
capela |
106 |
bServerStart = m_settings.readBoolEntry("/ServerStart", true); |
54 |
|
|
sServerCmdLine = m_settings.readEntry("/ServerCmdLine", "linuxsampler"); |
55 |
capela |
395 |
iStartDelay = m_settings.readNumEntry("/StartDelay", 3); |
56 |
capela |
106 |
m_settings.endGroup(); |
57 |
|
|
|
58 |
|
|
// Load display options... |
59 |
|
|
m_settings.beginGroup("/Display"); |
60 |
|
|
sDisplayFont = m_settings.readEntry("/DisplayFont", QString::null); |
61 |
capela |
267 |
bDisplayEffect = m_settings.readBoolEntry("/DisplayEffect", true); |
62 |
capela |
106 |
bAutoRefresh = m_settings.readBoolEntry("/AutoRefresh", true); |
63 |
capela |
400 |
iAutoRefreshTime = m_settings.readNumEntry("/AutoRefreshTime", 1000); |
64 |
capela |
119 |
iMaxVolume = m_settings.readNumEntry("/MaxVolume", 100); |
65 |
capela |
106 |
sMessagesFont = m_settings.readEntry("/MessagesFont", QString::null); |
66 |
|
|
bMessagesLimit = m_settings.readBoolEntry("/MessagesLimit", true); |
67 |
|
|
iMessagesLimitLines = m_settings.readNumEntry("/MessagesLimitLines", 1000); |
68 |
|
|
bConfirmRemove = m_settings.readBoolEntry("/ConfirmRemove", true); |
69 |
capela |
454 |
bKeepOnTop = m_settings.readBoolEntry("/KeepOnTop", true); |
70 |
capela |
106 |
bStdoutCapture = m_settings.readBoolEntry("/StdoutCapture", true); |
71 |
|
|
bCompletePath = m_settings.readBoolEntry("/CompletePath", true); |
72 |
|
|
iMaxRecentFiles = m_settings.readNumEntry("/MaxRecentFiles", 5); |
73 |
capela |
341 |
bInstrumentNames = m_settings.readBoolEntry("/InstrumentNames", false); |
74 |
capela |
106 |
m_settings.endGroup(); |
75 |
|
|
|
76 |
|
|
// And go into view options group. |
77 |
|
|
m_settings.beginGroup("/View"); |
78 |
|
|
bMenubar = m_settings.readBoolEntry("/Menubar", true); |
79 |
|
|
bToolbar = m_settings.readBoolEntry("/Toolbar", true); |
80 |
|
|
bStatusbar = m_settings.readBoolEntry("/Statusbar", true); |
81 |
|
|
bAutoArrange = m_settings.readBoolEntry("/AutoArrange", true); |
82 |
|
|
m_settings.endGroup(); |
83 |
|
|
|
84 |
|
|
m_settings.endGroup(); // Options group. |
85 |
|
|
|
86 |
|
|
// Recent file list. |
87 |
|
|
m_settings.beginGroup("/RecentFiles"); |
88 |
|
|
recentFiles.clear(); |
89 |
|
|
for (int i = 0; i < iMaxRecentFiles; i++) { |
90 |
|
|
QString sFilename = m_settings.readEntry("/File" + QString::number(i + 1), QString::null); |
91 |
|
|
if (!sFilename.isEmpty()) |
92 |
|
|
recentFiles.append(sFilename); |
93 |
|
|
} |
94 |
|
|
m_settings.endGroup(); |
95 |
|
|
|
96 |
|
|
// Last but not least, get the default directories. |
97 |
|
|
m_settings.beginGroup("/Default"); |
98 |
|
|
sSessionDir = m_settings.readEntry("/SessionDir", QString::null); |
99 |
|
|
sInstrumentDir = m_settings.readEntry("/InstrumentDir", QString::null); |
100 |
capela |
176 |
sEngineName = m_settings.readEntry("/EngineName", QString::null); |
101 |
|
|
sAudioDriver = m_settings.readEntry("/AudioDriver", QString::null); |
102 |
|
|
sMidiDriver = m_settings.readEntry("/MidiDriver", QString::null); |
103 |
capela |
980 |
iMidiMap = m_settings.readNumEntry("/MidiMap", 0); |
104 |
|
|
iMidiBank = m_settings.readNumEntry("/MidiBank", 0); |
105 |
|
|
iMidiProg = m_settings.readNumEntry("/MidiProg", 0); |
106 |
|
|
iVolume = m_settings.readNumEntry("/Volume", 100); |
107 |
|
|
iLoadMode = m_settings.readNumEntry("/Loadmode", 0); |
108 |
capela |
106 |
m_settings.endGroup(); |
109 |
|
|
} |
110 |
|
|
|
111 |
|
|
|
112 |
|
|
// Default Destructor. |
113 |
|
|
qsamplerOptions::~qsamplerOptions (void) |
114 |
|
|
{ |
115 |
|
|
// Make program version available in the future. |
116 |
|
|
m_settings.beginGroup("/Program"); |
117 |
|
|
m_settings.writeEntry("/Version", QSAMPLER_VERSION); |
118 |
|
|
m_settings.endGroup(); |
119 |
|
|
|
120 |
|
|
// And go into general options group. |
121 |
|
|
m_settings.beginGroup("/Options"); |
122 |
|
|
|
123 |
|
|
// Save server options. |
124 |
|
|
m_settings.beginGroup("/Server"); |
125 |
|
|
m_settings.writeEntry("/ServerHost", sServerHost); |
126 |
|
|
m_settings.writeEntry("/ServerPort", iServerPort); |
127 |
|
|
m_settings.writeEntry("/ServerTimeout", iServerTimeout); |
128 |
|
|
m_settings.writeEntry("/ServerStart", bServerStart); |
129 |
|
|
m_settings.writeEntry("/ServerCmdLine", sServerCmdLine); |
130 |
|
|
m_settings.writeEntry("/StartDelay", iStartDelay); |
131 |
|
|
m_settings.endGroup(); |
132 |
|
|
|
133 |
|
|
// Save display options. |
134 |
|
|
m_settings.beginGroup("/Display"); |
135 |
|
|
m_settings.writeEntry("/DisplayFont", sDisplayFont); |
136 |
capela |
267 |
m_settings.writeEntry("/DisplayEffect", bDisplayEffect); |
137 |
capela |
106 |
m_settings.writeEntry("/AutoRefresh", bAutoRefresh); |
138 |
|
|
m_settings.writeEntry("/AutoRefreshTime", iAutoRefreshTime); |
139 |
capela |
119 |
m_settings.writeEntry("/MaxVolume", iMaxVolume); |
140 |
capela |
106 |
m_settings.writeEntry("/MessagesFont", sMessagesFont); |
141 |
|
|
m_settings.writeEntry("/MessagesLimit", bMessagesLimit); |
142 |
|
|
m_settings.writeEntry("/MessagesLimitLines", iMessagesLimitLines); |
143 |
|
|
m_settings.writeEntry("/ConfirmRemove", bConfirmRemove); |
144 |
capela |
454 |
m_settings.writeEntry("/KeepOnTop", bKeepOnTop); |
145 |
capela |
106 |
m_settings.writeEntry("/StdoutCapture", bStdoutCapture); |
146 |
|
|
m_settings.writeEntry("/CompletePath", bCompletePath); |
147 |
|
|
m_settings.writeEntry("/MaxRecentFiles", iMaxRecentFiles); |
148 |
capela |
341 |
m_settings.writeEntry("/InstrumentNames", bInstrumentNames); |
149 |
capela |
106 |
m_settings.endGroup(); |
150 |
|
|
|
151 |
|
|
// View options group. |
152 |
|
|
m_settings.beginGroup("/View"); |
153 |
|
|
m_settings.writeEntry("/Menubar", bMenubar); |
154 |
|
|
m_settings.writeEntry("/Toolbar", bToolbar); |
155 |
|
|
m_settings.writeEntry("/Statusbar", bStatusbar); |
156 |
|
|
m_settings.writeEntry("/AutoArrange", bAutoArrange); |
157 |
|
|
m_settings.endGroup(); |
158 |
|
|
|
159 |
|
|
m_settings.endGroup(); // Options group. |
160 |
|
|
|
161 |
|
|
// Recent file list. |
162 |
|
|
m_settings.beginGroup("/RecentFiles"); |
163 |
|
|
for (int i = 0; i < (int) recentFiles.count(); i++) |
164 |
|
|
m_settings.writeEntry("/File" + QString::number(i + 1), recentFiles[i]); |
165 |
|
|
m_settings.endGroup(); |
166 |
|
|
|
167 |
|
|
// Default directories. |
168 |
|
|
m_settings.beginGroup("/Default"); |
169 |
|
|
m_settings.writeEntry("/SessionDir", sSessionDir); |
170 |
|
|
m_settings.writeEntry("/InstrumentDir", sInstrumentDir); |
171 |
capela |
176 |
m_settings.writeEntry("/EngineName", sEngineName); |
172 |
|
|
m_settings.writeEntry("/AudioDriver", sAudioDriver); |
173 |
|
|
m_settings.writeEntry("/MidiDriver", sMidiDriver); |
174 |
capela |
980 |
m_settings.writeEntry("/MidiMap", iMidiMap); |
175 |
|
|
m_settings.writeEntry("/MidiBank", iMidiBank); |
176 |
|
|
m_settings.writeEntry("/MidiProg", iMidiProg); |
177 |
|
|
m_settings.writeEntry("/Volume", iVolume); |
178 |
|
|
m_settings.writeEntry("/Loadmode", iLoadMode); |
179 |
capela |
106 |
m_settings.endGroup(); |
180 |
|
|
|
181 |
|
|
m_settings.endGroup(); |
182 |
|
|
} |
183 |
|
|
|
184 |
|
|
//------------------------------------------------------------------------- |
185 |
|
|
// Settings accessor. |
186 |
|
|
// |
187 |
|
|
|
188 |
|
|
QSettings& qsamplerOptions::settings (void) |
189 |
|
|
{ |
190 |
|
|
return m_settings; |
191 |
|
|
} |
192 |
|
|
|
193 |
|
|
|
194 |
|
|
//------------------------------------------------------------------------- |
195 |
|
|
// Command-line argument stuff. |
196 |
|
|
// |
197 |
|
|
|
198 |
|
|
// Help about command line options. |
199 |
|
|
void qsamplerOptions::print_usage ( const char *arg0 ) |
200 |
|
|
{ |
201 |
|
|
const QString sEot = "\n\t"; |
202 |
|
|
const QString sEol = "\n\n"; |
203 |
|
|
|
204 |
|
|
fprintf(stderr, QObject::tr("Usage") + ": %s [" + QObject::tr("options") + "] [" + |
205 |
|
|
QObject::tr("session-file") + "]" + sEol, arg0); |
206 |
|
|
fprintf(stderr, QSAMPLER_TITLE " - " + QObject::tr(QSAMPLER_SUBTITLE) + sEol); |
207 |
|
|
fprintf(stderr, QObject::tr("Options") + ":" + sEol); |
208 |
|
|
fprintf(stderr, " -s, --start" + sEot + |
209 |
|
|
QObject::tr("Start linuxsampler server locally") + sEol); |
210 |
|
|
fprintf(stderr, " -h, --hostname" + sEot + |
211 |
|
|
QObject::tr("Specify linuxsampler server hostname") + sEol); |
212 |
|
|
fprintf(stderr, " -p, --port" + sEot + |
213 |
|
|
QObject::tr("Specify linuxsampler server port number") + sEol); |
214 |
|
|
fprintf(stderr, " -?, --help" + sEot + |
215 |
|
|
QObject::tr("Show help about command line options") + sEol); |
216 |
|
|
fprintf(stderr, " -v, --version" + sEot + |
217 |
|
|
QObject::tr("Show version information") + sEol); |
218 |
|
|
} |
219 |
|
|
|
220 |
|
|
|
221 |
|
|
// Parse command line arguments into m_settings. |
222 |
|
|
bool qsamplerOptions::parse_args ( int argc, char **argv ) |
223 |
|
|
{ |
224 |
|
|
const QString sEol = "\n\n"; |
225 |
|
|
int iCmdArgs = 0; |
226 |
|
|
|
227 |
|
|
for (int i = 1; i < argc; i++) { |
228 |
|
|
|
229 |
|
|
if (iCmdArgs > 0) { |
230 |
|
|
sSessionFile += " "; |
231 |
|
|
sSessionFile += argv[i]; |
232 |
|
|
iCmdArgs++; |
233 |
|
|
continue; |
234 |
|
|
} |
235 |
|
|
|
236 |
|
|
QString sArg = argv[i]; |
237 |
|
|
QString sVal = QString::null; |
238 |
|
|
int iEqual = sArg.find("="); |
239 |
|
|
if (iEqual >= 0) { |
240 |
|
|
sVal = sArg.right(sArg.length() - iEqual - 1); |
241 |
|
|
sArg = sArg.left(iEqual); |
242 |
|
|
} |
243 |
|
|
else if (i < argc) |
244 |
|
|
sVal = argv[i + 1]; |
245 |
|
|
|
246 |
|
|
if (sArg == "-s" || sArg == "--start") { |
247 |
|
|
bServerStart = true; |
248 |
|
|
} |
249 |
|
|
else if (sArg == "-h" || sArg == "--hostname") { |
250 |
|
|
if (sVal.isNull()) { |
251 |
|
|
fprintf(stderr, QObject::tr("Option -h requires an argument (hostname).") + sEol); |
252 |
|
|
return false; |
253 |
|
|
} |
254 |
|
|
sServerHost = sVal; |
255 |
|
|
if (iEqual < 0) |
256 |
|
|
i++; |
257 |
|
|
} |
258 |
|
|
else if (sArg == "-p" || sArg == "--port") { |
259 |
|
|
if (sVal.isNull()) { |
260 |
|
|
fprintf(stderr, QObject::tr("Option -p requires an argument (port).") + sEol); |
261 |
|
|
return false; |
262 |
|
|
} |
263 |
|
|
iServerPort = sVal.toInt(); |
264 |
|
|
if (iEqual < 0) |
265 |
|
|
i++; |
266 |
|
|
} |
267 |
|
|
else if (sArg == "-?" || sArg == "--help") { |
268 |
|
|
print_usage(argv[0]); |
269 |
|
|
return false; |
270 |
|
|
} |
271 |
|
|
else if (sArg == "-v" || sArg == "--version") { |
272 |
|
|
fprintf(stderr, "Qt: %s\n", qVersion()); |
273 |
capela |
605 |
#ifdef CONFIG_LIBGIG |
274 |
|
|
fprintf(stderr, "%s: %s\n", gig::libraryName().c_str(), gig::libraryVersion().c_str()); |
275 |
|
|
#endif |
276 |
|
|
fprintf(stderr, "%s: %s\n", ::lscp_client_package(), ::lscp_client_version()); |
277 |
capela |
106 |
fprintf(stderr, "qsampler: %s\n", QSAMPLER_VERSION); |
278 |
|
|
return false; |
279 |
|
|
} |
280 |
|
|
else { |
281 |
|
|
// If we don't have one by now, |
282 |
|
|
// this will be the startup sesion file... |
283 |
|
|
sSessionFile += sArg; |
284 |
|
|
iCmdArgs++; |
285 |
|
|
} |
286 |
|
|
} |
287 |
|
|
|
288 |
|
|
// Alright with argument parsing. |
289 |
|
|
return true; |
290 |
|
|
} |
291 |
|
|
|
292 |
|
|
|
293 |
|
|
//--------------------------------------------------------------------------- |
294 |
|
|
// Widget geometry persistence helper methods. |
295 |
|
|
|
296 |
|
|
void qsamplerOptions::loadWidgetGeometry ( QWidget *pWidget ) |
297 |
|
|
{ |
298 |
|
|
// Try to restore old form window positioning. |
299 |
|
|
if (pWidget) { |
300 |
|
|
QPoint fpos; |
301 |
|
|
QSize fsize; |
302 |
|
|
bool bVisible; |
303 |
|
|
m_settings.beginGroup("/Geometry/" + QString(pWidget->name())); |
304 |
|
|
fpos.setX(m_settings.readNumEntry("/x", -1)); |
305 |
|
|
fpos.setY(m_settings.readNumEntry("/y", -1)); |
306 |
|
|
fsize.setWidth(m_settings.readNumEntry("/width", -1)); |
307 |
|
|
fsize.setHeight(m_settings.readNumEntry("/height", -1)); |
308 |
|
|
bVisible = m_settings.readBoolEntry("/visible", false); |
309 |
|
|
m_settings.endGroup(); |
310 |
|
|
if (fpos.x() > 0 && fpos.y() > 0) |
311 |
|
|
pWidget->move(fpos); |
312 |
|
|
if (fsize.width() > 0 && fsize.height() > 0) |
313 |
|
|
pWidget->resize(fsize); |
314 |
|
|
else |
315 |
|
|
pWidget->adjustSize(); |
316 |
|
|
if (bVisible) |
317 |
|
|
pWidget->show(); |
318 |
|
|
else |
319 |
|
|
pWidget->hide(); |
320 |
|
|
} |
321 |
|
|
} |
322 |
|
|
|
323 |
|
|
|
324 |
|
|
void qsamplerOptions::saveWidgetGeometry ( QWidget *pWidget ) |
325 |
|
|
{ |
326 |
|
|
// Try to save form window position... |
327 |
|
|
// (due to X11 window managers ideossincrasies, we better |
328 |
|
|
// only save the form geometry while its up and visible) |
329 |
|
|
if (pWidget) { |
330 |
|
|
m_settings.beginGroup("/Geometry/" + QString(pWidget->name())); |
331 |
|
|
bool bVisible = pWidget->isVisible(); |
332 |
|
|
if (bVisible) { |
333 |
|
|
QPoint fpos = pWidget->pos(); |
334 |
|
|
QSize fsize = pWidget->size(); |
335 |
|
|
m_settings.writeEntry("/x", fpos.x()); |
336 |
|
|
m_settings.writeEntry("/y", fpos.y()); |
337 |
|
|
m_settings.writeEntry("/width", fsize.width()); |
338 |
|
|
m_settings.writeEntry("/height", fsize.height()); |
339 |
|
|
} |
340 |
|
|
m_settings.writeEntry("/visible", bVisible); |
341 |
|
|
m_settings.endGroup(); |
342 |
|
|
} |
343 |
|
|
} |
344 |
|
|
|
345 |
|
|
|
346 |
|
|
//--------------------------------------------------------------------------- |
347 |
|
|
// Combo box history persistence helper implementation. |
348 |
|
|
|
349 |
|
|
void qsamplerOptions::add2ComboBoxHistory ( QComboBox *pComboBox, const QString& sNewText, int iLimit, int iIndex ) |
350 |
|
|
{ |
351 |
|
|
int iCount = pComboBox->count(); |
352 |
|
|
for (int i = 0; i < iCount; i++) { |
353 |
|
|
QString sText = pComboBox->text(i); |
354 |
|
|
if (sText == sNewText) { |
355 |
|
|
pComboBox->removeItem(i); |
356 |
|
|
iCount--; |
357 |
|
|
break; |
358 |
|
|
} |
359 |
|
|
} |
360 |
|
|
while (iCount >= iLimit) |
361 |
|
|
pComboBox->removeItem(--iCount); |
362 |
|
|
pComboBox->insertItem(sNewText, iIndex); |
363 |
|
|
} |
364 |
|
|
|
365 |
|
|
|
366 |
|
|
void qsamplerOptions::loadComboBoxHistory ( QComboBox *pComboBox, int iLimit ) |
367 |
|
|
{ |
368 |
|
|
pComboBox->setUpdatesEnabled(false); |
369 |
|
|
pComboBox->setDuplicatesEnabled(false); |
370 |
|
|
|
371 |
|
|
m_settings.beginGroup("/History/" + QString(pComboBox->name())); |
372 |
|
|
for (int i = 0; i < iLimit; i++) { |
373 |
|
|
QString sText = m_settings.readEntry("/Item" + QString::number(i + 1), QString::null); |
374 |
|
|
if (sText.isEmpty()) |
375 |
|
|
break; |
376 |
|
|
add2ComboBoxHistory(pComboBox, sText, iLimit); |
377 |
|
|
} |
378 |
|
|
m_settings.endGroup(); |
379 |
|
|
|
380 |
|
|
pComboBox->setUpdatesEnabled(true); |
381 |
|
|
} |
382 |
|
|
|
383 |
|
|
|
384 |
|
|
void qsamplerOptions::saveComboBoxHistory ( QComboBox *pComboBox, int iLimit ) |
385 |
|
|
{ |
386 |
|
|
add2ComboBoxHistory(pComboBox, pComboBox->currentText(), iLimit, 0); |
387 |
|
|
|
388 |
|
|
m_settings.beginGroup("/History/" + QString(pComboBox->name())); |
389 |
|
|
for (int i = 0; i < iLimit && i < pComboBox->count(); i++) { |
390 |
|
|
QString sText = pComboBox->text(i); |
391 |
|
|
if (sText.isEmpty()) |
392 |
|
|
break; |
393 |
|
|
m_settings.writeEntry("/Item" + QString::number(i + 1), sText); |
394 |
|
|
} |
395 |
|
|
m_settings.endGroup(); |
396 |
|
|
} |
397 |
|
|
|
398 |
|
|
|
399 |
|
|
// end of qsamplerOptions.cpp |