/[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 962 - (hide annotations) (download) (as text)
Sun Dec 3 18:27:23 2006 UTC (17 years, 4 months ago) by capela
File MIME type: text/x-c++hdr
File size: 8809 byte(s)
* Adding preliminary MIDI instrument mapping support; now
  with an instrument list widget and editing capabilities.

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

  ViewVC Help
Powered by ViewVC