/[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 463 - (hide annotations) (download) (as text)
Tue Mar 15 15:32:29 2005 UTC (19 years ago) by capela
File MIME type: text/x-c++hdr
File size: 13529 byte(s)
* Device port/channel configuration is now complete (EXPERIMENTAL).

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     #include "config.h"
30    
31    
32     // Kind of constructor.
33     void qsamplerChannelForm::init (void)
34     {
35     // Initialize locals.
36     m_pChannel = NULL;
37    
38     m_iDirtySetup = 0;
39     m_iDirtyCount = 0;
40    
41 capela 452 m_midiDevices.setAutoDelete(true);
42     m_audioDevices.setAutoDelete(true);
43    
44 capela 104 // Try to restore normal window positioning.
45     adjustSize();
46     }
47    
48    
49     // Kind of destructor.
50     void qsamplerChannelForm::destroy (void)
51     {
52     }
53    
54    
55     // Channel dialog setup formal initializer.
56 capela 295 void qsamplerChannelForm::setup ( qsamplerChannel *pChannel )
57 capela 104 {
58     m_pChannel = pChannel;
59    
60     m_iDirtySetup = 0;
61     m_iDirtyCount = 0;
62    
63     if (m_pChannel == NULL)
64     return;
65    
66 capela 295 // It can be a brand new channel, remember?
67     bool bNew = (m_pChannel->channelID() < 0);
68     setCaption(m_pChannel->channelName());
69 capela 104
70     // Check if we're up and connected.
71     if (m_pChannel->client() == NULL)
72     return;
73    
74     qsamplerOptions *pOptions = m_pChannel->options();
75     if (pOptions == NULL)
76     return;
77    
78     // Avoid nested changes.
79     m_iDirtySetup++;
80    
81     // Load combo box history...
82     pOptions->loadComboBoxHistory(InstrumentFileComboBox);
83    
84     // Populate Engines list.
85     const char **ppszEngines = ::lscp_get_available_engines(m_pChannel->client());
86     if (ppszEngines) {
87     EngineNameComboBox->clear();
88     for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)
89     EngineNameComboBox->insertItem(ppszEngines[iEngine]);
90     }
91     else m_pChannel->appendMessagesClient("lscp_get_available_engines");
92 capela 145
93 capela 104 // Populate Audio output type list.
94 capela 430 AudioDriverComboBox->clear();
95     AudioDriverComboBox->insertStringList(
96     qsamplerDevice::getDrivers(m_pChannel->client(), qsamplerDevice::Audio));
97 capela 104
98     // Populate MIDI input type list.
99 capela 430 MidiDriverComboBox->clear();
100     MidiDriverComboBox->insertStringList(
101     qsamplerDevice::getDrivers(m_pChannel->client(), qsamplerDevice::Midi));
102 capela 145
103 capela 104 // Read proper channel information,
104     // and populate the channel form fields.
105    
106     // Engine name...
107 capela 145 QString sEngineName = pChannel->engineName();
108 capela 400 if (sEngineName.isEmpty() || bNew)
109 capela 176 sEngineName = pOptions->sEngineName;
110 capela 145 if (sEngineName.isEmpty())
111 capela 388 sEngineName = qsamplerChannel::noEngineName();
112 capela 145 if (EngineNameComboBox->listBox()->findItem(sEngineName, Qt::ExactMatch) == NULL)
113     EngineNameComboBox->insertItem(sEngineName);
114     EngineNameComboBox->setCurrentText(sEngineName);
115 capela 104 // Instrument filename and index...
116 capela 145 QString sInstrumentFile = pChannel->instrumentFile();
117     if (sInstrumentFile.isEmpty())
118 capela 388 sInstrumentFile = qsamplerChannel::noInstrumentName();
119 capela 145 InstrumentFileComboBox->setCurrentText(sInstrumentFile);
120 capela 299 InstrumentNrComboBox->clear();
121 capela 344 InstrumentNrComboBox->insertStringList(
122     qsamplerChannel::getInstrumentList(sInstrumentFile,
123     pOptions->bInstrumentNames));
124 capela 299 InstrumentNrComboBox->setCurrentItem(pChannel->instrumentNr());
125 capela 452
126     // MIDI input device...
127     qsamplerDevice midiDevice(m_pChannel->client(),
128     qsamplerDevice::Midi, m_pChannel->midiDevice());
129 capela 176 // MIDI input driver...
130 capela 452 QString sMidiDriver = midiDevice.driverName();
131     if (sMidiDriver.isEmpty() || bNew)
132     sMidiDriver = pOptions->sMidiDriver;
133     if (!sMidiDriver.isEmpty()) {
134     if (MidiDriverComboBox->listBox()->findItem(sMidiDriver, Qt::ExactMatch) == NULL)
135     MidiDriverComboBox->insertItem(sMidiDriver);
136     MidiDriverComboBox->setCurrentText(sMidiDriver);
137     }
138     selectMidiDriver(sMidiDriver);
139     if (!bNew)
140     MidiDeviceComboBox->setCurrentText(midiDevice.deviceName());
141 capela 455 selectMidiDevice(MidiDeviceComboBox->currentItem());
142 capela 176 // MIDI input port...
143 capela 104 MidiPortSpinBox->setValue(pChannel->midiPort());
144 capela 176 // MIDI input channel...
145     int iMidiChannel = pChannel->midiChannel();
146 capela 295 // When new, try to suggest a sensible MIDI channel...
147     if (iMidiChannel < 0)
148     iMidiChannel = (::lscp_get_channels(m_pChannel->client()) % 16);
149 capela 255 MidiChannelComboBox->setCurrentItem(iMidiChannel);
150 capela 455
151 capela 452 // Audio output device...
152     qsamplerDevice audioDevice(m_pChannel->client(),
153     qsamplerDevice::Audio, m_pChannel->audioDevice());
154     // Audio output driver...
155     QString sAudioDriver = audioDevice.driverName();
156     if (sAudioDriver.isEmpty() || bNew)
157     sAudioDriver = pOptions->sAudioDriver;
158     if (!sAudioDriver.isEmpty()) {
159     if (AudioDriverComboBox->listBox()->findItem(sAudioDriver, Qt::ExactMatch) == NULL)
160     AudioDriverComboBox->insertItem(sAudioDriver);
161     AudioDriverComboBox->setCurrentText(sAudioDriver);
162     }
163     selectAudioDriver(sAudioDriver);
164     if (!bNew)
165     AudioDeviceComboBox->setCurrentText(audioDevice.deviceName());
166 capela 455 selectAudioDevice(AudioDeviceComboBox->currentItem());
167 capela 452
168 capela 391 // As convenient, make it ready on stabilizeForm() for
169     // prompt acceptance, if we got the minimum required...
170 capela 395 if (sEngineName != qsamplerChannel::noEngineName() &&
171     sInstrumentFile != qsamplerChannel::noInstrumentName())
172     m_iDirtyCount++;
173 capela 104 // Done.
174     m_iDirtySetup--;
175     stabilizeForm();
176     }
177    
178    
179     // Accept settings (OK button slot).
180     void qsamplerChannelForm::accept (void)
181     {
182     if (m_pChannel == NULL)
183     return;
184    
185     qsamplerOptions *pOptions = m_pChannel->options();
186     if (pOptions == NULL)
187     return;
188    
189     // We'll go for it!
190     if (m_iDirtyCount > 0) {
191     int iErrors = 0;
192 capela 295 // Are we a new channel?
193     if (!m_pChannel->addChannel())
194     iErrors++;
195 capela 452 // Accept Audio driver or device selection...
196     if (m_audioDevices.isEmpty()) {
197     if (!m_pChannel->setAudioDriver(AudioDriverComboBox->currentText()))
198     iErrors++;
199     } else {
200     qsamplerDevice *pDevice = m_audioDevices.at(AudioDeviceComboBox->currentItem());
201     if (pDevice == NULL)
202     iErrors++;
203     else if (!m_pChannel->setAudioDevice(pDevice->deviceID()))
204     iErrors++;
205     }
206     // Accept MIDI driver or device selection...
207     if (m_midiDevices.isEmpty()) {
208     if (!m_pChannel->setMidiDriver(MidiDriverComboBox->currentText()))
209     iErrors++;
210     } else {
211     qsamplerDevice *pDevice = m_midiDevices.at(MidiDeviceComboBox->currentItem());
212     if (pDevice == NULL)
213     iErrors++;
214     else if (!m_pChannel->setMidiDevice(pDevice->deviceID()))
215     iErrors++;
216     }
217 capela 104 // MIDI input port number...
218     if (!m_pChannel->setMidiPort(MidiPortSpinBox->value()))
219 capela 161 iErrors++;
220 capela 104 // MIDI input channel...
221 capela 255 if (!m_pChannel->setMidiChannel(MidiChannelComboBox->currentItem()))
222 capela 104 iErrors++;
223 capela 115 // Engine name...
224     if (!m_pChannel->loadEngine(EngineNameComboBox->currentText()))
225 capela 104 iErrors++;
226     // Instrument file and index...
227 capela 299 if (!m_pChannel->loadInstrument(InstrumentFileComboBox->currentText(), InstrumentNrComboBox->currentItem()))
228 capela 104 iErrors++;
229     // Show error messages?
230     if (iErrors > 0)
231     m_pChannel->appendMessagesError(tr("Some channel settings could not be set.\n\nSorry."));
232     }
233    
234 capela 176 // Save default engine name, instrument directory and history...
235 capela 104 pOptions->sInstrumentDir = QFileInfo(InstrumentFileComboBox->currentText()).dirPath(true);
236 capela 176 pOptions->sEngineName = EngineNameComboBox->currentText();
237     pOptions->sAudioDriver = AudioDriverComboBox->currentText();
238     pOptions->sMidiDriver = MidiDriverComboBox->currentText();
239 capela 104 pOptions->saveComboBoxHistory(InstrumentFileComboBox);
240    
241     // Just go with dialog acceptance.
242     QDialog::accept();
243     }
244    
245    
246     // Reject settings (Cancel button slot).
247     void qsamplerChannelForm::reject (void)
248     {
249     bool bReject = true;
250    
251     // Check if there's any pending changes...
252 capela 176 if (m_iDirtyCount > 0 && OkPushButton->isEnabled()) {
253 capela 104 switch (QMessageBox::warning(this, tr("Warning"),
254     tr("Some channel settings have been changed.\n\n"
255     "Do you want to apply the changes?"),
256     tr("Apply"), tr("Discard"), tr("Cancel"))) {
257     case 0: // Apply...
258     accept();
259     return;
260     case 1: // Discard
261     break;
262     default: // Cancel.
263     bReject = false;
264     }
265     }
266    
267     if (bReject)
268     QDialog::reject();
269     }
270    
271    
272     // Browse and open an instrument file.
273     void qsamplerChannelForm::openInstrumentFile (void)
274     {
275     qsamplerOptions *pOptions = m_pChannel->options();
276     if (pOptions == NULL)
277     return;
278    
279     // FIXME: the instrument file filters should be restricted,
280     // depending on the current engine.
281     QString sInstrumentFile = QFileDialog::getOpenFileName(
282     pOptions->sInstrumentDir, // Start here.
283     tr("Instrument files") + " (*.gig *.dls)", // Filter (GIG and DLS files)
284     this, 0, // Parent and name (none)
285     tr("Instrument files") // Caption.
286     );
287    
288     if (sInstrumentFile.isEmpty())
289     return;
290    
291     InstrumentFileComboBox->setCurrentText(sInstrumentFile);
292     }
293    
294    
295     // Refresh the actual instrument name.
296     void qsamplerChannelForm::updateInstrumentName (void)
297     {
298 capela 341 qsamplerOptions *pOptions = m_pChannel->options();
299     if (pOptions == NULL)
300     return;
301    
302 capela 299 // Finally this better idea would be to use libgig
303     // to retrieve the REAL instrument names.
304     InstrumentNrComboBox->clear();
305     InstrumentNrComboBox->insertStringList(
306 capela 344 qsamplerChannel::getInstrumentList(
307     InstrumentFileComboBox->currentText(),
308     pOptions->bInstrumentNames)
309 capela 299 );
310 capela 104
311     optionsChanged();
312     }
313    
314    
315 capela 452 // Refresh MIDI device options.
316     void qsamplerChannelForm::selectMidiDriver ( const QString& sMidiDriver )
317     {
318 capela 454 const QString sDriverName = sMidiDriver.upper();
319    
320 capela 452 MidiDeviceComboBox->clear();
321     m_audioDevices.clear();
322 capela 104
323 capela 452 const QPixmap& midiPixmap = QPixmap::fromMimeSource("midi2.png");
324     int *piDeviceIDs = qsamplerDevice::getDevices(m_pChannel->client(),
325     qsamplerDevice::Midi);
326     for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
327     qsamplerDevice *pDevice = new qsamplerDevice(m_pChannel->client(),
328     qsamplerDevice::Midi, piDeviceIDs[i]);
329 capela 454 if (pDevice->driverName().upper() == sDriverName) {
330 capela 452 MidiDeviceComboBox->insertItem(midiPixmap, pDevice->deviceName());
331     m_midiDevices.append(pDevice);
332     } else {
333     delete pDevice;
334     }
335     }
336    
337     bool bEnabled = !m_midiDevices.isEmpty();
338 capela 454 if (!bEnabled)
339     MidiDeviceComboBox->insertItem(tr("(New MIDI device)"));
340 capela 452 MidiDeviceTextLabel->setEnabled(bEnabled);
341     MidiDeviceComboBox->setEnabled(bEnabled);
342     optionsChanged();
343     }
344    
345    
346 capela 455 // Select MIDI device options.
347     void qsamplerChannelForm::selectMidiDevice ( int iMidiItem )
348     {
349     qsamplerDevice *pDevice = m_midiDevices.at(iMidiItem);
350     if (pDevice) {
351 capela 462 const qsamplerDeviceParamMap& params = pDevice->params();
352 capela 455 int iPorts = params["PORTS"].value.toInt();
353     MidiPortTextLabel->setEnabled(iPorts > 0);
354     MidiPortSpinBox->setEnabled(iPorts > 0);
355     if (iPorts > 0)
356     MidiPortSpinBox->setMaxValue(iPorts - 1);
357     }
358     optionsChanged();
359     }
360    
361    
362 capela 452 // Refresh Audio device options.
363     void qsamplerChannelForm::selectAudioDriver ( const QString& sAudioDriver )
364     {
365 capela 454 const QString sDriverName = sAudioDriver.upper();
366    
367 capela 452 AudioDeviceComboBox->clear();
368     m_audioDevices.clear();
369    
370     const QPixmap& audioPixmap = QPixmap::fromMimeSource("audio2.png");
371     int *piDeviceIDs = qsamplerDevice::getDevices(m_pChannel->client(),
372     qsamplerDevice::Audio);
373     for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
374     qsamplerDevice *pDevice = new qsamplerDevice(m_pChannel->client(),
375     qsamplerDevice::Audio, piDeviceIDs[i]);
376 capela 454 if (pDevice->driverName().upper() == sDriverName) {
377 capela 452 AudioDeviceComboBox->insertItem(audioPixmap, pDevice->deviceName());
378     m_audioDevices.append(pDevice);
379     } else {
380     delete pDevice;
381     }
382     }
383    
384     bool bEnabled = !m_audioDevices.isEmpty();
385 capela 454 if (!bEnabled)
386     AudioDeviceComboBox->insertItem(tr("(New Audio device)"));
387 capela 452 AudioDeviceTextLabel->setEnabled(bEnabled);
388     AudioDeviceComboBox->setEnabled(bEnabled);
389     optionsChanged();
390     }
391    
392    
393 capela 455 // Select Audio device options.
394     void qsamplerChannelForm::selectAudioDevice ( int iAudioItem )
395     {
396     qsamplerDevice *pDevice = m_audioDevices.at(iAudioItem);
397     if (pDevice) {
398     // Is there anything to do here?
399     }
400     optionsChanged();
401     }
402    
403    
404 capela 104 // Dirty up settings.
405     void qsamplerChannelForm::optionsChanged (void)
406     {
407     if (m_iDirtySetup > 0)
408     return;
409    
410     m_iDirtyCount++;
411     stabilizeForm();
412     }
413    
414    
415     // Stabilize current form state.
416     void qsamplerChannelForm::stabilizeForm (void)
417     {
418 capela 145 const QString& sFilename = InstrumentFileComboBox->currentText();
419 capela 104 OkPushButton->setEnabled(m_iDirtyCount > 0 && !sFilename.isEmpty() && QFileInfo(sFilename).exists());
420     }
421    
422    
423     // end of qsamplerChannelForm.ui.h
424    

  ViewVC Help
Powered by ViewVC