/[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 149 - (show annotations) (download) (as text)
Sat Jun 26 14:27:25 2004 UTC (15 years, 3 months ago) by capela
File MIME type: text/x-c++hdr
File size: 8916 byte(s)
* Prepared for client event protocol interface,
  via thread-safe QCustomEvent callback posting,
  on attempt to comply with draft-protocol v.11.

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 // Done.
142 m_iDirtySetup--;
143 stabilizeForm();
144 }
145
146
147 // Accept settings (OK button slot).
148 void qsamplerChannelForm::accept (void)
149 {
150 if (m_pChannel == NULL)
151 return;
152
153 qsamplerOptions *pOptions = m_pChannel->options();
154 if (pOptions == NULL)
155 return;
156
157 // We'll go for it!
158 if (m_iDirtyCount > 0) {
159 int iErrors = 0;
160 // Audio output driver type...
161 if (!m_pChannel->setAudioDriver(AudioDriverComboBox->currentText()))
162 iErrors++;
163 // MIDI input driver type...
164 if (!m_pChannel->setMidiDriver(MidiDriverComboBox->currentText()))
165 iErrors++;
166 // MIDI input port number...
167 // FIXME: Should increment error count, when properly implemented.
168 if (!m_pChannel->setMidiPort(MidiPortSpinBox->value()))
169 /* iErrors++ */;
170 // MIDI input channel...
171 if (!m_pChannel->setMidiChannel(MidiChannelSpinBox->value()))
172 iErrors++;
173 // Engine name...
174 if (!m_pChannel->loadEngine(EngineNameComboBox->currentText()))
175 iErrors++;
176 // Instrument file and index...
177 if (!m_pChannel->loadInstrument(InstrumentFileComboBox->currentText(), InstrumentNrSpinBox->value()))
178 iErrors++;
179 // Show error messages?
180 if (iErrors > 0)
181 m_pChannel->appendMessagesError(tr("Some channel settings could not be set.\n\nSorry."));
182 }
183
184 // Save default instrument directory and history...
185 pOptions->sInstrumentDir = QFileInfo(InstrumentFileComboBox->currentText()).dirPath(true);
186 pOptions->saveComboBoxHistory(InstrumentFileComboBox);
187
188 // Just go with dialog acceptance.
189 QDialog::accept();
190 }
191
192
193 // Reject settings (Cancel button slot).
194 void qsamplerChannelForm::reject (void)
195 {
196 bool bReject = true;
197
198 // Check if there's any pending changes...
199 if (m_iDirtyCount > 0) {
200 switch (QMessageBox::warning(this, tr("Warning"),
201 tr("Some channel settings have been changed.\n\n"
202 "Do you want to apply the changes?"),
203 tr("Apply"), tr("Discard"), tr("Cancel"))) {
204 case 0: // Apply...
205 accept();
206 return;
207 case 1: // Discard
208 break;
209 default: // Cancel.
210 bReject = false;
211 }
212 }
213
214 if (bReject)
215 QDialog::reject();
216 }
217
218
219 // Browse and open an instrument file.
220 void qsamplerChannelForm::openInstrumentFile (void)
221 {
222 qsamplerOptions *pOptions = m_pChannel->options();
223 if (pOptions == NULL)
224 return;
225
226 // FIXME: the instrument file filters should be restricted,
227 // depending on the current engine.
228 QString sInstrumentFile = QFileDialog::getOpenFileName(
229 pOptions->sInstrumentDir, // Start here.
230 tr("Instrument files") + " (*.gig *.dls)", // Filter (GIG and DLS files)
231 this, 0, // Parent and name (none)
232 tr("Instrument files") // Caption.
233 );
234
235 if (sInstrumentFile.isEmpty())
236 return;
237
238 InstrumentFileComboBox->setCurrentText(sInstrumentFile);
239 }
240
241
242 // Refresh the actual instrument name.
243 void qsamplerChannelForm::updateInstrumentName (void)
244 {
245 // FIXME: A better idea would be to use libgig
246 // to retrieve the REAL instrument name.
247 InstrumentNameTextLabel->setText(QFileInfo(InstrumentFileComboBox->currentText()).fileName()
248 + " [" + QString::number(InstrumentNrSpinBox->value()) + "]");
249
250 optionsChanged();
251 }
252
253
254
255 // Dirty up settings.
256 void qsamplerChannelForm::optionsChanged (void)
257 {
258 if (m_iDirtySetup > 0)
259 return;
260
261 m_iDirtyCount++;
262 stabilizeForm();
263 }
264
265
266 // Stabilize current form state.
267 void qsamplerChannelForm::stabilizeForm (void)
268 {
269 const QString& sFilename = InstrumentFileComboBox->currentText();
270 OkPushButton->setEnabled(m_iDirtyCount > 0 && !sFilename.isEmpty() && QFileInfo(sFilename).exists());
271 }
272
273
274 // end of qsamplerChannelForm.ui.h
275

  ViewVC Help
Powered by ViewVC