/[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 1464 by capela, Thu Nov 1 17:14:21 2007 UTC revision 1526 by capela, Mon Nov 26 10:58:23 2007 UTC
# 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    InstrumentForm::InstrumentForm ( QWidget* pParent )
50            : QDialog(pParent)
51    {
52            m_ui.setupUi(this);
53    
54          // Initialize locals.          // Initialize locals.
55          m_pInstrument = NULL;          m_pInstrument = NULL;
# Line 52  InstrumentForm::InstrumentForm(QWidget* Line 60  InstrumentForm::InstrumentForm(QWidget*
60    
61          // Try to restore normal window positioning.          // Try to restore normal window positioning.
62          adjustSize();          adjustSize();
63    
64    
65            QObject::connect(m_ui.MapComboBox,
66                    SIGNAL(activated(int)),
67                    SLOT(changed()));
68            QObject::connect(m_ui.BankSpinBox,
69                    SIGNAL(valueChanged(int)),
70                    SLOT(changed()));
71            QObject::connect(m_ui.ProgSpinBox,
72                    SIGNAL(valueChanged(int)),
73                    SLOT(changed()));
74            QObject::connect(m_ui.NameLineEdit,
75                    SIGNAL(textChanged(const QString&)),
76                    SLOT(nameChanged(const QString&)));
77            QObject::connect(m_ui.EngineNameComboBox,
78                    SIGNAL(activated(int)),
79                    SLOT(changed()));
80            QObject::connect(m_ui.InstrumentFileComboBox,
81                    SIGNAL(activated(const QString&)),
82                    SLOT(updateInstrumentName()));
83            QObject::connect(m_ui.InstrumentFileToolButton,
84                    SIGNAL(clicked()),
85                    SLOT(openInstrumentFile()));
86            QObject::connect(m_ui.InstrumentNrComboBox,
87                    SIGNAL(activated(int)),
88                    SLOT(instrumentNrChanged()));
89            QObject::connect(m_ui.VolumeSpinBox,
90                    SIGNAL(valueChanged(int)),
91                    SLOT(changed()));
92            QObject::connect(m_ui.LoadModeComboBox,
93                    SIGNAL(activated(int)),
94                    SLOT(changed()));
95            QObject::connect(m_ui.OkPushButton,
96                    SIGNAL(clicked()),
97                    SLOT(accept()));
98            QObject::connect(m_ui.CancelPushButton,
99                    SIGNAL(clicked()),
100                    SLOT(reject()));
101  }  }
102    
103  InstrumentForm::~InstrumentForm() {  
104    InstrumentForm::~InstrumentForm (void)
105    {
106  }  }
107    
108    
109  // Channel dialog setup formal initializer.  // Channel dialog setup formal initializer.
110  void InstrumentForm::setup ( qsamplerInstrument *pInstrument )  void InstrumentForm::setup ( qsamplerInstrument *pInstrument )
111  {  {
# Line 91  void InstrumentForm::setup ( qsamplerIns Line 140  void InstrumentForm::setup ( qsamplerIns
140          m_iDirtySetup++;          m_iDirtySetup++;
141    
142          // Load combo box history...          // Load combo box history...
143          pOptions->loadComboBoxHistory(ui.InstrumentFileComboBox);          pOptions->loadComboBoxHistory(m_ui.InstrumentFileComboBox);
144    
145          // Populate maps list.          // Populate maps list.
146          ui.MapComboBox->clear();          m_ui.MapComboBox->clear();
147          ui.MapComboBox->insertStringList(qsamplerInstrument::getMapNames());          m_ui.MapComboBox->insertItems(0, qsamplerInstrument::getMapNames());
148    
149          // Populate Engines list.          // Populate Engines list.
150          const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client());          const char **ppszEngines
151                    = ::lscp_list_available_engines(pMainForm->client());
152          if (ppszEngines) {          if (ppszEngines) {
153                  ui.EngineNameComboBox->clear();                  m_ui.EngineNameComboBox->clear();
154                  for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)                  for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)
155                          ui.EngineNameComboBox->insertItem(ppszEngines[iEngine]);                          m_ui.EngineNameComboBox->addItem(ppszEngines[iEngine]);
156          }          }
157          else pMainForm->appendMessagesClient("lscp_list_available_engines");          else pMainForm->appendMessagesClient("lscp_list_available_engines");
158    
# Line 114  void InstrumentForm::setup ( qsamplerIns Line 164  void InstrumentForm::setup ( qsamplerIns
164          if (iMap < 0)          if (iMap < 0)
165                  iMap = 0;                  iMap = 0;
166          const QString& sMapName = qsamplerInstrument::getMapName(iMap);          const QString& sMapName = qsamplerInstrument::getMapName(iMap);
167          if (!sMapName.isEmpty())          if (!sMapName.isEmpty()) {
168                  ui.MapComboBox->setCurrentText(sMapName);                  m_ui.MapComboBox->setCurrentIndex(
169                            m_ui.MapComboBox->findText(sMapName,
170                                    Qt::MatchExactly | Qt::MatchCaseSensitive));
171            }
172    
173          // It might be no maps around...          // It might be no maps around...
174          bool bMapEnabled = (ui.MapComboBox->count() > 0);          bool bMapEnabled = (m_ui.MapComboBox->count() > 0);
175          ui.MapTextLabel->setEnabled(bMapEnabled);          m_ui.MapTextLabel->setEnabled(bMapEnabled);
176          ui.MapComboBox->setEnabled(bMapEnabled);          m_ui.MapComboBox->setEnabled(bMapEnabled);
177    
178          // Instrument bank/program...          // Instrument bank/program...
179          int iBank = (bNew ? pOptions->iMidiBank : m_pInstrument->bank());          int iBank = (bNew ? pOptions->iMidiBank : m_pInstrument->bank());
# Line 128  void InstrumentForm::setup ( qsamplerIns Line 182  void InstrumentForm::setup ( qsamplerIns
182                  iProg = 1;                  iProg = 1;
183                  iBank++;                  iBank++;
184          }          }
185          ui.BankSpinBox->setValue(iBank);          m_ui.BankSpinBox->setValue(iBank);
186          ui.ProgSpinBox->setValue(iProg);          m_ui.ProgSpinBox->setValue(iProg);
187    
188          // Instrument name...          // Instrument name...
189          ui.NameLineEdit->setText(m_pInstrument->name());          m_ui.NameLineEdit->setText(m_pInstrument->name());
190    
191          // Engine name...          // Engine name...
192          QString sEngineName = m_pInstrument->engineName();          QString sEngineName = m_pInstrument->engineName();
# Line 140  void InstrumentForm::setup ( qsamplerIns Line 194  void InstrumentForm::setup ( qsamplerIns
194                  sEngineName = pOptions->sEngineName;                  sEngineName = pOptions->sEngineName;
195          if (sEngineName.isEmpty())          if (sEngineName.isEmpty())
196                  sEngineName = qsamplerChannel::noEngineName();                  sEngineName = qsamplerChannel::noEngineName();
197          if (ui.EngineNameComboBox->findText(sEngineName,          if (m_ui.EngineNameComboBox->findText(sEngineName,
198                          Qt::MatchExactly | Qt::MatchCaseSensitive) == 0) {                          Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
199                  ui.EngineNameComboBox->insertItem(sEngineName);                  m_ui.EngineNameComboBox->addItem(sEngineName);
200          }          }
201          ui.EngineNameComboBox->setCurrentText(sEngineName);          m_ui.EngineNameComboBox->setCurrentIndex(
202                    m_ui.EngineNameComboBox->findText(sEngineName,
203                            Qt::MatchExactly | Qt::MatchCaseSensitive));
204    
205          // Instrument filename and index...          // Instrument filename and index...
206          QString sInstrumentFile = m_pInstrument->instrumentFile();          QString sInstrumentFile = m_pInstrument->instrumentFile();
207          if (sInstrumentFile.isEmpty())          if (sInstrumentFile.isEmpty())
208                  sInstrumentFile = qsamplerChannel::noInstrumentName();                  sInstrumentFile = qsamplerChannel::noInstrumentName();
209          ui.InstrumentFileComboBox->setCurrentText(sInstrumentFile);          m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile);
210          ui.InstrumentNrComboBox->clear();          m_ui.InstrumentNrComboBox->clear();
211          ui.InstrumentNrComboBox->insertStringList(          m_ui.InstrumentNrComboBox->insertItems(0,
212                  qsamplerChannel::getInstrumentList(sInstrumentFile,                  qsamplerChannel::getInstrumentList(sInstrumentFile,
213                  pOptions->bInstrumentNames));                  pOptions->bInstrumentNames));
214          ui.InstrumentNrComboBox->setCurrentItem(m_pInstrument->instrumentNr());          m_ui.InstrumentNrComboBox->setCurrentIndex(m_pInstrument->instrumentNr());
215    
216          // Instrument volume....          // Instrument volume....
217          int iVolume = (bNew ? pOptions->iVolume :          int iVolume = (bNew ? pOptions->iVolume :
218                  ::lroundf(100.0f * m_pInstrument->volume()));                  ::lroundf(100.0f * m_pInstrument->volume()));
219          ui.VolumeSpinBox->setValue(iVolume);          m_ui.VolumeSpinBox->setValue(iVolume);
220    
221          // Instrument load mode...          // Instrument load mode...
222          int iLoadMode = (bNew ? pOptions->iLoadMode :          int iLoadMode = (bNew ? pOptions->iLoadMode :
223                  m_pInstrument->loadMode());                  m_pInstrument->loadMode());
224          ui.LoadModeComboBox->setCurrentItem(iLoadMode);          m_ui.LoadModeComboBox->setCurrentIndex(iLoadMode);
225    
226          // Done.          // Done.
227          m_iDirtySetup--;          m_iDirtySetup--;
# Line 200  void InstrumentForm::openInstrumentFile Line 257  void InstrumentForm::openInstrumentFile
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 228  void InstrumentForm::updateInstrumentNam Line 284  void InstrumentForm::updateInstrumentNam
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(                  qsamplerChannel::getInstrumentList(
290                          ui.InstrumentFileComboBox->currentText(),                          m_ui.InstrumentFileComboBox->currentText(),
291                          pOptions->bInstrumentNames)                          pOptions->bInstrumentNames)
292          );          );
293    
# Line 245  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 271  void InstrumentForm::accept (void) Line 327  void InstrumentForm::accept (void)
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 303  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"
# Line 339  void InstrumentForm::changed (void) Line 396  void InstrumentForm::changed (void)
396  // Stabilize current form state.  // Stabilize current form state.
397  void InstrumentForm::stabilizeForm (void)  void InstrumentForm::stabilizeForm (void)
398  {  {
399          bool bValid = !ui.NameLineEdit->text().isEmpty();          bool bValid =
400                    !m_ui.NameLineEdit->text().isEmpty() &&
401                    m_ui.EngineNameComboBox->currentIndex() >= 0 &&
402                    m_ui.EngineNameComboBox->currentText() !=
403                    qsamplerChannel::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.1464  
changed lines
  Added in v.1526

  ViewVC Help
Powered by ViewVC