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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 430 - (show annotations) (download) (as text)
Tue Mar 8 17:23:29 2005 UTC (19 years ago) by capela
File MIME type: text/x-c++hdr
File size: 9973 byte(s)
Still on-going with this new device configuration stuff.

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

  ViewVC Help
Powered by ViewVC