annotate rdf/RDFExporter.cpp @ 775:9aa3f343a6ea tonioni

added FlexiNoteModel to svcore.pro; small change in FlexiNoteModel.h
author matthiasm
date Tue, 26 Mar 2013 17:00:03 +0000
parents fb6313da1df6
children a1cd5abcb38b
rev   line source
Chris@500 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@500 2
Chris@500 3 /*
Chris@500 4 Sonic Visualiser
Chris@500 5 An audio file viewer and annotation editor.
Chris@500 6 Centre for Digital Music, Queen Mary, University of London.
Chris@500 7 This file copyright 2008 QMUL.
Chris@500 8
Chris@500 9 This program is free software; you can redistribute it and/or
Chris@500 10 modify it under the terms of the GNU General Public License as
Chris@500 11 published by the Free Software Foundation; either version 2 of the
Chris@500 12 License, or (at your option) any later version. See the file
Chris@500 13 COPYING included with this distribution for more information.
Chris@500 14 */
Chris@500 15
Chris@500 16 #include "RDFExporter.h"
Chris@500 17 #include "RDFFeatureWriter.h"
Chris@500 18
Chris@500 19 #include <vamp-hostsdk/Plugin.h>
Chris@500 20
Chris@500 21 #include "data/model/Model.h"
Chris@500 22 #include "data/model/RegionModel.h"
Chris@500 23 #include "data/model/NoteModel.h"
Chris@500 24 #include "data/model/SparseOneDimensionalModel.h"
Chris@500 25 #include "data/model/SparseTimeValueModel.h"
Chris@500 26 #include "data/model/TextModel.h"
Chris@500 27 #include "data/model/EditableDenseThreeDimensionalModel.h"
Chris@500 28
Chris@500 29 bool
Chris@500 30 RDFExporter::canExportModel(Model *m)
Chris@500 31 {
Chris@500 32 if (dynamic_cast<RegionModel *>(m)) return true;
Chris@500 33 if (dynamic_cast<NoteModel *>(m)) return true;
Chris@500 34 if (dynamic_cast<SparseTimeValueModel *>(m)) return true;
Chris@500 35 if (dynamic_cast<SparseOneDimensionalModel *>(m)) return true;
Chris@500 36 if (dynamic_cast<TextModel *>(m)) return true;
Chris@753 37 // no, looks like we never implemented this one
Chris@753 38 // if (dynamic_cast<EditableDenseThreeDimensionalModel *>(m)) return true;
Chris@500 39 return false;
Chris@500 40 }
Chris@500 41
Chris@500 42 RDFExporter::RDFExporter(QString path, Model *m) :
Chris@500 43 m_path(path),
Chris@500 44 m_model(m),
Chris@500 45 m_fw(new RDFFeatureWriter())
Chris@500 46 {
Chris@500 47 map<string, string> params;
Chris@500 48 params["one-file"] = path.toStdString();
Chris@500 49 params["force"] = "true";
Chris@500 50 m_fw->setParameters(params);
Chris@500 51 }
Chris@500 52
Chris@500 53 RDFExporter::~RDFExporter()
Chris@500 54 {
Chris@500 55 delete m_fw;
Chris@500 56 }
Chris@500 57
Chris@500 58 bool
Chris@500 59 RDFExporter::isOK() const
Chris@500 60 {
Chris@500 61 return true;
Chris@500 62 }
Chris@500 63
Chris@500 64 QString
Chris@500 65 RDFExporter::getError() const
Chris@500 66 {
Chris@500 67 return "";
Chris@500 68 }
Chris@500 69
Chris@500 70 void
Chris@500 71 RDFExporter::write()
Chris@500 72 {
Chris@500 73 QString trackId; // nil
Chris@500 74 Transform transform; // nil
Chris@500 75 Vamp::Plugin::OutputDescriptor output; // nil
Chris@500 76 std::string summaryType; // nil
Chris@500 77
Chris@500 78 Vamp::Plugin::FeatureList features;
Chris@500 79 features.push_back(Vamp::Plugin::Feature());
Chris@500 80 Vamp::Plugin::Feature &f = features[0];
Chris@500 81 int sr = m_model->getSampleRate();
Chris@500 82
Chris@500 83 {
Chris@500 84 RegionModel *m = dynamic_cast<RegionModel *>(m_model);
Chris@500 85 if (m) {
Chris@500 86 f.hasTimestamp = true;
Chris@500 87 f.hasDuration = true;
Chris@500 88 const RegionModel::PointList &pl(m->getPoints());
Chris@500 89 for (RegionModel::PointList::const_iterator i = pl.begin();
Chris@500 90 i != pl.end(); ++i) {
Chris@500 91 f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr);
Chris@500 92 f.duration = Vamp::RealTime::frame2RealTime(i->duration, sr);
Chris@500 93 f.values.clear();
Chris@500 94 f.values.push_back(i->value);
Chris@500 95 f.label = i->label.toStdString();
Chris@500 96 m_fw->write(trackId, transform, output, features, summaryType);
Chris@500 97 }
Chris@500 98 return;
Chris@500 99 }
Chris@500 100 }
Chris@500 101 {
Chris@500 102 NoteModel *m = dynamic_cast<NoteModel *>(m_model);
Chris@500 103 if (m) {
Chris@500 104 f.hasTimestamp = true;
Chris@500 105 f.hasDuration = true;
Chris@500 106 const NoteModel::PointList &pl(m->getPoints());
Chris@500 107 for (NoteModel::PointList::const_iterator i = pl.begin();
Chris@500 108 i != pl.end(); ++i) {
Chris@500 109 f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr);
Chris@500 110 f.duration = Vamp::RealTime::frame2RealTime(i->duration, sr);
Chris@500 111 f.values.clear();
Chris@500 112 f.values.push_back(i->value);
Chris@500 113 f.values.push_back(i->level);
Chris@500 114 f.label = i->label.toStdString();
Chris@500 115 m_fw->write(trackId, transform, output, features, summaryType);
Chris@500 116 }
Chris@500 117 return;
Chris@500 118 }
Chris@500 119 }
Chris@500 120 {
Chris@500 121 SparseOneDimensionalModel *m = dynamic_cast<SparseOneDimensionalModel *>(m_model);
Chris@500 122 if (m) {
Chris@500 123 f.hasTimestamp = true;
Chris@500 124 f.hasDuration = false;
Chris@500 125 const SparseOneDimensionalModel::PointList &pl(m->getPoints());
Chris@500 126 for (SparseOneDimensionalModel::PointList::const_iterator i = pl.begin();
Chris@500 127 i != pl.end(); ++i) {
Chris@500 128 f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr);
Chris@500 129 f.values.clear();
Chris@500 130 f.label = i->label.toStdString();
Chris@500 131 m_fw->write(trackId, transform, output, features, summaryType);
Chris@500 132 }
Chris@500 133 return;
Chris@500 134 }
Chris@500 135 }
Chris@500 136 {
Chris@500 137 SparseTimeValueModel *m = dynamic_cast<SparseTimeValueModel *>(m_model);
Chris@500 138 if (m) {
Chris@500 139 f.hasTimestamp = true;
Chris@500 140 f.hasDuration = false;
Chris@500 141 const SparseTimeValueModel::PointList &pl(m->getPoints());
Chris@500 142 for (SparseTimeValueModel::PointList::const_iterator i = pl.begin();
Chris@500 143 i != pl.end(); ++i) {
Chris@500 144 f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr);
Chris@500 145 f.values.clear();
Chris@500 146 f.values.push_back(i->value);
Chris@500 147 f.label = i->label.toStdString();
Chris@500 148 m_fw->write(trackId, transform, output, features, summaryType);
Chris@500 149 }
Chris@500 150 return;
Chris@500 151 }
Chris@500 152 }
Chris@500 153 {
Chris@500 154 TextModel *m = dynamic_cast<TextModel *>(m_model);
Chris@500 155 if (m) {
Chris@500 156 f.hasTimestamp = true;
Chris@500 157 f.hasDuration = false;
Chris@500 158 const TextModel::PointList &pl(m->getPoints());
Chris@510 159 m_fw->setFixedEventTypeURI("af:Text");
Chris@500 160 for (TextModel::PointList::const_iterator i = pl.begin();
Chris@500 161 i != pl.end(); ++i) {
Chris@500 162 f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr);
Chris@500 163 f.values.clear();
Chris@500 164 f.values.push_back(i->height);
Chris@500 165 f.label = i->label.toStdString();
Chris@500 166 m_fw->write(trackId, transform, output, features, summaryType);
Chris@500 167 }
Chris@500 168 return;
Chris@500 169 }
Chris@500 170 }
Chris@500 171 }
Chris@500 172
Chris@500 173 QString
Chris@500 174 RDFExporter::getSupportedExtensions()
Chris@500 175 {
Chris@736 176 return "*.ttl *.n3";
Chris@500 177 }
Chris@500 178