/[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 969 - (show annotations) (download) (as text)
Wed Dec 6 19:38:02 2006 UTC (17 years, 3 months ago) by capela
File MIME type: text/x-c++hdr
File size: 9068 byte(s)
* Fixed MIDI instrument volume setting.
* Enforcing uniqueness of bank and program key pair
  while editing the MIDI instrument map.

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

  ViewVC Help
Powered by ViewVC