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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1013 - (hide annotations) (download) (as text)
Mon Jan 8 16:52:48 2007 UTC (17 years, 4 months ago) by capela
File MIME type: text/x-c++hdr
File size: 9787 byte(s)
* Instruments window gets its own toolbar (and statusbar too);
  also introducing MIDI instrument map selection to the view;
  MIDI instrument item editing now allows changing map, bank
  or program key values (were previously disabled).

1 capela 971 // qsamplerInstrumentForm.ui.h
2     //
3     // ui.h extension file, included from the uic-generated form implementation.
4     /****************************************************************************
5 capela 1013 Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.
6 capela 971
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 capela 972 #ifndef CONFIG_ROUND
40 capela 980 static inline long lroundf ( float x )
41 capela 971 {
42 capela 980 if (x >= 0.0f)
43     return long(x + 0.5f);
44     else
45     return long(x - 0.5f);
46 capela 971 }
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 capela 980 bool bNew = (m_pInstrument->bank() < 0 || m_pInstrument->prog() < 0);
96 capela 971 if (!bNew) {
97 capela 980 m_pInstrument->getInstrument();
98 capela 971 m_iDirtyName++;
99     }
100    
101     // Avoid nested changes.
102     m_iDirtySetup++;
103    
104     // Load combo box history...
105     pOptions->loadComboBoxHistory(InstrumentFileComboBox);
106    
107 capela 980 // Populate maps list.
108     MapComboBox->clear();
109     MapComboBox->insertStringList(qsamplerInstrument::getMapNames());
110    
111 capela 971 // 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 capela 980 // 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 capela 1013 MapComboBox->setEnabled(bMapEnabled);
134 capela 980
135 capela 971 // Instrument bank/program...
136 capela 980 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 capela 971 BankSpinBox->setValue(iBank);
143 capela 980 ProgSpinBox->setValue(iProg);
144 capela 971
145     // Instrument name...
146     NameLineEdit->setText(m_pInstrument->name());
147    
148     // Engine name...
149     QString sEngineName = m_pInstrument->engineName();
150     if (sEngineName.isEmpty() || bNew)
151     sEngineName = pOptions->sEngineName;
152     if (sEngineName.isEmpty())
153     sEngineName = qsamplerChannel::noEngineName();
154     if (EngineNameComboBox->listBox()->findItem(sEngineName,
155     Qt::ExactMatch | Qt::CaseSensitive) == NULL) {
156     EngineNameComboBox->insertItem(sEngineName);
157     }
158     EngineNameComboBox->setCurrentText(sEngineName);
159     // Instrument filename and index...
160     QString sInstrumentFile = m_pInstrument->instrumentFile();
161     if (sInstrumentFile.isEmpty())
162     sInstrumentFile = qsamplerChannel::noInstrumentName();
163     InstrumentFileComboBox->setCurrentText(sInstrumentFile);
164     InstrumentNrComboBox->clear();
165     InstrumentNrComboBox->insertStringList(
166     qsamplerChannel::getInstrumentList(sInstrumentFile,
167     pOptions->bInstrumentNames));
168     InstrumentNrComboBox->setCurrentItem(m_pInstrument->instrumentNr());
169    
170     // Instrument volume....
171 capela 980 int iVolume = (bNew ? pOptions->iVolume :
172     ::lroundf(100.0f * m_pInstrument->volume()));
173     VolumeSpinBox->setValue(iVolume);
174 capela 971
175     // Instrument load mode...
176 capela 980 int iLoadMode = (bNew ? pOptions->iLoadMode :
177     m_pInstrument->loadMode());
178     LoadModeComboBox->setCurrentItem(iLoadMode);
179 capela 971
180     // Done.
181     m_iDirtySetup--;
182     stabilizeForm();
183    
184     // Done.
185     m_iDirtySetup--;
186     stabilizeForm();
187     }
188    
189    
190     // Special case for name change,
191     void qsamplerInstrumentForm::nameChanged ( const QString& /* sName */ )
192     {
193     if (m_iDirtySetup > 0)
194     return;
195    
196     m_iDirtyName++;
197     changed();
198     }
199    
200    
201     // Browse and open an instrument file.
202     void qsamplerInstrumentForm::openInstrumentFile (void)
203     {
204     qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
205     if (pMainForm == NULL)
206     return;
207    
208     qsamplerOptions *pOptions = pMainForm->options();
209     if (pOptions == NULL)
210     return;
211    
212     // FIXME: the instrument file filters should be restricted,
213     // depending on the current engine.
214     QString sInstrumentFile = QFileDialog::getOpenFileName(
215     pOptions->sInstrumentDir, // Start here.
216     tr("Instrument files") + " (*.gig *.dls)", // Filter (GIG and DLS files)
217     this, 0, // Parent and name (none)
218     QSAMPLER_TITLE ": " + tr("Instrument files")// Caption.
219     );
220    
221     if (sInstrumentFile.isEmpty())
222     return;
223    
224     InstrumentFileComboBox->setCurrentText(sInstrumentFile);
225     updateInstrumentName();
226     }
227    
228    
229     // Refresh the actual instrument name.
230     void qsamplerInstrumentForm::updateInstrumentName (void)
231     {
232     qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
233     if (pMainForm == NULL)
234     return;
235    
236     qsamplerOptions *pOptions = pMainForm->options();
237     if (pOptions == NULL)
238     return;
239    
240     // TODO: this better idea would be to use libgig
241     // to retrieve the REAL instrument names.
242     InstrumentNrComboBox->clear();
243     InstrumentNrComboBox->insertStringList(
244     qsamplerChannel::getInstrumentList(
245     InstrumentFileComboBox->currentText(),
246     pOptions->bInstrumentNames)
247     );
248    
249     instrumentNrChanged();
250     }
251    
252    
253     // Special case for instrumnet index change,
254     void qsamplerInstrumentForm::instrumentNrChanged (void)
255     {
256     if (m_iDirtySetup > 0)
257     return;
258    
259     if (NameLineEdit->text().isEmpty() || m_iDirtyName == 0) {
260     NameLineEdit->setText(InstrumentNrComboBox->currentText());
261     m_iDirtyName = 0;
262     }
263    
264     changed();
265     }
266    
267    
268     // Accept settings (OK button slot).
269     void qsamplerInstrumentForm::accept (void)
270     {
271     if (m_pInstrument == NULL)
272     return;
273    
274     qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
275     if (pMainForm == NULL)
276     return;
277     if (pMainForm->client() == NULL)
278     return;
279    
280     qsamplerOptions *pOptions = pMainForm->options();
281     if (pOptions == NULL)
282     return;
283    
284     if (m_iDirtyCount > 0) {
285 capela 980 m_pInstrument->setMap(MapComboBox->currentItem());
286 capela 971 m_pInstrument->setBank(BankSpinBox->value());
287 capela 980 m_pInstrument->setProg(ProgSpinBox->value() - 1);
288 capela 971 m_pInstrument->setName(NameLineEdit->text());
289     m_pInstrument->setEngineName(EngineNameComboBox->currentText());
290     m_pInstrument->setInstrumentFile(InstrumentFileComboBox->currentText());
291     m_pInstrument->setInstrumentNr(InstrumentNrComboBox->currentItem());
292     m_pInstrument->setVolume(0.01f * float(VolumeSpinBox->value()));
293     m_pInstrument->setLoadMode(LoadModeComboBox->currentItem());
294     }
295    
296     // Save default engine name, instrument directory and history...
297     pOptions->sInstrumentDir = QFileInfo(InstrumentFileComboBox->currentText()).dirPath(true);
298     pOptions->sEngineName = EngineNameComboBox->currentText();
299 capela 980 pOptions->iMidiMap = MapComboBox->currentItem();
300     pOptions->iMidiBank = BankSpinBox->value();
301     pOptions->iMidiProg = ProgSpinBox->value();
302     pOptions->iVolume = VolumeSpinBox->value();
303     pOptions->iLoadMode = LoadModeComboBox->currentItem();
304 capela 971 pOptions->saveComboBoxHistory(InstrumentFileComboBox);
305    
306     // Just go with dialog acceptance.
307     QDialog::accept();
308     }
309    
310    
311     // Reject settings (Cancel button slot).
312     void qsamplerInstrumentForm::reject (void)
313     {
314     bool bReject = true;
315    
316     // Check if there's any pending changes...
317     if (m_iDirtyCount > 0 && OkPushButton->isEnabled()) {
318     switch (QMessageBox::warning(this,
319     QSAMPLER_TITLE ": " + tr("Warning"),
320     tr("Some channel settings have been changed.\n\n"
321     "Do you want to apply the changes?"),
322     tr("Apply"), tr("Discard"), tr("Cancel"))) {
323     case 0: // Apply...
324     accept();
325     return;
326     case 1: // Discard
327     break;
328     default: // Cancel.
329     bReject = false;
330     break;
331     }
332     }
333    
334     if (bReject)
335     QDialog::reject();
336     }
337    
338    
339     // Dirty up settings.
340     void qsamplerInstrumentForm::changed (void)
341     {
342     if (m_iDirtySetup > 0)
343     return;
344    
345     m_iDirtyCount++;
346     stabilizeForm();
347     }
348    
349    
350     // Stabilize current form state.
351     void qsamplerInstrumentForm::stabilizeForm (void)
352     {
353     bool bValid =!NameLineEdit->text().isEmpty();
354    
355     const QString& sPath = InstrumentFileComboBox->currentText();
356     bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists();
357    
358     OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid);
359     }
360    
361    
362     // end of qsamplerInstrumentForm.ui.h

  ViewVC Help
Powered by ViewVC