void Zerberus::trigger(Channel* channel, int key, int velo, Trigger trigger) { ZInstrument* i = channel->instrument(); for (Zone* z : i->zones()) { if (z->match(channel, key, velo, trigger)) { if (freeVoices.empty()) { qDebug("Zerberus: out of voices..."); return; } Voice* voice = freeVoices.pop(); if (!voice->isOff()) abort(); voice->start(channel, key, velo, z); if (trigger == Trigger::RELEASE) voice->stop(); // start voice in stop mode voice->setNext(activeVoices); activeVoices = voice; // // handle offBy voices // if (z->group) { for (Voice* v = activeVoices; v; v = v->next()) { if (v->offBy() == z->group) { if (v->offMode() == OffMode::FAST) v->stop(1); else v->stop(); } } } } } }
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; }