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];
82 
83  {
84  RegionModel *m = dynamic_cast<RegionModel *>(m_model);
85  if (m) {
86  f.hasTimestamp = true;
87  f.hasDuration = true;
88  EventVector ee(m->getAllEvents());
89  for (auto e: ee) {
90  f.timestamp = RealTime::frame2RealTime(e.getFrame(), sr).toVampRealTime();
91  f.duration = RealTime::frame2RealTime(e.getDuration(), sr).toVampRealTime();
92  f.values.clear();
93  f.values.push_back(e.getValue());
94  f.label = e.getLabel().toStdString();
95  m_fw->write(trackId, transform, output, features, summaryType);
96  }
97  return;
98  }
99  }
100  {
101  NoteModel *m = dynamic_cast<NoteModel *>(m_model);
102  if (m) {
103  f.hasTimestamp = true;
104  f.hasDuration = true;
105  EventVector ee(m->getAllEvents());
106  for (auto e: ee) {
107  f.timestamp = RealTime::frame2RealTime(e.getFrame(), sr).toVampRealTime();
108  f.duration = RealTime::frame2RealTime(e.getDuration(), sr).toVampRealTime();
109  f.values.clear();
110  f.values.push_back(e.getValue());
111  f.values.push_back(e.getLevel());
112  f.label = e.getLabel().toStdString();
113  m_fw->write(trackId, transform, output, features, summaryType);
114  }
115  return;
116  }
117  }
118  {
120  if (m) {
121  f.hasTimestamp = true;
122  f.hasDuration = false;
123  EventVector ee(m->getAllEvents());
124  for (auto e: ee) {
125  f.timestamp = RealTime::frame2RealTime(e.getFrame(), sr).toVampRealTime();
126  f.values.clear();
127  f.label = e.getLabel().toStdString();
128  m_fw->write(trackId, transform, output, features, summaryType);
129  }
130  return;
131  }
132  }
133  {
134  SparseTimeValueModel *m = dynamic_cast<SparseTimeValueModel *>(m_model);
135  if (m) {
136  f.hasTimestamp = true;
137  f.hasDuration = false;
138  EventVector ee(m->getAllEvents());
139  for (auto e: ee) {
140  f.timestamp = RealTime::frame2RealTime(e.getFrame(), sr).toVampRealTime();
141  f.values.clear();
142  f.values.push_back(e.getValue());
143  f.label = e.getLabel().toStdString();
144  m_fw->write(trackId, transform, output, features, summaryType);
145  }
146  return;
147  }
148  }
149  {
150  TextModel *m = dynamic_cast<TextModel *>(m_model);
151  if (m) {
152  f.hasTimestamp = true;
153  f.hasDuration = false;
154  m_fw->setFixedEventTypeURI("af:Text");
155  EventVector ee(m->getAllEvents());
156  for (auto e: ee) {
157  f.timestamp = RealTime::frame2RealTime(e.getFrame(), sr).toVampRealTime();
158  f.values.clear();
159  f.values.push_back(e.getValue());
160  f.label = e.getLabel().toStdString();
161  m_fw->write(trackId, transform, output, features, summaryType);
162  }
163  return;
164  }
165  }
166 }
167 
168 QString
170 {
171  return "*.ttl *.n3";
172 }
173 
double sv_samplerate_t
Sample rate.
Definition: BaseTypes.h:51
static bool canExportModel(Model *)
Definition: RDFExporter.cpp:30
virtual void setFixedEventTypeURI(QString uri)
static RealTime frame2RealTime(sv_frame_t frame, sv_samplerate_t sampleRate)
Convert a sample frame at the given sample rate into a RealTime.
Definition: RealTimeSV.cpp:498
virtual QString getError() const
Definition: RDFExporter.cpp:65
EventVector getAllEvents() const
Definition: TextModel.h:108
virtual ~RDFExporter()
Definition: RDFExporter.cpp:53
EventVector getAllEvents() const
Definition: RegionModel.h:143
A model representing casual textual annotations.
Definition: TextModel.h:36
EventVector getAllEvents() const
QString m_path
Definition: RDFExporter.h:44
virtual void write()
Definition: RDFExporter.cpp:71
RDFFeatureWriter * m_fw
Definition: RDFExporter.h:46
virtual sv_samplerate_t 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:51
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.
A model representing a wiggly-line plot with points at arbitrary intervals of the model resolution...
void setParameters(map< string, string > &params) override
EventVector getAllEvents() const
Definition: NoteModel.h:175
RegionModel – a model for intervals associated with a value, which we call regions for no very compe...
Definition: RegionModel.h:33
virtual bool isOK() const
Definition: RDFExporter.cpp:59
A model representing a series of time instants with optional labels but without values.
std::vector< Event > EventVector
Definition: Event.h:494
void write(QString trackid, const Transform &transform, const Vamp::Plugin::OutputDescriptor &output, const Vamp::Plugin::FeatureList &features, std::string summaryType="") override
RDFExporter(QString path, Model *model)
Definition: RDFExporter.cpp:42