annotate rdf/RDFExporter.cpp @ 1725:78fe29adfd16

Re-implement extendEndFrame behaviour, used by Tony application
author Chris Cannam
date Wed, 19 Jun 2019 13:32:52 +0100
parents 353a2d15f213
children
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@1040 81 sv_samplerate_t 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@1649 88 EventVector ee(m->getAllEvents());
Chris@1649 89 for (auto e: ee) {
Chris@1649 90 f.timestamp = RealTime::frame2RealTime(e.getFrame(), sr).toVampRealTime();
Chris@1649 91 f.duration = RealTime::frame2RealTime(e.getDuration(), sr).toVampRealTime();
Chris@500 92 f.values.clear();
Chris@1649 93 f.values.push_back(e.getValue());
Chris@1649 94 f.label = e.getLabel().toStdString();
Chris@500 95 m_fw->write(trackId, transform, output, features, summaryType);
Chris@500 96 }
Chris@500 97 return;
Chris@500 98 }
Chris@500 99 }
Chris@500 100 {
Chris@500 101 NoteModel *m = dynamic_cast<NoteModel *>(m_model);
Chris@500 102 if (m) {
Chris@500 103 f.hasTimestamp = true;
Chris@500 104 f.hasDuration = true;
Chris@1644 105 EventVector ee(m->getAllEvents());
Chris@1643 106 for (auto e: ee) {
Chris@1643 107 f.timestamp = RealTime::frame2RealTime(e.getFrame(), sr).toVampRealTime();
Chris@1643 108 f.duration = RealTime::frame2RealTime(e.getDuration(), sr).toVampRealTime();
Chris@500 109 f.values.clear();
Chris@1643 110 f.values.push_back(e.getValue());
Chris@1643 111 f.values.push_back(e.getLevel());
Chris@1643 112 f.label = e.getLabel().toStdString();
Chris@500 113 m_fw->write(trackId, transform, output, features, summaryType);
Chris@500 114 }
Chris@500 115 return;
Chris@500 116 }
Chris@500 117 }
Chris@500 118 {
Chris@500 119 SparseOneDimensionalModel *m = dynamic_cast<SparseOneDimensionalModel *>(m_model);
Chris@500 120 if (m) {
Chris@500 121 f.hasTimestamp = true;
Chris@500 122 f.hasDuration = false;
Chris@1658 123 EventVector ee(m->getAllEvents());
Chris@1658 124 for (auto e: ee) {
Chris@1658 125 f.timestamp = RealTime::frame2RealTime(e.getFrame(), sr).toVampRealTime();
Chris@500 126 f.values.clear();
Chris@1658 127 f.label = e.getLabel().toStdString();
Chris@500 128 m_fw->write(trackId, transform, output, features, summaryType);
Chris@500 129 }
Chris@500 130 return;
Chris@500 131 }
Chris@500 132 }
Chris@500 133 {
Chris@500 134 SparseTimeValueModel *m = dynamic_cast<SparseTimeValueModel *>(m_model);
Chris@500 135 if (m) {
Chris@500 136 f.hasTimestamp = true;
Chris@500 137 f.hasDuration = false;
Chris@1651 138 EventVector ee(m->getAllEvents());
Chris@1651 139 for (auto e: ee) {
Chris@1651 140 f.timestamp = RealTime::frame2RealTime(e.getFrame(), sr).toVampRealTime();
Chris@500 141 f.values.clear();
Chris@1651 142 f.values.push_back(e.getValue());
Chris@1651 143 f.label = e.getLabel().toStdString();
Chris@500 144 m_fw->write(trackId, transform, output, features, summaryType);
Chris@500 145 }
Chris@500 146 return;
Chris@500 147 }
Chris@500 148 }
Chris@500 149 {
Chris@500 150 TextModel *m = dynamic_cast<TextModel *>(m_model);
Chris@500 151 if (m) {
Chris@500 152 f.hasTimestamp = true;
Chris@500 153 f.hasDuration = false;
Chris@510 154 m_fw->setFixedEventTypeURI("af:Text");
Chris@1661 155 EventVector ee(m->getAllEvents());
Chris@1661 156 for (auto e: ee) {
Chris@1661 157 f.timestamp = RealTime::frame2RealTime(e.getFrame(), sr).toVampRealTime();
Chris@500 158 f.values.clear();
Chris@1661 159 f.values.push_back(e.getValue());
Chris@1661 160 f.label = e.getLabel().toStdString();
Chris@500 161 m_fw->write(trackId, transform, output, features, summaryType);
Chris@500 162 }
Chris@500 163 return;
Chris@500 164 }
Chris@500 165 }
Chris@500 166 }
Chris@500 167
Chris@500 168 QString
Chris@500 169 RDFExporter::getSupportedExtensions()
Chris@500 170 {
Chris@736 171 return "*.ttl *.n3";
Chris@500 172 }
Chris@500 173