/[svn]/qsampler/trunk/src/qsamplerChannelForm.ui.h
ViewVC logotype

Annotation of /qsampler/trunk/src/qsamplerChannelForm.ui.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 488 - (hide annotations) (download) (as text)
Thu Mar 31 16:26:40 2005 UTC (19 years ago) by capela
File MIME type: text/x-c++hdr
File size: 17021 byte(s)
Device setup is now also accessible from the sampler channel dialog (fix).

1 capela 104 // qsamplerChannelForm.ui.h
2     //
3     // ui.h extension file, included from the uic-generated form implementation.
4     /****************************************************************************
5 capela 341 Copyright (C) 2004-2005, rncbc aka Rui Nuno Capela. All rights reserved.
6 capela 104
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 <qvalidator.h>
24     #include <qmessagebox.h>
25     #include <qfiledialog.h>
26     #include <qfileinfo.h>
27     #include <qlistbox.h>
28    
29 capela 487 #include "qsamplerDeviceForm.h"
30    
31 capela 104 #include "config.h"
32    
33    
34     // Kind of constructor.
35     void qsamplerChannelForm::init (void)
36     {
37     // Initialize locals.
38     m_pChannel = NULL;
39    
40     m_iDirtySetup = 0;
41     m_iDirtyCount = 0;
42    
43 capela 452 m_midiDevices.setAutoDelete(true);
44     m_audioDevices.setAutoDelete(true);
45    
46 capela 487 m_pDeviceForm = NULL;
47    
48 capela 104 // Try to restore normal window positioning.
49     adjustSize();
50     }
51    
52    
53     // Kind of destructor.
54     void qsamplerChannelForm::destroy (void)
55     {
56 capela 487 if (m_pDeviceForm)
57     delete m_pDeviceForm;
58     m_pDeviceForm = NULL;
59 capela 104 }
60    
61    
62     // Channel dialog setup formal initializer.
63 capela 295 void qsamplerChannelForm::setup ( qsamplerChannel *pChannel )
64 capela 104 {
65     m_pChannel = pChannel;
66    
67     m_iDirtySetup = 0;
68     m_iDirtyCount = 0;
69    
70     if (m_pChannel == NULL)
71     return;
72    
73 capela 295 // It can be a brand new channel, remember?
74     bool bNew = (m_pChannel->channelID() < 0);
75     setCaption(m_pChannel->channelName());
76 capela 104
77     // Check if we're up and connected.
78     if (m_pChannel->client() == NULL)
79     return;
80    
81     qsamplerOptions *pOptions = m_pChannel->options();
82     if (pOptions == NULL)
83     return;
84    
85     // Avoid nested changes.
86     m_iDirtySetup++;
87    
88     // Load combo box history...
89     pOptions->loadComboBoxHistory(InstrumentFileComboBox);
90    
91     // Populate Engines list.
92     const char **ppszEngines = ::lscp_get_available_engines(m_pChannel->client());
93     if (ppszEngines) {
94     EngineNameComboBox->clear();
95     for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)
96     EngineNameComboBox->insertItem(ppszEngines[iEngine]);
97     }
98     else m_pChannel->appendMessagesClient("lscp_get_available_engines");
99 capela 145
100 capela 104 // Populate Audio output type list.
101 capela 430 AudioDriverComboBox->clear();
102     AudioDriverComboBox->insertStringList(
103     qsamplerDevice::getDrivers(m_pChannel->client(), qsamplerDevice::Audio));
104 capela 104
105     // Populate MIDI input type list.
106 capela 430 MidiDriverComboBox->clear();
107     MidiDriverComboBox->insertStringList(
108     qsamplerDevice::getDrivers(m_pChannel->client(), qsamplerDevice::Midi));
109 capela 145
110 capela 104 // Read proper channel information,
111     // and populate the channel form fields.
112    
113     // Engine name...
114 capela 145 QString sEngineName = pChannel->engineName();
115 capela 400 if (sEngineName.isEmpty() || bNew)
116 capela 176 sEngineName = pOptions->sEngineName;
117 capela 145 if (sEngineName.isEmpty())
118 capela 388 sEngineName = qsamplerChannel::noEngineName();
119 capela 145 if (EngineNameComboBox->listBox()->findItem(sEngineName, Qt::ExactMatch) == NULL)
120     EngineNameComboBox->insertItem(sEngineName);
121     EngineNameComboBox->setCurrentText(sEngineName);
122 capela 104 // Instrument filename and index...
123 capela 145 QString sInstrumentFile = pChannel->instrumentFile();
124     if (sInstrumentFile.isEmpty())
125 capela 388 sInstrumentFile = qsamplerChannel::noInstrumentName();
126 capela 145 InstrumentFileComboBox->setCurrentText(sInstrumentFile);
127 capela 299 InstrumentNrComboBox->clear();
128 capela 344 InstrumentNrComboBox->insertStringList(
129     qsamplerChannel::getInstrumentList(sInstrumentFile,
130     pOptions->bInstrumentNames));
131 capela 299 InstrumentNrComboBox->setCurrentItem(pChannel->instrumentNr());
132 capela 452
133     // MIDI input device...
134 capela 484 qsamplerDevice midiDevice(m_pChannel->mainForm(),
135 capela 452 qsamplerDevice::Midi, m_pChannel->midiDevice());
136 capela 176 // MIDI input driver...
137 capela 452 QString sMidiDriver = midiDevice.driverName();
138     if (sMidiDriver.isEmpty() || bNew)
139     sMidiDriver = pOptions->sMidiDriver;
140     if (!sMidiDriver.isEmpty()) {
141     if (MidiDriverComboBox->listBox()->findItem(sMidiDriver, Qt::ExactMatch) == NULL)
142     MidiDriverComboBox->insertItem(sMidiDriver);
143     MidiDriverComboBox->setCurrentText(sMidiDriver);
144     }
145 capela 488 selectMidiDriverItem(sMidiDriver);
146 capela 452 if (!bNew)
147     MidiDeviceComboBox->setCurrentText(midiDevice.deviceName());
148 capela 488 selectMidiDeviceItem(MidiDeviceComboBox->currentItem());
149 capela 176 // MIDI input port...
150 capela 104 MidiPortSpinBox->setValue(pChannel->midiPort());
151 capela 176 // MIDI input channel...
152     int iMidiChannel = pChannel->midiChannel();
153 capela 295 // When new, try to suggest a sensible MIDI channel...
154     if (iMidiChannel < 0)
155     iMidiChannel = (::lscp_get_channels(m_pChannel->client()) % 16);
156 capela 255 MidiChannelComboBox->setCurrentItem(iMidiChannel);
157 capela 455
158 capela 452 // Audio output device...
159 capela 484 qsamplerDevice audioDevice(m_pChannel->mainForm(),
160 capela 452 qsamplerDevice::Audio, m_pChannel->audioDevice());
161     // Audio output driver...
162     QString sAudioDriver = audioDevice.driverName();
163     if (sAudioDriver.isEmpty() || bNew)
164     sAudioDriver = pOptions->sAudioDriver;
165     if (!sAudioDriver.isEmpty()) {
166     if (AudioDriverComboBox->listBox()->findItem(sAudioDriver, Qt::ExactMatch) == NULL)
167     AudioDriverComboBox->insertItem(sAudioDriver);
168     AudioDriverComboBox->setCurrentText(sAudioDriver);
169     }
170 capela 488 selectAudioDriverItem(sAudioDriver);
171 capela 452 if (!bNew)
172     AudioDeviceComboBox->setCurrentText(audioDevice.deviceName());
173 capela 488 selectAudioDeviceItem(AudioDeviceComboBox->currentItem());
174 capela 452
175 capela 391 // As convenient, make it ready on stabilizeForm() for
176     // prompt acceptance, if we got the minimum required...
177 capela 395 if (sEngineName != qsamplerChannel::noEngineName() &&
178     sInstrumentFile != qsamplerChannel::noInstrumentName())
179     m_iDirtyCount++;
180 capela 104 // Done.
181     m_iDirtySetup--;
182     stabilizeForm();
183     }
184    
185    
186     // Accept settings (OK button slot).
187     void qsamplerChannelForm::accept (void)
188     {
189     if (m_pChannel == NULL)
190     return;
191    
192     qsamplerOptions *pOptions = m_pChannel->options();
193     if (pOptions == NULL)
194     return;
195    
196     // We'll go for it!
197     if (m_iDirtyCount > 0) {
198     int iErrors = 0;
199 capela 295 // Are we a new channel?
200     if (!m_pChannel->addChannel())
201     iErrors++;
202 capela 452 // Accept Audio driver or device selection...
203     if (m_audioDevices.isEmpty()) {
204     if (!m_pChannel->setAudioDriver(AudioDriverComboBox->currentText()))
205     iErrors++;
206     } else {
207     qsamplerDevice *pDevice = m_audioDevices.at(AudioDeviceComboBox->currentItem());
208     if (pDevice == NULL)
209     iErrors++;
210     else if (!m_pChannel->setAudioDevice(pDevice->deviceID()))
211     iErrors++;
212     }
213     // Accept MIDI driver or device selection...
214     if (m_midiDevices.isEmpty()) {
215     if (!m_pChannel->setMidiDriver(MidiDriverComboBox->currentText()))
216     iErrors++;
217     } else {
218     qsamplerDevice *pDevice = m_midiDevices.at(MidiDeviceComboBox->currentItem());
219     if (pDevice == NULL)
220     iErrors++;
221     else if (!m_pChannel->setMidiDevice(pDevice->deviceID()))
222     iErrors++;
223     }
224 capela 104 // MIDI input port number...
225     if (!m_pChannel->setMidiPort(MidiPortSpinBox->value()))
226 capela 161 iErrors++;
227 capela 104 // MIDI input channel...
228 capela 255 if (!m_pChannel->setMidiChannel(MidiChannelComboBox->currentItem()))
229 capela 104 iErrors++;
230 capela 115 // Engine name...
231     if (!m_pChannel->loadEngine(EngineNameComboBox->currentText()))
232 capela 104 iErrors++;
233     // Instrument file and index...
234 capela 299 if (!m_pChannel->loadInstrument(InstrumentFileComboBox->currentText(), InstrumentNrComboBox->currentItem()))
235 capela 104 iErrors++;
236     // Show error messages?
237     if (iErrors > 0)
238     m_pChannel->appendMessagesError(tr("Some channel settings could not be set.\n\nSorry."));
239     }
240    
241 capela 176 // Save default engine name, instrument directory and history...
242 capela 104 pOptions->sInstrumentDir = QFileInfo(InstrumentFileComboBox->currentText()).dirPath(true);
243 capela 176 pOptions->sEngineName = EngineNameComboBox->currentText();
244     pOptions->sAudioDriver = AudioDriverComboBox->currentText();
245     pOptions->sMidiDriver = MidiDriverComboBox->currentText();
246 capela 104 pOptions->saveComboBoxHistory(InstrumentFileComboBox);
247    
248     // Just go with dialog acceptance.
249     QDialog::accept();
250     }
251    
252    
253     // Reject settings (Cancel button slot).
254     void qsamplerChannelForm::reject (void)
255     {
256     bool bReject = true;
257    
258     // Check if there's any pending changes...
259 capela 176 if (m_iDirtyCount > 0 && OkPushButton->isEnabled()) {
260 capela 104 switch (QMessageBox::warning(this, tr("Warning"),
261     tr("Some channel settings have been changed.\n\n"
262     "Do you want to apply the changes?"),
263     tr("Apply"), tr("Discard"), tr("Cancel"))) {
264     case 0: // Apply...
265     accept();
266     return;
267     case 1: // Discard
268     break;
269     default: // Cancel.
270     bReject = false;
271     }
272     }
273    
274     if (bReject)
275     QDialog::reject();
276     }
277    
278    
279     // Browse and open an instrument file.
280     void qsamplerChannelForm::openInstrumentFile (void)
281     {
282     qsamplerOptions *pOptions = m_pChannel->options();
283     if (pOptions == NULL)
284     return;
285    
286     // FIXME: the instrument file filters should be restricted,
287     // depending on the current engine.
288     QString sInstrumentFile = QFileDialog::getOpenFileName(
289     pOptions->sInstrumentDir, // Start here.
290     tr("Instrument files") + " (*.gig *.dls)", // Filter (GIG and DLS files)
291     this, 0, // Parent and name (none)
292     tr("Instrument files") // Caption.
293     );
294    
295     if (sInstrumentFile.isEmpty())
296     return;
297    
298     InstrumentFileComboBox->setCurrentText(sInstrumentFile);
299     }
300    
301    
302     // Refresh the actual instrument name.
303     void qsamplerChannelForm::updateInstrumentName (void)
304     {
305 capela 341 qsamplerOptions *pOptions = m_pChannel->options();
306     if (pOptions == NULL)
307     return;
308    
309 capela 299 // Finally this better idea would be to use libgig
310     // to retrieve the REAL instrument names.
311     InstrumentNrComboBox->clear();
312     InstrumentNrComboBox->insertStringList(
313 capela 344 qsamplerChannel::getInstrumentList(
314     InstrumentFileComboBox->currentText(),
315     pOptions->bInstrumentNames)
316 capela 299 );
317 capela 104
318     optionsChanged();
319     }
320    
321 capela 487 // Show device options dialog.
322     void qsamplerChannelForm::setupDevice ( qsamplerDevice *pDevice )
323     {
324     if (pDevice == NULL)
325     return;
326 capela 104
327 capela 487 // Create the device form if not already...
328     if (m_pDeviceForm == NULL) {
329     m_pDeviceForm = new qsamplerDeviceForm(this, 0,
330     WType_Dialog | WShowModal);
331     m_pDeviceForm->setMainForm(m_pChannel->mainForm());
332 capela 488 QObject::connect(m_pDeviceForm, SIGNAL(devicesChanged()),
333     this, SLOT(updateDevices()));
334 capela 487 }
335    
336     // Refresh the device form with selected data.
337     if (m_pDeviceForm) {
338     m_pDeviceForm->setClient(m_pChannel->client()); // <-- refreshDevices().
339     m_pDeviceForm->setDevice(pDevice->deviceType(),
340     pDevice->deviceID());
341     m_pDeviceForm->show();
342     }
343     }
344    
345    
346 capela 488 // Refresh MIDI driver item devices.
347     void qsamplerChannelForm::selectMidiDriverItem ( const QString& sMidiDriver )
348 capela 452 {
349 capela 454 const QString sDriverName = sMidiDriver.upper();
350 capela 488
351     // Save current device id.
352     int iDeviceID = -1;
353     qsamplerDevice *pDevice = m_midiDevices.at(MidiDeviceComboBox->currentItem());
354     if (pDevice)
355     iDeviceID = pDevice->deviceID();
356    
357     // Clean maplist.
358 capela 452 MidiDeviceComboBox->clear();
359 capela 488 m_midiDevices.clear();
360 capela 104
361 capela 488 // Populate with the current ones...
362 capela 452 const QPixmap& midiPixmap = QPixmap::fromMimeSource("midi2.png");
363     int *piDeviceIDs = qsamplerDevice::getDevices(m_pChannel->client(),
364     qsamplerDevice::Midi);
365     for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
366 capela 488 pDevice = new qsamplerDevice(m_pChannel->mainForm(),
367 capela 452 qsamplerDevice::Midi, piDeviceIDs[i]);
368 capela 454 if (pDevice->driverName().upper() == sDriverName) {
369 capela 452 MidiDeviceComboBox->insertItem(midiPixmap, pDevice->deviceName());
370     m_midiDevices.append(pDevice);
371     } else {
372     delete pDevice;
373     }
374     }
375    
376 capela 488 // Do proper enabling...
377 capela 452 bool bEnabled = !m_midiDevices.isEmpty();
378 capela 454 if (!bEnabled)
379     MidiDeviceComboBox->insertItem(tr("(New MIDI device)"));
380 capela 488 else if (iDeviceID >= 0) {
381     // Select the previous current device...
382     int iMidiItem = 0;
383     for (pDevice = m_midiDevices.first();
384     pDevice;
385     pDevice = m_midiDevices.next()) {
386     if (pDevice->deviceID() == iDeviceID) {
387     MidiDeviceComboBox->setCurrentItem(iMidiItem);
388     // selectMidiDeviceItem(iMidiItem);
389     break;
390     }
391     iMidiItem++;
392     }
393     }
394 capela 452 MidiDeviceTextLabel->setEnabled(bEnabled);
395     MidiDeviceComboBox->setEnabled(bEnabled);
396 capela 488 }
397    
398    
399     // Refresh MIDI device options slot.
400     void qsamplerChannelForm::selectMidiDriver ( const QString& sMidiDriver )
401     {
402     if (m_iDirtySetup > 0)
403     return;
404    
405     selectMidiDriverItem(sMidiDriver);
406 capela 452 optionsChanged();
407     }
408    
409    
410 capela 488 // Select MIDI device item.
411     void qsamplerChannelForm::selectMidiDeviceItem ( int iMidiItem )
412 capela 455 {
413     qsamplerDevice *pDevice = m_midiDevices.at(iMidiItem);
414     if (pDevice) {
415 capela 462 const qsamplerDeviceParamMap& params = pDevice->params();
416 capela 455 int iPorts = params["PORTS"].value.toInt();
417     MidiPortTextLabel->setEnabled(iPorts > 0);
418     MidiPortSpinBox->setEnabled(iPorts > 0);
419     if (iPorts > 0)
420     MidiPortSpinBox->setMaxValue(iPorts - 1);
421     }
422 capela 488 }
423    
424    
425     // Select MIDI device options slot.
426     void qsamplerChannelForm::selectMidiDevice ( int iMidiItem )
427     {
428     if (m_iDirtySetup > 0)
429     return;
430    
431     selectMidiDeviceItem(iMidiItem);
432 capela 455 optionsChanged();
433     }
434    
435    
436 capela 487 // MIDI device options.
437     void qsamplerChannelForm::setupMidiDevice (void)
438     {
439     setupDevice(m_midiDevices.at(MidiDeviceComboBox->currentItem()));
440     }
441    
442    
443 capela 488 // Refresh Audio driver item devices.
444     void qsamplerChannelForm::selectAudioDriverItem ( const QString& sAudioDriver )
445 capela 452 {
446 capela 454 const QString sDriverName = sAudioDriver.upper();
447    
448 capela 488 // Save current device id.
449     int iDeviceID = -1;
450     qsamplerDevice *pDevice = m_audioDevices.at(AudioDeviceComboBox->currentItem());
451     if (pDevice)
452     iDeviceID = pDevice->deviceID();
453    
454     // Clean maplist.
455 capela 452 AudioDeviceComboBox->clear();
456     m_audioDevices.clear();
457    
458 capela 488 // Populate with the current ones...
459 capela 452 const QPixmap& audioPixmap = QPixmap::fromMimeSource("audio2.png");
460     int *piDeviceIDs = qsamplerDevice::getDevices(m_pChannel->client(),
461     qsamplerDevice::Audio);
462     for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
463 capela 488 pDevice = new qsamplerDevice(m_pChannel->mainForm(),
464 capela 452 qsamplerDevice::Audio, piDeviceIDs[i]);
465 capela 454 if (pDevice->driverName().upper() == sDriverName) {
466 capela 452 AudioDeviceComboBox->insertItem(audioPixmap, pDevice->deviceName());
467     m_audioDevices.append(pDevice);
468     } else {
469     delete pDevice;
470     }
471     }
472    
473 capela 488 // Do proper enabling...
474 capela 452 bool bEnabled = !m_audioDevices.isEmpty();
475 capela 454 if (!bEnabled)
476     AudioDeviceComboBox->insertItem(tr("(New Audio device)"));
477 capela 488 else if (iDeviceID >= 0) {
478     // Select the previous current device...
479     int iAudioItem = 0;
480     for (pDevice = m_audioDevices.first();
481     pDevice;
482     pDevice = m_audioDevices.next()) {
483     if (pDevice->deviceID() == iDeviceID) {
484     AudioDeviceComboBox->setCurrentItem(iAudioItem);
485     // selectAudioDeviceItem(iAudioItem);
486     break;
487     }
488     iAudioItem++;
489     }
490     }
491 capela 452 AudioDeviceTextLabel->setEnabled(bEnabled);
492     AudioDeviceComboBox->setEnabled(bEnabled);
493 capela 488 }
494    
495    
496     // Refresh Audio device options slot.
497     void qsamplerChannelForm::selectAudioDriver ( const QString& sAudioDriver )
498     {
499     if (m_iDirtySetup > 0)
500     return;
501    
502     selectAudioDriverItem(sAudioDriver);
503 capela 452 optionsChanged();
504     }
505    
506    
507 capela 488 // Select Audio device item.
508     void qsamplerChannelForm::selectAudioDeviceItem ( int iAudioItem )
509 capela 455 {
510     qsamplerDevice *pDevice = m_audioDevices.at(iAudioItem);
511     if (pDevice) {
512     // Is there anything to do here?
513     }
514 capela 488 }
515    
516    
517     // Select Audio device options slot.
518     void qsamplerChannelForm::selectAudioDevice ( int iAudioItem )
519     {
520     if (m_iDirtySetup > 0)
521     return;
522    
523     selectAudioDeviceItem(iAudioItem);
524 capela 455 optionsChanged();
525     }
526    
527    
528 capela 487 // Audio device options.
529     void qsamplerChannelForm::setupAudioDevice (void)
530     {
531     setupDevice(m_audioDevices.at(AudioDeviceComboBox->currentItem()));
532     }
533    
534    
535 capela 488 // UPdate all device lists slot.
536     void qsamplerChannelForm::updateDevices (void)
537     {
538     if (m_iDirtySetup > 0)
539     return;
540    
541     selectMidiDriverItem(MidiDriverComboBox->currentText());
542     selectAudioDriverItem(AudioDriverComboBox->currentText());
543     optionsChanged();
544     }
545    
546    
547 capela 104 // Dirty up settings.
548     void qsamplerChannelForm::optionsChanged (void)
549     {
550     if (m_iDirtySetup > 0)
551     return;
552    
553     m_iDirtyCount++;
554     stabilizeForm();
555     }
556    
557    
558     // Stabilize current form state.
559     void qsamplerChannelForm::stabilizeForm (void)
560     {
561 capela 145 const QString& sFilename = InstrumentFileComboBox->currentText();
562 capela 104 OkPushButton->setEnabled(m_iDirtyCount > 0 && !sFilename.isEmpty() && QFileInfo(sFilename).exists());
563     }
564    
565    
566     // end of qsamplerChannelForm.ui.h
567    

  ViewVC Help
Powered by ViewVC