/[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 1526 by capela, Mon Nov 26 10:58:23 2007 UTC revision 2108 by capela, Thu Jul 15 08:03:32 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 27  Line 27 
27  #include "qsamplerChannel.h"  #include "qsamplerChannel.h"
28  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
29    
 #include <QFileDialog>  
30  #include <QMessageBox>  #include <QMessageBox>
31    #include <QPushButton>
32    #include <QFileDialog>
33    
34  // Needed for lroundf()  // Needed for lroundf()
35  #include <math.h>  #include <math.h>
# Line 46  static inline long lroundf ( float x ) Line 47  static inline long lroundf ( float x )
47    
48  namespace QSampler {  namespace QSampler {
49    
50  InstrumentForm::InstrumentForm ( QWidget* pParent )  //-------------------------------------------------------------------------
51    // QSampler::InstrumentForm -- Instrument map item form implementation.
52    //
53    
54    InstrumentForm::InstrumentForm ( QWidget *pParent )
55          : QDialog(pParent)          : QDialog(pParent)
56  {  {
57          m_ui.setupUi(this);          m_ui.setupUi(this);
# Line 92  InstrumentForm::InstrumentForm ( QWidget Line 97  InstrumentForm::InstrumentForm ( QWidget
97          QObject::connect(m_ui.LoadModeComboBox,          QObject::connect(m_ui.LoadModeComboBox,
98                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
99                  SLOT(changed()));                  SLOT(changed()));
100          QObject::connect(m_ui.OkPushButton,          QObject::connect(m_ui.DialogButtonBox,
101                  SIGNAL(clicked()),                  SIGNAL(accepted()),
102                  SLOT(accept()));                  SLOT(accept()));
103          QObject::connect(m_ui.CancelPushButton,          QObject::connect(m_ui.DialogButtonBox,
104                  SIGNAL(clicked()),                  SIGNAL(rejected()),
105                  SLOT(reject()));                  SLOT(reject()));
106  }  }
107    
# Line 107  InstrumentForm::~InstrumentForm (void) Line 112  InstrumentForm::~InstrumentForm (void)
112    
113    
114  // Channel dialog setup formal initializer.  // Channel dialog setup formal initializer.
115  void InstrumentForm::setup ( qsamplerInstrument *pInstrument )  void InstrumentForm::setup ( Instrument *pInstrument )
116  {  {
117          m_pInstrument = pInstrument;          m_pInstrument = pInstrument;
118    
# Line 125  void InstrumentForm::setup ( qsamplerIns Line 130  void InstrumentForm::setup ( qsamplerIns
130          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
131                  return;                  return;
132    
133          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
134          if (pOptions == NULL)          if (pOptions == NULL)
135                  return;                  return;
136    
# Line 144  void InstrumentForm::setup ( qsamplerIns Line 149  void InstrumentForm::setup ( qsamplerIns
149    
150          // Populate maps list.          // Populate maps list.
151          m_ui.MapComboBox->clear();          m_ui.MapComboBox->clear();
152          m_ui.MapComboBox->insertItems(0, qsamplerInstrument::getMapNames());          m_ui.MapComboBox->insertItems(0, Instrument::getMapNames());
153    
154          // Populate Engines list.          // Populate Engines list.
155          const char **ppszEngines          const char **ppszEngines
# Line 163  void InstrumentForm::setup ( qsamplerIns Line 168  void InstrumentForm::setup ( qsamplerIns
168          int iMap = (bNew ? pOptions->iMidiMap : m_pInstrument->map());          int iMap = (bNew ? pOptions->iMidiMap : m_pInstrument->map());
169          if (iMap < 0)          if (iMap < 0)
170                  iMap = 0;                  iMap = 0;
171          const QString& sMapName = qsamplerInstrument::getMapName(iMap);          const QString& sMapName = Instrument::getMapName(iMap);
172          if (!sMapName.isEmpty()) {          if (!sMapName.isEmpty()) {
173                  m_ui.MapComboBox->setCurrentIndex(                  m_ui.MapComboBox->setCurrentIndex(
174                          m_ui.MapComboBox->findText(sMapName,                          m_ui.MapComboBox->findText(sMapName,
# Line 193  void InstrumentForm::setup ( qsamplerIns Line 198  void InstrumentForm::setup ( qsamplerIns
198          if (sEngineName.isEmpty() || bNew)          if (sEngineName.isEmpty() || bNew)
199                  sEngineName = pOptions->sEngineName;                  sEngineName = pOptions->sEngineName;
200          if (sEngineName.isEmpty())          if (sEngineName.isEmpty())
201                  sEngineName = qsamplerChannel::noEngineName();                  sEngineName = Channel::noEngineName();
202          if (m_ui.EngineNameComboBox->findText(sEngineName,          if (m_ui.EngineNameComboBox->findText(sEngineName,
203                          Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {                          Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
204                  m_ui.EngineNameComboBox->addItem(sEngineName);                  m_ui.EngineNameComboBox->addItem(sEngineName);
# Line 205  void InstrumentForm::setup ( qsamplerIns Line 210  void InstrumentForm::setup ( qsamplerIns
210          // Instrument filename and index...          // Instrument filename and index...
211          QString sInstrumentFile = m_pInstrument->instrumentFile();          QString sInstrumentFile = m_pInstrument->instrumentFile();
212          if (sInstrumentFile.isEmpty())          if (sInstrumentFile.isEmpty())
213                  sInstrumentFile = qsamplerChannel::noInstrumentName();                  sInstrumentFile = Channel::noInstrumentName();
214          m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile);          m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile);
215          m_ui.InstrumentNrComboBox->clear();          m_ui.InstrumentNrComboBox->clear();
216          m_ui.InstrumentNrComboBox->insertItems(0,          m_ui.InstrumentNrComboBox->insertItems(0,
217                  qsamplerChannel::getInstrumentList(sInstrumentFile,                  Channel::getInstrumentList(sInstrumentFile,
218                  pOptions->bInstrumentNames));                  pOptions->bInstrumentNames));
219          m_ui.InstrumentNrComboBox->setCurrentIndex(m_pInstrument->instrumentNr());          m_ui.InstrumentNrComboBox->setCurrentIndex(m_pInstrument->instrumentNr());
220    
# Line 226  void InstrumentForm::setup ( qsamplerIns Line 231  void InstrumentForm::setup ( qsamplerIns
231          // Done.          // Done.
232          m_iDirtySetup--;          m_iDirtySetup--;
233          stabilizeForm();          stabilizeForm();
   
         // Done.  
         m_iDirtySetup--;  
         stabilizeForm();  
234  }  }
235    
236    
# Line 251  void InstrumentForm::openInstrumentFile Line 252  void InstrumentForm::openInstrumentFile
252          if (pMainForm == NULL)          if (pMainForm == NULL)
253                  return;                  return;
254    
255          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
256          if (pOptions == NULL)          if (pOptions == NULL)
257                  return;                  return;
258    
259          // FIXME: the instrument file filters should be restricted,          // FIXME: the instrument file filters should be restricted,
260          // depending on the current engine.          // depending on the current engine.
261            QStringList filters;
262            filters << tr("GIG Instrument files") + " (*.gig *.dls)";
263            filters << tr("SFZ Instrument files") + " (*.sfz)";
264    //      filters << tr("SF2 Instrument files") + " (*.sf2)";
265            filters << tr("All files") + " (*.*)";
266            const QString& filter = filters.join(";;");
267    
268          QString sInstrumentFile = QFileDialog::getOpenFileName(this,          QString sInstrumentFile = QFileDialog::getOpenFileName(this,
269                  QSAMPLER_TITLE ": " + tr("Instrument files"), // Caption.                  QSAMPLER_TITLE ": " + tr("Instrument files"), // Caption.
270                  pOptions->sInstrumentDir,                 // Start here.                  pOptions->sInstrumentDir, // Start here.
271                  tr("Instrument files") + " (*.gig *.dls)" // Filter (GIG and DLS files)                  filter                    // File filter.
272          );          );
273    
274          if (sInstrumentFile.isEmpty())          if (sInstrumentFile.isEmpty())
# Line 278  void InstrumentForm::updateInstrumentNam Line 286  void InstrumentForm::updateInstrumentNam
286          if (pMainForm == NULL)          if (pMainForm == NULL)
287                  return;                  return;
288    
289          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
290          if (pOptions == NULL)          if (pOptions == NULL)
291                  return;                  return;
292    
# Line 286  void InstrumentForm::updateInstrumentNam Line 294  void InstrumentForm::updateInstrumentNam
294          // to retrieve the REAL instrument names.          // to retrieve the REAL instrument names.
295          m_ui.InstrumentNrComboBox->clear();          m_ui.InstrumentNrComboBox->clear();
296          m_ui.InstrumentNrComboBox->insertItems(0,          m_ui.InstrumentNrComboBox->insertItems(0,
297                  qsamplerChannel::getInstrumentList(                  Channel::getInstrumentList(
298                          m_ui.InstrumentFileComboBox->currentText(),                          m_ui.InstrumentFileComboBox->currentText(),
299                          pOptions->bInstrumentNames)                          pOptions->bInstrumentNames)
300          );          );
# Line 322  void InstrumentForm::accept (void) Line 330  void InstrumentForm::accept (void)
330          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
331                  return;                  return;
332    
333          qsamplerOptions *pOptions = pMainForm->options();          Options *pOptions = pMainForm->options();
334          if (pOptions == NULL)          if (pOptions == NULL)
335                  return;                  return;
336    
# Line 360  void InstrumentForm::reject (void) Line 368  void InstrumentForm::reject (void)
368          bool bReject = true;          bool bReject = true;
369    
370          // Check if there's any pending changes...          // Check if there's any pending changes...
371          if (m_iDirtyCount > 0 && m_ui.OkPushButton->isEnabled()) {          if (m_iDirtyCount > 0) {
372                  switch (QMessageBox::warning(this,                  switch (QMessageBox::warning(this,
373                          QSAMPLER_TITLE ": " + tr("Warning"),                          QSAMPLER_TITLE ": " + tr("Warning"),
374                          tr("Some channel settings have been changed.\n\n"                          tr("Some channel settings have been changed.\n\n"
375                          "Do you want to apply the changes?"),                          "Do you want to apply the changes?"),
376                          tr("Apply"), tr("Discard"), tr("Cancel"))) {                          QMessageBox::Apply |
377                  case 0:     // Apply...                          QMessageBox::Discard |
378                            QMessageBox::Cancel)) {
379                    case QMessageBox::Apply:
380                          accept();                          accept();
381                          return;                          return;
382                  case 1:     // Discard                  case QMessageBox::Discard:
383                          break;                          break;
384                  default:    // Cancel.                  default:    // Cancel.
385                          bReject = false;                          bReject = false;
# Line 396  void InstrumentForm::changed (void) Line 406  void InstrumentForm::changed (void)
406  // Stabilize current form state.  // Stabilize current form state.
407  void InstrumentForm::stabilizeForm (void)  void InstrumentForm::stabilizeForm (void)
408  {  {
409          bool bValid =          bool bValid = !m_ui.NameLineEdit->text().isEmpty()
410                  !m_ui.NameLineEdit->text().isEmpty() &&                  && m_ui.EngineNameComboBox->currentIndex() >= 0
411                  m_ui.EngineNameComboBox->currentIndex() >= 0 &&                  && m_ui.EngineNameComboBox->currentText() != Channel::noEngineName();
                 m_ui.EngineNameComboBox->currentText() !=  
                 qsamplerChannel::noEngineName();  
412    
413          const QString& sPath = m_ui.InstrumentFileComboBox->currentText();          const QString& sPath = m_ui.InstrumentFileComboBox->currentText();
414          bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists();          bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists();
415    
416          m_ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid);          m_ui.DialogButtonBox->button(
417                    QDialogButtonBox::Ok)->setEnabled(m_iDirtyCount > 0 && bValid);
418  }  }
419    
420  } // namespace QSampler  } // namespace QSampler

Legend:
Removed from v.1526  
changed lines
  Added in v.2108

  ViewVC Help
Powered by ViewVC