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