comparison framework/SVFileReader.cpp @ 72:4aa40182321f

* Merge from transforms branch -- switch over to using Transform object properly
author Chris Cannam
date Fri, 07 Dec 2007 16:47:31 +0000
parents 215b8b1b0308
children 2da0999dac1d
comparison
equal deleted inserted replaced
70:716e9d2f91c7 72:4aa40182321f
29 #include "data/model/SparseOneDimensionalModel.h" 29 #include "data/model/SparseOneDimensionalModel.h"
30 #include "data/model/SparseTimeValueModel.h" 30 #include "data/model/SparseTimeValueModel.h"
31 #include "data/model/NoteModel.h" 31 #include "data/model/NoteModel.h"
32 #include "data/model/TextModel.h" 32 #include "data/model/TextModel.h"
33 #include "data/model/ImageModel.h" 33 #include "data/model/ImageModel.h"
34
35 #include "plugin/transform/TransformFactory.h"
34 36
35 #include "view/Pane.h" 37 #include "view/Pane.h"
36 38
37 #include "Document.h" 39 #include "Document.h"
38 40
51 m_currentPane(0), 53 m_currentPane(0),
52 m_currentDataset(0), 54 m_currentDataset(0),
53 m_currentDerivedModel(0), 55 m_currentDerivedModel(0),
54 m_currentDerivedModelId(-1), 56 m_currentDerivedModelId(-1),
55 m_currentPlayParameters(0), 57 m_currentPlayParameters(0),
58 m_currentTransformSource(0),
56 m_datasetSeparator(" "), 59 m_datasetSeparator(" "),
57 m_inRow(false), 60 m_inRow(false),
58 m_inLayer(false), 61 m_inLayer(false),
59 m_inView(false), 62 m_inView(false),
60 m_rowNumber(0), 63 m_rowNumber(0),
134 // model 137 // model
135 // point 138 // point
136 // row 139 // row
137 // view 140 // view
138 // window 141 // window
142 // plugin
143 // transform
144 // selections
145 // selection
146 // measurement
139 147
140 if (name == "sv") { 148 if (name == "sv") {
141 149
142 // nothing needed 150 // nothing needed
143 ok = true; 151 ok = true;
209 ok = readSelection(attributes); 217 ok = readSelection(attributes);
210 218
211 } else if (name == "measurement") { 219 } else if (name == "measurement") {
212 220
213 ok = readMeasurement(attributes); 221 ok = readMeasurement(attributes);
222
223 } else if (name == "transform") {
224
225 ok = readTransform(attributes);
226
227 } else if (name == "parameter") {
228
229 ok = readParameter(attributes);
214 230
215 } else { 231 } else {
216 std::cerr << "WARNING: SV-XML: Unexpected element \"" 232 std::cerr << "WARNING: SV-XML: Unexpected element \""
217 << name.toLocal8Bit().data() << "\"" << std::endl; 233 << name.toLocal8Bit().data() << "\"" << std::endl;
218 } 234 }
284 std::cerr << "WARNING: SV-XML: Derivation has existing model " 300 std::cerr << "WARNING: SV-XML: Derivation has existing model "
285 << m_currentDerivedModelId 301 << m_currentDerivedModelId
286 << " as target, not regenerating" << std::endl; 302 << " as target, not regenerating" << std::endl;
287 } else { 303 } else {
288 m_currentDerivedModel = m_models[m_currentDerivedModelId] = 304 m_currentDerivedModel = m_models[m_currentDerivedModelId] =
289 m_document->addDerivedModel(m_currentTransformer, 305 m_document->addDerivedModel
290 m_currentTransformerSource, 306 (m_currentTransform,
291 m_currentTransformerContext, 307 ModelTransformer::Input(m_currentTransformSource,
292 m_currentTransformerConfiguration); 308 m_currentTransformChannel));
293 } 309 }
294 } else { 310 } else {
295 m_document->addDerivedModel(m_currentTransformer, 311 m_document->addDerivedModel
296 m_currentTransformerSource, 312 (m_currentTransform,
297 m_currentTransformerContext, 313 ModelTransformer::Input(m_currentTransformSource,
298 m_currentDerivedModel, 314 m_currentTransformChannel),
299 m_currentTransformerConfiguration); 315 m_currentDerivedModel);
300 } 316 }
301 317
302 m_addedModels.insert(m_currentDerivedModel); 318 m_addedModels.insert(m_currentDerivedModel);
303 m_currentDerivedModel = 0; 319 m_currentDerivedModel = 0;
304 m_currentDerivedModelId = -1; 320 m_currentDerivedModelId = -1;
305 m_currentTransformer = ""; 321 m_currentTransformSource = 0;
306 m_currentTransformerConfiguration = ""; 322 m_currentTransform = Transform();
323 m_currentTransformChannel = -1;
307 324
308 } else if (name == "row") { 325 } else if (name == "row") {
309 m_inRow = false; 326 m_inRow = false;
310 } else if (name == "layer") { 327 } else if (name == "layer") {
311 m_inLayer = false; 328 m_inLayer = false;
991 if (!modelOk) { 1008 if (!modelOk) {
992 std::cerr << "WARNING: SV-XML: No model id specified for derivation" << std::endl; 1009 std::cerr << "WARNING: SV-XML: No model id specified for derivation" << std::endl;
993 return false; 1010 return false;
994 } 1011 }
995 1012
996 QString transform = attributes.value("transform");
997
998 if (haveModel(modelId)) { 1013 if (haveModel(modelId)) {
999 m_currentDerivedModel = m_models[modelId]; 1014 m_currentDerivedModel = m_models[modelId];
1000 } else { 1015 } else {
1001 // we'll regenerate the model when the derivation element ends 1016 // we'll regenerate the model when the derivation element ends
1002 m_currentDerivedModel = 0; 1017 m_currentDerivedModel = 0;
1007 int sourceId = 0; 1022 int sourceId = 0;
1008 bool sourceOk = false; 1023 bool sourceOk = false;
1009 sourceId = attributes.value("source").trimmed().toInt(&sourceOk); 1024 sourceId = attributes.value("source").trimmed().toInt(&sourceOk);
1010 1025
1011 if (sourceOk && haveModel(sourceId)) { 1026 if (sourceOk && haveModel(sourceId)) {
1012 m_currentTransformerSource = m_models[sourceId]; 1027 m_currentTransformSource = m_models[sourceId];
1013 } else { 1028 } else {
1014 m_currentTransformerSource = m_document->getMainModel(); 1029 m_currentTransformSource = m_document->getMainModel();
1015 } 1030 }
1016 1031
1017 m_currentTransformer = transform; 1032 m_currentTransform = Transform();
1018 m_currentTransformerConfiguration = "";
1019
1020 m_currentTransformerContext = PluginTransformer::ExecutionContext();
1021 1033
1022 bool ok = false; 1034 bool ok = false;
1023 int channel = attributes.value("channel").trimmed().toInt(&ok); 1035 int channel = attributes.value("channel").trimmed().toInt(&ok);
1024 if (ok) m_currentTransformerContext.channel = channel; 1036 if (ok) m_currentTransformChannel = channel;
1025 1037 else m_currentTransformChannel = -1;
1026 int domain = attributes.value("domain").trimmed().toInt(&ok); 1038
1027 if (ok) m_currentTransformerContext.domain = Vamp::Plugin::InputDomain(domain); 1039 QString type = attributes.value("type");
1040
1041 if (type == "transform") {
1042 m_currentTransformIsNewStyle = true;
1043 return true;
1044 } else {
1045 m_currentTransformIsNewStyle = false;
1046 std::cerr << "NOTE: SV-XML: Reading old-style derivation element"
1047 << std::endl;
1048 }
1049
1050 QString transformId = attributes.value("transform");
1051
1052 m_currentTransform.setIdentifier(transformId);
1028 1053
1029 int stepSize = attributes.value("stepSize").trimmed().toInt(&ok); 1054 int stepSize = attributes.value("stepSize").trimmed().toInt(&ok);
1030 if (ok) m_currentTransformerContext.stepSize = stepSize; 1055 if (ok) m_currentTransform.setStepSize(stepSize);
1031 1056
1032 int blockSize = attributes.value("blockSize").trimmed().toInt(&ok); 1057 int blockSize = attributes.value("blockSize").trimmed().toInt(&ok);
1033 if (ok) m_currentTransformerContext.blockSize = blockSize; 1058 if (ok) m_currentTransform.setBlockSize(blockSize);
1034 1059
1035 int windowType = attributes.value("windowType").trimmed().toInt(&ok); 1060 int windowType = attributes.value("windowType").trimmed().toInt(&ok);
1036 if (ok) m_currentTransformerContext.windowType = WindowType(windowType); 1061 if (ok) m_currentTransform.setWindowType(WindowType(windowType));
1062
1063 if (!m_currentTransformSource) return true;
1037 1064
1038 QString startFrameStr = attributes.value("startFrame"); 1065 QString startFrameStr = attributes.value("startFrame");
1039 QString durationStr = attributes.value("duration"); 1066 QString durationStr = attributes.value("duration");
1040 1067
1041 size_t startFrame = 0; 1068 size_t startFrame = 0;
1048 if (durationStr != "") { 1075 if (durationStr != "") {
1049 duration = durationStr.trimmed().toInt(&ok); 1076 duration = durationStr.trimmed().toInt(&ok);
1050 if (!ok) duration = 0; 1077 if (!ok) duration = 0;
1051 } 1078 }
1052 1079
1053 m_currentTransformerContext.startFrame = startFrame; 1080 m_currentTransform.setStartTime
1054 m_currentTransformerContext.duration = duration; 1081 (RealTime::frame2RealTime
1082 (startFrame, m_currentTransformSource->getSampleRate()));
1083
1084 m_currentTransform.setDuration
1085 (RealTime::frame2RealTime
1086 (duration, m_currentTransformSource->getSampleRate()));
1055 1087
1056 return true; 1088 return true;
1057 } 1089 }
1058 1090
1059 bool 1091 bool
1117 if (m_currentDerivedModelId < 0 && !m_currentPlayParameters) { 1149 if (m_currentDerivedModelId < 0 && !m_currentPlayParameters) {
1118 std::cerr << "WARNING: SV-XML: Plugin found outside derivation or play parameters" << std::endl; 1150 std::cerr << "WARNING: SV-XML: Plugin found outside derivation or play parameters" << std::endl;
1119 return false; 1151 return false;
1120 } 1152 }
1121 1153
1154 if (!m_currentPlayParameters && m_currentTransformIsNewStyle) {
1155 return true;
1156 }
1157
1122 QString configurationXml = "<plugin"; 1158 QString configurationXml = "<plugin";
1123 1159
1124 for (int i = 0; i < attributes.length(); ++i) { 1160 for (int i = 0; i < attributes.length(); ++i) {
1125 configurationXml += QString(" %1=\"%2\"") 1161 configurationXml += QString(" %1=\"%2\"")
1126 .arg(attributes.qName(i)) 1162 .arg(attributes.qName(i))
1130 configurationXml += "/>"; 1166 configurationXml += "/>";
1131 1167
1132 if (m_currentPlayParameters) { 1168 if (m_currentPlayParameters) {
1133 m_currentPlayParameters->setPlayPluginConfiguration(configurationXml); 1169 m_currentPlayParameters->setPlayPluginConfiguration(configurationXml);
1134 } else { 1170 } else {
1135 m_currentTransformerConfiguration += configurationXml; 1171 TransformFactory::getInstance()->
1136 } 1172 setParametersFromPluginConfigurationXml(m_currentTransform,
1137 1173 configurationXml);
1174 }
1175
1176 return true;
1177 }
1178
1179 bool
1180 SVFileReader::readTransform(const QXmlAttributes &attributes)
1181 {
1182 if (m_currentDerivedModelId < 0) {
1183 std::cerr << "WARNING: SV-XML: Transform found outside derivation" << std::endl;
1184 return false;
1185 }
1186
1187 m_currentTransform.setFromXmlAttributes(attributes);
1188 return true;
1189 }
1190
1191 bool
1192 SVFileReader::readParameter(const QXmlAttributes &attributes)
1193 {
1194 if (m_currentDerivedModelId < 0) {
1195 std::cerr << "WARNING: SV-XML: Parameter found outside derivation" << std::endl;
1196 return false;
1197 }
1198
1199 QString name = attributes.value("name");
1200 if (name == "") {
1201 std::cerr << "WARNING: SV-XML: Ignoring nameless transform parameter"
1202 << std::endl;
1203 return false;
1204 }
1205
1206 float value = attributes.value("value").trimmed().toFloat();
1207
1208 m_currentTransform.setParameter(name, value);
1138 return true; 1209 return true;
1139 } 1210 }
1140 1211
1141 bool 1212 bool
1142 SVFileReader::readSelection(const QXmlAttributes &attributes) 1213 SVFileReader::readSelection(const QXmlAttributes &attributes)