fix loading soundfonts to synth
Fix mutex locking Fix progress bar drawing
This commit is contained in:
parent
9b2268fb46
commit
f50c7778ab
2 changed files with 13 additions and 6 deletions
|
@ -281,7 +281,7 @@ void FluidGui::loadSf()
|
||||||
_loadedSfPath = sfPath;
|
_loadedSfPath = sfPath;
|
||||||
QFuture<bool> future = QtConcurrent::run(fluid(), &FluidS::Fluid::addSoundFont, sfPath);
|
QFuture<bool> future = QtConcurrent::run(fluid(), &FluidS::Fluid::addSoundFont, sfPath);
|
||||||
_futureWatcher.setFuture(future);
|
_futureWatcher.setFuture(future);
|
||||||
_progressTimer->start(1);
|
_progressTimer->start(1000);
|
||||||
_progressDialog->exec();
|
_progressDialog->exec();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,9 +81,7 @@ bool SFont::read(const QString& s)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
synth->setLoadProgress(0);
|
synth->setLoadProgress(0);
|
||||||
int currentInstument = 0;
|
|
||||||
for (auto instrument : instruments) {
|
for (auto instrument : instruments) {
|
||||||
synth->setLoadProgress(currentInstument++ * 100 / instruments.count() / 2);
|
|
||||||
if (synth->loadWasCanceled())
|
if (synth->loadWasCanceled())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -92,7 +90,6 @@ bool SFont::read(const QString& s)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto preset : presets) {
|
for (auto preset : presets) {
|
||||||
synth->setLoadProgress(currentInstument++ * 100 / instruments.count() / 2);
|
|
||||||
if (synth->loadWasCanceled())
|
if (synth->loadWasCanceled())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -147,7 +144,7 @@ Preset::~Preset()
|
||||||
|
|
||||||
void Preset::loadSamples()
|
void Preset::loadSamples()
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&sfont->synth->mutex);
|
bool locked = sfont->synth->mutex.tryLock();
|
||||||
|
|
||||||
if (_global_zone && _global_zone->instrument) {
|
if (_global_zone && _global_zone->instrument) {
|
||||||
Instrument* i = _global_zone->instrument;
|
Instrument* i = _global_zone->instrument;
|
||||||
|
@ -158,18 +155,28 @@ void Preset::loadSamples()
|
||||||
iz->sample->load();
|
iz->sample->load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int currentInstrZone = 0;
|
||||||
|
float instrSize = (float)zones.size(); //float is used to properly calculate progress
|
||||||
for (Zone* z : zones) {
|
for (Zone* z : zones) {
|
||||||
|
sfont->synth->setLoadProgress(currentInstrZone++ / instrSize * 100);
|
||||||
Instrument* i = z->instrument;
|
Instrument* i = z->instrument;
|
||||||
if (i->global_zone && i->global_zone->sample)
|
if (i->global_zone && i->global_zone->sample)
|
||||||
i->global_zone->sample->load();
|
i->global_zone->sample->load();
|
||||||
|
|
||||||
|
int instrZonesSize = i->zones.size();
|
||||||
for (Zone* iz : i->zones) {
|
for (Zone* iz : i->zones) {
|
||||||
if (sfont->synth->globalTerminate())
|
if (sfont->synth->globalTerminate()) {
|
||||||
|
if (locked)
|
||||||
|
sfont->synth->mutex.unlock();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
iz->sample->load();
|
iz->sample->load();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (locked)
|
||||||
|
sfont->synth->mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------
|
//---------------------------------------------------------
|
||||||
|
|
Loading…
Reference in a new issue