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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.970  
changed lines
  Added in v.971

  ViewVC Help
Powered by ViewVC