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 inline long lroundf ( float x ) |
41 |
{ |
42 |
if (x >= 0.0f) |
43 |
return long(x + 0.5f); |
44 |
else |
45 |
return long(x - 0.5f); |
46 |
} |
47 |
#endif |
48 |
|
49 |
|
50 |
// Kind of constructor. |
51 |
void qsamplerInstrumentForm::init (void) |
52 |
{ |
53 |
// Initialize locals. |
54 |
m_pInstrument = NULL; |
55 |
|
56 |
m_iDirtySetup = 0; |
57 |
m_iDirtyCount = 0; |
58 |
m_iDirtyName = 0; |
59 |
|
60 |
// Try to restore normal window positioning. |
61 |
adjustSize(); |
62 |
} |
63 |
|
64 |
|
65 |
// Kind of destructor. |
66 |
void qsamplerInstrumentForm::destroy (void) |
67 |
{ |
68 |
} |
69 |
|
70 |
|
71 |
// Channel dialog setup formal initializer. |
72 |
void qsamplerInstrumentForm::setup ( qsamplerInstrument *pInstrument ) |
73 |
{ |
74 |
m_pInstrument = pInstrument; |
75 |
|
76 |
m_iDirtySetup = 0; |
77 |
m_iDirtyCount = 0; |
78 |
m_iDirtyName = 0; |
79 |
|
80 |
if (m_pInstrument == NULL) |
81 |
return; |
82 |
|
83 |
// Check if we're up and connected. |
84 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
85 |
if (pMainForm == NULL) |
86 |
return; |
87 |
if (pMainForm->client() == NULL) |
88 |
return; |
89 |
|
90 |
qsamplerOptions *pOptions = pMainForm->options(); |
91 |
if (pOptions == NULL) |
92 |
return; |
93 |
|
94 |
// It can be a brand new channel, remember? |
95 |
bool bNew = (m_pInstrument->bank() < 0 || m_pInstrument->prog() < 0); |
96 |
if (!bNew) { |
97 |
m_pInstrument->getInstrument(); |
98 |
m_iDirtyName++; |
99 |
} |
100 |
|
101 |
// Avoid nested changes. |
102 |
m_iDirtySetup++; |
103 |
|
104 |
// Load combo box history... |
105 |
pOptions->loadComboBoxHistory(InstrumentFileComboBox); |
106 |
|
107 |
// Populate maps list. |
108 |
MapComboBox->clear(); |
109 |
MapComboBox->insertStringList(qsamplerInstrument::getMapNames()); |
110 |
|
111 |
// Populate Engines list. |
112 |
const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client()); |
113 |
if (ppszEngines) { |
114 |
EngineNameComboBox->clear(); |
115 |
for (int iEngine = 0; ppszEngines[iEngine]; iEngine++) |
116 |
EngineNameComboBox->insertItem(ppszEngines[iEngine]); |
117 |
} |
118 |
else pMainForm->appendMessagesClient("lscp_list_available_engines"); |
119 |
|
120 |
// Read proper instrument information, |
121 |
// and populate the instrument form fields. |
122 |
|
123 |
// Instrument map name... |
124 |
int iMap = (bNew ? pOptions->iMidiMap : m_pInstrument->map()); |
125 |
if (iMap < 0) |
126 |
iMap = 0; |
127 |
const QString& sMapName = qsamplerInstrument::getMapName(iMap); |
128 |
if (!sMapName.isEmpty()) |
129 |
MapComboBox->setCurrentText(sMapName); |
130 |
// It might be no maps around... |
131 |
bool bMapEnabled = (MapComboBox->count() > 0); |
132 |
MapTextLabel->setEnabled(bMapEnabled); |
133 |
MapComboBox->setEnabled(bNew && bMapEnabled); |
134 |
|
135 |
// Instrument bank/program... |
136 |
int iBank = (bNew ? pOptions->iMidiBank : m_pInstrument->bank()); |
137 |
int iProg = (bNew ? pOptions->iMidiProg : m_pInstrument->prog()) + 1; |
138 |
if (bNew && iProg > 128) { |
139 |
iProg = 1; |
140 |
iBank++; |
141 |
} |
142 |
BankSpinBox->setValue(iBank); |
143 |
ProgSpinBox->setValue(iProg); |
144 |
// Spacial hack to avoid changes on the key... |
145 |
if (bNew) { |
146 |
BankSpinBox->setRange(0, 16383); |
147 |
ProgSpinBox->setRange(1, 128); |
148 |
} else { |
149 |
BankSpinBox->setRange(iBank, iBank); |
150 |
ProgSpinBox->setRange(iProg, iProg); |
151 |
} |
152 |
|
153 |
// Instrument name... |
154 |
NameLineEdit->setText(m_pInstrument->name()); |
155 |
|
156 |
// Engine name... |
157 |
QString sEngineName = m_pInstrument->engineName(); |
158 |
if (sEngineName.isEmpty() || bNew) |
159 |
sEngineName = pOptions->sEngineName; |
160 |
if (sEngineName.isEmpty()) |
161 |
sEngineName = qsamplerChannel::noEngineName(); |
162 |
if (EngineNameComboBox->listBox()->findItem(sEngineName, |
163 |
Qt::ExactMatch | Qt::CaseSensitive) == NULL) { |
164 |
EngineNameComboBox->insertItem(sEngineName); |
165 |
} |
166 |
EngineNameComboBox->setCurrentText(sEngineName); |
167 |
// Instrument filename and index... |
168 |
QString sInstrumentFile = m_pInstrument->instrumentFile(); |
169 |
if (sInstrumentFile.isEmpty()) |
170 |
sInstrumentFile = qsamplerChannel::noInstrumentName(); |
171 |
InstrumentFileComboBox->setCurrentText(sInstrumentFile); |
172 |
InstrumentNrComboBox->clear(); |
173 |
InstrumentNrComboBox->insertStringList( |
174 |
qsamplerChannel::getInstrumentList(sInstrumentFile, |
175 |
pOptions->bInstrumentNames)); |
176 |
InstrumentNrComboBox->setCurrentItem(m_pInstrument->instrumentNr()); |
177 |
|
178 |
// Instrument volume.... |
179 |
int iVolume = (bNew ? pOptions->iVolume : |
180 |
::lroundf(100.0f * m_pInstrument->volume())); |
181 |
VolumeSpinBox->setValue(iVolume); |
182 |
|
183 |
// Instrument load mode... |
184 |
int iLoadMode = (bNew ? pOptions->iLoadMode : |
185 |
m_pInstrument->loadMode()); |
186 |
LoadModeComboBox->setCurrentItem(iLoadMode); |
187 |
|
188 |
// Done. |
189 |
m_iDirtySetup--; |
190 |
stabilizeForm(); |
191 |
|
192 |
// Done. |
193 |
m_iDirtySetup--; |
194 |
stabilizeForm(); |
195 |
} |
196 |
|
197 |
|
198 |
// Special case for name change, |
199 |
void qsamplerInstrumentForm::nameChanged ( const QString& /* sName */ ) |
200 |
{ |
201 |
if (m_iDirtySetup > 0) |
202 |
return; |
203 |
|
204 |
m_iDirtyName++; |
205 |
changed(); |
206 |
} |
207 |
|
208 |
|
209 |
// Browse and open an instrument file. |
210 |
void qsamplerInstrumentForm::openInstrumentFile (void) |
211 |
{ |
212 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
213 |
if (pMainForm == NULL) |
214 |
return; |
215 |
|
216 |
qsamplerOptions *pOptions = pMainForm->options(); |
217 |
if (pOptions == NULL) |
218 |
return; |
219 |
|
220 |
// FIXME: the instrument file filters should be restricted, |
221 |
// depending on the current engine. |
222 |
QString sInstrumentFile = QFileDialog::getOpenFileName( |
223 |
pOptions->sInstrumentDir, // Start here. |
224 |
tr("Instrument files") + " (*.gig *.dls)", // Filter (GIG and DLS files) |
225 |
this, 0, // Parent and name (none) |
226 |
QSAMPLER_TITLE ": " + tr("Instrument files")// Caption. |
227 |
); |
228 |
|
229 |
if (sInstrumentFile.isEmpty()) |
230 |
return; |
231 |
|
232 |
InstrumentFileComboBox->setCurrentText(sInstrumentFile); |
233 |
updateInstrumentName(); |
234 |
} |
235 |
|
236 |
|
237 |
// Refresh the actual instrument name. |
238 |
void qsamplerInstrumentForm::updateInstrumentName (void) |
239 |
{ |
240 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
241 |
if (pMainForm == NULL) |
242 |
return; |
243 |
|
244 |
qsamplerOptions *pOptions = pMainForm->options(); |
245 |
if (pOptions == NULL) |
246 |
return; |
247 |
|
248 |
// TODO: this better idea would be to use libgig |
249 |
// to retrieve the REAL instrument names. |
250 |
InstrumentNrComboBox->clear(); |
251 |
InstrumentNrComboBox->insertStringList( |
252 |
qsamplerChannel::getInstrumentList( |
253 |
InstrumentFileComboBox->currentText(), |
254 |
pOptions->bInstrumentNames) |
255 |
); |
256 |
|
257 |
instrumentNrChanged(); |
258 |
} |
259 |
|
260 |
|
261 |
// Special case for instrumnet index change, |
262 |
void qsamplerInstrumentForm::instrumentNrChanged (void) |
263 |
{ |
264 |
if (m_iDirtySetup > 0) |
265 |
return; |
266 |
|
267 |
if (NameLineEdit->text().isEmpty() || m_iDirtyName == 0) { |
268 |
NameLineEdit->setText(InstrumentNrComboBox->currentText()); |
269 |
m_iDirtyName = 0; |
270 |
} |
271 |
|
272 |
changed(); |
273 |
} |
274 |
|
275 |
|
276 |
// Accept settings (OK button slot). |
277 |
void qsamplerInstrumentForm::accept (void) |
278 |
{ |
279 |
if (m_pInstrument == NULL) |
280 |
return; |
281 |
|
282 |
qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); |
283 |
if (pMainForm == NULL) |
284 |
return; |
285 |
if (pMainForm->client() == NULL) |
286 |
return; |
287 |
|
288 |
qsamplerOptions *pOptions = pMainForm->options(); |
289 |
if (pOptions == NULL) |
290 |
return; |
291 |
|
292 |
if (m_iDirtyCount > 0) { |
293 |
m_pInstrument->setMap(MapComboBox->currentItem()); |
294 |
m_pInstrument->setMap(MapComboBox->currentItem()); |
295 |
m_pInstrument->setBank(BankSpinBox->value()); |
296 |
m_pInstrument->setProg(ProgSpinBox->value() - 1); |
297 |
m_pInstrument->setName(NameLineEdit->text()); |
298 |
m_pInstrument->setEngineName(EngineNameComboBox->currentText()); |
299 |
m_pInstrument->setInstrumentFile(InstrumentFileComboBox->currentText()); |
300 |
m_pInstrument->setInstrumentNr(InstrumentNrComboBox->currentItem()); |
301 |
m_pInstrument->setVolume(0.01f * float(VolumeSpinBox->value())); |
302 |
m_pInstrument->setLoadMode(LoadModeComboBox->currentItem()); |
303 |
} |
304 |
|
305 |
// Save default engine name, instrument directory and history... |
306 |
pOptions->sInstrumentDir = QFileInfo(InstrumentFileComboBox->currentText()).dirPath(true); |
307 |
pOptions->sEngineName = EngineNameComboBox->currentText(); |
308 |
pOptions->iMidiMap = MapComboBox->currentItem(); |
309 |
pOptions->iMidiBank = BankSpinBox->value(); |
310 |
pOptions->iMidiProg = ProgSpinBox->value(); |
311 |
pOptions->iVolume = VolumeSpinBox->value(); |
312 |
pOptions->iLoadMode = LoadModeComboBox->currentItem(); |
313 |
pOptions->saveComboBoxHistory(InstrumentFileComboBox); |
314 |
|
315 |
// Just go with dialog acceptance. |
316 |
QDialog::accept(); |
317 |
} |
318 |
|
319 |
|
320 |
// Reject settings (Cancel button slot). |
321 |
void qsamplerInstrumentForm::reject (void) |
322 |
{ |
323 |
bool bReject = true; |
324 |
|
325 |
// Check if there's any pending changes... |
326 |
if (m_iDirtyCount > 0 && OkPushButton->isEnabled()) { |
327 |
switch (QMessageBox::warning(this, |
328 |
QSAMPLER_TITLE ": " + tr("Warning"), |
329 |
tr("Some channel settings have been changed.\n\n" |
330 |
"Do you want to apply the changes?"), |
331 |
tr("Apply"), tr("Discard"), tr("Cancel"))) { |
332 |
case 0: // Apply... |
333 |
accept(); |
334 |
return; |
335 |
case 1: // Discard |
336 |
break; |
337 |
default: // Cancel. |
338 |
bReject = false; |
339 |
break; |
340 |
} |
341 |
} |
342 |
|
343 |
if (bReject) |
344 |
QDialog::reject(); |
345 |
} |
346 |
|
347 |
|
348 |
// Dirty up settings. |
349 |
void qsamplerInstrumentForm::changed (void) |
350 |
{ |
351 |
if (m_iDirtySetup > 0) |
352 |
return; |
353 |
|
354 |
m_iDirtyCount++; |
355 |
stabilizeForm(); |
356 |
} |
357 |
|
358 |
|
359 |
// Stabilize current form state. |
360 |
void qsamplerInstrumentForm::stabilizeForm (void) |
361 |
{ |
362 |
bool bValid =!NameLineEdit->text().isEmpty(); |
363 |
|
364 |
const QString& sPath = InstrumentFileComboBox->currentText(); |
365 |
bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists(); |
366 |
|
367 |
OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid); |
368 |
} |
369 |
|
370 |
|
371 |
// end of qsamplerInstrumentForm.ui.h |