/[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 145 - (show annotations) (download) (as text)
Thu Jun 24 18:26:57 2004 UTC (17 years, 6 months ago) by capela
File MIME type: text/x-c++hdr
File size: 8979 byte(s)
* Mon-modal intrument file loading and status experimental support.

1 // 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 "qsamplerOptions.h"
30 #include "qsamplerChannelStrip.h"
31
32 #include "config.h"
33
34
35 // Kind of constructor.
36 void qsamplerChannelForm::init (void)
37 {
38 // Initialize locals.
39 m_pChannel = NULL;
40
41 m_iDirtySetup = 0;
42 m_iDirtyCount = 0;
43
44 // 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 void qsamplerChannelForm::setup ( qsamplerChannelStrip *pChannel )
57 {
58 m_pChannel = pChannel;
59
60 m_iDirtySetup = 0;
61 m_iDirtyCount = 0;
62
63 if (m_pChannel == NULL)
64 return;
65
66 setCaption(m_pChannel->caption());
67
68 // Check if we're up and connected.
69 if (m_pChannel->client() == NULL)
70 return;
71
72 qsamplerOptions *pOptions = m_pChannel->options();
73 if (pOptions == NULL)
74 return;
75
76 // Avoid nested changes.
77 m_iDirtySetup++;
78
79 // Load combo box history...
80 pOptions->loadComboBoxHistory(InstrumentFileComboBox);
81
82 // Populate Engines list.
83 const char **ppszEngines = ::lscp_get_available_engines(m_pChannel->client());
84 if (ppszEngines) {
85 EngineNameComboBox->clear();
86 for (int iEngine = 0; ppszEngines[iEngine]; iEngine++)
87 EngineNameComboBox->insertItem(ppszEngines[iEngine]);
88 }
89 else m_pChannel->appendMessagesClient("lscp_get_available_engines");
90
91 // Populate Audio output type list.
92 const char **ppszAudioDrivers = ::lscp_get_available_audio_drivers(m_pChannel->client());
93 if (ppszAudioDrivers) {
94 AudioDriverComboBox->clear();
95 for (int iAudioDriver = 0; ppszAudioDrivers[iAudioDriver]; iAudioDriver++)
96 AudioDriverComboBox->insertItem(ppszAudioDrivers[iAudioDriver]);
97 }
98 else m_pChannel->appendMessagesClient("lscp_get_available_audio_drivers");
99
100 // Populate MIDI input type list.
101 const char **ppszMidiDrivers = ::lscp_get_available_midi_drivers(m_pChannel->client());
102 if (ppszMidiDrivers) {
103 MidiDriverComboBox->clear();
104 for (int iMidiDriver = 0; ppszMidiDrivers[iMidiDriver]; iMidiDriver++)
105 MidiDriverComboBox->insertItem(ppszMidiDrivers[iMidiDriver]);
106 }
107 else m_pChannel->appendMessagesClient("lscp_get_available_midi_drivers");
108
109 // Read proper channel information,
110 // and populate the channel form fields.
111
112 // Engine name...
113 QString sEngineName = pChannel->engineName();
114 if (sEngineName.isEmpty())
115 sEngineName = tr("(No engine)");
116 if (EngineNameComboBox->listBox()->findItem(sEngineName, Qt::ExactMatch) == NULL)
117 EngineNameComboBox->insertItem(sEngineName);
118 EngineNameComboBox->setCurrentText(sEngineName);
119 // Instrument filename and index...
120 QString sInstrumentFile = pChannel->instrumentFile();
121 if (sInstrumentFile.isEmpty())
122 sInstrumentFile = tr("(No instrument)");
123 InstrumentFileComboBox->setCurrentText(sInstrumentFile);
124 InstrumentNrSpinBox->setValue(pChannel->instrumentNr());
125 // MIDI input...
126 const QString& sMidiDriver = pChannel->midiDriver();
127 if (!sMidiDriver.isEmpty()) {
128 if (MidiDriverComboBox->listBox()->findItem(sMidiDriver, Qt::ExactMatch) == NULL)
129 MidiDriverComboBox->insertItem(sMidiDriver);
130 MidiDriverComboBox->setCurrentText(sMidiDriver);
131 }
132 MidiPortSpinBox->setValue(pChannel->midiPort());
133 MidiChannelSpinBox->setValue(pChannel->midiChannel());
134 // Audio output...
135 const QString& sAudioDriver = pChannel->audioDriver();
136 if (!sAudioDriver.isEmpty()) {
137 if (AudioDriverComboBox->listBox()->findItem(sAudioDriver, Qt::ExactMatch) == NULL)
138 AudioDriverComboBox->insertItem(sAudioDriver);
139 AudioDriverComboBox->setCurrentText(sAudioDriver);
140 }
141 // FIXME: Disable this while we don't know what to do.
142 MidiPortTextLabel->setEnabled(false);
143 MidiPortSpinBox->setEnabled(false);
144 // Done.
145 m_iDirtySetup--;
146 stabilizeForm();
147 }
148
149
150 // Accept settings (OK button slot).
151 void qsamplerChannelForm::accept (void)
152 {
153 if (m_pChannel == NULL)
154 return;
155
156 qsamplerOptions *pOptions = m_pChannel->options();
157 if (pOptions == NULL)
158 return;
159
160 // We'll go for it!
161 if (m_iDirtyCount > 0) {
162 int iErrors = 0;
163 // Audio output driver type...
164 if (!m_pChannel->setAudioDriver(AudioDriverComboBox->currentText()))
165 iErrors++;
166 // MIDI input driver type...
167 if (!m_pChannel->setMidiDriver(MidiDriverComboBox->currentText()))
168 iErrors++;
169 // MIDI input port number...
170 if (!m_pChannel->setMidiPort(MidiPortSpinBox->value()))
171 iErrors++;
172 // MIDI input channel...
173 if (!m_pChannel->setMidiChannel(MidiChannelSpinBox->value()))
174 iErrors++;
175 // Engine name...
176 if (!m_pChannel->loadEngine(EngineNameComboBox->currentText()))
177 iErrors++;
178 // Instrument file and index...
179 if (!m_pChannel->loadInstrument(InstrumentFileComboBox->currentText(), InstrumentNrSpinBox->value()))
180 iErrors++;
181 // Show error messages?
182 if (iErrors > 0)
183 m_pChannel->appendMessagesError(tr("Some channel settings could not be set.\n\nSorry."));
184 }
185
186 // Save default instrument directory and history...
187 pOptions->sInstrumentDir = QFileInfo(InstrumentFileComboBox->currentText()).dirPath(true);
188 pOptions->saveComboBoxHistory(InstrumentFileComboBox);
189
190 // Just go with dialog acceptance.
191 QDialog::accept();
192 }
193
194
195 // Reject settings (Cancel button slot).
196 void qsamplerChannelForm::reject (void)
197 {
198 bool bReject = true;
199
200 // Check if there's any pending changes...
201 if (m_iDirtyCount > 0) {
202 switch (QMessageBox::warning(this, tr("Warning"),
203 tr("Some channel settings have been changed.\n\n"
204 "Do you want to apply the changes?"),
205 tr("Apply"), tr("Discard"), tr("Cancel"))) {
206 case 0: // Apply...
207 accept();
208 return;
209 case 1: // Discard
210 break;
211 default: // Cancel.
212 bReject = false;
213 }
214 }
215
216 if (bReject)
217 QDialog::reject();
218 }
219
220
221 // Browse and open an instrument file.
222 void qsamplerChannelForm::openInstrumentFile (void)
223 {
224 qsamplerOptions *pOptions = m_pChannel->options();
225 if (pOptions == NULL)
226 return;
227
228 // FIXME: the instrument file filters should be restricted,
229 // depending on the current engine.
230 QString sInstrumentFile = QFileDialog::getOpenFileName(
231 pOptions->sInstrumentDir, // Start here.
232 tr("Instrument files") + " (*.gig *.dls)", // Filter (GIG and DLS files)
233 this, 0, // Parent and name (none)
234 tr("Instrument files") // Caption.
235 );
236
237 if (sInstrumentFile.isEmpty())
238 return;
239
240 InstrumentFileComboBox->setCurrentText(sInstrumentFile);
241 }
242
243
244 // Refresh the actual instrument name.
245 void qsamplerChannelForm::updateInstrumentName (void)
246 {
247 // FIXME: A better idea would be to use libgig
248 // to retrieve the REAL instrument name.
249 InstrumentNameTextLabel->setText(QFileInfo(InstrumentFileComboBox->currentText()).fileName()
250 + " [" + QString::number(InstrumentNrSpinBox->value()) + "]");
251
252 optionsChanged();
253 }
254
255
256
257 // Dirty up settings.
258 void qsamplerChannelForm::optionsChanged (void)
259 {
260 if (m_iDirtySetup > 0)
261 return;
262
263 m_iDirtyCount++;
264 stabilizeForm();
265 }
266
267
268 // Stabilize current form state.
269 void qsamplerChannelForm::stabilizeForm (void)
270 {
271 const QString& sFilename = InstrumentFileComboBox->currentText();
272 OkPushButton->setEnabled(m_iDirtyCount > 0 && !sFilename.isEmpty() && QFileInfo(sFilename).exists());
273 }
274
275
276 // end of qsamplerChannelForm.ui.h
277

  ViewVC Help
Powered by ViewVC