/[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 299 - (hide annotations) (download) (as text)
Wed Nov 17 15:41:58 2004 UTC (19 years, 5 months ago) by capela
File MIME type: text/x-c++hdr
File size: 9868 byte(s)
* Instrument index selection now made via combo box widget;
  actual instrument names are now properly retrieved from
  the instrument file, provided if libgig is available.

1 capela 104 // qsamplerChannelForm.ui.h
2     //
3     // ui.h extension file, included from the uic-generated form implementation.
4     /****************************************************************************
5     Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved.
6    
7     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License
9     as published by the Free Software Foundation; either version 2
10     of the License, or (at your option) any later version.
11    
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20    
21     *****************************************************************************/
22    
23     #include <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     // Try to restore normal window positioning.
42     adjustSize();
43     }
44    
45    
46     // Kind of destructor.
47     void qsamplerChannelForm::destroy (void)
48     {
49     }
50    
51    
52     // Channel dialog setup formal initializer.
53 capela 295 void qsamplerChannelForm::setup ( qsamplerChannel *pChannel )
54 capela 104 {
55     m_pChannel = pChannel;
56    
57     m_iDirtySetup = 0;
58     m_iDirtyCount = 0;
59    
60     if (m_pChannel == NULL)
61     return;
62    
63 capela 295 // It can be a brand new channel, remember?
64     bool bNew = (m_pChannel->channelID() < 0);
65     setCaption(m_pChannel->channelName());
66 capela 104
67     // Check if we're up and connected.
68     if (m_pChannel->client() == NULL)
69     return;
70    
71     qsamplerOptions *pOptions = m_pChannel->options();
72     if (pOptions == NULL)
73     return;
74    
75     // Avoid nested changes.
76     m_iDirtySetup++;
77    
78     // Load combo box history...
79     pOptions->loadComboBoxHistory(InstrumentFileComboBox);
80    
81     // Populate Engines list.
82     const char **ppszEngines = ::lscp_get_available_engines(m_pChannel->client());
83     if (ppszEngines) {
84     EngineNameComboBox->clear();
85     for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)
86     EngineNameComboBox->insertItem(ppszEngines[iEngine]);
87     }
88     else m_pChannel->appendMessagesClient("lscp_get_available_engines");
89 capela 145
90 capela 104 // Populate Audio output type list.
91     const char **ppszAudioDrivers = ::lscp_get_available_audio_drivers(m_pChannel->client());
92     if (ppszAudioDrivers) {
93     AudioDriverComboBox->clear();
94     for (int iAudioDriver = 0; ppszAudioDrivers[iAudioDriver]; iAudioDriver++)
95     AudioDriverComboBox->insertItem(ppszAudioDrivers[iAudioDriver]);
96     }
97     else m_pChannel->appendMessagesClient("lscp_get_available_audio_drivers");
98    
99     // Populate MIDI input type list.
100     const char **ppszMidiDrivers = ::lscp_get_available_midi_drivers(m_pChannel->client());
101     if (ppszMidiDrivers) {
102     MidiDriverComboBox->clear();
103     for (int iMidiDriver = 0; ppszMidiDrivers[iMidiDriver]; iMidiDriver++)
104     MidiDriverComboBox->insertItem(ppszMidiDrivers[iMidiDriver]);
105     }
106     else m_pChannel->appendMessagesClient("lscp_get_available_midi_drivers");
107 capela 145
108 capela 104 // Read proper channel information,
109     // and populate the channel form fields.
110    
111     // Engine name...
112 capela 145 QString sEngineName = pChannel->engineName();
113 capela 176 if (sEngineName.isEmpty() && bNew)
114     sEngineName = pOptions->sEngineName;
115 capela 145 if (sEngineName.isEmpty())
116     sEngineName = tr("(No engine)");
117     if (EngineNameComboBox->listBox()->findItem(sEngineName, Qt::ExactMatch) == NULL)
118     EngineNameComboBox->insertItem(sEngineName);
119     EngineNameComboBox->setCurrentText(sEngineName);
120 capela 104 // Instrument filename and index...
121 capela 145 QString sInstrumentFile = pChannel->instrumentFile();
122     if (sInstrumentFile.isEmpty())
123     sInstrumentFile = tr("(No instrument)");
124     InstrumentFileComboBox->setCurrentText(sInstrumentFile);
125 capela 299 InstrumentNrComboBox->clear();
126     InstrumentNrComboBox->insertStringList(qsamplerChannel::getInstrumentList(sInstrumentFile));
127     InstrumentNrComboBox->setCurrentItem(pChannel->instrumentNr());
128 capela 176 // MIDI input driver...
129     QString sMidiDriver = pChannel->midiDriver();
130 capela 295 if (sMidiDriver.isEmpty() || bNew)
131 capela 176 sMidiDriver = pOptions->sMidiDriver;
132 capela 104 if (!sMidiDriver.isEmpty()) {
133     if (MidiDriverComboBox->listBox()->findItem(sMidiDriver, Qt::ExactMatch) == NULL)
134     MidiDriverComboBox->insertItem(sMidiDriver);
135     MidiDriverComboBox->setCurrentText(sMidiDriver);
136     }
137 capela 176 // MIDI input port...
138 capela 104 MidiPortSpinBox->setValue(pChannel->midiPort());
139 capela 176 // MIDI input channel...
140     int iMidiChannel = pChannel->midiChannel();
141 capela 295 // When new, try to suggest a sensible MIDI channel...
142     if (iMidiChannel < 0)
143     iMidiChannel = (::lscp_get_channels(m_pChannel->client()) % 16);
144 capela 255 MidiChannelComboBox->setCurrentItem(iMidiChannel);
145 capela 176 // Audio output driver...
146     QString sAudioDriver = pChannel->audioDriver();
147 capela 295 if (sAudioDriver.isEmpty() || bNew)
148 capela 176 sAudioDriver = pOptions->sAudioDriver;
149 capela 104 if (!sAudioDriver.isEmpty()) {
150     if (AudioDriverComboBox->listBox()->findItem(sAudioDriver, Qt::ExactMatch) == NULL)
151     AudioDriverComboBox->insertItem(sAudioDriver);
152     AudioDriverComboBox->setCurrentText(sAudioDriver);
153     }
154     // Done.
155     m_iDirtySetup--;
156     stabilizeForm();
157     }
158    
159    
160     // Accept settings (OK button slot).
161     void qsamplerChannelForm::accept (void)
162     {
163     if (m_pChannel == NULL)
164     return;
165    
166     qsamplerOptions *pOptions = m_pChannel->options();
167     if (pOptions == NULL)
168     return;
169    
170     // We'll go for it!
171     if (m_iDirtyCount > 0) {
172     int iErrors = 0;
173 capela 295 // Are we a new channel?
174     if (!m_pChannel->addChannel())
175     iErrors++;
176 capela 115 // Audio output driver type...
177     if (!m_pChannel->setAudioDriver(AudioDriverComboBox->currentText()))
178 capela 104 iErrors++;
179     // MIDI input driver type...
180     if (!m_pChannel->setMidiDriver(MidiDriverComboBox->currentText()))
181     iErrors++;
182     // MIDI input port number...
183     if (!m_pChannel->setMidiPort(MidiPortSpinBox->value()))
184 capela 161 iErrors++;
185 capela 104 // MIDI input channel...
186 capela 255 if (!m_pChannel->setMidiChannel(MidiChannelComboBox->currentItem()))
187 capela 104 iErrors++;
188 capela 115 // Engine name...
189     if (!m_pChannel->loadEngine(EngineNameComboBox->currentText()))
190 capela 104 iErrors++;
191     // Instrument file and index...
192 capela 299 if (!m_pChannel->loadInstrument(InstrumentFileComboBox->currentText(), InstrumentNrComboBox->currentItem()))
193 capela 104 iErrors++;
194     // Show error messages?
195     if (iErrors > 0)
196     m_pChannel->appendMessagesError(tr("Some channel settings could not be set.\n\nSorry."));
197     }
198    
199 capela 176 // Save default engine name, instrument directory and history...
200 capela 104 pOptions->sInstrumentDir = QFileInfo(InstrumentFileComboBox->currentText()).dirPath(true);
201 capela 176 pOptions->sEngineName = EngineNameComboBox->currentText();
202     pOptions->sAudioDriver = AudioDriverComboBox->currentText();
203     pOptions->sMidiDriver = MidiDriverComboBox->currentText();
204 capela 104 pOptions->saveComboBoxHistory(InstrumentFileComboBox);
205    
206     // Just go with dialog acceptance.
207     QDialog::accept();
208     }
209    
210    
211     // Reject settings (Cancel button slot).
212     void qsamplerChannelForm::reject (void)
213     {
214     bool bReject = true;
215    
216     // Check if there's any pending changes...
217 capela 176 if (m_iDirtyCount > 0 && OkPushButton->isEnabled()) {
218 capela 104 switch (QMessageBox::warning(this, tr("Warning"),
219     tr("Some channel settings have been changed.\n\n"
220     "Do you want to apply the changes?"),
221     tr("Apply"), tr("Discard"), tr("Cancel"))) {
222     case 0: // Apply...
223     accept();
224     return;
225     case 1: // Discard
226     break;
227     default: // Cancel.
228     bReject = false;
229     }
230     }
231    
232     if (bReject)
233     QDialog::reject();
234     }
235    
236    
237     // Browse and open an instrument file.
238     void qsamplerChannelForm::openInstrumentFile (void)
239     {
240     qsamplerOptions *pOptions = m_pChannel->options();
241     if (pOptions == NULL)
242     return;
243    
244     // FIXME: the instrument file filters should be restricted,
245     // depending on the current engine.
246     QString sInstrumentFile = QFileDialog::getOpenFileName(
247     pOptions->sInstrumentDir, // Start here.
248     tr("Instrument files") + " (*.gig *.dls)", // Filter (GIG and DLS files)
249     this, 0, // Parent and name (none)
250     tr("Instrument files") // Caption.
251     );
252    
253     if (sInstrumentFile.isEmpty())
254     return;
255    
256     InstrumentFileComboBox->setCurrentText(sInstrumentFile);
257     }
258    
259    
260     // Refresh the actual instrument name.
261     void qsamplerChannelForm::updateInstrumentName (void)
262     {
263 capela 299 // Finally this better idea would be to use libgig
264     // to retrieve the REAL instrument names.
265     InstrumentNrComboBox->clear();
266     InstrumentNrComboBox->insertStringList(
267     qsamplerChannel::getInstrumentList(InstrumentFileComboBox->currentText())
268     );
269 capela 104
270     optionsChanged();
271     }
272    
273    
274    
275     // Dirty up settings.
276     void qsamplerChannelForm::optionsChanged (void)
277     {
278     if (m_iDirtySetup > 0)
279     return;
280    
281     m_iDirtyCount++;
282     stabilizeForm();
283     }
284    
285    
286     // Stabilize current form state.
287     void qsamplerChannelForm::stabilizeForm (void)
288     {
289 capela 145 const QString& sFilename = InstrumentFileComboBox->currentText();
290 capela 104 OkPushButton->setEnabled(m_iDirtyCount > 0 && !sFilename.isEmpty() && QFileInfo(sFilename).exists());
291     }
292    
293    
294     // end of qsamplerChannelForm.ui.h
295    

  ViewVC Help
Powered by ViewVC