1 |
capela |
426 |
// qsamplerDeviceForm.ui.h |
2 |
|
|
// |
3 |
|
|
// ui.h extension file, included from the uic-generated form implementation. |
4 |
|
|
/**************************************************************************** |
5 |
capela |
430 |
Copyright (C) 2005, rncbc aka Rui Nuno Capela. All rights reserved. |
6 |
capela |
426 |
|
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 <qmessagebox.h> |
24 |
capela |
428 |
#include <qfiledialog.h> |
25 |
|
|
#include <qfileinfo.h> |
26 |
capela |
430 |
#include <qlistbox.h> |
27 |
capela |
426 |
|
28 |
|
|
#include "qsamplerMainForm.h" |
29 |
|
|
|
30 |
|
|
#include "config.h" |
31 |
|
|
|
32 |
|
|
|
33 |
|
|
// Kind of constructor. |
34 |
|
|
void qsamplerDeviceForm::init (void) |
35 |
|
|
{ |
36 |
|
|
// Initialize locals. |
37 |
capela |
428 |
m_pMainForm = (qsamplerMainForm *) QWidget::parentWidget(); |
38 |
|
|
m_pClient = NULL; |
39 |
capela |
426 |
m_iDirtySetup = 0; |
40 |
|
|
m_iDirtyCount = 0; |
41 |
capela |
428 |
m_iUntitled = 1; |
42 |
capela |
430 |
m_bNewDevice = false; |
43 |
capela |
426 |
|
44 |
|
|
// Try to restore normal window positioning. |
45 |
|
|
adjustSize(); |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
|
49 |
|
|
// Kind of destructor. |
50 |
|
|
void qsamplerDeviceForm::destroy (void) |
51 |
|
|
{ |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
|
55 |
capela |
428 |
// Notify our parent that we're emerging. |
56 |
|
|
void qsamplerDeviceForm::showEvent ( QShowEvent *pShowEvent ) |
57 |
|
|
{ |
58 |
|
|
if (m_pMainForm) |
59 |
|
|
m_pMainForm->stabilizeForm(); |
60 |
|
|
|
61 |
|
|
stabilizeForm(); |
62 |
|
|
|
63 |
|
|
QWidget::showEvent(pShowEvent); |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
|
67 |
|
|
// Notify our parent that we're closing. |
68 |
|
|
void qsamplerDeviceForm::hideEvent ( QHideEvent *pHideEvent ) |
69 |
|
|
{ |
70 |
|
|
QWidget::hideEvent(pHideEvent); |
71 |
|
|
|
72 |
|
|
if (m_pMainForm) |
73 |
|
|
m_pMainForm->stabilizeForm(); |
74 |
|
|
} |
75 |
|
|
|
76 |
|
|
|
77 |
capela |
426 |
// Device configuration dialog setup formal initializer. |
78 |
capela |
428 |
void qsamplerDeviceForm::setClient ( lscp_client_t *pClient ) |
79 |
capela |
426 |
{ |
80 |
capela |
428 |
// If it has not changed, do nothing. |
81 |
|
|
if (m_pClient && m_pClient == pClient) |
82 |
|
|
return; |
83 |
capela |
426 |
|
84 |
capela |
428 |
// Set new reference. |
85 |
|
|
m_pClient = pClient; |
86 |
|
|
|
87 |
|
|
// OK. Do a whole refresh around. |
88 |
|
|
refreshDevices(); |
89 |
|
|
} |
90 |
|
|
|
91 |
|
|
|
92 |
|
|
// Format the displayable device configuration filename. |
93 |
|
|
QString qsamplerDeviceForm::devicesName ( const QString& sFilename ) |
94 |
|
|
{ |
95 |
|
|
QString sDevicesName = sFilename; |
96 |
capela |
426 |
qsamplerOptions *pOptions = m_pMainForm->options(); |
97 |
capela |
428 |
if (pOptions) { |
98 |
|
|
bool bCompletePath = (pOptions && pOptions->bCompletePath); |
99 |
|
|
if (sDevicesName.isEmpty()) |
100 |
|
|
sDevicesName = tr("Untitled") + QString::number(m_iUntitled); |
101 |
|
|
else if (!bCompletePath) |
102 |
|
|
sDevicesName = QFileInfo(sDevicesName).fileName(); |
103 |
|
|
} |
104 |
|
|
return sDevicesName; |
105 |
|
|
} |
106 |
capela |
426 |
|
107 |
|
|
|
108 |
capela |
428 |
// Window close event handlers. |
109 |
|
|
bool qsamplerDeviceForm::queryClose (void) |
110 |
|
|
{ |
111 |
|
|
bool bQueryClose = true; |
112 |
capela |
426 |
|
113 |
capela |
428 |
if (m_iDirtyCount > 0) { |
114 |
|
|
switch (QMessageBox::warning(this, tr("Warning"), |
115 |
|
|
tr("The device configuration has been changed.\n\n" |
116 |
|
|
"\"%1\"\n\n" |
117 |
|
|
"Do you want to save the changes?") |
118 |
|
|
.arg(devicesName(m_sFilename)), |
119 |
|
|
tr("Save"), tr("Discard"), tr("Cancel"))) { |
120 |
|
|
case 0: // Save... |
121 |
|
|
saveDevices(); |
122 |
|
|
// Fall thru.... |
123 |
|
|
case 1: // Discard |
124 |
|
|
break; |
125 |
|
|
default: // Cancel. |
126 |
|
|
bQueryClose = false; |
127 |
|
|
} |
128 |
|
|
} |
129 |
capela |
426 |
|
130 |
capela |
428 |
return bQueryClose; |
131 |
capela |
426 |
} |
132 |
|
|
|
133 |
|
|
|
134 |
capela |
428 |
|
135 |
capela |
426 |
// Dirty up settings. |
136 |
|
|
void qsamplerDeviceForm::contentsChanged (void) |
137 |
|
|
{ |
138 |
|
|
if (m_iDirtySetup > 0) |
139 |
|
|
return; |
140 |
|
|
|
141 |
|
|
m_iDirtyCount++; |
142 |
|
|
stabilizeForm(); |
143 |
|
|
} |
144 |
|
|
|
145 |
|
|
|
146 |
capela |
428 |
// Load device configuration slot. |
147 |
|
|
void qsamplerDeviceForm::loadDevices (void) |
148 |
|
|
{ |
149 |
|
|
QString sFilename = QFileDialog::getOpenFileName( |
150 |
|
|
m_sFilename, // Start here. |
151 |
|
|
tr("Device Configuration files") + " (*.lscp)", // Filter (XML files) |
152 |
|
|
this, 0, // Parent and name (none) |
153 |
|
|
tr("Load Device Configuration") // Caption. |
154 |
|
|
); |
155 |
|
|
|
156 |
|
|
if (sFilename.isEmpty()) |
157 |
|
|
return; |
158 |
|
|
|
159 |
|
|
// Check if we're going to discard safely the current one... |
160 |
|
|
if (!queryClose()) |
161 |
|
|
return; |
162 |
|
|
|
163 |
|
|
// Load it right away... |
164 |
|
|
loadDevicesFile(sFilename); |
165 |
|
|
} |
166 |
|
|
|
167 |
|
|
|
168 |
|
|
// Save device configuration slot. |
169 |
|
|
void qsamplerDeviceForm::saveDevices (void) |
170 |
|
|
{ |
171 |
|
|
QString sFilename = QFileDialog::getSaveFileName( |
172 |
|
|
m_sFilename, // Start here. |
173 |
|
|
tr("Device Configuration files") + " (*.lscp)", // Filter (XML files) |
174 |
|
|
this, 0, // Parent and name (none) |
175 |
|
|
tr("Save Device Configuration") // Caption. |
176 |
|
|
); |
177 |
|
|
|
178 |
|
|
if (sFilename.isEmpty()) |
179 |
|
|
return; |
180 |
|
|
|
181 |
|
|
// Enforce .xml extension... |
182 |
|
|
if (QFileInfo(sFilename).extension().isEmpty()) |
183 |
|
|
sFilename += ".lscp"; |
184 |
|
|
|
185 |
|
|
// Save it right away... |
186 |
|
|
saveDevicesFile(sFilename); |
187 |
|
|
} |
188 |
|
|
|
189 |
|
|
|
190 |
|
|
// Load device configuration from file. |
191 |
|
|
void qsamplerDeviceForm::loadDevicesFile ( const QString& sFilename ) |
192 |
|
|
{ |
193 |
|
|
// |
194 |
|
|
// TODO: Load device configuration from file... |
195 |
|
|
// |
196 |
|
|
m_pMainForm->appendMessages("qsamplerDeviceForm::loadDevicesFile(\"" + sFilename + "\")..."); |
197 |
|
|
|
198 |
|
|
m_sFilename = sFilename; |
199 |
|
|
m_iDirtyCount = 0; |
200 |
|
|
|
201 |
|
|
refreshDevices(); |
202 |
|
|
} |
203 |
|
|
|
204 |
|
|
|
205 |
|
|
// Save device configuration into file. |
206 |
|
|
void qsamplerDeviceForm::saveDevicesFile ( const QString& sFilename ) |
207 |
|
|
{ |
208 |
|
|
// |
209 |
|
|
// TODO: Save device configuration into file... |
210 |
|
|
// |
211 |
|
|
m_pMainForm->appendMessages("qsamplerDeviceForm::saveDevicesFile(\"" + sFilename + "\")..."); |
212 |
|
|
|
213 |
|
|
m_sFilename = sFilename; |
214 |
|
|
m_iDirtyCount = 0; |
215 |
|
|
stabilizeForm(); |
216 |
|
|
} |
217 |
|
|
|
218 |
|
|
|
219 |
|
|
// Create a new device from current table view. |
220 |
|
|
void qsamplerDeviceForm::createDevice (void) |
221 |
|
|
{ |
222 |
|
|
// |
223 |
|
|
// TODO: Create a new device from current table view... |
224 |
|
|
// |
225 |
|
|
m_pMainForm->appendMessages("qsamplerDeviceForm::createDevice()..."); |
226 |
capela |
430 |
|
227 |
|
|
m_iDirtyCount++; |
228 |
|
|
stabilizeForm(); |
229 |
capela |
428 |
} |
230 |
|
|
|
231 |
|
|
|
232 |
|
|
// Update current device in table view. |
233 |
|
|
void qsamplerDeviceForm::updateDevice (void) |
234 |
|
|
{ |
235 |
|
|
// |
236 |
|
|
// TODO: Update current device in table view... |
237 |
|
|
// |
238 |
|
|
m_pMainForm->appendMessages("qsamplerDeviceForm::updateDevice()..."); |
239 |
capela |
430 |
|
240 |
|
|
m_iDirtyCount++; |
241 |
|
|
stabilizeForm(); |
242 |
capela |
428 |
} |
243 |
|
|
|
244 |
|
|
|
245 |
|
|
// Delete current device in table view. |
246 |
|
|
void qsamplerDeviceForm::deleteDevice (void) |
247 |
|
|
{ |
248 |
|
|
// |
249 |
|
|
// TODO: Delete current device in table view... |
250 |
|
|
// |
251 |
|
|
m_pMainForm->appendMessages("qsamplerDeviceForm::deleteDevice()..."); |
252 |
capela |
430 |
|
253 |
|
|
m_iDirtyCount++; |
254 |
|
|
stabilizeForm(); |
255 |
capela |
428 |
} |
256 |
|
|
|
257 |
|
|
|
258 |
|
|
// Refresh all device list and views. |
259 |
|
|
void qsamplerDeviceForm::refreshDevices (void) |
260 |
|
|
{ |
261 |
|
|
// Avoid nested changes. |
262 |
|
|
m_iDirtySetup++; |
263 |
|
|
|
264 |
|
|
// |
265 |
|
|
// TODO: Load device configuration data ... |
266 |
|
|
// |
267 |
|
|
m_pMainForm->appendMessages("qsamplerDeviceForm::refreshDevices()"); |
268 |
|
|
|
269 |
capela |
429 |
DeviceListView->clear(); |
270 |
|
|
if (m_pClient) { |
271 |
|
|
qsamplerDeviceItem *pItem; |
272 |
|
|
int *piDeviceIDs; |
273 |
capela |
430 |
// Grab and pop Audio devices... |
274 |
capela |
429 |
pItem = new qsamplerDeviceItem(DeviceListView, m_pClient, |
275 |
|
|
qsamplerDevice::Audio); |
276 |
|
|
if (pItem) { |
277 |
|
|
pItem->setText(0, tr("Audio")); |
278 |
|
|
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio); |
279 |
|
|
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
280 |
|
|
new qsamplerDeviceItem(pItem, m_pClient, |
281 |
|
|
qsamplerDevice::Audio, piDeviceIDs[i]); |
282 |
|
|
} |
283 |
capela |
430 |
pItem->setOpen(true); |
284 |
capela |
428 |
} |
285 |
capela |
430 |
// Grab and pop MIDI devices... |
286 |
capela |
429 |
pItem = new qsamplerDeviceItem(DeviceListView, m_pClient, |
287 |
|
|
qsamplerDevice::Midi); |
288 |
|
|
if (pItem) { |
289 |
|
|
pItem->setText(0, tr("MIDI")); |
290 |
|
|
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi); |
291 |
|
|
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
292 |
|
|
new qsamplerDeviceItem(pItem, m_pClient, |
293 |
|
|
qsamplerDevice::Midi, piDeviceIDs[i]); |
294 |
|
|
} |
295 |
capela |
430 |
pItem->setOpen(true); |
296 |
capela |
429 |
} |
297 |
capela |
428 |
} |
298 |
|
|
|
299 |
|
|
// Done. |
300 |
capela |
430 |
selectDevice(); |
301 |
capela |
428 |
m_iDirtySetup--; |
302 |
|
|
} |
303 |
|
|
|
304 |
capela |
430 |
|
305 |
|
|
// Driver selection slot. |
306 |
|
|
void qsamplerDeviceForm::selectDriver ( const QString& sDriverName ) |
307 |
|
|
{ |
308 |
|
|
// |
309 |
|
|
// TODO: Driver name has changed for a new device... |
310 |
|
|
// |
311 |
|
|
m_pMainForm->appendMessages("qsamplerDeviceForm::selectDriver(\"" + sDriverName + "\")"); |
312 |
|
|
|
313 |
|
|
m_iDirtyCount++; |
314 |
|
|
stabilizeForm(); |
315 |
|
|
} |
316 |
|
|
|
317 |
|
|
|
318 |
capela |
429 |
// Device selection slot. |
319 |
capela |
430 |
void qsamplerDeviceForm::selectDevice (void) |
320 |
capela |
429 |
{ |
321 |
capela |
430 |
// |
322 |
|
|
// TODO: Device selection has changed... |
323 |
|
|
// |
324 |
|
|
m_pMainForm->appendMessages("qsamplerDeviceForm::selectDevice()"); |
325 |
capela |
428 |
|
326 |
capela |
430 |
QListViewItem *pItem = DeviceListView->selectedItem(); |
327 |
|
|
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) { |
328 |
|
|
stabilizeForm(); |
329 |
|
|
return; |
330 |
|
|
} |
331 |
capela |
429 |
|
332 |
|
|
const qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
333 |
capela |
430 |
m_bNewDevice = (device.deviceID() < 0); |
334 |
|
|
|
335 |
|
|
// Fill the device heading... |
336 |
|
|
DeviceNameTextLabel->setText(' ' + device.deviceName()); |
337 |
|
|
DriverNameComboBox->clear(); |
338 |
|
|
DriverNameComboBox->insertStringList( |
339 |
|
|
qsamplerDevice::getDrivers(m_pClient, device.deviceType())); |
340 |
|
|
const QString& sDriverName = device.driverName(); |
341 |
|
|
if (!sDriverName.isEmpty()) { |
342 |
|
|
if (DriverNameComboBox->listBox()->findItem(sDriverName, Qt::ExactMatch) == NULL) |
343 |
|
|
DriverNameComboBox->insertItem(sDriverName); |
344 |
|
|
DriverNameComboBox->setCurrentText(sDriverName); |
345 |
|
|
} |
346 |
|
|
DriverNameTextLabel->setEnabled(m_bNewDevice); |
347 |
|
|
DriverNameComboBox->setEnabled(m_bNewDevice); |
348 |
|
|
|
349 |
|
|
// Fill the device parameter table... |
350 |
|
|
DeviceParamTable->setEnabled(true); |
351 |
capela |
429 |
DeviceParamTable->setDevice(m_pClient, |
352 |
|
|
device.deviceType(), device.deviceID()); |
353 |
capela |
430 |
|
354 |
|
|
// Done. |
355 |
|
|
stabilizeForm(); |
356 |
capela |
429 |
} |
357 |
|
|
|
358 |
|
|
|
359 |
capela |
426 |
// Stabilize current form state. |
360 |
|
|
void qsamplerDeviceForm::stabilizeForm (void) |
361 |
|
|
{ |
362 |
capela |
428 |
// Update the main caption... |
363 |
|
|
QString sDevicesName = devicesName(m_sFilename); |
364 |
|
|
if (m_iDirtyCount > 0) |
365 |
|
|
sDevicesName += '*'; |
366 |
|
|
setCaption(tr("Devices - [%1]").arg(sDevicesName)); |
367 |
|
|
|
368 |
|
|
// |
369 |
capela |
426 |
// TODO: Enable/disable available command buttons. |
370 |
capela |
428 |
// |
371 |
|
|
m_pMainForm->appendMessages("qsamplerDeviceForm::stabilizeForm()"); |
372 |
|
|
|
373 |
|
|
SaveDevicesPushButton->setEnabled(m_iDirtyCount > 0); |
374 |
capela |
430 |
|
375 |
|
|
QListViewItem *pItem = DeviceListView->selectedItem(); |
376 |
|
|
bool bEnabled = (pItem != NULL); |
377 |
|
|
DeviceNameTextLabel->setEnabled(bEnabled); |
378 |
|
|
DriverNameTextLabel->setEnabled(bEnabled && m_bNewDevice); |
379 |
|
|
DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice); |
380 |
|
|
DeviceParamTable->setEnabled(bEnabled); |
381 |
|
|
CreateDevicePushButton->setEnabled(bEnabled && (m_iDirtyCount > 0 || m_bNewDevice)); |
382 |
|
|
UpdateDevicePushButton->setEnabled(bEnabled && (m_iDirtyCount > 0 && !m_bNewDevice)); |
383 |
|
|
DeleteDevicePushButton->setEnabled(bEnabled && (m_iDirtyCount > 0 && !m_bNewDevice)); |
384 |
capela |
426 |
} |
385 |
|
|
|
386 |
|
|
|
387 |
|
|
// end of qsamplerDeviceForm.ui.h |
388 |
|
|
|