Chris@500: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@500: Chris@500: /* Chris@500: Sonic Visualiser Chris@500: An audio file viewer and annotation editor. Chris@500: Centre for Digital Music, Queen Mary, University of London. Chris@500: This file copyright 2008 QMUL. Chris@500: Chris@500: This program is free software; you can redistribute it and/or Chris@500: modify it under the terms of the GNU General Public License as Chris@500: published by the Free Software Foundation; either version 2 of the Chris@500: License, or (at your option) any later version. See the file Chris@500: COPYING included with this distribution for more information. Chris@500: */ Chris@500: Chris@500: #include "RDFExporter.h" Chris@500: #include "RDFFeatureWriter.h" Chris@500: Chris@500: #include Chris@500: Chris@500: #include "data/model/Model.h" Chris@500: #include "data/model/RegionModel.h" Chris@500: #include "data/model/NoteModel.h" Chris@500: #include "data/model/SparseOneDimensionalModel.h" Chris@500: #include "data/model/SparseTimeValueModel.h" Chris@500: #include "data/model/TextModel.h" Chris@500: #include "data/model/EditableDenseThreeDimensionalModel.h" Chris@500: Chris@500: bool Chris@500: RDFExporter::canExportModel(Model *m) Chris@500: { Chris@500: if (dynamic_cast(m)) return true; Chris@500: if (dynamic_cast(m)) return true; Chris@500: if (dynamic_cast(m)) return true; Chris@500: if (dynamic_cast(m)) return true; Chris@500: if (dynamic_cast(m)) return true; Chris@500: if (dynamic_cast(m)) return true; Chris@500: return false; Chris@500: } Chris@500: Chris@500: RDFExporter::RDFExporter(QString path, Model *m) : Chris@500: m_path(path), Chris@500: m_model(m), Chris@500: m_fw(new RDFFeatureWriter()) Chris@500: { Chris@500: map params; Chris@500: params["one-file"] = path.toStdString(); Chris@500: params["force"] = "true"; Chris@500: m_fw->setParameters(params); Chris@500: } Chris@500: Chris@500: RDFExporter::~RDFExporter() Chris@500: { Chris@500: delete m_fw; Chris@500: } Chris@500: Chris@500: bool Chris@500: RDFExporter::isOK() const Chris@500: { Chris@500: return true; Chris@500: } Chris@500: Chris@500: QString Chris@500: RDFExporter::getError() const Chris@500: { Chris@500: return ""; Chris@500: } Chris@500: Chris@500: void Chris@500: RDFExporter::write() Chris@500: { Chris@500: QString trackId; // nil Chris@500: Transform transform; // nil Chris@500: Vamp::Plugin::OutputDescriptor output; // nil Chris@500: std::string summaryType; // nil Chris@500: Chris@500: Vamp::Plugin::FeatureList features; Chris@500: features.push_back(Vamp::Plugin::Feature()); Chris@500: Vamp::Plugin::Feature &f = features[0]; Chris@500: int sr = m_model->getSampleRate(); Chris@500: Chris@500: { Chris@500: RegionModel *m = dynamic_cast(m_model); Chris@500: if (m) { Chris@500: f.hasTimestamp = true; Chris@500: f.hasDuration = true; Chris@500: const RegionModel::PointList &pl(m->getPoints()); Chris@500: for (RegionModel::PointList::const_iterator i = pl.begin(); Chris@500: i != pl.end(); ++i) { Chris@500: f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr); Chris@500: f.duration = Vamp::RealTime::frame2RealTime(i->duration, sr); Chris@500: f.values.clear(); Chris@500: f.values.push_back(i->value); Chris@500: f.label = i->label.toStdString(); Chris@500: m_fw->write(trackId, transform, output, features, summaryType); Chris@500: } Chris@500: return; Chris@500: } Chris@500: } Chris@500: { Chris@500: NoteModel *m = dynamic_cast(m_model); Chris@500: if (m) { Chris@500: f.hasTimestamp = true; Chris@500: f.hasDuration = true; Chris@500: const NoteModel::PointList &pl(m->getPoints()); Chris@500: for (NoteModel::PointList::const_iterator i = pl.begin(); Chris@500: i != pl.end(); ++i) { Chris@500: f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr); Chris@500: f.duration = Vamp::RealTime::frame2RealTime(i->duration, sr); Chris@500: f.values.clear(); Chris@500: f.values.push_back(i->value); Chris@500: f.values.push_back(i->level); Chris@500: f.label = i->label.toStdString(); Chris@500: m_fw->write(trackId, transform, output, features, summaryType); Chris@500: } Chris@500: return; Chris@500: } Chris@500: } Chris@500: { Chris@500: SparseOneDimensionalModel *m = dynamic_cast(m_model); Chris@500: if (m) { Chris@500: f.hasTimestamp = true; Chris@500: f.hasDuration = false; Chris@500: const SparseOneDimensionalModel::PointList &pl(m->getPoints()); Chris@500: for (SparseOneDimensionalModel::PointList::const_iterator i = pl.begin(); Chris@500: i != pl.end(); ++i) { Chris@500: f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr); Chris@500: f.values.clear(); Chris@500: f.label = i->label.toStdString(); Chris@500: m_fw->write(trackId, transform, output, features, summaryType); Chris@500: } Chris@500: return; Chris@500: } Chris@500: } Chris@500: { Chris@500: SparseTimeValueModel *m = dynamic_cast(m_model); Chris@500: if (m) { Chris@500: f.hasTimestamp = true; Chris@500: f.hasDuration = false; Chris@500: const SparseTimeValueModel::PointList &pl(m->getPoints()); Chris@500: for (SparseTimeValueModel::PointList::const_iterator i = pl.begin(); Chris@500: i != pl.end(); ++i) { Chris@500: f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr); Chris@500: f.values.clear(); Chris@500: f.values.push_back(i->value); Chris@500: f.label = i->label.toStdString(); Chris@500: m_fw->write(trackId, transform, output, features, summaryType); Chris@500: } Chris@500: return; Chris@500: } Chris@500: } Chris@500: { Chris@500: TextModel *m = dynamic_cast(m_model); Chris@500: if (m) { Chris@500: f.hasTimestamp = true; Chris@500: f.hasDuration = false; Chris@500: const TextModel::PointList &pl(m->getPoints()); Chris@500: for (TextModel::PointList::const_iterator i = pl.begin(); Chris@500: i != pl.end(); ++i) { Chris@500: f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr); Chris@500: f.values.clear(); Chris@500: f.values.push_back(i->height); Chris@500: f.label = i->label.toStdString(); Chris@500: m_fw->write(trackId, transform, output, features, summaryType); Chris@500: } Chris@500: return; Chris@500: } Chris@500: } Chris@500: } Chris@500: Chris@500: QString Chris@500: RDFExporter::getSupportedExtensions() Chris@500: { Chris@500: return "*.n3 *.ttl"; Chris@500: } Chris@500: