void AudioFormatsManager::addFormat(std::shared_ptr<AudioFormat> fmt_) {
  for (auto format: fmt_->getSupportedFormatsForReading()) {
    if (m_formatsForReading.find(format) != m_formatsForReading.end()) {
      std::cerr << "The format " << formatToStr(format) << " has already been added to the AudioFormatManager (reading)" << std::endl;
      continue;
    }
    m_formatsForReading.insert(std::make_pair(format, fmt_));
  }
  for (auto format: fmt_->getSupportedFormatsForWriting()) {
    if (m_formatsForWriting.find(format) != m_formatsForWriting.end()) {
      std::cerr << "The format " << formatToStr(format) << " has already been added to the AudioFormatManager (writing)" << std::endl;
      continue;
    }
    m_formatsForWriting.insert(std::make_pair(format, fmt_));
  }
}
bool AudioFormatsManager::writeFile(const std::string& path_,
    AudioBuffer& buffer_,
    const float samplingRate_,
    const AudioFormatTypes format_,
    const void* formatDetail_) {
  std::string extension = utils::getFileExtension(path_);
  auto formatForFile = m_formatsForWriting.find(format_);
  if (formatForFile == m_formatsForWriting.end()) {
    std::cerr << "No encoder for type " << formatToStr(format_) << std::endl;
    return false;
  }
  return formatForFile->second->writeFile(path_, buffer_, samplingRate_, format_);
}
Example #3
0
  bool save(std::string const& filename)
  {
    logInfo("Saving document: ", filename);

    std::ofstream file(filename.c_str());
    if (!file.is_open())
    {
      flashMessage("Could not save document!");
      return false;
    }


    // Collect and sort the cells, so they are saved in the same order
    std::vector<Index> allCells;
    allCells.reserve(currentDoc().cells_.size());

    for (auto it : currentDoc().cells_)
      allCells.push_back(it.first);

    std::stable_sort(allCells.begin(), allCells.end(), [](Index const& lhs, Index const& rhs) -> bool { return lhs.y < rhs.y; });
    std::stable_sort(allCells.begin(), allCells.end(), [](Index const& lhs, Index const& rhs) -> bool { return lhs.x < rhs.x; });

    // Collect and sort all columns so they are saved in the same order
    std::vector<int> allColumns;
    allColumns.reserve(currentDoc().columnWidth_.size());
    for (auto it : currentDoc().columnWidth_)
      allColumns.push_back(it.first);

    std::stable_sort(allColumns.begin(), allColumns.end());


    // Write file header
    file << "ZUM1" << std::endl;

    // Write column information section
    file << std::endl << "[columns]" << std::endl;
    for (auto col : allColumns)
      file << Index::columnToStr(col) << " = " << currentDoc().columnWidth_[col] << std::endl;
    
    // Write cell content
    file << std::endl << "[data]" << std::endl;
    for (auto idx: allCells)
    {
      const std::string text = getText(getCell(idx));

      if (!text.empty())
        file << idx.toStr() << " = " << text << std::endl;
    }

    // Write cell format
    file << std::endl << "[format]" << std::endl;
    for (auto idx: allCells)
    { 
      const Cell & cell = getCell(idx);

      if (cell.format != 0)
        file << idx.toStr() << " = " << formatToStr(cell.format) << std::endl;
    }

    file << std::endl;

    currentDoc().filename_ = filename;
    return true;
  }