1 |
// qsamplerInstrumentForm.cpp |
// qsamplerInstrumentForm.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2003-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2003-2010, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
Copyright (C) 2007, Christian Schoenebeck |
Copyright (C) 2007, Christian Schoenebeck |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
20 |
|
|
21 |
*****************************************************************************/ |
*****************************************************************************/ |
22 |
|
|
23 |
|
#include "qsamplerAbout.h" |
24 |
#include "qsamplerInstrumentForm.h" |
#include "qsamplerInstrumentForm.h" |
25 |
|
|
26 |
#include "qsamplerAbout.h" |
#include "qsamplerOptions.h" |
27 |
|
#include "qsamplerChannel.h" |
28 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
29 |
|
|
30 |
#include <QFileDialog> |
#include <QFileDialog> |
33 |
// Needed for lroundf() |
// Needed for lroundf() |
34 |
#include <math.h> |
#include <math.h> |
35 |
|
|
|
|
|
|
namespace QSampler { |
|
|
|
|
36 |
#ifndef CONFIG_ROUND |
#ifndef CONFIG_ROUND |
37 |
static inline long lroundf ( float x ) |
static inline long lroundf ( float x ) |
38 |
{ |
{ |
43 |
} |
} |
44 |
#endif |
#endif |
45 |
|
|
46 |
InstrumentForm::InstrumentForm ( QWidget* pParent ) |
|
47 |
|
namespace QSampler { |
48 |
|
|
49 |
|
//------------------------------------------------------------------------- |
50 |
|
// QSampler::InstrumentForm -- Instrument map item form implementation. |
51 |
|
// |
52 |
|
|
53 |
|
InstrumentForm::InstrumentForm ( QWidget *pParent ) |
54 |
: QDialog(pParent) |
: QDialog(pParent) |
55 |
{ |
{ |
56 |
m_ui.setupUi(this); |
m_ui.setupUi(this); |
111 |
|
|
112 |
|
|
113 |
// Channel dialog setup formal initializer. |
// Channel dialog setup formal initializer. |
114 |
void InstrumentForm::setup ( qsamplerInstrument *pInstrument ) |
void InstrumentForm::setup ( Instrument *pInstrument ) |
115 |
{ |
{ |
116 |
m_pInstrument = pInstrument; |
m_pInstrument = pInstrument; |
117 |
|
|
129 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
130 |
return; |
return; |
131 |
|
|
132 |
qsamplerOptions *pOptions = pMainForm->options(); |
Options *pOptions = pMainForm->options(); |
133 |
if (pOptions == NULL) |
if (pOptions == NULL) |
134 |
return; |
return; |
135 |
|
|
148 |
|
|
149 |
// Populate maps list. |
// Populate maps list. |
150 |
m_ui.MapComboBox->clear(); |
m_ui.MapComboBox->clear(); |
151 |
m_ui.MapComboBox->insertItems(0, qsamplerInstrument::getMapNames()); |
m_ui.MapComboBox->insertItems(0, Instrument::getMapNames()); |
152 |
|
|
153 |
// Populate Engines list. |
// Populate Engines list. |
154 |
const char **ppszEngines |
const char **ppszEngines |
167 |
int iMap = (bNew ? pOptions->iMidiMap : m_pInstrument->map()); |
int iMap = (bNew ? pOptions->iMidiMap : m_pInstrument->map()); |
168 |
if (iMap < 0) |
if (iMap < 0) |
169 |
iMap = 0; |
iMap = 0; |
170 |
const QString& sMapName = qsamplerInstrument::getMapName(iMap); |
const QString& sMapName = Instrument::getMapName(iMap); |
171 |
if (!sMapName.isEmpty()) { |
if (!sMapName.isEmpty()) { |
172 |
m_ui.MapComboBox->setItemText( |
m_ui.MapComboBox->setCurrentIndex( |
173 |
m_ui.MapComboBox->currentIndex(), |
m_ui.MapComboBox->findText(sMapName, |
174 |
sMapName); |
Qt::MatchExactly | Qt::MatchCaseSensitive)); |
175 |
} |
} |
176 |
|
|
177 |
// It might be no maps around... |
// It might be no maps around... |
178 |
bool bMapEnabled = (m_ui.MapComboBox->count() > 0); |
bool bMapEnabled = (m_ui.MapComboBox->count() > 0); |
179 |
m_ui.MapTextLabel->setEnabled(bMapEnabled); |
m_ui.MapTextLabel->setEnabled(bMapEnabled); |
197 |
if (sEngineName.isEmpty() || bNew) |
if (sEngineName.isEmpty() || bNew) |
198 |
sEngineName = pOptions->sEngineName; |
sEngineName = pOptions->sEngineName; |
199 |
if (sEngineName.isEmpty()) |
if (sEngineName.isEmpty()) |
200 |
sEngineName = qsamplerChannel::noEngineName(); |
sEngineName = Channel::noEngineName(); |
201 |
if (m_ui.EngineNameComboBox->findText(sEngineName, |
if (m_ui.EngineNameComboBox->findText(sEngineName, |
202 |
Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) { |
Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) { |
203 |
m_ui.EngineNameComboBox->addItem(sEngineName); |
m_ui.EngineNameComboBox->addItem(sEngineName); |
209 |
// Instrument filename and index... |
// Instrument filename and index... |
210 |
QString sInstrumentFile = m_pInstrument->instrumentFile(); |
QString sInstrumentFile = m_pInstrument->instrumentFile(); |
211 |
if (sInstrumentFile.isEmpty()) |
if (sInstrumentFile.isEmpty()) |
212 |
sInstrumentFile = qsamplerChannel::noInstrumentName(); |
sInstrumentFile = Channel::noInstrumentName(); |
213 |
m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile); |
m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile); |
214 |
m_ui.InstrumentNrComboBox->clear(); |
m_ui.InstrumentNrComboBox->clear(); |
215 |
m_ui.InstrumentNrComboBox->insertItems(0, |
m_ui.InstrumentNrComboBox->insertItems(0, |
216 |
qsamplerChannel::getInstrumentList(sInstrumentFile, |
Channel::getInstrumentList(sInstrumentFile, |
217 |
pOptions->bInstrumentNames)); |
pOptions->bInstrumentNames)); |
218 |
m_ui.InstrumentNrComboBox->setCurrentIndex(m_pInstrument->instrumentNr()); |
m_ui.InstrumentNrComboBox->setCurrentIndex(m_pInstrument->instrumentNr()); |
219 |
|
|
230 |
// Done. |
// Done. |
231 |
m_iDirtySetup--; |
m_iDirtySetup--; |
232 |
stabilizeForm(); |
stabilizeForm(); |
|
|
|
|
// Done. |
|
|
m_iDirtySetup--; |
|
|
stabilizeForm(); |
|
233 |
} |
} |
234 |
|
|
235 |
|
|
251 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
252 |
return; |
return; |
253 |
|
|
254 |
qsamplerOptions *pOptions = pMainForm->options(); |
Options *pOptions = pMainForm->options(); |
255 |
if (pOptions == NULL) |
if (pOptions == NULL) |
256 |
return; |
return; |
257 |
|
|
278 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
279 |
return; |
return; |
280 |
|
|
281 |
qsamplerOptions *pOptions = pMainForm->options(); |
Options *pOptions = pMainForm->options(); |
282 |
if (pOptions == NULL) |
if (pOptions == NULL) |
283 |
return; |
return; |
284 |
|
|
286 |
// to retrieve the REAL instrument names. |
// to retrieve the REAL instrument names. |
287 |
m_ui.InstrumentNrComboBox->clear(); |
m_ui.InstrumentNrComboBox->clear(); |
288 |
m_ui.InstrumentNrComboBox->insertItems(0, |
m_ui.InstrumentNrComboBox->insertItems(0, |
289 |
qsamplerChannel::getInstrumentList( |
Channel::getInstrumentList( |
290 |
m_ui.InstrumentFileComboBox->currentText(), |
m_ui.InstrumentFileComboBox->currentText(), |
291 |
pOptions->bInstrumentNames) |
pOptions->bInstrumentNames) |
292 |
); |
); |
322 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
323 |
return; |
return; |
324 |
|
|
325 |
qsamplerOptions *pOptions = pMainForm->options(); |
Options *pOptions = pMainForm->options(); |
326 |
if (pOptions == NULL) |
if (pOptions == NULL) |
327 |
return; |
return; |
328 |
|
|
365 |
QSAMPLER_TITLE ": " + tr("Warning"), |
QSAMPLER_TITLE ": " + tr("Warning"), |
366 |
tr("Some channel settings have been changed.\n\n" |
tr("Some channel settings have been changed.\n\n" |
367 |
"Do you want to apply the changes?"), |
"Do you want to apply the changes?"), |
368 |
tr("Apply"), tr("Discard"), tr("Cancel"))) { |
QMessageBox::Apply | |
369 |
case 0: // Apply... |
QMessageBox::Discard | |
370 |
|
QMessageBox::Cancel)) { |
371 |
|
case QMessageBox::Apply: |
372 |
accept(); |
accept(); |
373 |
return; |
return; |
374 |
case 1: // Discard |
case QMessageBox::Discard: |
375 |
break; |
break; |
376 |
default: // Cancel. |
default: // Cancel. |
377 |
bReject = false; |
bReject = false; |
398 |
// Stabilize current form state. |
// Stabilize current form state. |
399 |
void InstrumentForm::stabilizeForm (void) |
void InstrumentForm::stabilizeForm (void) |
400 |
{ |
{ |
401 |
bool bValid = |
bool bValid = !m_ui.NameLineEdit->text().isEmpty() |
402 |
!m_ui.NameLineEdit->text().isEmpty() && |
&& m_ui.EngineNameComboBox->currentIndex() >= 0 |
403 |
m_ui.EngineNameComboBox->currentIndex() >= 0 && |
&& m_ui.EngineNameComboBox->currentText() != Channel::noEngineName(); |
|
m_ui.EngineNameComboBox->currentText() != |
|
|
qsamplerChannel::noEngineName(); |
|
404 |
|
|
405 |
const QString& sPath = m_ui.InstrumentFileComboBox->currentText(); |
const QString& sPath = m_ui.InstrumentFileComboBox->currentText(); |
406 |
bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists(); |
bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists(); |