/[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 409 - (show annotations) (download) (as text)
Thu Feb 24 12:10:54 2005 UTC (19 years, 1 month ago) by capela
File MIME type: text/x-c++hdr
File size: 10439 byte(s)
* Channels are now properly renumbered when saving to a
  session LSCP script, assuming that it should be always
  loaded from scratch (i.e. zero channels).

* Disabled MIDI port setting on channel dialog, and on
  session file save, as its use is still troublesome.

* Descrimination as for drag-and-drop of instrument files
  has been refined and fixed again.

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

  ViewVC Help
Powered by ViewVC