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

Diff of /qsampler/trunk/src/qsamplerChannelForm.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 1509 by capela, Thu Nov 22 11:10:44 2007 UTC
# Line 28  Line 28 
28  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
29  #include "qsamplerInstrument.h"  #include "qsamplerInstrument.h"
30    
31  #include <qvalidator.h>  #include <QValidator>
32  #include <qmessagebox.h>  #include <QMessageBox>
33  #include <qfiledialog.h>  #include <QFileDialog>
34  #include <qfileinfo.h>  #include <QFileInfo>
35    
36    #include <QHeaderView>
37    
38    
39  namespace QSampler {  namespace QSampler {
40    
41  ChannelForm::ChannelForm(QWidget* parent) : QDialog(parent) {  ChannelForm::ChannelForm ( QWidget* pParent )
42      ui.setupUi(this);          : QDialog(pParent)
43    {
44        m_ui.setupUi(this);
45    
46          // Initialize locals.          // Initialize locals.
47          m_pChannel = NULL;          m_pChannel = NULL;
# Line 44  ChannelForm::ChannelForm(QWidget* parent Line 49  ChannelForm::ChannelForm(QWidget* parent
49          m_iDirtySetup = 0;          m_iDirtySetup = 0;
50          m_iDirtyCount = 0;          m_iDirtyCount = 0;
51    
52          m_midiDevices.setAutoDelete(true);  //      m_midiDevices.setAutoDelete(true);
53          m_audioDevices.setAutoDelete(true);  //      m_audioDevices.setAutoDelete(true);
54    
55          m_pDeviceForm = NULL;          m_pDeviceForm = NULL;
56    
57            m_ui.AudioRoutingTable->setModel(&m_routingModel);
58            m_ui.AudioRoutingTable->setItemDelegate(&m_routingDelegate);
59            m_ui.AudioRoutingTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
60    //      m_ui.AudioRoutingTable->verticalHeader()->hide();
61    
62            // This goes initially hidden, and will be shown
63        // on setup() for currently existing channels...
64            m_ui.AudioRoutingTable->hide();
65    
66          // Try to restore normal window positioning.          // Try to restore normal window positioning.
67          adjustSize();          adjustSize();
68    
69          QObject::connect(ui.EngineNameComboBox,          QObject::connect(m_ui.EngineNameComboBox,
70                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
71                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
72          QObject::connect(ui.InstrumentFileComboBox,          QObject::connect(m_ui.InstrumentFileComboBox,
73                  SIGNAL(activated(const QString&)),                  SIGNAL(activated(const QString&)),
74                  SLOT(updateInstrumentName()));                  SLOT(updateInstrumentName()));
75          QObject::connect(ui.InstrumentFileToolButton,          QObject::connect(m_ui.InstrumentFileToolButton,
76                  SIGNAL(clicked()),                  SIGNAL(clicked()),
77                  SLOT(openInstrumentFile()));                  SLOT(openInstrumentFile()));
78          QObject::connect(ui.InstrumentNrComboBox,          QObject::connect(m_ui.InstrumentNrComboBox,
79                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
80                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
81          QObject::connect(ui.MidiDriverComboBox,          QObject::connect(m_ui.MidiDriverComboBox,
82                  SIGNAL(activated(const QString&)),                  SIGNAL(activated(const QString&)),
83                  SLOT(selectMidiDriver(const QString&)));                  SLOT(selectMidiDriver(const QString&)));
84          QObject::connect(ui.MidiDeviceComboBox,          QObject::connect(m_ui.MidiDeviceComboBox,
85                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
86                  SLOT(selectMidiDevice(int)));                  SLOT(selectMidiDevice(int)));
87          QObject::connect(ui.MidiPortSpinBox,          QObject::connect(m_ui.MidiPortSpinBox,
88                  SIGNAL(valueChanged(int)),                  SIGNAL(valueChanged(int)),
89                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
90          QObject::connect(ui.MidiChannelComboBox,          QObject::connect(m_ui.MidiChannelComboBox,
91                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
92                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
93          QObject::connect(ui.MidiMapComboBox,          QObject::connect(m_ui.MidiMapComboBox,
94                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
95                  SLOT(optionsChanged()));                  SLOT(optionsChanged()));
96          QObject::connect(ui.AudioDriverComboBox,          QObject::connect(m_ui.AudioDriverComboBox,
97                  SIGNAL(activated(const QString&)),                  SIGNAL(activated(const QString&)),
98                  SLOT(selectAudioDriver(const QString&)));                  SLOT(selectAudioDriver(const QString&)));
99          QObject::connect(ui.AudioDeviceComboBox,          QObject::connect(m_ui.AudioDeviceComboBox,
100                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
101                  SLOT(selectAudioDevice(int)));                  SLOT(selectAudioDevice(int)));
102          QObject::connect(ui.OkPushButton,          QObject::connect(m_ui.OkPushButton,
103                  SIGNAL(clicked()),                  SIGNAL(clicked()),
104                  SLOT(accept()));                  SLOT(accept()));
105          QObject::connect(ui.CancelPushButton,          QObject::connect(m_ui.CancelPushButton,
106                  SIGNAL(clicked()),                  SIGNAL(clicked()),
107                  SLOT(reject()));                  SLOT(reject()));
108          QObject::connect(ui.MidiDeviceToolButton,          QObject::connect(m_ui.MidiDeviceToolButton,
109                  SIGNAL(clicked()),                  SIGNAL(clicked()),
110                  SLOT(setupMidiDevice()));                  SLOT(setupMidiDevice()));
111          QObject::connect(ui.AudioDeviceToolButton,          QObject::connect(m_ui.AudioDeviceToolButton,
112                  SIGNAL(clicked()),                  SIGNAL(clicked()),
113                  SLOT(setupAudioDevice()));                  SLOT(setupAudioDevice()));
114            QObject::connect(&m_routingModel,
115                    SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
116                    SLOT(optionsChanged()));
117            QObject::connect(&m_routingModel,
118                    SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
119                    SLOT(updateTableCellRenderers(const QModelIndex&, const QModelIndex&)));
120            QObject::connect(&m_routingModel,
121                    SIGNAL(modelReset()),
122                    SLOT(updateTableCellRenderers()));
123  }  }
124    
125  ChannelForm::~ChannelForm() {  ChannelForm::~ChannelForm()
126    {
127          if (m_pDeviceForm)          if (m_pDeviceForm)
128                  delete m_pDeviceForm;                  delete m_pDeviceForm;
129          m_pDeviceForm = NULL;          m_pDeviceForm = NULL;
130    
131            qDeleteAll(m_midiDevices);
132            m_midiDevices.clear();
133    
134            qDeleteAll(m_audioDevices);
135            m_audioDevices.clear();
136  }  }
137    
138    
# Line 119  void ChannelForm::setup ( qsamplerChanne Line 149  void ChannelForm::setup ( qsamplerChanne
149    
150          // It can be a brand new channel, remember?          // It can be a brand new channel, remember?
151          bool bNew = (m_pChannel->channelID() < 0);          bool bNew = (m_pChannel->channelID() < 0);
152          setCaption(QSAMPLER_TITLE ": " + m_pChannel->channelName());          setWindowTitle(QSAMPLER_TITLE ": " + m_pChannel->channelName());
153    
154          // Check if we're up and connected.          // Check if we're up and connected.
155          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
# Line 136  void ChannelForm::setup ( qsamplerChanne Line 166  void ChannelForm::setup ( qsamplerChanne
166          m_iDirtySetup++;          m_iDirtySetup++;
167    
168          // Load combo box history...          // Load combo box history...
169          pOptions->loadComboBoxHistory(ui.InstrumentFileComboBox);          pOptions->loadComboBoxHistory(m_ui.InstrumentFileComboBox);
   
         // Notify.that we've just changed one audio route.  
         QObject::connect(ui.AudioRoutingTable, SIGNAL(valueChanged(int,int)),  
                 this, SLOT(changeAudioRouting(int,int)));  
170    
171          // Populate Engines list.          // Populate Engines list.
172          const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client());          const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client());
173          if (ppszEngines) {          if (ppszEngines) {
174                  ui.EngineNameComboBox->clear();                  m_ui.EngineNameComboBox->clear();
175                  for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)                  for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)
176                          ui.EngineNameComboBox->addItem(QString(ppszEngines[iEngine]));                          m_ui.EngineNameComboBox->addItem(QString(ppszEngines[iEngine]));
177          }          }
178          else m_pChannel->appendMessagesClient("lscp_list_available_engines");          else m_pChannel->appendMessagesClient("lscp_list_available_engines");
179    
180          // Populate Audio output type list.          // Populate Audio output type list.
181          ui.AudioDriverComboBox->clear();          m_ui.AudioDriverComboBox->clear();
182          ui.AudioDriverComboBox->insertStringList(          m_ui.AudioDriverComboBox->insertItems(0,
183                  qsamplerDevice::getDrivers(pMainForm->client(), qsamplerDevice::Audio));                  qsamplerDevice::getDrivers(pMainForm->client(), qsamplerDevice::Audio));
184    
185          // Populate MIDI input type list.          // Populate MIDI input type list.
186          ui.MidiDriverComboBox->clear();          m_ui.MidiDriverComboBox->clear();
187          ui.MidiDriverComboBox->insertStringList(          m_ui.MidiDriverComboBox->insertItems(0,
188                  qsamplerDevice::getDrivers(pMainForm->client(), qsamplerDevice::Midi));                  qsamplerDevice::getDrivers(pMainForm->client(), qsamplerDevice::Midi));
189    
190          // Populate Maps list.          // Populate Maps list.
191          ui.MidiMapComboBox->clear();          m_ui.MidiMapComboBox->clear();
192          ui.MidiMapComboBox->insertStringList(qsamplerInstrument::getMapNames());          m_ui.MidiMapComboBox->insertItems(0,
193                    qsamplerInstrument::getMapNames());
194    
195          // Read proper channel information,          // Read proper channel information,
196          // and populate the channel form fields.          // and populate the channel form fields.
# Line 174  void ChannelForm::setup ( qsamplerChanne Line 201  void ChannelForm::setup ( qsamplerChanne
201                  sEngineName = pOptions->sEngineName;                  sEngineName = pOptions->sEngineName;
202          if (sEngineName.isEmpty())          if (sEngineName.isEmpty())
203                  sEngineName = qsamplerChannel::noEngineName();                  sEngineName = qsamplerChannel::noEngineName();
204          if (ui.EngineNameComboBox->findText(sEngineName,          if (m_ui.EngineNameComboBox->findText(sEngineName,
205                          Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {                          Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
206                  ui.EngineNameComboBox->addItem(sEngineName);                  m_ui.EngineNameComboBox->addItem(sEngineName);
207          }          }
208          ui.EngineNameComboBox->setCurrentIndex(          m_ui.EngineNameComboBox->setCurrentIndex(
209                  ui.EngineNameComboBox->findText(sEngineName,                  m_ui.EngineNameComboBox->findText(sEngineName,
210                          Qt::MatchExactly | Qt::MatchCaseSensitive));                          Qt::MatchExactly | Qt::MatchCaseSensitive));
211    
212          // Instrument filename and index...          // Instrument filename and index...
213          QString sInstrumentFile = pChannel->instrumentFile();          QString sInstrumentFile = pChannel->instrumentFile();
214          if (sInstrumentFile.isEmpty())          if (sInstrumentFile.isEmpty())
215                  sInstrumentFile = qsamplerChannel::noInstrumentName();                  sInstrumentFile = qsamplerChannel::noInstrumentName();
216          ui.InstrumentFileComboBox->setCurrentText(sInstrumentFile);          m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile);
217          ui.InstrumentNrComboBox->clear();          m_ui.InstrumentNrComboBox->clear();
218          ui.InstrumentNrComboBox->insertStringList(          m_ui.InstrumentNrComboBox->insertItems(0,
219                  qsamplerChannel::getInstrumentList(sInstrumentFile,                  qsamplerChannel::getInstrumentList(sInstrumentFile,
220                  pOptions->bInstrumentNames));                  pOptions->bInstrumentNames));
221          ui.InstrumentNrComboBox->setCurrentItem(pChannel->instrumentNr());          m_ui.InstrumentNrComboBox->setCurrentIndex(pChannel->instrumentNr());
222    
223          // MIDI input device...          // MIDI input device...
224          qsamplerDevice midiDevice(qsamplerDevice::Midi, m_pChannel->midiDevice());          qsamplerDevice midiDevice(qsamplerDevice::Midi, m_pChannel->midiDevice());
225          // MIDI input driver...          // MIDI input driver...
226          QString sMidiDriver = midiDevice.driverName();          QString sMidiDriver = midiDevice.driverName();
227          if (sMidiDriver.isEmpty() || bNew)          if (sMidiDriver.isEmpty() || bNew)
228                  sMidiDriver = pOptions->sMidiDriver.upper();                  sMidiDriver = pOptions->sMidiDriver.toUpper();
229          if (!sMidiDriver.isEmpty()) {          if (!sMidiDriver.isEmpty()) {
230                  if (ui.MidiDriverComboBox->findText(sMidiDriver,                  if (m_ui.MidiDriverComboBox->findText(sMidiDriver,
231                                  Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {                                  Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
232                          ui.MidiDriverComboBox->insertItem(sMidiDriver);                          m_ui.MidiDriverComboBox->insertItem(0, sMidiDriver);
233                  }                  }
234                  ui.MidiDriverComboBox->setCurrentText(sMidiDriver);                  m_ui.MidiDriverComboBox->setItemText(
235                            m_ui.MidiDriverComboBox->currentIndex(),
236                            sMidiDriver);
237          }          }
238          selectMidiDriverItem(sMidiDriver);          selectMidiDriverItem(sMidiDriver);
239          if (!bNew)          if (!bNew) {
240                  ui.MidiDeviceComboBox->setCurrentText(midiDevice.deviceName());                  m_ui.MidiDeviceComboBox->setItemText(
241          selectMidiDeviceItem(ui.MidiDeviceComboBox->currentItem());                          m_ui.MidiDeviceComboBox->currentIndex(),
242                            midiDevice.deviceName());
243            }
244            selectMidiDeviceItem(m_ui.MidiDeviceComboBox->currentIndex());
245          // MIDI input port...          // MIDI input port...
246          ui.MidiPortSpinBox->setValue(pChannel->midiPort());          m_ui.MidiPortSpinBox->setValue(pChannel->midiPort());
247          // MIDI input channel...          // MIDI input channel...
248          int iMidiChannel = pChannel->midiChannel();          int iMidiChannel = pChannel->midiChannel();
249          // When new, try to suggest a sensible MIDI channel...          // When new, try to suggest a sensible MIDI channel...
250          if (iMidiChannel < 0)          if (iMidiChannel < 0)
251                  iMidiChannel = (::lscp_get_channels(pMainForm->client()) % 16);                  iMidiChannel = (::lscp_get_channels(pMainForm->client()) % 16);
252          ui.MidiChannelComboBox->setCurrentItem(iMidiChannel);          m_ui.MidiChannelComboBox->setCurrentIndex(iMidiChannel);
253          // MIDI instrument map...          // MIDI instrument map...
254          int iMidiMap = (bNew ? pOptions->iMidiMap : pChannel->midiMap());          int iMidiMap = (bNew ? pOptions->iMidiMap : pChannel->midiMap());
255          // When new, try to suggest a sensible MIDI map...          // When new, try to suggest a sensible MIDI map...
256          if (iMidiMap < 0)          if (iMidiMap < 0)
257                  iMidiMap = 0;                  iMidiMap = 0;
258          const QString& sMapName = qsamplerInstrument::getMapName(iMidiMap);          const QString& sMapName = qsamplerInstrument::getMapName(iMidiMap);
259          if (!sMapName.isEmpty())          if (!sMapName.isEmpty()) {
260                  ui.MidiMapComboBox->setCurrentText(sMapName);                  m_ui.MidiMapComboBox->setItemText(
261                            m_ui.MidiMapComboBox->currentIndex(),
262                            sMapName);
263            }
264          // It might be no maps around...          // It might be no maps around...
265          bool bMidiMapEnabled = (ui.MidiMapComboBox->count() > 0);          bool bMidiMapEnabled = (m_ui.MidiMapComboBox->count() > 0);
266          ui.MidiMapTextLabel->setEnabled(bMidiMapEnabled);          m_ui.MidiMapTextLabel->setEnabled(bMidiMapEnabled);
267          ui.MidiMapComboBox->setEnabled(bMidiMapEnabled);          m_ui.MidiMapComboBox->setEnabled(bMidiMapEnabled);
268    
269          // Audio output device...          // Audio output device...
270          qsamplerDevice audioDevice(qsamplerDevice::Audio, m_pChannel->audioDevice());          qsamplerDevice audioDevice(qsamplerDevice::Audio, m_pChannel->audioDevice());
271          // Audio output driver...          // Audio output driver...
272          QString sAudioDriver = audioDevice.driverName();          QString sAudioDriver = audioDevice.driverName();
273          if (sAudioDriver.isEmpty() || bNew)          if (sAudioDriver.isEmpty() || bNew)
274                  sAudioDriver = pOptions->sAudioDriver.upper();                  sAudioDriver = pOptions->sAudioDriver.toUpper();
275          if (!sAudioDriver.isEmpty()) {          if (!sAudioDriver.isEmpty()) {
276                  if (ui.AudioDriverComboBox->findText(sAudioDriver,                  if (m_ui.AudioDriverComboBox->findText(sAudioDriver,
277                                  Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {                                  Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) {
278                          ui.AudioDriverComboBox->insertItem(sAudioDriver);                          m_ui.AudioDriverComboBox->insertItem(0, sAudioDriver);
279                  }                  }
280                  ui.AudioDriverComboBox->setCurrentText(sAudioDriver);                  m_ui.AudioDriverComboBox->setItemText(
281                            m_ui.AudioDriverComboBox->currentIndex(),
282                            sAudioDriver);
283          }          }
284          selectAudioDriverItem(sAudioDriver);          selectAudioDriverItem(sAudioDriver);
285          if (!bNew)          if (!bNew) {
286                  ui.AudioDeviceComboBox->setCurrentText(audioDevice.deviceName());                  m_ui.AudioDeviceComboBox->setItemText(
287          selectAudioDeviceItem(ui.AudioDeviceComboBox->currentItem());                          m_ui.AudioDeviceComboBox->currentIndex(),
288                            audioDevice.deviceName());
289            }
290            selectAudioDeviceItem(m_ui.AudioDeviceComboBox->currentIndex());
291    
292            // Let the audio routing table see the light,
293            // if we're editing an existing sampler channel...
294            m_ui.AudioRoutingTable->setVisible(!bNew);
295    
296          // As convenient, make it ready on stabilizeForm() for          // As convenient, make it ready on stabilizeForm() for
297          // prompt acceptance, if we got the minimum required...          // prompt acceptance, if we got the minimum required...
# Line 276  void ChannelForm::accept (void) Line 321  void ChannelForm::accept (void)
321                  return;                  return;
322    
323          // Flush any pending editing...          // Flush any pending editing...
324          //ui.AudioRoutingTable->flush();          //m_ui.AudioRoutingTable->flush();
325    
326          // We'll go for it!          // We'll go for it!
327          if (m_iDirtyCount > 0) {          if (m_iDirtyCount > 0) {
# Line 286  void ChannelForm::accept (void) Line 331  void ChannelForm::accept (void)
331                          iErrors++;                          iErrors++;
332                  // Accept Audio driver or device selection...                  // Accept Audio driver or device selection...
333                  if (m_audioDevices.isEmpty()) {                  if (m_audioDevices.isEmpty()) {
334                          if (!m_pChannel->setAudioDriver(ui.AudioDriverComboBox->currentText()))                          if (!m_pChannel->setAudioDriver(m_ui.AudioDriverComboBox->currentText()))
335                                  iErrors++;                                  iErrors++;
336                  } else {                  } else {
337                          qsamplerDevice *pDevice = m_audioDevices.at(ui.AudioDeviceComboBox->currentItem());                          qsamplerDevice *pDevice = NULL;
338                            int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex();
339                            if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
340                                    pDevice = m_audioDevices.at(iAudioItem);
341                            qsamplerChannelRoutingMap routingMap = m_routingModel.routingMap();
342                          if (pDevice == NULL)                          if (pDevice == NULL)
343                                  iErrors++;                                  iErrors++;
344                          else if (!m_pChannel->setAudioDevice(pDevice->deviceID()))                          else if (!m_pChannel->setAudioDevice(pDevice->deviceID()))
345                                  iErrors++;                                  iErrors++;
346                          else if (!m_audioRouting.isEmpty()) {                          else if (!routingMap.isEmpty()) {
347                                  // Set the audio route changes...                                  // Set the audio route changes...
348                                  qsamplerChannelRoutingMap::ConstIterator iter;                                  qsamplerChannelRoutingMap::ConstIterator iter;
349                                  for (iter = m_audioRouting.begin();                                  for (iter = routingMap.begin();
350                                                  iter != m_audioRouting.end(); ++iter) {                                                  iter != routingMap.end(); ++iter) {
351                                          if (!m_pChannel->setAudioChannel(iter.key(), iter.data()))                                          if (!m_pChannel->setAudioChannel(iter.key(), iter.value()))
352                                                  iErrors++;                                                  iErrors++;
353                                  }                                  }
354                          }                          }
355                  }                  }
356                  // Accept MIDI driver or device selection...                  // Accept MIDI driver or device selection...
357                  if (m_midiDevices.isEmpty()) {                  if (m_midiDevices.isEmpty()) {
358                          if (!m_pChannel->setMidiDriver(ui.MidiDriverComboBox->currentText()))                          if (!m_pChannel->setMidiDriver(m_ui.MidiDriverComboBox->currentText()))
359                                  iErrors++;                                  iErrors++;
360                  } else {                  } else {
361                          qsamplerDevice *pDevice = m_midiDevices.at(ui.MidiDeviceComboBox->currentItem());                          qsamplerDevice *pDevice = NULL;
362                            int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex();
363                            if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
364                                    pDevice = m_midiDevices.at(iMidiItem);
365                          if (pDevice == NULL)                          if (pDevice == NULL)
366                                  iErrors++;                                  iErrors++;
367                          else if (!m_pChannel->setMidiDevice(pDevice->deviceID()))                          else if (!m_pChannel->setMidiDevice(pDevice->deviceID()))
368                                  iErrors++;                                  iErrors++;
369                  }                  }
370                  // MIDI input port number...                  // MIDI input port number...
371                  if (!m_pChannel->setMidiPort(ui.MidiPortSpinBox->value()))                  if (!m_pChannel->setMidiPort(m_ui.MidiPortSpinBox->value()))
372                          iErrors++;                          iErrors++;
373                  // MIDI input channel...                  // MIDI input channel...
374                  if (!m_pChannel->setMidiChannel(ui.MidiChannelComboBox->currentItem()))                  if (!m_pChannel->setMidiChannel(m_ui.MidiChannelComboBox->currentIndex()))
375                          iErrors++;                          iErrors++;
376                  // Engine name...                  // Engine name...
377                  if (!m_pChannel->loadEngine(ui.EngineNameComboBox->currentText()))                  if (!m_pChannel->loadEngine(m_ui.EngineNameComboBox->currentText()))
378                          iErrors++;                          iErrors++;
379                  // Instrument file and index...                  // Instrument file and index...
380                  const QString& sPath = ui.InstrumentFileComboBox->currentText();                  const QString& sPath = m_ui.InstrumentFileComboBox->currentText();
381                  if (!sPath.isEmpty() && QFileInfo(sPath).exists()) {                  if (!sPath.isEmpty() && QFileInfo(sPath).exists()) {
382                          if (!m_pChannel->loadInstrument(sPath, ui.InstrumentNrComboBox->currentItem()))                          if (!m_pChannel->loadInstrument(sPath, m_ui.InstrumentNrComboBox->currentIndex()))
383                                  iErrors++;                                  iErrors++;
384                  }                  }
385                  // MIDI intrument map...                  // MIDI intrument map...
386                  if (!m_pChannel->setMidiMap(ui.MidiMapComboBox->currentItem()))                  if (!m_pChannel->setMidiMap(m_ui.MidiMapComboBox->currentIndex()))
387                          iErrors++;                          iErrors++;
388                  // Show error messages?                  // Show error messages?
389                  if (iErrors > 0)                  if (iErrors > 0)
# Line 339  void ChannelForm::accept (void) Line 391  void ChannelForm::accept (void)
391          }          }
392    
393          // Save default engine name, instrument directory and history...          // Save default engine name, instrument directory and history...
394          pOptions->sInstrumentDir = QFileInfo(ui.InstrumentFileComboBox->currentText()).dirPath(true);          pOptions->sInstrumentDir = QFileInfo(
395          pOptions->sEngineName  = ui.EngineNameComboBox->currentText();                  m_ui.InstrumentFileComboBox->currentText()).dir().absolutePath();
396          pOptions->sAudioDriver = ui.AudioDriverComboBox->currentText();          pOptions->sEngineName  = m_ui.EngineNameComboBox->currentText();
397          pOptions->sMidiDriver  = ui.MidiDriverComboBox->currentText();          pOptions->sAudioDriver = m_ui.AudioDriverComboBox->currentText();
398          pOptions->iMidiMap     = ui.MidiMapComboBox->currentItem();          pOptions->sMidiDriver  = m_ui.MidiDriverComboBox->currentText();
399          pOptions->saveComboBoxHistory(ui.InstrumentFileComboBox);          pOptions->iMidiMap     = m_ui.MidiMapComboBox->currentIndex();
400            pOptions->saveComboBoxHistory(m_ui.InstrumentFileComboBox);
401    
402          // Just go with dialog acceptance.          // Just go with dialog acceptance.
403          QDialog::accept();          QDialog::accept();
# Line 357  void ChannelForm::reject (void) Line 410  void ChannelForm::reject (void)
410          bool bReject = true;          bool bReject = true;
411    
412          // Check if there's any pending changes...          // Check if there's any pending changes...
413          if (m_iDirtyCount > 0 && ui.OkPushButton->isEnabled()) {          if (m_iDirtyCount > 0 && m_ui.OkPushButton->isEnabled()) {
414                  switch (QMessageBox::warning(this,                  switch (QMessageBox::warning(this,
415                          QSAMPLER_TITLE ": " + tr("Warning"),                          QSAMPLER_TITLE ": " + tr("Warning"),
416                          tr("Some channel settings have been changed.\n\n"                          tr("Some channel settings have been changed.\n\n"
# Line 394  void ChannelForm::openInstrumentFile (vo Line 447  void ChannelForm::openInstrumentFile (vo
447    
448          // FIXME: the instrument file filters should be restricted,          // FIXME: the instrument file filters should be restricted,
449          // depending on the current engine.          // depending on the current engine.
450          QString sInstrumentFile = QFileDialog::getOpenFileName(          QString sInstrumentFile = QFileDialog::getOpenFileName(this,
451                  pOptions->sInstrumentDir,                   // Start here.                  QSAMPLER_TITLE ": " + tr("Instrument files"), // Caption.
452                  tr("Instrument files") + " (*.gig *.dls)",  // Filter (GIG and DLS files)                  pOptions->sInstrumentDir,                 // Start here.
453                  this, 0,                                    // Parent and name (none)                  tr("Instrument files") + " (*.gig *.dls)" // Filter (GIG and DLS files)
                 QSAMPLER_TITLE ": " + tr("Instrument files")    // Caption.  
454          );          );
455    
456          if (sInstrumentFile.isEmpty())          if (sInstrumentFile.isEmpty())
457                  return;                  return;
458    
459          ui.InstrumentFileComboBox->setCurrentText(sInstrumentFile);          m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile);
460          updateInstrumentName();          updateInstrumentName();
461  }  }
462    
# Line 424  void ChannelForm::updateInstrumentName ( Line 476  void ChannelForm::updateInstrumentName (
476    
477          // Finally this better idea would be to use libgig          // Finally this better idea would be to use libgig
478          // to retrieve the REAL instrument names.          // to retrieve the REAL instrument names.
479          ui.InstrumentNrComboBox->clear();          m_ui.InstrumentNrComboBox->clear();
480          ui.InstrumentNrComboBox->insertStringList(          m_ui.InstrumentNrComboBox->insertItems(0,
481                  qsamplerChannel::getInstrumentList(                  qsamplerChannel::getInstrumentList(
482                          ui.InstrumentFileComboBox->currentText(),                          m_ui.InstrumentFileComboBox->currentText(),
483                          pOptions->bInstrumentNames)                          pOptions->bInstrumentNames)
484          );          );
485    
# Line 437  void ChannelForm::updateInstrumentName ( Line 489  void ChannelForm::updateInstrumentName (
489    
490  // Show device options dialog.  // Show device options dialog.
491  void ChannelForm::setupDevice ( qsamplerDevice *pDevice,  void ChannelForm::setupDevice ( qsamplerDevice *pDevice,
492          qsamplerDevice::qsamplerDeviceType deviceTypeMode,          qsamplerDevice::DeviceType deviceTypeMode,
493          const QString& sDriverName )          const QString& sDriverName )
494  {  {
495            if (pDevice == NULL)
496                    return;
497    
498          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
499          if (pMainForm == NULL)          if (pMainForm == NULL)
500                  return;                  return;
# Line 474  void ChannelForm::selectMidiDriverItem ( Line 529  void ChannelForm::selectMidiDriverItem (
529          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
530                  return;                  return;
531    
532          const QString sDriverName = sMidiDriver.upper();          const QString sDriverName = sMidiDriver.toUpper();
533    
534          // Save current device id.          // Save current device id.
535            // Save current device id.
536          int iDeviceID = 0;          int iDeviceID = 0;
537          qsamplerDevice *pDevice = m_midiDevices.at(ui.MidiDeviceComboBox->currentItem());          qsamplerDevice *pDevice = NULL;
538            int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex();
539            if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
540                    pDevice = m_midiDevices.at(iMidiItem);
541          if (pDevice)          if (pDevice)
542                  iDeviceID = pDevice->deviceID();                  iDeviceID = pDevice->deviceID();
543    
544          // Clean maplist.          // Clean maplist.
545          ui.MidiDeviceComboBox->clear();          m_ui.MidiDeviceComboBox->clear();
546            qDeleteAll(m_midiDevices);
547          m_midiDevices.clear();          m_midiDevices.clear();
548    
549          // Populate with the current ones...          // Populate with the current ones...
550          const QPixmap midiPixmap(":/qsampler/pixmaps/midi2.png");          const QPixmap midiPixmap(":/icons/midi2.png");
551          int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),          int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),
552                  qsamplerDevice::Midi);                  qsamplerDevice::Midi);
553          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
554                  pDevice = new qsamplerDevice(qsamplerDevice::Midi, piDeviceIDs[i]);                  pDevice = new qsamplerDevice(qsamplerDevice::Midi, piDeviceIDs[i]);
555                  if (pDevice->driverName().upper() == sDriverName) {                  if (pDevice->driverName().toUpper() == sDriverName) {
556                          ui.MidiDeviceComboBox->insertItem(midiPixmap, pDevice->deviceName());                          m_ui.MidiDeviceComboBox->insertItem(0, midiPixmap, pDevice->deviceName());
557                          m_midiDevices.append(pDevice);                          m_midiDevices.append(pDevice);
558                  } else {                  } else {
559                          delete pDevice;                          delete pDevice;
# Line 504  void ChannelForm::selectMidiDriverItem ( Line 564  void ChannelForm::selectMidiDriverItem (
564          bool bEnabled = !m_midiDevices.isEmpty();          bool bEnabled = !m_midiDevices.isEmpty();
565          if (bEnabled) {          if (bEnabled) {
566                  // Select the previous current device...                  // Select the previous current device...
567                  int iMidiItem = 0;                  iMidiItem = 0;
568                  for (pDevice = m_midiDevices.first();                  QListIterator<qsamplerDevice *> iter(m_midiDevices);
569                                  pDevice;                  while (iter.hasNext()) {
570                                          pDevice = m_midiDevices.next()) {                          pDevice = iter.next();
571                          if (pDevice->deviceID() == iDeviceID) {                          if (pDevice->deviceID() == iDeviceID) {
572                                  ui.MidiDeviceComboBox->setCurrentItem(iMidiItem);                                  m_ui.MidiDeviceComboBox->setCurrentIndex(iMidiItem);
573                                  selectMidiDeviceItem(iMidiItem);                                  selectMidiDeviceItem(iMidiItem);
574                                  break;                                  break;
575                          }                          }
576                          iMidiItem++;                          iMidiItem++;
577                  }                  }
578          } else {          } else {
579                  ui.MidiDeviceComboBox->insertItem(                  m_ui.MidiDeviceComboBox->insertItem(0,
580                          tr("(New MIDI %1 device)").arg(sMidiDriver));                          tr("(New MIDI %1 device)").arg(sMidiDriver));
581          }          }
582          ui.MidiDeviceTextLabel->setEnabled(bEnabled);          m_ui.MidiDeviceTextLabel->setEnabled(bEnabled);
583          ui.MidiDeviceComboBox->setEnabled(bEnabled);          m_ui.MidiDeviceComboBox->setEnabled(bEnabled);
584  }  }
585    
586    
# Line 538  void ChannelForm::selectMidiDriver ( con Line 598  void ChannelForm::selectMidiDriver ( con
598  // Select MIDI device item.  // Select MIDI device item.
599  void ChannelForm::selectMidiDeviceItem ( int iMidiItem )  void ChannelForm::selectMidiDeviceItem ( int iMidiItem )
600  {  {
601          qsamplerDevice *pDevice = m_midiDevices.at(iMidiItem);          qsamplerDevice *pDevice = NULL;
602            if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
603                    pDevice = m_midiDevices.at(iMidiItem);
604          if (pDevice) {          if (pDevice) {
605                  const qsamplerDeviceParamMap& params = pDevice->params();                  const qsamplerDeviceParamMap& params = pDevice->params();
606                  int iPorts = params["PORTS"].value.toInt();                  int iPorts = params["PORTS"].value.toInt();
607                  ui.MidiPortTextLabel->setEnabled(iPorts > 0);                  m_ui.MidiPortTextLabel->setEnabled(iPorts > 0);
608                  ui.MidiPortSpinBox->setEnabled(iPorts > 0);                  m_ui.MidiPortSpinBox->setEnabled(iPorts > 0);
609                  if (iPorts > 0)                  if (iPorts > 0)
610                          ui.MidiPortSpinBox->setMaxValue(iPorts - 1);                          m_ui.MidiPortSpinBox->setMaximum(iPorts - 1);
611          }          }
612  }  }
613    
# Line 564  void ChannelForm::selectMidiDevice ( int Line 626  void ChannelForm::selectMidiDevice ( int
626  // MIDI device options.  // MIDI device options.
627  void ChannelForm::setupMidiDevice (void)  void ChannelForm::setupMidiDevice (void)
628  {  {
629          setupDevice(m_midiDevices.at(ui.MidiDeviceComboBox->currentItem()),          qsamplerDevice *pDevice = NULL;
630                  qsamplerDevice::Midi, ui.MidiDriverComboBox->currentText());          int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex();
631            if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count())
632                    pDevice = m_midiDevices.at(iMidiItem);
633            setupDevice(pDevice,
634                    qsamplerDevice::Midi, m_ui.MidiDriverComboBox->currentText());
635  }  }
636    
637    
# Line 578  void ChannelForm::selectAudioDriverItem Line 644  void ChannelForm::selectAudioDriverItem
644          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
645                  return;                  return;
646    
647          const QString sDriverName = sAudioDriver.upper();          const QString sDriverName = sAudioDriver.toUpper();
648    
649          // Save current device id.          // Save current device id.
650          int iDeviceID = 0;          int iDeviceID = 0;
651          qsamplerDevice *pDevice = m_audioDevices.at(ui.AudioDeviceComboBox->currentItem());          qsamplerDevice *pDevice = NULL;
652            int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex();
653            if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
654                    pDevice = m_audioDevices.at(iAudioItem);
655          if (pDevice)          if (pDevice)
656                  iDeviceID = pDevice->deviceID();                  iDeviceID = pDevice->deviceID();
657    
658          // Clean maplist.          // Clean maplist.
659          ui.AudioDeviceComboBox->clear();          m_ui.AudioDeviceComboBox->clear();
660            qDeleteAll(m_audioDevices);
661          m_audioDevices.clear();          m_audioDevices.clear();
662    
663          // Populate with the current ones...          // Populate with the current ones...
664          const QPixmap audioPixmap(":/qsampler/pixmaps/audio2.png");          const QPixmap audioPixmap(":/icons/audio2.png");
665          int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),          int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),
666                  qsamplerDevice::Audio);                  qsamplerDevice::Audio);
667          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
668                  pDevice = new qsamplerDevice(qsamplerDevice::Audio, piDeviceIDs[i]);                  pDevice = new qsamplerDevice(qsamplerDevice::Audio, piDeviceIDs[i]);
669                  if (pDevice->driverName().upper() == sDriverName) {                  if (pDevice->driverName().toUpper() == sDriverName) {
670                          ui.AudioDeviceComboBox->insertItem(audioPixmap, pDevice->deviceName());                          m_ui.AudioDeviceComboBox->insertItem(0, audioPixmap, pDevice->deviceName());
671                          m_audioDevices.append(pDevice);                          m_audioDevices.append(pDevice);
672                  } else {                  } else {
673                          delete pDevice;                          delete pDevice;
# Line 608  void ChannelForm::selectAudioDriverItem Line 678  void ChannelForm::selectAudioDriverItem
678          bool bEnabled = !m_audioDevices.isEmpty();          bool bEnabled = !m_audioDevices.isEmpty();
679          if (bEnabled) {          if (bEnabled) {
680                  // Select the previous current device...                  // Select the previous current device...
681                  int iAudioItem = 0;                  iAudioItem = 0;
682                  for (pDevice = m_audioDevices.first();                  QListIterator<qsamplerDevice *> iter(m_audioDevices);
683                                  pDevice;                  while (iter.hasNext()) {
684                                          pDevice = m_audioDevices.next()) {                          pDevice = iter.next();
685                          if (pDevice->deviceID() == iDeviceID) {                          if (pDevice->deviceID() == iDeviceID) {
686                                  ui.AudioDeviceComboBox->setCurrentItem(iAudioItem);                                  m_ui.AudioDeviceComboBox->setCurrentIndex(iAudioItem);
687                                  selectAudioDeviceItem(iAudioItem);                                  selectAudioDeviceItem(iAudioItem);
688                                  break;                                  break;
689                          }                          }
690                          iAudioItem++;                          iAudioItem++;
691                  }                  }
692          } else {          } else {
693                  ui.AudioDeviceComboBox->insertItem(                  m_ui.AudioDeviceComboBox->insertItem(0,
694                          tr("(New Audio %1 device)").arg(sAudioDriver));                          tr("(New Audio %1 device)").arg(sAudioDriver));
695                  //ui.AudioRoutingTable->setNumRows(0);                  //m_ui.AudioRoutingTable->setNumRows(0);
696          }          }
697          ui.AudioDeviceTextLabel->setEnabled(bEnabled);          m_ui.AudioDeviceTextLabel->setEnabled(bEnabled);
698          ui.AudioDeviceComboBox->setEnabled(bEnabled);          m_ui.AudioDeviceComboBox->setEnabled(bEnabled);
699          ui.AudioRoutingTable->setEnabled(bEnabled);          m_ui.AudioRoutingTable->setEnabled(bEnabled);
700  }  }
701    
702    
# Line 644  void ChannelForm::selectAudioDriver ( co Line 714  void ChannelForm::selectAudioDriver ( co
714  // Select Audio device item.  // Select Audio device item.
715  void ChannelForm::selectAudioDeviceItem ( int iAudioItem )  void ChannelForm::selectAudioDeviceItem ( int iAudioItem )
716  {  {
717          qsamplerDevice *pDevice = m_audioDevices.at(iAudioItem);          qsamplerDevice *pDevice = NULL;
718            if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
719                    pDevice = m_audioDevices.at(iAudioItem);
720          if (pDevice) {          if (pDevice) {
721                  // Refresh the audio routing table.                  // Refresh the audio routing table.
722                  routingModel.refresh(pDevice, m_pChannel->audioRouting());                  m_routingModel.refresh(pDevice, m_pChannel->audioRouting());
723                  // Reset routing change map.                  // Reset routing change map.
724                  m_audioRouting.clear();                  m_routingModel.clear();
725          }          }
726  }  }
727    
# Line 668  void ChannelForm::selectAudioDevice ( in Line 740  void ChannelForm::selectAudioDevice ( in
740  // Audio device options.  // Audio device options.
741  void ChannelForm::setupAudioDevice (void)  void ChannelForm::setupAudioDevice (void)
742  {  {
743          setupDevice(m_audioDevices.at(ui.AudioDeviceComboBox->currentItem()),          qsamplerDevice *pDevice = NULL;
744                  qsamplerDevice::Audio, ui.AudioDriverComboBox->currentText());          int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex();
745  }          if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count())
746                    pDevice = m_audioDevices.at(iAudioItem);
747            setupDevice(pDevice,
748  // Audio routing change slot.                  qsamplerDevice::Audio, m_ui.AudioDriverComboBox->currentText());
 void ChannelForm::changeAudioRouting ( int iRow, int iCol )  
 {  
 #if 0  
         if (m_iDirtySetup > 0)  
                 return;  
         if (iRow < 0 || iCol < 0)  
                 return;  
   
         // Verify that this is a QComboTableItem (magic rtti == 1)  
         QTableItem *pItem = ui.AudioRoutingTable->item(iRow, iCol);  
         if (pItem == NULL)  
                 return;  
         qsamplerChannelRoutingComboBox *pComboItem =  
                 static_cast<qsamplerChannelRoutingComboBox*> (pItem);  
         // FIXME: Its not garanteed that we must have  
         // iAudioOut == iRow on all times forth!  
         m_audioRouting[iRow] = pComboItem->currentItem();  
   
         // And let's get dirty...  
         optionsChanged();  
 #endif  
749  }  }
750    
   
751  // UPdate all device lists slot.  // UPdate all device lists slot.
752  void ChannelForm::updateDevices (void)  void ChannelForm::updateDevices (void)
753  {  {
754          if (m_iDirtySetup > 0)          if (m_iDirtySetup > 0)
755                  return;                  return;
756    
757          selectMidiDriverItem(ui.MidiDriverComboBox->currentText());          selectMidiDriverItem(m_ui.MidiDriverComboBox->currentText());
758          selectAudioDriverItem(ui.AudioDriverComboBox->currentText());          selectAudioDriverItem(m_ui.AudioDriverComboBox->currentText());
759          optionsChanged();          optionsChanged();
760  }  }
761    
# Line 724  void ChannelForm::optionsChanged (void) Line 774  void ChannelForm::optionsChanged (void)
774  // Stabilize current form state.  // Stabilize current form state.
775  void ChannelForm::stabilizeForm (void)  void ChannelForm::stabilizeForm (void)
776  {  {
777          bool bValid = true;          const bool bValid =
778                    m_ui.EngineNameComboBox->currentIndex() >= 0 &&
779                    m_ui.EngineNameComboBox->currentText() !=
780                    qsamplerChannel::noEngineName();
781  #if 0  #if 0
782          const QString& sPath = InstrumentFileComboBox->currentText();          const QString& sPath = InstrumentFileComboBox->currentText();
783          bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists();          bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists();
784  #endif  #endif
785          ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid);          m_ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid);
786  }  }
787    
788    
789    void ChannelForm::updateTableCellRenderers (void)
790    {
791        const int rows = m_routingModel.rowCount();
792        const int cols = m_routingModel.columnCount();
793        updateTableCellRenderers(
794                    m_routingModel.index(0, 0),
795                    m_routingModel.index(rows - 1, cols - 1));
796    }
797    
798    
799    void ChannelForm::updateTableCellRenderers (
800            const QModelIndex& topLeft, const QModelIndex& bottomRight )
801    {
802        for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
803            for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
804                const QModelIndex index = m_routingModel.index(r, c);
805                m_ui.AudioRoutingTable->openPersistentEditor(index);
806            }
807        }
808    }
809    
810  } // namespace QSampler  } // namespace QSampler
811    
812    

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

  ViewVC Help
Powered by ViewVC