bool Zerberus::loadInstrument(const QString& s) { printf("Zerberus::loadInstrument <%s>\n", qPrintable(s)); if (s.isEmpty()) return false; for (ZInstrument* instr : instruments) { if (instr->path() == s) // already loaded? return true; } QFileInfoList l = sfzFiles(); QString path; foreach (const QFileInfo& fi, l) { if (fi.fileName() == s) { path = fi.absoluteFilePath(); break; } } busy = true; ZInstrument* instr = new ZInstrument(this); if (instr->load(path)) { instruments.push_back(instr); if (instruments.size() == 1) { for (int i = 0; i < MAX_CHANNEL; ++i) _channel[i]->setInstrument(instr); } busy = false; return true; } qDebug("Zerberus::loadInstrument failed"); busy = false; delete instr; return false; }
bool Zerberus::loadInstrument(const QString& s) { if (s.isEmpty()) return false; for (ZInstrument* instr : instruments) { if (QFileInfo(instr->path()).fileName() == s) { // already loaded? return true; } } for (ZInstrument* instr : globalInstruments) { if (QFileInfo(instr->path()).fileName() == s) { instruments.push_back(instr); instr->setRefCount(instr->refCount() + 1); if (instruments.size() == 1) { for (int i = 0; i < MAX_CHANNEL; ++i) _channel[i]->setInstrument(instr); } busy = false; return true; } } QFileInfoList l = Zerberus::sfzFiles(); QString path; foreach (const QFileInfo& fi, l) { if (fi.fileName() == s) { path = fi.absoluteFilePath(); break; } } busy = true; ZInstrument* instr = new ZInstrument(this); try { if (instr->load(path)) { globalInstruments.push_back(instr); instruments.push_back(instr); instr->setRefCount(1); // // set default instrument for all channels: // if (instruments.size() == 1) { for (int i = 0; i < MAX_CHANNEL; ++i) _channel[i]->setInstrument(instr); } busy = false; return true; } } catch (...) { } qDebug("Zerberus::loadInstrument failed"); busy = false; delete instr; return false; }