/[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 264 - (show annotations) (download) (as text)
Wed Sep 29 13:12:45 2004 UTC (19 years, 6 months ago) by capela
File MIME type: text/x-c++hdr
File size: 9471 byte(s)
Initial rewrite of sampler channel strips internal control structures.

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

  ViewVC Help
Powered by ViewVC