/[svn]/qsampler/trunk/src/qsamplerInstrumentForm.ui.h
ViewVC logotype

Contents of /qsampler/trunk/src/qsamplerInstrumentForm.ui.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 972 - (show annotations) (download) (as text)
Sun Dec 10 17:07:02 2006 UTC (16 years, 1 month ago) by capela
File MIME type: text/x-c++hdr
File size: 9098 byte(s)
- Minor autoconf adaptations for lroundf conditional compilation.

1 // qsamplerInstrumentForm.ui.h
2 //
3 // ui.h extension file, included from the uic-generated form implementation.
4 /****************************************************************************
5 Copyright (C) 2004-2006, rncbc aka Rui Nuno Capela. All rights reserved.
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21 *****************************************************************************/
22
23 #include "qsamplerAbout.h"
24 #include "qsamplerInstrument.h"
25
26 #include "qsamplerOptions.h"
27 #include "qsamplerChannel.h"
28
29 #include "qsamplerMainForm.h"
30
31 #include <qmessagebox.h>
32 #include <qfiledialog.h>
33 #include <qfileinfo.h>
34 #include <qlistbox.h>
35
36 // Needed for lroundf()
37 #include <math.h>
38
39 #ifndef CONFIG_ROUND
40 static long lroundf ( float fval )
41 {
42 double fint = 0.0;
43 float frac = float(::modf(fval, &fint));
44 long lint = long(fint);
45 if (frac >= +0.5f)
46 lint++;
47 else
48 if (frac <= -0.5f)
49 lint--;
50 return lint;
51 }
52 #endif
53
54
55 // Kind of constructor.
56 void qsamplerInstrumentForm::init (void)
57 {
58 // Initialize locals.
59 m_pInstrument = NULL;
60
61 m_iDirtySetup = 0;
62 m_iDirtyCount = 0;
63 m_iDirtyName = 0;
64
65 // Try to restore normal window positioning.
66 adjustSize();
67 }
68
69
70 // Kind of destructor.
71 void qsamplerInstrumentForm::destroy (void)
72 {
73 }
74
75
76 // Channel dialog setup formal initializer.
77 void qsamplerInstrumentForm::setup ( qsamplerInstrument *pInstrument )
78 {
79 m_pInstrument = pInstrument;
80
81 m_iDirtySetup = 0;
82 m_iDirtyCount = 0;
83 m_iDirtyName = 0;
84
85 if (m_pInstrument == NULL)
86 return;
87
88 // Check if we're up and connected.
89 qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
90 if (pMainForm == NULL)
91 return;
92 if (pMainForm->client() == NULL)
93 return;
94
95 qsamplerOptions *pOptions = pMainForm->options();
96 if (pOptions == NULL)
97 return;
98
99 // It can be a brand new channel, remember?
100 bool bNew = (m_pInstrument->bank() < 0 || m_pInstrument->program() < 0);
101 if (!bNew) {
102 m_pInstrument->get();
103 m_iDirtyName++;
104 }
105
106 // Avoid nested changes.
107 m_iDirtySetup++;
108
109 // Load combo box history...
110 pOptions->loadComboBoxHistory(InstrumentFileComboBox);
111
112 // Populate Engines list.
113 const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client());
114 if (ppszEngines) {
115 EngineNameComboBox->clear();
116 for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)
117 EngineNameComboBox->insertItem(ppszEngines[iEngine]);
118 }
119 else pMainForm->appendMessagesClient("lscp_list_available_engines");
120
121 // Read proper instrument information,
122 // and populate the instrument form fields.
123
124 // Instrument bank/program...
125 int iBank = m_pInstrument->bank();
126 int iProgram = m_pInstrument->program() + 1;
127 BankSpinBox->setValue(iBank);
128 ProgramSpinBox->setValue(iProgram);
129 // Spacial hack to avoid changes on the key...
130 if (bNew) {
131 BankSpinBox->setRange(0, 16383);
132 ProgramSpinBox->setRange(1, 128);
133 } else {
134 BankSpinBox->setRange(iBank, iBank);
135 ProgramSpinBox->setRange(iProgram, iProgram);
136 }
137
138 // Instrument name...
139 NameLineEdit->setText(m_pInstrument->name());
140
141 // Engine name...
142 QString sEngineName = m_pInstrument->engineName();
143 if (sEngineName.isEmpty() || bNew)
144 sEngineName = pOptions->sEngineName;
145 if (sEngineName.isEmpty())
146 sEngineName = qsamplerChannel::noEngineName();
147 if (EngineNameComboBox->listBox()->findItem(sEngineName,
148 Qt::ExactMatch | Qt::CaseSensitive) == NULL) {
149 EngineNameComboBox->insertItem(sEngineName);
150 }
151 EngineNameComboBox->setCurrentText(sEngineName);
152 // Instrument filename and index...
153 QString sInstrumentFile = m_pInstrument->instrumentFile();
154 if (sInstrumentFile.isEmpty())
155 sInstrumentFile = qsamplerChannel::noInstrumentName();
156 InstrumentFileComboBox->setCurrentText(sInstrumentFile);
157 InstrumentNrComboBox->clear();
158 InstrumentNrComboBox->insertStringList(
159 qsamplerChannel::getInstrumentList(sInstrumentFile,
160 pOptions->bInstrumentNames));
161 InstrumentNrComboBox->setCurrentItem(m_pInstrument->instrumentNr());
162
163 // Instrument volume....
164 VolumeSpinBox->setValue(::lroundf(100.0f * m_pInstrument->volume()));
165
166 // Instrument load mode...
167 LoadModeComboBox->setCurrentItem(m_pInstrument->loadMode());
168
169 // Done.
170 m_iDirtySetup--;
171 stabilizeForm();
172
173 // Done.
174 m_iDirtySetup--;
175 stabilizeForm();
176 }
177
178
179 // Special case for name change,
180 void qsamplerInstrumentForm::nameChanged ( const QString& /* sName */ )
181 {
182 if (m_iDirtySetup > 0)
183 return;
184
185 m_iDirtyName++;
186 changed();
187 }
188
189
190 // Browse and open an instrument file.
191 void qsamplerInstrumentForm::openInstrumentFile (void)
192 {
193 qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
194 if (pMainForm == NULL)
195 return;
196
197 qsamplerOptions *pOptions = pMainForm->options();
198 if (pOptions == NULL)
199 return;
200
201 // FIXME: the instrument file filters should be restricted,
202 // depending on the current engine.
203 QString sInstrumentFile = QFileDialog::getOpenFileName(
204 pOptions->sInstrumentDir, // Start here.
205 tr("Instrument files") + " (*.gig *.dls)", // Filter (GIG and DLS files)
206 this, 0, // Parent and name (none)
207 QSAMPLER_TITLE ": " + tr("Instrument files")// Caption.
208 );
209
210 if (sInstrumentFile.isEmpty())
211 return;
212
213 InstrumentFileComboBox->setCurrentText(sInstrumentFile);
214 updateInstrumentName();
215 }
216
217
218 // Refresh the actual instrument name.
219 void qsamplerInstrumentForm::updateInstrumentName (void)
220 {
221 qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
222 if (pMainForm == NULL)
223 return;
224
225 qsamplerOptions *pOptions = pMainForm->options();
226 if (pOptions == NULL)
227 return;
228
229 // TODO: this better idea would be to use libgig
230 // to retrieve the REAL instrument names.
231 InstrumentNrComboBox->clear();
232 InstrumentNrComboBox->insertStringList(
233 qsamplerChannel::getInstrumentList(
234 InstrumentFileComboBox->currentText(),
235 pOptions->bInstrumentNames)
236 );
237
238 instrumentNrChanged();
239 }
240
241
242 // Special case for instrumnet index change,
243 void qsamplerInstrumentForm::instrumentNrChanged (void)
244 {
245 if (m_iDirtySetup > 0)
246 return;
247
248 if (NameLineEdit->text().isEmpty() || m_iDirtyName == 0) {
249 NameLineEdit->setText(InstrumentNrComboBox->currentText());
250 m_iDirtyName = 0;
251 }
252
253 changed();
254 }
255
256
257 // Accept settings (OK button slot).
258 void qsamplerInstrumentForm::accept (void)
259 {
260 if (m_pInstrument == NULL)
261 return;
262
263 qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
264 if (pMainForm == NULL)
265 return;
266 if (pMainForm->client() == NULL)
267 return;
268
269 qsamplerOptions *pOptions = pMainForm->options();
270 if (pOptions == NULL)
271 return;
272
273 if (m_iDirtyCount > 0) {
274 m_pInstrument->setBank(BankSpinBox->value());
275 m_pInstrument->setProgram(ProgramSpinBox->value() - 1);
276 m_pInstrument->setName(NameLineEdit->text());
277 m_pInstrument->setEngineName(EngineNameComboBox->currentText());
278 m_pInstrument->setInstrumentFile(InstrumentFileComboBox->currentText());
279 m_pInstrument->setInstrumentNr(InstrumentNrComboBox->currentItem());
280 m_pInstrument->setVolume(0.01f * float(VolumeSpinBox->value()));
281 m_pInstrument->setLoadMode(LoadModeComboBox->currentItem());
282 }
283
284 // Save default engine name, instrument directory and history...
285 pOptions->sInstrumentDir = QFileInfo(InstrumentFileComboBox->currentText()).dirPath(true);
286 pOptions->sEngineName = EngineNameComboBox->currentText();
287 pOptions->saveComboBoxHistory(InstrumentFileComboBox);
288
289 // Just go with dialog acceptance.
290 QDialog::accept();
291 }
292
293
294 // Reject settings (Cancel button slot).
295 void qsamplerInstrumentForm::reject (void)
296 {
297 bool bReject = true;
298
299 // Check if there's any pending changes...
300 if (m_iDirtyCount > 0 && OkPushButton->isEnabled()) {
301 switch (QMessageBox::warning(this,
302 QSAMPLER_TITLE ": " + tr("Warning"),
303 tr("Some channel settings have been changed.\n\n"
304 "Do you want to apply the changes?"),
305 tr("Apply"), tr("Discard"), tr("Cancel"))) {
306 case 0: // Apply...
307 accept();
308 return;
309 case 1: // Discard
310 break;
311 default: // Cancel.
312 bReject = false;
313 break;
314 }
315 }
316
317 if (bReject)
318 QDialog::reject();
319 }
320
321
322 // Dirty up settings.
323 void qsamplerInstrumentForm::changed (void)
324 {
325 if (m_iDirtySetup > 0)
326 return;
327
328 m_iDirtyCount++;
329 stabilizeForm();
330 }
331
332
333 // Stabilize current form state.
334 void qsamplerInstrumentForm::stabilizeForm (void)
335 {
336 bool bValid =!NameLineEdit->text().isEmpty();
337
338 const QString& sPath = InstrumentFileComboBox->currentText();
339 bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists();
340
341 OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid);
342 }
343
344
345 // end of qsamplerInstrumentForm.ui.h

  ViewVC Help
Powered by ViewVC