37 |
#include <math.h> |
#include <math.h> |
38 |
|
|
39 |
#ifndef CONFIG_ROUND |
#ifndef CONFIG_ROUND |
40 |
static long lroundf ( float fval ) |
static inline long lroundf ( float x ) |
41 |
{ |
{ |
42 |
double fint = 0.0; |
if (x >= 0.0f) |
43 |
float frac = float(::modf(fval, &fint)); |
return long(x + 0.5f); |
44 |
long lint = long(fint); |
else |
45 |
if (frac >= +0.5f) |
return long(x - 0.5f); |
|
lint++; |
|
|
else |
|
|
if (frac <= -0.5f) |
|
|
lint--; |
|
|
return lint; |
|
46 |
} |
} |
47 |
#endif |
#endif |
48 |
|
|
92 |
return; |
return; |
93 |
|
|
94 |
// It can be a brand new channel, remember? |
// It can be a brand new channel, remember? |
95 |
bool bNew = (m_pInstrument->bank() < 0 || m_pInstrument->program() < 0); |
bool bNew = (m_pInstrument->bank() < 0 || m_pInstrument->prog() < 0); |
96 |
if (!bNew) { |
if (!bNew) { |
97 |
m_pInstrument->get(); |
m_pInstrument->getInstrument(); |
98 |
m_iDirtyName++; |
m_iDirtyName++; |
99 |
} |
} |
100 |
|
|
104 |
// Load combo box history... |
// Load combo box history... |
105 |
pOptions->loadComboBoxHistory(InstrumentFileComboBox); |
pOptions->loadComboBoxHistory(InstrumentFileComboBox); |
106 |
|
|
107 |
|
// Populate maps list. |
108 |
|
MapComboBox->clear(); |
109 |
|
MapComboBox->insertStringList(qsamplerInstrument::getMapNames()); |
110 |
|
|
111 |
// Populate Engines list. |
// Populate Engines list. |
112 |
const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client()); |
const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client()); |
113 |
if (ppszEngines) { |
if (ppszEngines) { |
120 |
// Read proper instrument information, |
// Read proper instrument information, |
121 |
// and populate the instrument form fields. |
// and populate the instrument form fields. |
122 |
|
|
123 |
|
// Instrument map name... |
124 |
|
int iMap = (bNew ? pOptions->iMidiMap : m_pInstrument->map()); |
125 |
|
if (iMap < 0) |
126 |
|
iMap = 0; |
127 |
|
const QString& sMapName = qsamplerInstrument::getMapName(iMap); |
128 |
|
if (!sMapName.isEmpty()) |
129 |
|
MapComboBox->setCurrentText(sMapName); |
130 |
|
// It might be no maps around... |
131 |
|
bool bMapEnabled = (MapComboBox->count() > 0); |
132 |
|
MapTextLabel->setEnabled(bMapEnabled); |
133 |
|
MapComboBox->setEnabled(bNew && bMapEnabled); |
134 |
|
|
135 |
// Instrument bank/program... |
// Instrument bank/program... |
136 |
int iBank = m_pInstrument->bank(); |
int iBank = (bNew ? pOptions->iMidiBank : m_pInstrument->bank()); |
137 |
int iProgram = m_pInstrument->program() + 1; |
int iProg = (bNew ? pOptions->iMidiProg : m_pInstrument->prog()) + 1; |
138 |
|
if (bNew && iProg > 128) { |
139 |
|
iProg = 1; |
140 |
|
iBank++; |
141 |
|
} |
142 |
BankSpinBox->setValue(iBank); |
BankSpinBox->setValue(iBank); |
143 |
ProgramSpinBox->setValue(iProgram); |
ProgSpinBox->setValue(iProg); |
144 |
// Spacial hack to avoid changes on the key... |
// Spacial hack to avoid changes on the key... |
145 |
if (bNew) { |
if (bNew) { |
146 |
BankSpinBox->setRange(0, 16383); |
BankSpinBox->setRange(0, 16383); |
147 |
ProgramSpinBox->setRange(1, 128); |
ProgSpinBox->setRange(1, 128); |
148 |
} else { |
} else { |
149 |
BankSpinBox->setRange(iBank, iBank); |
BankSpinBox->setRange(iBank, iBank); |
150 |
ProgramSpinBox->setRange(iProgram, iProgram); |
ProgSpinBox->setRange(iProg, iProg); |
151 |
} |
} |
152 |
|
|
153 |
// Instrument name... |
// Instrument name... |
176 |
InstrumentNrComboBox->setCurrentItem(m_pInstrument->instrumentNr()); |
InstrumentNrComboBox->setCurrentItem(m_pInstrument->instrumentNr()); |
177 |
|
|
178 |
// Instrument volume.... |
// Instrument volume.... |
179 |
VolumeSpinBox->setValue(::lroundf(100.0f * m_pInstrument->volume())); |
int iVolume = (bNew ? pOptions->iVolume : |
180 |
|
::lroundf(100.0f * m_pInstrument->volume())); |
181 |
|
VolumeSpinBox->setValue(iVolume); |
182 |
|
|
183 |
// Instrument load mode... |
// Instrument load mode... |
184 |
LoadModeComboBox->setCurrentItem(m_pInstrument->loadMode()); |
int iLoadMode = (bNew ? pOptions->iLoadMode : |
185 |
|
m_pInstrument->loadMode()); |
186 |
|
LoadModeComboBox->setCurrentItem(iLoadMode); |
187 |
|
|
188 |
// Done. |
// Done. |
189 |
m_iDirtySetup--; |
m_iDirtySetup--; |
290 |
return; |
return; |
291 |
|
|
292 |
if (m_iDirtyCount > 0) { |
if (m_iDirtyCount > 0) { |
293 |
|
m_pInstrument->setMap(MapComboBox->currentItem()); |
294 |
|
m_pInstrument->setMap(MapComboBox->currentItem()); |
295 |
m_pInstrument->setBank(BankSpinBox->value()); |
m_pInstrument->setBank(BankSpinBox->value()); |
296 |
m_pInstrument->setProgram(ProgramSpinBox->value() - 1); |
m_pInstrument->setProg(ProgSpinBox->value() - 1); |
297 |
m_pInstrument->setName(NameLineEdit->text()); |
m_pInstrument->setName(NameLineEdit->text()); |
298 |
m_pInstrument->setEngineName(EngineNameComboBox->currentText()); |
m_pInstrument->setEngineName(EngineNameComboBox->currentText()); |
299 |
m_pInstrument->setInstrumentFile(InstrumentFileComboBox->currentText()); |
m_pInstrument->setInstrumentFile(InstrumentFileComboBox->currentText()); |
305 |
// Save default engine name, instrument directory and history... |
// Save default engine name, instrument directory and history... |
306 |
pOptions->sInstrumentDir = QFileInfo(InstrumentFileComboBox->currentText()).dirPath(true); |
pOptions->sInstrumentDir = QFileInfo(InstrumentFileComboBox->currentText()).dirPath(true); |
307 |
pOptions->sEngineName = EngineNameComboBox->currentText(); |
pOptions->sEngineName = EngineNameComboBox->currentText(); |
308 |
|
pOptions->iMidiMap = MapComboBox->currentItem(); |
309 |
|
pOptions->iMidiBank = BankSpinBox->value(); |
310 |
|
pOptions->iMidiProg = ProgSpinBox->value(); |
311 |
|
pOptions->iVolume = VolumeSpinBox->value(); |
312 |
|
pOptions->iLoadMode = LoadModeComboBox->currentItem(); |
313 |
pOptions->saveComboBoxHistory(InstrumentFileComboBox); |
pOptions->saveComboBoxHistory(InstrumentFileComboBox); |
314 |
|
|
315 |
// Just go with dialog acceptance. |
// Just go with dialog acceptance. |