/[svn]/qsampler/trunk/src/qsamplerInstrumentForm.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerInstrumentForm.cpp

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

revision 1474 by schoenebeck, Mon Nov 5 20:47:38 2007 UTC revision 2069 by capela, Mon Mar 15 10:45:35 2010 UTC
# Line 1  Line 1 
1  // qsamplerInstrumentForm.cpp  // qsamplerInstrumentForm.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2003-2007, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2003-2010, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007, Christian Schoenebeck     Copyright (C) 2007, Christian Schoenebeck
6    
7     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
# Line 20  Line 20 
20    
21  *****************************************************************************/  *****************************************************************************/
22    
23    #include "qsamplerAbout.h"
24  #include "qsamplerInstrumentForm.h"  #include "qsamplerInstrumentForm.h"
25    
26  #include "qsamplerAbout.h"  #include "qsamplerOptions.h"
27    #include "qsamplerChannel.h"
28  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
29    
30    #include <QFileDialog>
31    #include <QMessageBox>
32    
33  // Needed for lroundf()  // Needed for lroundf()
34  #include <math.h>  #include <math.h>
35    
 namespace QSampler {  
   
36  #ifndef CONFIG_ROUND  #ifndef CONFIG_ROUND
37  static inline long lroundf ( float x )  static inline long lroundf ( float x )
38  {  {
# Line 40  static inline long lroundf ( float x ) Line 43  static inline long lroundf ( float x )
43  }  }
44  #endif  #endif
45    
46  InstrumentForm::InstrumentForm(QWidget* parent) : QDialog(parent) {  
47      ui.setupUi(this);  namespace QSampler {
48    
49    //-------------------------------------------------------------------------
50    // QSampler::InstrumentForm -- Instrument map item form implementation.
51    //
52    
53    InstrumentForm::InstrumentForm ( QWidget *pParent )
54            : QDialog(pParent)
55    {
56            m_ui.setupUi(this);
57    
58          // Initialize locals.          // Initialize locals.
59          m_pInstrument = NULL;          m_pInstrument = NULL;
# Line 54  InstrumentForm::InstrumentForm(QWidget* Line 66  InstrumentForm::InstrumentForm(QWidget*
66          adjustSize();          adjustSize();
67    
68    
69          QObject::connect(ui.MapComboBox,          QObject::connect(m_ui.MapComboBox,
70                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
71                  SLOT(changed()));                  SLOT(changed()));
72          QObject::connect(ui.BankSpinBox,          QObject::connect(m_ui.BankSpinBox,
73                  SIGNAL(valueChanged(int)),                  SIGNAL(valueChanged(int)),
74                  SLOT(changed()));                  SLOT(changed()));
75          QObject::connect(ui.ProgSpinBox,          QObject::connect(m_ui.ProgSpinBox,
76                  SIGNAL(valueChanged(int)),                  SIGNAL(valueChanged(int)),
77                  SLOT(changed()));                  SLOT(changed()));
78          QObject::connect(ui.NameLineEdit,          QObject::connect(m_ui.NameLineEdit,
79                  SIGNAL(textChanged(const QString&)),                  SIGNAL(textChanged(const QString&)),
80                  SLOT(nameChanged(const QString&)));                  SLOT(nameChanged(const QString&)));
81          QObject::connect(ui.EngineNameComboBox,          QObject::connect(m_ui.EngineNameComboBox,
82                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
83                  SLOT(changed()));                  SLOT(changed()));
84          QObject::connect(ui.InstrumentFileComboBox,          QObject::connect(m_ui.InstrumentFileComboBox,
85                  SIGNAL(activated(const QString&)),                  SIGNAL(activated(const QString&)),
86                  SLOT(updateInstrumentName()));                  SLOT(updateInstrumentName()));
87          QObject::connect(ui.InstrumentFileToolButton,          QObject::connect(m_ui.InstrumentFileToolButton,
88                  SIGNAL(clicked()),                  SIGNAL(clicked()),
89                  SLOT(openInstrumentFile()));                  SLOT(openInstrumentFile()));
90          QObject::connect(ui.InstrumentNrComboBox,          QObject::connect(m_ui.InstrumentNrComboBox,
91                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
92                  SLOT(instrumentNrChanged()));                  SLOT(instrumentNrChanged()));
93          QObject::connect(ui.VolumeSpinBox,          QObject::connect(m_ui.VolumeSpinBox,
94                  SIGNAL(valueChanged(int)),                  SIGNAL(valueChanged(int)),
95                  SLOT(changed()));                  SLOT(changed()));
96          QObject::connect(ui.LoadModeComboBox,          QObject::connect(m_ui.LoadModeComboBox,
97                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
98                  SLOT(changed()));                  SLOT(changed()));
99          QObject::connect(ui.OkPushButton,          QObject::connect(m_ui.OkPushButton,
100                  SIGNAL(clicked()),                  SIGNAL(clicked()),
101                  SLOT(accept()));                  SLOT(accept()));
102          QObject::connect(ui.CancelPushButton,          QObject::connect(m_ui.CancelPushButton,
103                  SIGNAL(clicked()),                  SIGNAL(clicked()),
104                  SLOT(reject()));                  SLOT(reject()));
105  }  }
106    
107  InstrumentForm::~InstrumentForm() {  
108    InstrumentForm::~InstrumentForm (void)
109    {
110  }  }
111    
112    
113  // Channel dialog setup formal initializer.  // Channel dialog setup formal initializer.
114  void InstrumentForm::setup ( qsamplerInstrument *pInstrument )  void InstrumentForm::setup ( Instrument *pInstrument )
115  {  {
116          m_pInstrument = pInstrument;          m_pInstrument = pInstrument;
117    
# Line 114  void InstrumentForm::setup ( qsamplerIns Line 129  void InstrumentForm::setup ( qsamplerIns
129          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
130                  return;                  return;
131    
132          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
133          if (pOptions == NULL)          if (pOptions == NULL)
134                  return;                  return;
135    
# Line 129  void InstrumentForm::setup ( qsamplerIns Line 144  void InstrumentForm::setup ( qsamplerIns
144          m_iDirtySetup++;          m_iDirtySetup++;
145    
146          // Load combo box history...          // Load combo box history...
147          pOptions->loadComboBoxHistory(ui.InstrumentFileComboBox);          pOptions->loadComboBoxHistory(m_ui.InstrumentFileComboBox);
148    
149          // Populate maps list.          // Populate maps list.
150          ui.MapComboBox->clear();          m_ui.MapComboBox->clear();
151          ui.MapComboBox->insertStringList(qsamplerInstrument::getMapNames());          m_ui.MapComboBox->insertItems(0, Instrument::getMapNames());
152    
153          // Populate Engines list.          // Populate Engines list.
154          const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client());          const char **ppszEngines
155                    = ::lscp_list_available_engines(pMainForm->client());
156          if (ppszEngines) {          if (ppszEngines) {
157                  ui.EngineNameComboBox->clear();                  m_ui.EngineNameComboBox->clear();
158                  for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)                  for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)
159                          ui.EngineNameComboBox->insertItem(ppszEngines[iEngine]);                          m_ui.EngineNameComboBox->addItem(ppszEngines[iEngine]);
160          }          }
161          else pMainForm->appendMessagesClient("lscp_list_available_engines");          else pMainForm->appendMessagesClient("lscp_list_available_engines");
162    
# Line 151  void InstrumentForm::setup ( qsamplerIns Line 167  void InstrumentForm::setup ( qsamplerIns
167          int iMap = (bNew ? pOptions->iMidiMap : m_pInstrument->map());          int iMap = (bNew ? pOptions->iMidiMap : m_pInstrument->map());
168          if (iMap < 0)          if (iMap < 0)
169                  iMap = 0;                  iMap = 0;
170          const QString& sMapName = qsamplerInstrument::getMapName(iMap);          const QString& sMapName = Instrument::getMapName(iMap);
171          if (!sMapName.isEmpty())          if (!sMapName.isEmpty()) {
172                  ui.MapComboBox->setCurrentText(sMapName);                  m_ui.MapComboBox->setCurrentIndex(
173                            m_ui.MapComboBox->findText(sMapName,
174                                    Qt::MatchExactly | Qt::MatchCaseSensitive));
175            }
176    
177          // It might be no maps around...          // It might be no maps around...
178          bool bMapEnabled = (ui.MapComboBox->count() > 0);          bool bMapEnabled = (m_ui.MapComboBox->count() > 0);
179          ui.MapTextLabel->setEnabled(bMapEnabled);          m_ui.MapTextLabel->setEnabled(bMapEnabled);
180          ui.MapComboBox->setEnabled(bMapEnabled);          m_ui.MapComboBox->setEnabled(bMapEnabled);
181    
182          // Instrument bank/program...          // Instrument bank/program...
183          int iBank = (bNew ? pOptions->iMidiBank : m_pInstrument->bank());          int iBank = (bNew ? pOptions->iMidiBank : m_pInstrument->bank());
# Line 166  void InstrumentForm::setup ( qsamplerIns Line 186  void InstrumentForm::setup ( qsamplerIns
186                  iProg = 1;                  iProg = 1;
187                  iBank++;                  iBank++;
188          }          }
189          ui.BankSpinBox->setValue(iBank);          m_ui.BankSpinBox->setValue(iBank);
190          ui.ProgSpinBox->setValue(iProg);          m_ui.ProgSpinBox->setValue(iProg);
191    
192          // Instrument name...          // Instrument name...
193          ui.NameLineEdit->setText(m_pInstrument->name());          m_ui.NameLineEdit->setText(m_pInstrument->name());
194    
195          // Engine name...          // Engine name...
196          QString sEngineName = m_pInstrument->engineName();          QString sEngineName = m_pInstrument->engineName();
197          if (sEngineName.isEmpty() || bNew)          if (sEngineName.isEmpty() || bNew)
198                  sEngineName = pOptions->sEngineName;                  sEngineName = pOptions->sEngineName;
199          if (sEngineName.isEmpty())          if (sEngineName.isEmpty())
200                  sEngineName = qsamplerChannel::noEngineName();                  sEngineName = Channel::noEngineName();
201          if (ui.EngineNameComboBox->findText(sEngineName,          if (m_ui.EngineNameComboBox->findText(sEngineName,
202                          Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {                          Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
203                  ui.EngineNameComboBox->insertItem(sEngineName);                  m_ui.EngineNameComboBox->addItem(sEngineName);
204          }          }
205          ui.EngineNameComboBox->setCurrentText(sEngineName);          m_ui.EngineNameComboBox->setCurrentIndex(
206                    m_ui.EngineNameComboBox->findText(sEngineName,
207                            Qt::MatchExactly | Qt::MatchCaseSensitive));
208    
209          // Instrument filename and index...          // Instrument filename and index...
210          QString sInstrumentFile = m_pInstrument->instrumentFile();          QString sInstrumentFile = m_pInstrument->instrumentFile();
211          if (sInstrumentFile.isEmpty())          if (sInstrumentFile.isEmpty())
212                  sInstrumentFile = qsamplerChannel::noInstrumentName();                  sInstrumentFile = Channel::noInstrumentName();
213          ui.InstrumentFileComboBox->setCurrentText(sInstrumentFile);          m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile);
214          ui.InstrumentNrComboBox->clear();          m_ui.InstrumentNrComboBox->clear();
215          ui.InstrumentNrComboBox->insertStringList(          m_ui.InstrumentNrComboBox->insertItems(0,
216                  qsamplerChannel::getInstrumentList(sInstrumentFile,                  Channel::getInstrumentList(sInstrumentFile,
217                  pOptions->bInstrumentNames));                  pOptions->bInstrumentNames));
218          ui.InstrumentNrComboBox->setCurrentItem(m_pInstrument->instrumentNr());          m_ui.InstrumentNrComboBox->setCurrentIndex(m_pInstrument->instrumentNr());
219    
220          // Instrument volume....          // Instrument volume....
221          int iVolume = (bNew ? pOptions->iVolume :          int iVolume = (bNew ? pOptions->iVolume :
222                  ::lroundf(100.0f * m_pInstrument->volume()));                  ::lroundf(100.0f * m_pInstrument->volume()));
223          ui.VolumeSpinBox->setValue(iVolume);          m_ui.VolumeSpinBox->setValue(iVolume);
224    
225          // Instrument load mode...          // Instrument load mode...
226          int iLoadMode = (bNew ? pOptions->iLoadMode :          int iLoadMode = (bNew ? pOptions->iLoadMode :
227                  m_pInstrument->loadMode());                  m_pInstrument->loadMode());
228          ui.LoadModeComboBox->setCurrentItem(iLoadMode);          m_ui.LoadModeComboBox->setCurrentIndex(iLoadMode);
   
         // Done.  
         m_iDirtySetup--;  
         stabilizeForm();  
229    
230          // Done.          // Done.
231          m_iDirtySetup--;          m_iDirtySetup--;
# Line 232  void InstrumentForm::openInstrumentFile Line 251  void InstrumentForm::openInstrumentFile
251          if (pMainForm == NULL)          if (pMainForm == NULL)
252                  return;                  return;
253    
254          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
255          if (pOptions == NULL)          if (pOptions == NULL)
256                  return;                  return;
257    
258          // FIXME: the instrument file filters should be restricted,          // FIXME: the instrument file filters should be restricted,
259          // depending on the current engine.          // depending on the current engine.
260          QString sInstrumentFile = QFileDialog::getOpenFileName(          QString sInstrumentFile = QFileDialog::getOpenFileName(this,
261                  pOptions->sInstrumentDir,                   // Start here.                  QSAMPLER_TITLE ": " + tr("Instrument files"), // Caption.
262                  tr("Instrument files") + " (*.gig *.dls)",  // Filter (GIG and DLS files)                  pOptions->sInstrumentDir,                 // Start here.
263                  this, 0,                                    // Parent and name (none)                  tr("Instrument files") + " (*.gig *.dls)" // Filter (GIG and DLS files)
                 QSAMPLER_TITLE ": " + tr("Instrument files")// Caption.  
264          );          );
265    
266          if (sInstrumentFile.isEmpty())          if (sInstrumentFile.isEmpty())
267                  return;                  return;
268    
269          ui.InstrumentFileComboBox->setCurrentText(sInstrumentFile);          m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile);
270          updateInstrumentName();          updateInstrumentName();
271  }  }
272    
# Line 260  void InstrumentForm::updateInstrumentNam Line 278  void InstrumentForm::updateInstrumentNam
278          if (pMainForm == NULL)          if (pMainForm == NULL)
279                  return;                  return;
280    
281          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
282          if (pOptions == NULL)          if (pOptions == NULL)
283                  return;                  return;
284    
285          // TODO: this better idea would be to use libgig          // TODO: this better idea would be to use libgig
286          // to retrieve the REAL instrument names.          // to retrieve the REAL instrument names.
287          ui.InstrumentNrComboBox->clear();          m_ui.InstrumentNrComboBox->clear();
288          ui.InstrumentNrComboBox->insertStringList(          m_ui.InstrumentNrComboBox->insertItems(0,
289                  qsamplerChannel::getInstrumentList(                  Channel::getInstrumentList(
290                          ui.InstrumentFileComboBox->currentText(),                          m_ui.InstrumentFileComboBox->currentText(),
291                          pOptions->bInstrumentNames)                          pOptions->bInstrumentNames)
292          );          );
293    
# Line 283  void InstrumentForm::instrumentNrChanged Line 301  void InstrumentForm::instrumentNrChanged
301          if (m_iDirtySetup > 0)          if (m_iDirtySetup > 0)
302                  return;                  return;
303    
304          if (ui.NameLineEdit->text().isEmpty() || m_iDirtyName == 0) {          if (m_ui.NameLineEdit->text().isEmpty() || m_iDirtyName == 0) {
305                  ui.NameLineEdit->setText(ui.InstrumentNrComboBox->currentText());                  m_ui.NameLineEdit->setText(m_ui.InstrumentNrComboBox->currentText());
306                  m_iDirtyName = 0;                  m_iDirtyName = 0;
307          }          }
308    
# Line 304  void InstrumentForm::accept (void) Line 322  void InstrumentForm::accept (void)
322          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
323                  return;                  return;
324    
325          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
326          if (pOptions == NULL)          if (pOptions == NULL)
327                  return;                  return;
328    
329          if (m_iDirtyCount > 0) {          if (m_iDirtyCount > 0) {
330                  m_pInstrument->setMap(ui.MapComboBox->currentItem());                  m_pInstrument->setMap(m_ui.MapComboBox->currentIndex());
331                  m_pInstrument->setBank(ui.BankSpinBox->value());                  m_pInstrument->setBank(m_ui.BankSpinBox->value());
332                  m_pInstrument->setProg(ui.ProgSpinBox->value() - 1);                  m_pInstrument->setProg(m_ui.ProgSpinBox->value() - 1);
333                  m_pInstrument->setName(ui.NameLineEdit->text());                  m_pInstrument->setName(m_ui.NameLineEdit->text());
334                  m_pInstrument->setEngineName(ui.EngineNameComboBox->currentText());                  m_pInstrument->setEngineName(m_ui.EngineNameComboBox->currentText());
335                  m_pInstrument->setInstrumentFile(ui.InstrumentFileComboBox->currentText());                  m_pInstrument->setInstrumentFile(m_ui.InstrumentFileComboBox->currentText());
336                  m_pInstrument->setInstrumentNr(ui.InstrumentNrComboBox->currentItem());                  m_pInstrument->setInstrumentNr(m_ui.InstrumentNrComboBox->currentIndex());
337                  m_pInstrument->setVolume(0.01f * float(ui.VolumeSpinBox->value()));                  m_pInstrument->setVolume(0.01f * float(m_ui.VolumeSpinBox->value()));
338                  m_pInstrument->setLoadMode(ui.LoadModeComboBox->currentItem());                  m_pInstrument->setLoadMode(m_ui.LoadModeComboBox->currentIndex());
339          }          }
340    
341          // Save default engine name, instrument directory and history...          // Save default engine name, instrument directory and history...
342          pOptions->sInstrumentDir = QFileInfo(ui.InstrumentFileComboBox->currentText()).dirPath(true);          pOptions->sInstrumentDir = QFileInfo(
343          pOptions->sEngineName = ui.EngineNameComboBox->currentText();                  m_ui.InstrumentFileComboBox->currentText()).dir().absolutePath();
344          pOptions->iMidiMap  = ui.MapComboBox->currentItem();          pOptions->sEngineName = m_ui.EngineNameComboBox->currentText();
345          pOptions->iMidiBank = ui.BankSpinBox->value();          pOptions->iMidiMap  = m_ui.MapComboBox->currentIndex();
346          pOptions->iMidiProg = ui.ProgSpinBox->value();          pOptions->iMidiBank = m_ui.BankSpinBox->value();
347          pOptions->iVolume   = ui.VolumeSpinBox->value();          pOptions->iMidiProg = m_ui.ProgSpinBox->value();
348          pOptions->iLoadMode = ui.LoadModeComboBox->currentItem();          pOptions->iVolume   = m_ui.VolumeSpinBox->value();
349          pOptions->saveComboBoxHistory(ui.InstrumentFileComboBox);          pOptions->iLoadMode = m_ui.LoadModeComboBox->currentIndex();
350            pOptions->saveComboBoxHistory(m_ui.InstrumentFileComboBox);
351    
352          // Just go with dialog acceptance.          // Just go with dialog acceptance.
353          QDialog::accept();          QDialog::accept();
# Line 341  void InstrumentForm::reject (void) Line 360  void InstrumentForm::reject (void)
360          bool bReject = true;          bool bReject = true;
361    
362          // Check if there's any pending changes...          // Check if there's any pending changes...
363          if (m_iDirtyCount > 0 && ui.OkPushButton->isEnabled()) {          if (m_iDirtyCount > 0 && m_ui.OkPushButton->isEnabled()) {
364                  switch (QMessageBox::warning(this,                  switch (QMessageBox::warning(this,
365                          QSAMPLER_TITLE ": " + tr("Warning"),                          QSAMPLER_TITLE ": " + tr("Warning"),
366                          tr("Some channel settings have been changed.\n\n"                          tr("Some channel settings have been changed.\n\n"
367                          "Do you want to apply the changes?"),                          "Do you want to apply the changes?"),
368                          tr("Apply"), tr("Discard"), tr("Cancel"))) {                          QMessageBox::Apply |
369                  case 0:     // Apply...                          QMessageBox::Discard |
370                            QMessageBox::Cancel)) {
371                    case QMessageBox::Apply:
372                          accept();                          accept();
373                          return;                          return;
374                  case 1:     // Discard                  case QMessageBox::Discard:
375                          break;                          break;
376                  default:    // Cancel.                  default:    // Cancel.
377                          bReject = false;                          bReject = false;
# Line 377  void InstrumentForm::changed (void) Line 398  void InstrumentForm::changed (void)
398  // Stabilize current form state.  // Stabilize current form state.
399  void InstrumentForm::stabilizeForm (void)  void InstrumentForm::stabilizeForm (void)
400  {  {
401          bool bValid = !ui.NameLineEdit->text().isEmpty();          bool bValid = !m_ui.NameLineEdit->text().isEmpty()
402                    && m_ui.EngineNameComboBox->currentIndex() >= 0
403                    && m_ui.EngineNameComboBox->currentText() != Channel::noEngineName();
404    
405          const QString& sPath = ui.InstrumentFileComboBox->currentText();          const QString& sPath = m_ui.InstrumentFileComboBox->currentText();
406          bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists();          bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists();
407    
408          ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid);          m_ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid);
409  }  }
410    
411  } // namespace QSampler  } // namespace QSampler

Legend:
Removed from v.1474  
changed lines
  Added in v.2069

  ViewVC Help
Powered by ViewVC