/[svn]/qsampler/trunk/src/qsamplerOptionsForm.cpp
ViewVC logotype

Annotation of /qsampler/trunk/src/qsamplerOptionsForm.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1803 - (hide annotations) (download)
Sun Dec 7 13:58:16 2008 UTC (15 years, 4 months ago) by schoenebeck
File size: 15424 byte(s)
* Added support for runtime max. voices / disk streams setting (accessible
  from the "Options..." dialog). Those fine tuning settins will be saved
  in case the user modified them and automatically restored to the sampler
  when reconnecting to a sampler the next time.
* bumped version to 0.2.1.20

1 capela 1464 // qsamplerOptionsForm.cpp
2     //
3     /****************************************************************************
4 capela 1738 Copyright (C) 2004-2008, rncbc aka Rui Nuno Capela. All rights reserved.
5 capela 1464 Copyright (C) 2007, 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 schoenebeck 1461 #include "qsamplerOptionsForm.h"
24    
25     #include "qsamplerAbout.h"
26     #include "qsamplerOptions.h"
27    
28     #include <QMessageBox>
29     #include <QFontDialog>
30 capela 1738 #include <QFileDialog>
31 schoenebeck 1461
32 capela 1499
33 schoenebeck 1461 namespace QSampler {
34    
35 capela 1558 //-------------------------------------------------------------------------
36     // QSampler::OptionsForm -- Options form implementation.
37     //
38    
39 capela 1509 OptionsForm::OptionsForm ( QWidget* pParent )
40     : QDialog(pParent)
41 capela 1473 {
42 capela 1509 m_ui.setupUi(this);
43 schoenebeck 1461
44 capela 1473 // No settings descriptor initially (the caller will set it).
45     m_pOptions = NULL;
46 schoenebeck 1461
47 capela 1473 // Initialize dirty control state.
48     m_iDirtySetup = 0;
49     m_iDirtyCount = 0;
50 schoenebeck 1461
51 capela 1473 // Set dialog validators...
52 capela 1509 m_ui.ServerPortComboBox->setValidator(
53     new QIntValidator(m_ui.ServerPortComboBox));
54 schoenebeck 1461
55 capela 1473 // Try to restore old window positioning.
56     adjustSize();
57 capela 1466
58 capela 1509 QObject::connect(m_ui.ServerHostComboBox,
59 capela 1504 SIGNAL(editTextChanged(const QString&)),
60 capela 1466 SLOT(optionsChanged()));
61 capela 1509 QObject::connect(m_ui.ServerPortComboBox,
62 capela 1504 SIGNAL(editTextChanged(const QString&)),
63 capela 1466 SLOT(optionsChanged()));
64 capela 1509 QObject::connect(m_ui.ServerTimeoutSpinBox,
65 capela 1466 SIGNAL(valueChanged(int)),
66     SLOT(optionsChanged()));
67 capela 1509 QObject::connect(m_ui.ServerStartCheckBox,
68 capela 1466 SIGNAL(stateChanged(int)),
69     SLOT(optionsChanged()));
70 capela 1509 QObject::connect(m_ui.ServerCmdLineComboBox,
71 capela 1504 SIGNAL(editTextChanged(const QString&)),
72 capela 1466 SLOT(optionsChanged()));
73 capela 1509 QObject::connect(m_ui.StartDelaySpinBox,
74 capela 1466 SIGNAL(valueChanged(int)),
75     SLOT(optionsChanged()));
76 capela 1738 QObject::connect(m_ui.MessagesLogCheckBox,
77     SIGNAL(stateChanged(int)),
78     SLOT(optionsChanged()));
79     QObject::connect(m_ui.MessagesLogPathComboBox,
80     SIGNAL(editTextChanged(const QString&)),
81     SLOT(optionsChanged()));
82     QObject::connect(m_ui.MessagesLogPathToolButton,
83     SIGNAL(clicked()),
84     SLOT(browseMessagesLogPath()));
85 capela 1509 QObject::connect(m_ui.DisplayFontPushButton,
86 capela 1466 SIGNAL(clicked()),
87     SLOT(chooseDisplayFont()));
88 capela 1509 QObject::connect(m_ui.DisplayEffectCheckBox,
89 capela 1466 SIGNAL(toggled(bool)),
90     SLOT(toggleDisplayEffect(bool)));
91 capela 1509 QObject::connect(m_ui.AutoRefreshCheckBox,
92 capela 1466 SIGNAL(stateChanged(int)),
93     SLOT(optionsChanged()));
94 capela 1509 QObject::connect(m_ui.AutoRefreshTimeSpinBox,
95 capela 1466 SIGNAL(valueChanged(int)),
96     SLOT(optionsChanged()));
97 capela 1509 QObject::connect(m_ui.MaxVolumeSpinBox,
98 capela 1466 SIGNAL(valueChanged(int)),
99     SLOT(optionsChanged()));
100 capela 1509 QObject::connect(m_ui.MessagesFontPushButton,
101 capela 1466 SIGNAL(clicked()),
102     SLOT(chooseMessagesFont()));
103 capela 1509 QObject::connect(m_ui.MessagesLimitCheckBox,
104 capela 1466 SIGNAL(stateChanged(int)),
105     SLOT(optionsChanged()));
106 capela 1509 QObject::connect(m_ui.MessagesLimitLinesSpinBox,
107 capela 1466 SIGNAL(valueChanged(int)),
108     SLOT(optionsChanged()));
109 capela 1509 QObject::connect(m_ui.ConfirmRemoveCheckBox,
110 capela 1466 SIGNAL(stateChanged(int)),
111     SLOT(optionsChanged()));
112 capela 1509 QObject::connect(m_ui.KeepOnTopCheckBox,
113 capela 1466 SIGNAL(stateChanged(int)),
114     SLOT(optionsChanged()));
115 capela 1509 QObject::connect(m_ui.StdoutCaptureCheckBox,
116 capela 1466 SIGNAL(stateChanged(int)),
117     SLOT(optionsChanged()));
118 capela 1509 QObject::connect(m_ui.MaxRecentFilesSpinBox,
119 capela 1466 SIGNAL(valueChanged(int)),
120     SLOT(optionsChanged()));
121 capela 1509 QObject::connect(m_ui.CompletePathCheckBox,
122 capela 1466 SIGNAL(stateChanged(int)),
123     SLOT(optionsChanged()));
124 capela 1509 QObject::connect(m_ui.InstrumentNamesCheckBox,
125 capela 1466 SIGNAL(stateChanged(int)),
126     SLOT(optionsChanged()));
127 capela 1749 QObject::connect(m_ui.BaseFontSizeComboBox,
128     SIGNAL(editTextChanged(const QString&)),
129     SLOT(optionsChanged()));
130 schoenebeck 1803 QObject::connect(m_ui.MaxVoicesSpinBox,
131     SIGNAL(valueChanged(int)),
132     SLOT(maxVoicesChanged(int)));
133     QObject::connect(m_ui.MaxStreamsSpinBox,
134     SIGNAL(valueChanged(int)),
135     SLOT(maxStreamsChanged(int)));
136 capela 1509 QObject::connect(m_ui.OkPushButton,
137 capela 1466 SIGNAL(clicked()),
138     SLOT(accept()));
139 capela 1509 QObject::connect(m_ui.CancelPushButton,
140 capela 1466 SIGNAL(clicked()),
141     SLOT(reject()));
142 schoenebeck 1461 }
143    
144 capela 1473 OptionsForm::~OptionsForm()
145     {
146 schoenebeck 1461 }
147    
148     // Populate (setup) dialog controls from settings descriptors.
149 capela 1558 void OptionsForm::setup ( Options *pOptions )
150 schoenebeck 1461 {
151 capela 1509 // Set reference descriptor.
152     m_pOptions = pOptions;
153 schoenebeck 1461
154 capela 1509 // Start clean.
155     m_iDirtyCount = 0;
156     // Avoid nested changes.
157     m_iDirtySetup++;
158 schoenebeck 1461
159 capela 1509 // Load combo box history...
160     m_pOptions->loadComboBoxHistory(m_ui.ServerHostComboBox);
161     m_pOptions->loadComboBoxHistory(m_ui.ServerPortComboBox);
162     m_pOptions->loadComboBoxHistory(m_ui.ServerCmdLineComboBox);
163 capela 1738 m_pOptions->loadComboBoxHistory(m_ui.MessagesLogPathComboBox);
164 schoenebeck 1461
165 capela 1509 // Load Server settings...
166     m_ui.ServerHostComboBox->setEditText(m_pOptions->sServerHost);
167     m_ui.ServerPortComboBox->setEditText(QString::number(m_pOptions->iServerPort));
168     m_ui.ServerTimeoutSpinBox->setValue(m_pOptions->iServerTimeout);
169     m_ui.ServerStartCheckBox->setChecked(m_pOptions->bServerStart);
170     m_ui.ServerCmdLineComboBox->setEditText(m_pOptions->sServerCmdLine);
171     m_ui.StartDelaySpinBox->setValue(m_pOptions->iStartDelay);
172 schoenebeck 1461
173 capela 1738 // Logging options...
174     m_ui.MessagesLogCheckBox->setChecked(m_pOptions->bMessagesLog);
175     m_ui.MessagesLogPathComboBox->setEditText(m_pOptions->sMessagesLogPath);
176    
177 capela 1509 // Load Display options...
178     QFont font;
179 capela 1504 QPalette pal;
180 schoenebeck 1461
181 capela 1509 // Display font.
182     if (m_pOptions->sDisplayFont.isEmpty()
183     || !font.fromString(m_pOptions->sDisplayFont))
184     font = QFont("Sans Serif", 8);
185     m_ui.DisplayFontTextLabel->setFont(font);
186     m_ui.DisplayFontTextLabel->setText(font.family()
187     + ' ' + QString::number(font.pointSize()));
188 schoenebeck 1461
189 capela 1509 // Display effect.
190     m_ui.DisplayEffectCheckBox->setChecked(m_pOptions->bDisplayEffect);
191     toggleDisplayEffect(m_pOptions->bDisplayEffect);
192 schoenebeck 1461
193 capela 1509 // Auto-refresh and maximum volume options.
194     m_ui.AutoRefreshCheckBox->setChecked(m_pOptions->bAutoRefresh);
195     m_ui.AutoRefreshTimeSpinBox->setValue(m_pOptions->iAutoRefreshTime);
196     m_ui.MaxVolumeSpinBox->setValue(m_pOptions->iMaxVolume);
197 schoenebeck 1461
198 capela 1509 // Messages font.
199     if (m_pOptions->sMessagesFont.isEmpty()
200     || !font.fromString(m_pOptions->sMessagesFont))
201 capela 1788 font = QFont("Monospace", 8);
202 capela 1509 pal = m_ui.MessagesFontTextLabel->palette();
203 capela 1788 pal.setColor(QPalette::Background, pal.base().color());
204 capela 1509 m_ui.MessagesFontTextLabel->setPalette(pal);
205     m_ui.MessagesFontTextLabel->setFont(font);
206     m_ui.MessagesFontTextLabel->setText(font.family()
207     + ' ' + QString::number(font.pointSize()));
208 schoenebeck 1461
209 capela 1509 // Messages limit option.
210     m_ui.MessagesLimitCheckBox->setChecked(m_pOptions->bMessagesLimit);
211     m_ui.MessagesLimitLinesSpinBox->setValue(m_pOptions->iMessagesLimitLines);
212 schoenebeck 1461
213 capela 1509 // Other options finally.
214     m_ui.ConfirmRemoveCheckBox->setChecked(m_pOptions->bConfirmRemove);
215     m_ui.KeepOnTopCheckBox->setChecked(m_pOptions->bKeepOnTop);
216     m_ui.StdoutCaptureCheckBox->setChecked(m_pOptions->bStdoutCapture);
217     m_ui.CompletePathCheckBox->setChecked(m_pOptions->bCompletePath);
218     m_ui.InstrumentNamesCheckBox->setChecked(m_pOptions->bInstrumentNames);
219     m_ui.MaxRecentFilesSpinBox->setValue(m_pOptions->iMaxRecentFiles);
220 capela 1749 if (m_pOptions->iBaseFontSize > 0)
221     m_ui.BaseFontSizeComboBox->setEditText(QString::number(m_pOptions->iBaseFontSize));
222     else
223     m_ui.BaseFontSizeComboBox->setCurrentIndex(0);
224 schoenebeck 1461
225     #ifndef CONFIG_LIBGIG
226 capela 1509 m_ui.InstrumentNamesCheckBox->setEnabled(false);
227 schoenebeck 1461 #endif
228    
229 schoenebeck 1803 bMaxVoicesModified = bMaxStreamsModified = false;
230     #ifdef CONFIG_MAX_VOICES
231     const bool bMaxVoicesSupported =
232     m_pOptions->getEffectiveMaxVoices() >= 0;
233     const bool bMaxStreamsSupported =
234     m_pOptions->getEffectiveMaxStreams() >= 0;
235    
236     m_ui.MaxVoicesSpinBox->setEnabled(bMaxVoicesSupported);
237     m_ui.MaxVoicesSpinBox->setValue(m_pOptions->getMaxVoices());
238     if (!bMaxVoicesSupported)
239     m_ui.MaxVoicesSpinBox->setToolTip(
240     tr("This parameter is not supported by the current sampler "
241     "version in use.")
242     );
243     else
244     m_ui.MaxVoicesSpinBox->setToolTip(
245     tr("The max. amount of voices the sampler shall process "
246     "simultaniously.")
247     );
248    
249     m_ui.MaxStreamsSpinBox->setEnabled(bMaxStreamsSupported);
250     m_ui.MaxStreamsSpinBox->setValue(m_pOptions->getMaxStreams());
251     if (!bMaxStreamsSupported)
252     m_ui.MaxStreamsSpinBox->setToolTip(
253     tr("This parameter is not supported by the current sampler "
254     "version in use.")
255     );
256     else
257     m_ui.MaxStreamsSpinBox->setToolTip(
258     tr("The max. amount of disk streams the sampler shall process "
259     "simultaniously.")
260     );
261     #else
262     m_ui.MaxVoicesSpinBox->setEnabled(false);
263     m_ui.MaxStreamsSpinBox->setEnabled(false);
264     m_ui.MaxVoicesSpinBox->setToolTip(
265     tr("QSampler was built without support for this parameter.")
266     );
267     m_ui.MaxStreamsSpinBox->setToolTip(
268     tr("QSampler was built without support for this parameter.")
269     );
270     #endif // CONFIG_MAX_VOICES
271    
272 capela 1509 // Done.
273     m_iDirtySetup--;
274     stabilizeForm();
275 schoenebeck 1461 }
276    
277    
278     // Accept settings (OK button slot).
279     void OptionsForm::accept (void)
280     {
281 capela 1509 // Save options...
282     if (m_iDirtyCount > 0) {
283     // Server settings....
284     m_pOptions->sServerHost = m_ui.ServerHostComboBox->currentText().trimmed();
285     m_pOptions->iServerPort = m_ui.ServerPortComboBox->currentText().toInt();
286     m_pOptions->iServerTimeout = m_ui.ServerTimeoutSpinBox->value();
287     m_pOptions->bServerStart = m_ui.ServerStartCheckBox->isChecked();
288     m_pOptions->sServerCmdLine = m_ui.ServerCmdLineComboBox->currentText().trimmed();
289 capela 1738 m_pOptions->iStartDelay = m_ui.StartDelaySpinBox->value();
290     // Logging options...
291     m_pOptions->bMessagesLog = m_ui.MessagesLogCheckBox->isChecked();
292     m_pOptions->sMessagesLogPath = m_ui.MessagesLogPathComboBox->currentText();
293 capela 1509 // Channels options...
294     m_pOptions->sDisplayFont = m_ui.DisplayFontTextLabel->font().toString();
295     m_pOptions->bDisplayEffect = m_ui.DisplayEffectCheckBox->isChecked();
296     m_pOptions->bAutoRefresh = m_ui.AutoRefreshCheckBox->isChecked();
297     m_pOptions->iAutoRefreshTime = m_ui.AutoRefreshTimeSpinBox->value();
298     m_pOptions->iMaxVolume = m_ui.MaxVolumeSpinBox->value();
299     // Messages options...
300     m_pOptions->sMessagesFont = m_ui.MessagesFontTextLabel->font().toString();
301     m_pOptions->bMessagesLimit = m_ui.MessagesLimitCheckBox->isChecked();
302     m_pOptions->iMessagesLimitLines = m_ui.MessagesLimitLinesSpinBox->value();
303     // Other options...
304     m_pOptions->bConfirmRemove = m_ui.ConfirmRemoveCheckBox->isChecked();
305     m_pOptions->bKeepOnTop = m_ui.KeepOnTopCheckBox->isChecked();
306     m_pOptions->bStdoutCapture = m_ui.StdoutCaptureCheckBox->isChecked();
307     m_pOptions->bCompletePath = m_ui.CompletePathCheckBox->isChecked();
308     m_pOptions->bInstrumentNames = m_ui.InstrumentNamesCheckBox->isChecked();
309     m_pOptions->iMaxRecentFiles = m_ui.MaxRecentFilesSpinBox->value();
310 capela 1749 m_pOptions->iBaseFontSize = m_ui.BaseFontSizeComboBox->currentText().toInt();
311 capela 1509 // Reset dirty flag.
312     m_iDirtyCount = 0;
313     }
314 schoenebeck 1461
315 schoenebeck 1803 // if the user modified the limits, apply them to the sampler
316     // (and store it later in qsampler's configuration)
317     if (bMaxVoicesModified && m_ui.MaxVoicesSpinBox->isEnabled())
318     m_pOptions->setMaxVoices(m_ui.MaxVoicesSpinBox->value());
319     if (bMaxStreamsModified && m_ui.MaxStreamsSpinBox->isEnabled())
320     m_pOptions->setMaxStreams(m_ui.MaxStreamsSpinBox->value());
321    
322 capela 1509 // Save combobox history...
323     m_pOptions->saveComboBoxHistory(m_ui.ServerHostComboBox);
324     m_pOptions->saveComboBoxHistory(m_ui.ServerPortComboBox);
325     m_pOptions->saveComboBoxHistory(m_ui.ServerCmdLineComboBox);
326 capela 1738 m_pOptions->saveComboBoxHistory(m_ui.MessagesLogPathComboBox);
327 schoenebeck 1461
328 capela 1509 // Just go with dialog acceptance.
329     QDialog::accept();
330 schoenebeck 1461 }
331    
332    
333     // Reject settings (Cancel button slot).
334     void OptionsForm::reject (void)
335     {
336 capela 1509 bool bReject = true;
337 schoenebeck 1461
338 capela 1509 // Check if there's any pending changes...
339     if (m_iDirtyCount > 0) {
340     switch (QMessageBox::warning(this,
341 schoenebeck 1461 QSAMPLER_TITLE ": " + tr("Warning"),
342 capela 1509 tr("Some settings have been changed.\n\n"
343     "Do you want to apply the changes?"),
344     tr("Apply"), tr("Discard"), tr("Cancel"))) {
345     case 0: // Apply...
346     accept();
347     return;
348     case 1: // Discard
349     break;
350     default: // Cancel.
351     bReject = false;
352     }
353     }
354 schoenebeck 1461
355 capela 1509 if (bReject)
356     QDialog::reject();
357 schoenebeck 1461 }
358    
359    
360     // Dirty up settings.
361     void OptionsForm::optionsChanged (void)
362     {
363 capela 1509 if (m_iDirtySetup > 0)
364     return;
365 schoenebeck 1461
366 capela 1509 m_iDirtyCount++;
367     stabilizeForm();
368 schoenebeck 1461 }
369    
370    
371     // Stabilize current form state.
372     void OptionsForm::stabilizeForm (void)
373     {
374 capela 1738 bool bValid = (m_iDirtyCount > 0);
375    
376 capela 1509 bool bEnabled = m_ui.ServerStartCheckBox->isChecked();
377     m_ui.ServerCmdLineTextLabel->setEnabled(bEnabled);
378     m_ui.ServerCmdLineComboBox->setEnabled(bEnabled);
379     m_ui.StartDelayTextLabel->setEnabled(bEnabled);
380     m_ui.StartDelaySpinBox->setEnabled(bEnabled);
381 schoenebeck 1461
382 capela 1738 bEnabled = m_ui.MessagesLogCheckBox->isChecked();
383     m_ui.MessagesLogPathComboBox->setEnabled(bEnabled);
384     m_ui.MessagesLogPathToolButton->setEnabled(bEnabled);
385     if (bEnabled && bValid) {
386     const QString& sPath = m_ui.MessagesLogPathComboBox->currentText();
387     bValid = !sPath.isEmpty();
388     }
389    
390 capela 1509 m_ui.AutoRefreshTimeSpinBox->setEnabled(
391     m_ui.AutoRefreshCheckBox->isChecked());
392     m_ui.MessagesLimitLinesSpinBox->setEnabled(
393     m_ui.MessagesLimitCheckBox->isChecked());
394 schoenebeck 1461
395 capela 1738 m_ui.OkPushButton->setEnabled(bValid);
396 schoenebeck 1461 }
397    
398    
399 capela 1738 // Messages log path browse slot.
400     void OptionsForm::browseMessagesLogPath (void)
401     {
402     QString sFileName = QFileDialog::getSaveFileName(
403     this, // Parent.
404     tr("Messages Log"), // Caption.
405     m_ui.MessagesLogPathComboBox->currentText(), // Start here.
406     tr("Log files") + " (*.log)" // Filter (log files)
407     );
408    
409     if (!sFileName.isEmpty()) {
410     m_ui.MessagesLogPathComboBox->setEditText(sFileName);
411     m_ui.MessagesLogPathComboBox->setFocus();
412     optionsChanged();
413     }
414     }
415    
416    
417 schoenebeck 1461 // The channel display font selection dialog.
418     void OptionsForm::chooseDisplayFont (void)
419     {
420 capela 1509 bool bOk = false;
421     QFont font = QFontDialog::getFont(&bOk,
422     m_ui.DisplayFontTextLabel->font(), this);
423     if (bOk) {
424     m_ui.DisplayFontTextLabel->setFont(font);
425     m_ui.DisplayFontTextLabel->setText(font.family()
426     + ' ' + QString::number(font.pointSize()));
427     optionsChanged();
428     }
429 schoenebeck 1461 }
430    
431    
432     // The messages font selection dialog.
433     void OptionsForm::chooseMessagesFont (void)
434     {
435 capela 1509 bool bOk = false;
436     QFont font = QFontDialog::getFont(&bOk,
437     m_ui.MessagesFontTextLabel->font(), this);
438     if (bOk) {
439     m_ui.MessagesFontTextLabel->setFont(font);
440     m_ui.MessagesFontTextLabel->setText(font.family()
441     + ' ' + QString::number(font.pointSize()));
442     optionsChanged();
443     }
444 schoenebeck 1461 }
445    
446    
447     // The channel display effect demo changer.
448     void OptionsForm::toggleDisplayEffect ( bool bOn )
449     {
450 capela 1499 QPalette pal;
451     pal.setColor(QPalette::Foreground, Qt::green);
452     if (bOn) {
453 capela 1504 QPixmap pm(":/icons/displaybg1.png");
454 capela 1499 pal.setBrush(QPalette::Background, QBrush(pm));
455     } else {
456     pal.setColor(QPalette::Background, Qt::black);
457     }
458 capela 1509 m_ui.DisplayFontTextLabel->setPalette(pal);
459 schoenebeck 1461
460 capela 1499 optionsChanged();
461 schoenebeck 1461 }
462    
463 schoenebeck 1803 void OptionsForm::maxVoicesChanged(int /*iMaxVoices*/)
464     {
465     bMaxVoicesModified = true;
466     optionsChanged();
467     }
468    
469     void OptionsForm::maxStreamsChanged(int /*iMaxStreams*/)
470     {
471     bMaxStreamsModified = true;
472     optionsChanged();
473     }
474    
475 schoenebeck 1461 } // namespace QSampler
476 capela 1464
477 capela 1466 // end of qsamplerOptionsForm.cpp

  ViewVC Help
Powered by ViewVC