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@500
|
37 if (dynamic_cast<EditableDenseThreeDimensionalModel *>(m)) return true;
|
Chris@500
|
38 return false;
|
Chris@500
|
39 }
|
Chris@500
|
40
|
Chris@500
|
41 RDFExporter::RDFExporter(QString path, Model *m) :
|
Chris@500
|
42 m_path(path),
|
Chris@500
|
43 m_model(m),
|
Chris@500
|
44 m_fw(new RDFFeatureWriter())
|
Chris@500
|
45 {
|
Chris@500
|
46 map<string, string> params;
|
Chris@500
|
47 params["one-file"] = path.toStdString();
|
Chris@500
|
48 params["force"] = "true";
|
Chris@500
|
49 m_fw->setParameters(params);
|
Chris@500
|
50 }
|
Chris@500
|
51
|
Chris@500
|
52 RDFExporter::~RDFExporter()
|
Chris@500
|
53 {
|
Chris@500
|
54 delete m_fw;
|
Chris@500
|
55 }
|
Chris@500
|
56
|
Chris@500
|
57 bool
|
Chris@500
|
58 RDFExporter::isOK() const
|
Chris@500
|
59 {
|
Chris@500
|
60 return true;
|
Chris@500
|
61 }
|
Chris@500
|
62
|
Chris@500
|
63 QString
|
Chris@500
|
64 RDFExporter::getError() const
|
Chris@500
|
65 {
|
Chris@500
|
66 return "";
|
Chris@500
|
67 }
|
Chris@500
|
68
|
Chris@500
|
69 void
|
Chris@500
|
70 RDFExporter::write()
|
Chris@500
|
71 {
|
Chris@500
|
72 QString trackId; // nil
|
Chris@500
|
73 Transform transform; // nil
|
Chris@500
|
74 Vamp::Plugin::OutputDescriptor output; // nil
|
Chris@500
|
75 std::string summaryType; // nil
|
Chris@500
|
76
|
Chris@500
|
77 Vamp::Plugin::FeatureList features;
|
Chris@500
|
78 features.push_back(Vamp::Plugin::Feature());
|
Chris@500
|
79 Vamp::Plugin::Feature &f = features[0];
|
Chris@500
|
80 int sr = m_model->getSampleRate();
|
Chris@500
|
81
|
Chris@500
|
82 {
|
Chris@500
|
83 RegionModel *m = dynamic_cast<RegionModel *>(m_model);
|
Chris@500
|
84 if (m) {
|
Chris@500
|
85 f.hasTimestamp = true;
|
Chris@500
|
86 f.hasDuration = true;
|
Chris@500
|
87 const RegionModel::PointList &pl(m->getPoints());
|
Chris@500
|
88 for (RegionModel::PointList::const_iterator i = pl.begin();
|
Chris@500
|
89 i != pl.end(); ++i) {
|
Chris@500
|
90 f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr);
|
Chris@500
|
91 f.duration = Vamp::RealTime::frame2RealTime(i->duration, sr);
|
Chris@500
|
92 f.values.clear();
|
Chris@500
|
93 f.values.push_back(i->value);
|
Chris@500
|
94 f.label = i->label.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@500
|
105 const NoteModel::PointList &pl(m->getPoints());
|
Chris@500
|
106 for (NoteModel::PointList::const_iterator i = pl.begin();
|
Chris@500
|
107 i != pl.end(); ++i) {
|
Chris@500
|
108 f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr);
|
Chris@500
|
109 f.duration = Vamp::RealTime::frame2RealTime(i->duration, sr);
|
Chris@500
|
110 f.values.clear();
|
Chris@500
|
111 f.values.push_back(i->value);
|
Chris@500
|
112 f.values.push_back(i->level);
|
Chris@500
|
113 f.label = i->label.toStdString();
|
Chris@500
|
114 m_fw->write(trackId, transform, output, features, summaryType);
|
Chris@500
|
115 }
|
Chris@500
|
116 return;
|
Chris@500
|
117 }
|
Chris@500
|
118 }
|
Chris@500
|
119 {
|
Chris@500
|
120 SparseOneDimensionalModel *m = dynamic_cast<SparseOneDimensionalModel *>(m_model);
|
Chris@500
|
121 if (m) {
|
Chris@500
|
122 f.hasTimestamp = true;
|
Chris@500
|
123 f.hasDuration = false;
|
Chris@500
|
124 const SparseOneDimensionalModel::PointList &pl(m->getPoints());
|
Chris@500
|
125 for (SparseOneDimensionalModel::PointList::const_iterator i = pl.begin();
|
Chris@500
|
126 i != pl.end(); ++i) {
|
Chris@500
|
127 f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr);
|
Chris@500
|
128 f.values.clear();
|
Chris@500
|
129 f.label = i->label.toStdString();
|
Chris@500
|
130 m_fw->write(trackId, transform, output, features, summaryType);
|
Chris@500
|
131 }
|
Chris@500
|
132 return;
|
Chris@500
|
133 }
|
Chris@500
|
134 }
|
Chris@500
|
135 {
|
Chris@500
|
136 SparseTimeValueModel *m = dynamic_cast<SparseTimeValueModel *>(m_model);
|
Chris@500
|
137 if (m) {
|
Chris@500
|
138 f.hasTimestamp = true;
|
Chris@500
|
139 f.hasDuration = false;
|
Chris@500
|
140 const SparseTimeValueModel::PointList &pl(m->getPoints());
|
Chris@500
|
141 for (SparseTimeValueModel::PointList::const_iterator i = pl.begin();
|
Chris@500
|
142 i != pl.end(); ++i) {
|
Chris@500
|
143 f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr);
|
Chris@500
|
144 f.values.clear();
|
Chris@500
|
145 f.values.push_back(i->value);
|
Chris@500
|
146 f.label = i->label.toStdString();
|
Chris@500
|
147 m_fw->write(trackId, transform, output, features, summaryType);
|
Chris@500
|
148 }
|
Chris@500
|
149 return;
|
Chris@500
|
150 }
|
Chris@500
|
151 }
|
Chris@500
|
152 {
|
Chris@500
|
153 TextModel *m = dynamic_cast<TextModel *>(m_model);
|
Chris@500
|
154 if (m) {
|
Chris@500
|
155 f.hasTimestamp = true;
|
Chris@500
|
156 f.hasDuration = false;
|
Chris@500
|
157 const TextModel::PointList &pl(m->getPoints());
|
Chris@510
|
158 m_fw->setFixedEventTypeURI("af:Text");
|
Chris@500
|
159 for (TextModel::PointList::const_iterator i = pl.begin();
|
Chris@500
|
160 i != pl.end(); ++i) {
|
Chris@500
|
161 f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr);
|
Chris@500
|
162 f.values.clear();
|
Chris@500
|
163 f.values.push_back(i->height);
|
Chris@500
|
164 f.label = i->label.toStdString();
|
Chris@500
|
165 m_fw->write(trackId, transform, output, features, summaryType);
|
Chris@500
|
166 }
|
Chris@500
|
167 return;
|
Chris@500
|
168 }
|
Chris@500
|
169 }
|
Chris@500
|
170 }
|
Chris@500
|
171
|
Chris@500
|
172 QString
|
Chris@500
|
173 RDFExporter::getSupportedExtensions()
|
Chris@500
|
174 {
|
Chris@736
|
175 return "*.ttl *.n3";
|
Chris@500
|
176 }
|
Chris@500
|
177
|