/[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 454 - (hide annotations) (download) (as text)
Mon Mar 14 10:59:57 2005 UTC (19 years ago) by capela
File MIME type: text/x-c++hdr
File size: 12869 byte(s)
New keep child windows always on top option; device icon retouching;

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 176 // MIDI input port...
142 capela 104 MidiPortSpinBox->setValue(pChannel->midiPort());
143 capela 176 // MIDI input channel...
144     int iMidiChannel = pChannel->midiChannel();
145 capela 295 // When new, try to suggest a sensible MIDI channel...
146     if (iMidiChannel < 0)
147     iMidiChannel = (::lscp_get_channels(m_pChannel->client()) % 16);
148 capela 255 MidiChannelComboBox->setCurrentItem(iMidiChannel);
149 capela 452
150     // Audio output device...
151     qsamplerDevice audioDevice(m_pChannel->client(),
152     qsamplerDevice::Audio, m_pChannel->audioDevice());
153     // Audio output driver...
154     QString sAudioDriver = audioDevice.driverName();
155     if (sAudioDriver.isEmpty() || bNew)
156     sAudioDriver = pOptions->sAudioDriver;
157     if (!sAudioDriver.isEmpty()) {
158     if (AudioDriverComboBox->listBox()->findItem(sAudioDriver, Qt::ExactMatch) == NULL)
159     AudioDriverComboBox->insertItem(sAudioDriver);
160     AudioDriverComboBox->setCurrentText(sAudioDriver);
161     }
162     selectAudioDriver(sAudioDriver);
163     if (!bNew)
164     AudioDeviceComboBox->setCurrentText(audioDevice.deviceName());
165    
166 capela 391 // As convenient, make it ready on stabilizeForm() for
167     // prompt acceptance, if we got the minimum required...
168 capela 395 if (sEngineName != qsamplerChannel::noEngineName() &&
169     sInstrumentFile != qsamplerChannel::noInstrumentName())
170     m_iDirtyCount++;
171 capela 409 // FIXME: These are better leave diabled...
172     MidiPortTextLabel->setEnabled(false);
173     MidiPortSpinBox->setEnabled(false);
174 capela 104 // Done.
175     m_iDirtySetup--;
176     stabilizeForm();
177     }
178    
179    
180     // Accept settings (OK button slot).
181     void qsamplerChannelForm::accept (void)
182     {
183     if (m_pChannel == NULL)
184     return;
185    
186     qsamplerOptions *pOptions = m_pChannel->options();
187     if (pOptions == NULL)
188     return;
189    
190     // We'll go for it!
191     if (m_iDirtyCount > 0) {
192     int iErrors = 0;
193 capela 295 // Are we a new channel?
194     if (!m_pChannel->addChannel())
195     iErrors++;
196 capela 452 // Accept Audio driver or device selection...
197     if (m_audioDevices.isEmpty()) {
198     if (!m_pChannel->setAudioDriver(AudioDriverComboBox->currentText()))
199     iErrors++;
200     } else {
201     qsamplerDevice *pDevice = m_audioDevices.at(AudioDeviceComboBox->currentItem());
202     if (pDevice == NULL)
203     iErrors++;
204     else if (!m_pChannel->setAudioDevice(pDevice->deviceID()))
205     iErrors++;
206     }
207     // Accept MIDI driver or device selection...
208     if (m_midiDevices.isEmpty()) {
209     if (!m_pChannel->setMidiDriver(MidiDriverComboBox->currentText()))
210     iErrors++;
211     } else {
212     qsamplerDevice *pDevice = m_midiDevices.at(MidiDeviceComboBox->currentItem());
213     if (pDevice == NULL)
214     iErrors++;
215     else if (!m_pChannel->setMidiDevice(pDevice->deviceID()))
216     iErrors++;
217     }
218 capela 104 // MIDI input port number...
219     if (!m_pChannel->setMidiPort(MidiPortSpinBox->value()))
220 capela 161 iErrors++;
221 capela 104 // MIDI input channel...
222 capela 255 if (!m_pChannel->setMidiChannel(MidiChannelComboBox->currentItem()))
223 capela 104 iErrors++;
224 capela 115 // Engine name...
225     if (!m_pChannel->loadEngine(EngineNameComboBox->currentText()))
226 capela 104 iErrors++;
227     // Instrument file and index...
228 capela 299 if (!m_pChannel->loadInstrument(InstrumentFileComboBox->currentText(), InstrumentNrComboBox->currentItem()))
229 capela 104 iErrors++;
230     // Show error messages?
231     if (iErrors > 0)
232     m_pChannel->appendMessagesError(tr("Some channel settings could not be set.\n\nSorry."));
233     }
234    
235 capela 176 // Save default engine name, instrument directory and history...
236 capela 104 pOptions->sInstrumentDir = QFileInfo(InstrumentFileComboBox->currentText()).dirPath(true);
237 capela 176 pOptions->sEngineName = EngineNameComboBox->currentText();
238     pOptions->sAudioDriver = AudioDriverComboBox->currentText();
239     pOptions->sMidiDriver = MidiDriverComboBox->currentText();
240 capela 104 pOptions->saveComboBoxHistory(InstrumentFileComboBox);
241    
242     // Just go with dialog acceptance.
243     QDialog::accept();
244     }
245    
246    
247     // Reject settings (Cancel button slot).
248     void qsamplerChannelForm::reject (void)
249     {
250     bool bReject = true;
251    
252     // Check if there's any pending changes...
253 capela 176 if (m_iDirtyCount > 0 && OkPushButton->isEnabled()) {
254 capela 104 switch (QMessageBox::warning(this, tr("Warning"),
255     tr("Some channel settings have been changed.\n\n"
256     "Do you want to apply the changes?"),
257     tr("Apply"), tr("Discard"), tr("Cancel"))) {
258     case 0: // Apply...
259     accept();
260     return;
261     case 1: // Discard
262     break;
263     default: // Cancel.
264     bReject = false;
265     }
266     }
267    
268     if (bReject)
269     QDialog::reject();
270     }
271    
272    
273     // Browse and open an instrument file.
274     void qsamplerChannelForm::openInstrumentFile (void)
275     {
276     qsamplerOptions *pOptions = m_pChannel->options();
277     if (pOptions == NULL)
278     return;
279    
280     // FIXME: the instrument file filters should be restricted,
281     // depending on the current engine.
282     QString sInstrumentFile = QFileDialog::getOpenFileName(
283     pOptions->sInstrumentDir, // Start here.
284     tr("Instrument files") + " (*.gig *.dls)", // Filter (GIG and DLS files)
285     this, 0, // Parent and name (none)
286     tr("Instrument files") // Caption.
287     );
288    
289     if (sInstrumentFile.isEmpty())
290     return;
291    
292     InstrumentFileComboBox->setCurrentText(sInstrumentFile);
293     }
294    
295    
296     // Refresh the actual instrument name.
297     void qsamplerChannelForm::updateInstrumentName (void)
298     {
299 capela 341 qsamplerOptions *pOptions = m_pChannel->options();
300     if (pOptions == NULL)
301     return;
302    
303 capela 299 // Finally this better idea would be to use libgig
304     // to retrieve the REAL instrument names.
305     InstrumentNrComboBox->clear();
306     InstrumentNrComboBox->insertStringList(
307 capela 344 qsamplerChannel::getInstrumentList(
308     InstrumentFileComboBox->currentText(),
309     pOptions->bInstrumentNames)
310 capela 299 );
311 capela 104
312     optionsChanged();
313     }
314    
315    
316 capela 452 // Refresh MIDI device options.
317     void qsamplerChannelForm::selectMidiDriver ( const QString& sMidiDriver )
318     {
319 capela 454 const QString sDriverName = sMidiDriver.upper();
320    
321 capela 452 MidiDeviceComboBox->clear();
322     m_audioDevices.clear();
323 capela 104
324 capela 452 const QPixmap& midiPixmap = QPixmap::fromMimeSource("midi2.png");
325     int *piDeviceIDs = qsamplerDevice::getDevices(m_pChannel->client(),
326     qsamplerDevice::Midi);
327     for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
328     qsamplerDevice *pDevice = new qsamplerDevice(m_pChannel->client(),
329     qsamplerDevice::Midi, piDeviceIDs[i]);
330 capela 454 if (pDevice->driverName().upper() == sDriverName) {
331 capela 452 MidiDeviceComboBox->insertItem(midiPixmap, pDevice->deviceName());
332     m_midiDevices.append(pDevice);
333     } else {
334     delete pDevice;
335     }
336     }
337    
338     bool bEnabled = !m_midiDevices.isEmpty();
339 capela 454 if (!bEnabled)
340     MidiDeviceComboBox->insertItem(tr("(New MIDI device)"));
341 capela 452 MidiDeviceTextLabel->setEnabled(bEnabled);
342     MidiDeviceComboBox->setEnabled(bEnabled);
343     optionsChanged();
344     }
345    
346    
347     // Refresh Audio device options.
348     void qsamplerChannelForm::selectAudioDriver ( const QString& sAudioDriver )
349     {
350 capela 454 const QString sDriverName = sAudioDriver.upper();
351    
352 capela 452 AudioDeviceComboBox->clear();
353     m_audioDevices.clear();
354    
355     const QPixmap& audioPixmap = QPixmap::fromMimeSource("audio2.png");
356     int *piDeviceIDs = qsamplerDevice::getDevices(m_pChannel->client(),
357     qsamplerDevice::Audio);
358     for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
359     qsamplerDevice *pDevice = new qsamplerDevice(m_pChannel->client(),
360     qsamplerDevice::Audio, piDeviceIDs[i]);
361 capela 454 if (pDevice->driverName().upper() == sDriverName) {
362 capela 452 AudioDeviceComboBox->insertItem(audioPixmap, pDevice->deviceName());
363     m_audioDevices.append(pDevice);
364     } else {
365     delete pDevice;
366     }
367     }
368    
369     bool bEnabled = !m_audioDevices.isEmpty();
370 capela 454 if (!bEnabled)
371     AudioDeviceComboBox->insertItem(tr("(New Audio device)"));
372 capela 452 AudioDeviceTextLabel->setEnabled(bEnabled);
373     AudioDeviceComboBox->setEnabled(bEnabled);
374     optionsChanged();
375     }
376    
377    
378 capela 104 // Dirty up settings.
379     void qsamplerChannelForm::optionsChanged (void)
380     {
381     if (m_iDirtySetup > 0)
382     return;
383    
384     m_iDirtyCount++;
385     stabilizeForm();
386     }
387    
388    
389     // Stabilize current form state.
390     void qsamplerChannelForm::stabilizeForm (void)
391     {
392 capela 145 const QString& sFilename = InstrumentFileComboBox->currentText();
393 capela 104 OkPushButton->setEnabled(m_iDirtyCount > 0 && !sFilename.isEmpty() && QFileInfo(sFilename).exists());
394     }
395    
396    
397     // end of qsamplerChannelForm.ui.h
398    

  ViewVC Help
Powered by ViewVC