Mercurial > hg > svcore
comparison rdf/RDFExporter.cpp @ 500:83eae5239db6
* Permit viewing (though not editing) colour 3d plot layer data in
the spreadsheet data viewer dialog
* Add somewhat simplistic RDF export for layers
* Fix display of peak frequencies in spectrum layer
* Fix (I hope) sizing of plugin parameter dialog
author | Chris Cannam |
---|---|
date | Tue, 02 Dec 2008 17:17:25 +0000 |
parents | |
children | af7b6e55895b |
comparison
equal
deleted
inserted
replaced
499:b71116d3c180 | 500:83eae5239db6 |
---|---|
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" | |
24 #include "data/model/SparseOneDimensionalModel.h" | |
25 #include "data/model/SparseTimeValueModel.h" | |
26 #include "data/model/TextModel.h" | |
27 #include "data/model/EditableDenseThreeDimensionalModel.h" | |
28 | |
29 bool | |
30 RDFExporter::canExportModel(Model *m) | |
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 if (dynamic_cast<EditableDenseThreeDimensionalModel *>(m)) return true; | |
38 return false; | |
39 } | |
40 | |
41 RDFExporter::RDFExporter(QString path, Model *m) : | |
42 m_path(path), | |
43 m_model(m), | |
44 m_fw(new RDFFeatureWriter()) | |
45 { | |
46 map<string, string> params; | |
47 params["one-file"] = path.toStdString(); | |
48 params["force"] = "true"; | |
49 m_fw->setParameters(params); | |
50 } | |
51 | |
52 RDFExporter::~RDFExporter() | |
53 { | |
54 delete m_fw; | |
55 } | |
56 | |
57 bool | |
58 RDFExporter::isOK() const | |
59 { | |
60 return true; | |
61 } | |
62 | |
63 QString | |
64 RDFExporter::getError() const | |
65 { | |
66 return ""; | |
67 } | |
68 | |
69 void | |
70 RDFExporter::write() | |
71 { | |
72 QString trackId; // nil | |
73 Transform transform; // nil | |
74 Vamp::Plugin::OutputDescriptor output; // nil | |
75 std::string summaryType; // nil | |
76 | |
77 Vamp::Plugin::FeatureList features; | |
78 features.push_back(Vamp::Plugin::Feature()); | |
79 Vamp::Plugin::Feature &f = features[0]; | |
80 int sr = m_model->getSampleRate(); | |
81 | |
82 { | |
83 RegionModel *m = dynamic_cast<RegionModel *>(m_model); | |
84 if (m) { | |
85 f.hasTimestamp = true; | |
86 f.hasDuration = true; | |
87 const RegionModel::PointList &pl(m->getPoints()); | |
88 for (RegionModel::PointList::const_iterator i = pl.begin(); | |
89 i != pl.end(); ++i) { | |
90 f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr); | |
91 f.duration = Vamp::RealTime::frame2RealTime(i->duration, sr); | |
92 f.values.clear(); | |
93 f.values.push_back(i->value); | |
94 f.label = i->label.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 const NoteModel::PointList &pl(m->getPoints()); | |
106 for (NoteModel::PointList::const_iterator i = pl.begin(); | |
107 i != pl.end(); ++i) { | |
108 f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr); | |
109 f.duration = Vamp::RealTime::frame2RealTime(i->duration, sr); | |
110 f.values.clear(); | |
111 f.values.push_back(i->value); | |
112 f.values.push_back(i->level); | |
113 f.label = i->label.toStdString(); | |
114 m_fw->write(trackId, transform, output, features, summaryType); | |
115 } | |
116 return; | |
117 } | |
118 } | |
119 { | |
120 SparseOneDimensionalModel *m = dynamic_cast<SparseOneDimensionalModel *>(m_model); | |
121 if (m) { | |
122 f.hasTimestamp = true; | |
123 f.hasDuration = false; | |
124 const SparseOneDimensionalModel::PointList &pl(m->getPoints()); | |
125 for (SparseOneDimensionalModel::PointList::const_iterator i = pl.begin(); | |
126 i != pl.end(); ++i) { | |
127 f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr); | |
128 f.values.clear(); | |
129 f.label = i->label.toStdString(); | |
130 m_fw->write(trackId, transform, output, features, summaryType); | |
131 } | |
132 return; | |
133 } | |
134 } | |
135 { | |
136 SparseTimeValueModel *m = dynamic_cast<SparseTimeValueModel *>(m_model); | |
137 if (m) { | |
138 f.hasTimestamp = true; | |
139 f.hasDuration = false; | |
140 const SparseTimeValueModel::PointList &pl(m->getPoints()); | |
141 for (SparseTimeValueModel::PointList::const_iterator i = pl.begin(); | |
142 i != pl.end(); ++i) { | |
143 f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr); | |
144 f.values.clear(); | |
145 f.values.push_back(i->value); | |
146 f.label = i->label.toStdString(); | |
147 m_fw->write(trackId, transform, output, features, summaryType); | |
148 } | |
149 return; | |
150 } | |
151 } | |
152 { | |
153 TextModel *m = dynamic_cast<TextModel *>(m_model); | |
154 if (m) { | |
155 f.hasTimestamp = true; | |
156 f.hasDuration = false; | |
157 const TextModel::PointList &pl(m->getPoints()); | |
158 for (TextModel::PointList::const_iterator i = pl.begin(); | |
159 i != pl.end(); ++i) { | |
160 f.timestamp = Vamp::RealTime::frame2RealTime(i->frame, sr); | |
161 f.values.clear(); | |
162 f.values.push_back(i->height); | |
163 f.label = i->label.toStdString(); | |
164 m_fw->write(trackId, transform, output, features, summaryType); | |
165 } | |
166 return; | |
167 } | |
168 } | |
169 } | |
170 | |
171 QString | |
172 RDFExporter::getSupportedExtensions() | |
173 { | |
174 return "*.n3 *.ttl"; | |
175 } | |
176 |