Exemplo n.º 1
0
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;
      }