/[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 1461 by schoenebeck, Sun Oct 28 23:30:36 2007 UTC revision 1499 by capela, Tue Nov 20 16:48:04 2007 UTC
# Line 1  Line 1 
1    // qsamplerInstrumentForm.cpp
2    //
3    /****************************************************************************
4       Copyright (C) 2003-2007, rncbc aka Rui Nuno Capela. All rights reserved.
5       Copyright (C) 2007, Christian Schoenebeck
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
18       along with this program; if not, write to the Free Software
19       Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20    
21    *****************************************************************************/
22    
23  #include "qsamplerInstrumentForm.h"  #include "qsamplerInstrumentForm.h"
24    
25  #include "qsamplerAbout.h"  #include "qsamplerAbout.h"
26  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
27    
28    #include <QFileDialog>
29    #include <QMessageBox>
30    
31  // Needed for lroundf()  // Needed for lroundf()
32  #include <math.h>  #include <math.h>
33    
34    
35  namespace QSampler {  namespace QSampler {
36    
37  #ifndef CONFIG_ROUND  #ifndef CONFIG_ROUND
# Line 30  InstrumentForm::InstrumentForm(QWidget* Line 56  InstrumentForm::InstrumentForm(QWidget*
56    
57          // Try to restore normal window positioning.          // Try to restore normal window positioning.
58          adjustSize();          adjustSize();
59    
60    
61            QObject::connect(ui.MapComboBox,
62                    SIGNAL(activated(int)),
63                    SLOT(changed()));
64            QObject::connect(ui.BankSpinBox,
65                    SIGNAL(valueChanged(int)),
66                    SLOT(changed()));
67            QObject::connect(ui.ProgSpinBox,
68                    SIGNAL(valueChanged(int)),
69                    SLOT(changed()));
70            QObject::connect(ui.NameLineEdit,
71                    SIGNAL(textChanged(const QString&)),
72                    SLOT(nameChanged(const QString&)));
73            QObject::connect(ui.EngineNameComboBox,
74                    SIGNAL(activated(int)),
75                    SLOT(changed()));
76            QObject::connect(ui.InstrumentFileComboBox,
77                    SIGNAL(activated(const QString&)),
78                    SLOT(updateInstrumentName()));
79            QObject::connect(ui.InstrumentFileToolButton,
80                    SIGNAL(clicked()),
81                    SLOT(openInstrumentFile()));
82            QObject::connect(ui.InstrumentNrComboBox,
83                    SIGNAL(activated(int)),
84                    SLOT(instrumentNrChanged()));
85            QObject::connect(ui.VolumeSpinBox,
86                    SIGNAL(valueChanged(int)),
87                    SLOT(changed()));
88            QObject::connect(ui.LoadModeComboBox,
89                    SIGNAL(activated(int)),
90                    SLOT(changed()));
91            QObject::connect(ui.OkPushButton,
92                    SIGNAL(clicked()),
93                    SLOT(accept()));
94            QObject::connect(ui.CancelPushButton,
95                    SIGNAL(clicked()),
96                    SLOT(reject()));
97  }  }
98    
99  InstrumentForm::~InstrumentForm() {  InstrumentForm::~InstrumentForm() {
# Line 73  void InstrumentForm::setup ( qsamplerIns Line 137  void InstrumentForm::setup ( qsamplerIns
137    
138          // Populate maps list.          // Populate maps list.
139          ui.MapComboBox->clear();          ui.MapComboBox->clear();
140          ui.MapComboBox->insertStringList(qsamplerInstrument::getMapNames());          ui.MapComboBox->insertItems(0, qsamplerInstrument::getMapNames());
141    
142          // Populate Engines list.          // Populate Engines list.
143          const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client());          const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client());
144          if (ppszEngines) {          if (ppszEngines) {
145                  ui.EngineNameComboBox->clear();                  ui.EngineNameComboBox->clear();
146                  for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)                  for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)
147                          ui.EngineNameComboBox->insertItem(ppszEngines[iEngine]);                          ui.EngineNameComboBox->addItem(ppszEngines[iEngine]);
148          }          }
149          else pMainForm->appendMessagesClient("lscp_list_available_engines");          else pMainForm->appendMessagesClient("lscp_list_available_engines");
150    
# Line 92  void InstrumentForm::setup ( qsamplerIns Line 156  void InstrumentForm::setup ( qsamplerIns
156          if (iMap < 0)          if (iMap < 0)
157                  iMap = 0;                  iMap = 0;
158          const QString& sMapName = qsamplerInstrument::getMapName(iMap);          const QString& sMapName = qsamplerInstrument::getMapName(iMap);
159          if (!sMapName.isEmpty())          if (!sMapName.isEmpty()) {
160                  ui.MapComboBox->setCurrentText(sMapName);                  ui.MapComboBox->setItemText(
161                            ui.MapComboBox->currentIndex(),
162                            sMapName);
163            }
164          // It might be no maps around...          // It might be no maps around...
165          bool bMapEnabled = (ui.MapComboBox->count() > 0);          bool bMapEnabled = (ui.MapComboBox->count() > 0);
166          ui.MapTextLabel->setEnabled(bMapEnabled);          ui.MapTextLabel->setEnabled(bMapEnabled);
# Line 119  void InstrumentForm::setup ( qsamplerIns Line 186  void InstrumentForm::setup ( qsamplerIns
186          if (sEngineName.isEmpty())          if (sEngineName.isEmpty())
187                  sEngineName = qsamplerChannel::noEngineName();                  sEngineName = qsamplerChannel::noEngineName();
188          if (ui.EngineNameComboBox->findText(sEngineName,          if (ui.EngineNameComboBox->findText(sEngineName,
189                          Qt::MatchExactly | Qt::MatchCaseSensitive) == 0) {                          Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
190                  ui.EngineNameComboBox->insertItem(sEngineName);                  ui.EngineNameComboBox->addItem(sEngineName);
191          }          }
192          ui.EngineNameComboBox->setCurrentText(sEngineName);          ui.EngineNameComboBox->setItemText(
193                    ui.EngineNameComboBox->currentIndex(),
194                    sEngineName);
195          // Instrument filename and index...          // Instrument filename and index...
196          QString sInstrumentFile = m_pInstrument->instrumentFile();          QString sInstrumentFile = m_pInstrument->instrumentFile();
197          if (sInstrumentFile.isEmpty())          if (sInstrumentFile.isEmpty())
198                  sInstrumentFile = qsamplerChannel::noInstrumentName();                  sInstrumentFile = qsamplerChannel::noInstrumentName();
199          ui.InstrumentFileComboBox->setCurrentText(sInstrumentFile);          ui.InstrumentFileComboBox->setItemText(
200                    ui.InstrumentFileComboBox->currentIndex(),
201                    sInstrumentFile);
202          ui.InstrumentNrComboBox->clear();          ui.InstrumentNrComboBox->clear();
203          ui.InstrumentNrComboBox->insertStringList(          ui.InstrumentNrComboBox->insertItems(0,
204                  qsamplerChannel::getInstrumentList(sInstrumentFile,                  qsamplerChannel::getInstrumentList(sInstrumentFile,
205                  pOptions->bInstrumentNames));                  pOptions->bInstrumentNames));
206          ui.InstrumentNrComboBox->setCurrentItem(m_pInstrument->instrumentNr());          ui.InstrumentNrComboBox->setCurrentIndex(m_pInstrument->instrumentNr());
207    
208          // Instrument volume....          // Instrument volume....
209          int iVolume = (bNew ? pOptions->iVolume :          int iVolume = (bNew ? pOptions->iVolume :
# Line 142  void InstrumentForm::setup ( qsamplerIns Line 213  void InstrumentForm::setup ( qsamplerIns
213          // Instrument load mode...          // Instrument load mode...
214          int iLoadMode = (bNew ? pOptions->iLoadMode :          int iLoadMode = (bNew ? pOptions->iLoadMode :
215                  m_pInstrument->loadMode());                  m_pInstrument->loadMode());
216          ui.LoadModeComboBox->setCurrentItem(iLoadMode);          ui.LoadModeComboBox->setCurrentIndex(iLoadMode);
217    
218          // Done.          // Done.
219          m_iDirtySetup--;          m_iDirtySetup--;
# Line 178  void InstrumentForm::openInstrumentFile Line 249  void InstrumentForm::openInstrumentFile
249    
250          // FIXME: the instrument file filters should be restricted,          // FIXME: the instrument file filters should be restricted,
251          // depending on the current engine.          // depending on the current engine.
252          QString sInstrumentFile = QFileDialog::getOpenFileName(          QString sInstrumentFile = QFileDialog::getOpenFileName(this,
253                  pOptions->sInstrumentDir,                   // Start here.                  QSAMPLER_TITLE ": " + tr("Instrument files"), // Caption.
254                  tr("Instrument files") + " (*.gig *.dls)",  // Filter (GIG and DLS files)                  pOptions->sInstrumentDir,                 // Start here.
255                  this, 0,                                    // Parent and name (none)                  tr("Instrument files") + " (*.gig *.dls)" // Filter (GIG and DLS files)
                 QSAMPLER_TITLE ": " + tr("Instrument files")// Caption.  
256          );          );
257    
258          if (sInstrumentFile.isEmpty())          if (sInstrumentFile.isEmpty())
259                  return;                  return;
260    
261          ui.InstrumentFileComboBox->setCurrentText(sInstrumentFile);          ui.InstrumentFileComboBox->setItemText(
262                    ui.InstrumentFileComboBox->currentIndex(),
263                    sInstrumentFile);
264    
265          updateInstrumentName();          updateInstrumentName();
266  }  }
267    
# Line 207  void InstrumentForm::updateInstrumentNam Line 280  void InstrumentForm::updateInstrumentNam
280          // TODO: this better idea would be to use libgig          // TODO: this better idea would be to use libgig
281          // to retrieve the REAL instrument names.          // to retrieve the REAL instrument names.
282          ui.InstrumentNrComboBox->clear();          ui.InstrumentNrComboBox->clear();
283          ui.InstrumentNrComboBox->insertStringList(          ui.InstrumentNrComboBox->insertItems(0,
284                  qsamplerChannel::getInstrumentList(                  qsamplerChannel::getInstrumentList(
285                          ui.InstrumentFileComboBox->currentText(),                          ui.InstrumentFileComboBox->currentText(),
286                          pOptions->bInstrumentNames)                          pOptions->bInstrumentNames)
# Line 249  void InstrumentForm::accept (void) Line 322  void InstrumentForm::accept (void)
322                  return;                  return;
323    
324          if (m_iDirtyCount > 0) {          if (m_iDirtyCount > 0) {
325                  m_pInstrument->setMap(ui.MapComboBox->currentItem());                  m_pInstrument->setMap(ui.MapComboBox->currentIndex());
326                  m_pInstrument->setBank(ui.BankSpinBox->value());                  m_pInstrument->setBank(ui.BankSpinBox->value());
327                  m_pInstrument->setProg(ui.ProgSpinBox->value() - 1);                  m_pInstrument->setProg(ui.ProgSpinBox->value() - 1);
328                  m_pInstrument->setName(ui.NameLineEdit->text());                  m_pInstrument->setName(ui.NameLineEdit->text());
329                  m_pInstrument->setEngineName(ui.EngineNameComboBox->currentText());                  m_pInstrument->setEngineName(ui.EngineNameComboBox->currentText());
330                  m_pInstrument->setInstrumentFile(ui.InstrumentFileComboBox->currentText());                  m_pInstrument->setInstrumentFile(ui.InstrumentFileComboBox->currentText());
331                  m_pInstrument->setInstrumentNr(ui.InstrumentNrComboBox->currentItem());                  m_pInstrument->setInstrumentNr(ui.InstrumentNrComboBox->currentIndex());
332                  m_pInstrument->setVolume(0.01f * float(ui.VolumeSpinBox->value()));                  m_pInstrument->setVolume(0.01f * float(ui.VolumeSpinBox->value()));
333                  m_pInstrument->setLoadMode(ui.LoadModeComboBox->currentItem());                  m_pInstrument->setLoadMode(ui.LoadModeComboBox->currentIndex());
334          }          }
335    
336          // Save default engine name, instrument directory and history...          // Save default engine name, instrument directory and history...
337          pOptions->sInstrumentDir = QFileInfo(ui.InstrumentFileComboBox->currentText()).dirPath(true);          pOptions->sInstrumentDir = QFileInfo(
338                    ui.InstrumentFileComboBox->currentText()).dir().absolutePath();
339          pOptions->sEngineName = ui.EngineNameComboBox->currentText();          pOptions->sEngineName = ui.EngineNameComboBox->currentText();
340          pOptions->iMidiMap  = ui.MapComboBox->currentItem();          pOptions->iMidiMap  = ui.MapComboBox->currentIndex();
341          pOptions->iMidiBank = ui.BankSpinBox->value();          pOptions->iMidiBank = ui.BankSpinBox->value();
342          pOptions->iMidiProg = ui.ProgSpinBox->value();          pOptions->iMidiProg = ui.ProgSpinBox->value();
343          pOptions->iVolume   = ui.VolumeSpinBox->value();          pOptions->iVolume   = ui.VolumeSpinBox->value();
344          pOptions->iLoadMode = ui.LoadModeComboBox->currentItem();          pOptions->iLoadMode = ui.LoadModeComboBox->currentIndex();
345          pOptions->saveComboBoxHistory(ui.InstrumentFileComboBox);          pOptions->saveComboBoxHistory(ui.InstrumentFileComboBox);
346    
347          // Just go with dialog acceptance.          // Just go with dialog acceptance.
# Line 326  void InstrumentForm::stabilizeForm (void Line 400  void InstrumentForm::stabilizeForm (void
400  }  }
401    
402  } // namespace QSampler  } // namespace QSampler
403    
404    
405    // end of qsamplerInstrumentForm.cpp

Legend:
Removed from v.1461  
changed lines
  Added in v.1499

  ViewVC Help
Powered by ViewVC