Mercurial > hg > svapp
comparison framework/SVFileReader.cpp @ 100:22bf057ea151 1.2-stable
* merge from trunk (1.2 ended up being tracked from trunk, but we may want
this branch for fixes later)
author | Chris Cannam |
---|---|
date | Wed, 27 Feb 2008 10:32:45 +0000 |
parents | 215b8b1b0308 |
children |
comparison
equal
deleted
inserted
replaced
71:a8acc7841d70 | 100:22bf057ea151 |
---|---|
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 } |
283 } else if (haveModel(m_currentDerivedModelId)) { | 299 } else if (haveModel(m_currentDerivedModelId)) { |
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 { |
304 QString message; | |
288 m_currentDerivedModel = m_models[m_currentDerivedModelId] = | 305 m_currentDerivedModel = m_models[m_currentDerivedModelId] = |
289 m_document->addDerivedModel(m_currentTransformer, | 306 m_document->addDerivedModel |
290 m_currentTransformerSource, | 307 (m_currentTransform, |
291 m_currentTransformerContext, | 308 ModelTransformer::Input(m_currentTransformSource, |
292 m_currentTransformerConfiguration); | 309 m_currentTransformChannel), |
310 message); | |
311 if (!m_currentDerivedModel) { | |
312 emit modelRegenerationFailed(tr("(derived model in SV-XML)"), | |
313 m_currentTransform.getIdentifier(), | |
314 message); | |
315 } else if (message != "") { | |
316 emit modelRegenerationWarning(tr("(derived model in SV-XML)"), | |
317 m_currentTransform.getIdentifier(), | |
318 message); | |
319 } | |
293 } | 320 } |
294 } else { | 321 } else { |
295 m_document->addDerivedModel(m_currentTransformer, | 322 m_document->addDerivedModel |
296 m_currentTransformerSource, | 323 (m_currentTransform, |
297 m_currentTransformerContext, | 324 ModelTransformer::Input(m_currentTransformSource, |
298 m_currentDerivedModel, | 325 m_currentTransformChannel), |
299 m_currentTransformerConfiguration); | 326 m_currentDerivedModel); |
300 } | 327 } |
301 | 328 |
302 m_addedModels.insert(m_currentDerivedModel); | 329 m_addedModels.insert(m_currentDerivedModel); |
303 m_currentDerivedModel = 0; | 330 m_currentDerivedModel = 0; |
304 m_currentDerivedModelId = -1; | 331 m_currentDerivedModelId = -1; |
305 m_currentTransformer = ""; | 332 m_currentTransformSource = 0; |
306 m_currentTransformerConfiguration = ""; | 333 m_currentTransform = Transform(); |
334 m_currentTransformChannel = -1; | |
307 | 335 |
308 } else if (name == "row") { | 336 } else if (name == "row") { |
309 m_inRow = false; | 337 m_inRow = false; |
310 } else if (name == "layer") { | 338 } else if (name == "layer") { |
311 m_inLayer = false; | 339 m_inLayer = false; |
411 FileFinder *ff = FileFinder::getInstance(); | 439 FileFinder *ff = FileFinder::getInstance(); |
412 QString originalPath = attributes.value("file"); | 440 QString originalPath = attributes.value("file"); |
413 QString path = ff->find(FileFinder::AudioFile, | 441 QString path = ff->find(FileFinder::AudioFile, |
414 originalPath, m_location); | 442 originalPath, m_location); |
415 | 443 |
416 FileSource file(path, true); | 444 FileSource file(path, FileSource::ProgressDialog); |
417 file.waitForStatus(); | 445 file.waitForStatus(); |
418 | 446 |
419 if (!file.isOK()) { | 447 if (!file.isOK()) { |
420 std::cerr << "SVFileReader::readModel: Failed to retrieve file \"" << path.toStdString() << "\" for wave file model: " << file.getErrorString().toStdString() << std::endl; | 448 std::cerr << "SVFileReader::readModel: Failed to retrieve file \"" << path.toStdString() << "\" for wave file model: " << file.getErrorString().toStdString() << std::endl; |
421 } else if (!file.isAvailable()) { | 449 } else if (!file.isAvailable()) { |
711 if (isNewLayer) { | 739 if (isNewLayer) { |
712 | 740 |
713 QString name = attributes.value("name"); | 741 QString name = attributes.value("name"); |
714 layer->setObjectName(name); | 742 layer->setObjectName(name); |
715 | 743 |
744 QString presentationName = attributes.value("presentationName"); | |
745 layer->setPresentationName(presentationName); | |
746 | |
716 int modelId; | 747 int modelId; |
717 bool modelOk = false; | 748 bool modelOk = false; |
718 modelId = attributes.value("model").trimmed().toInt(&modelOk); | 749 modelId = attributes.value("model").trimmed().toInt(&modelOk); |
719 | 750 |
720 if (modelOk) { | 751 if (modelOk) { |
991 if (!modelOk) { | 1022 if (!modelOk) { |
992 std::cerr << "WARNING: SV-XML: No model id specified for derivation" << std::endl; | 1023 std::cerr << "WARNING: SV-XML: No model id specified for derivation" << std::endl; |
993 return false; | 1024 return false; |
994 } | 1025 } |
995 | 1026 |
996 QString transform = attributes.value("transform"); | |
997 | |
998 if (haveModel(modelId)) { | 1027 if (haveModel(modelId)) { |
999 m_currentDerivedModel = m_models[modelId]; | 1028 m_currentDerivedModel = m_models[modelId]; |
1000 } else { | 1029 } else { |
1001 // we'll regenerate the model when the derivation element ends | 1030 // we'll regenerate the model when the derivation element ends |
1002 m_currentDerivedModel = 0; | 1031 m_currentDerivedModel = 0; |
1007 int sourceId = 0; | 1036 int sourceId = 0; |
1008 bool sourceOk = false; | 1037 bool sourceOk = false; |
1009 sourceId = attributes.value("source").trimmed().toInt(&sourceOk); | 1038 sourceId = attributes.value("source").trimmed().toInt(&sourceOk); |
1010 | 1039 |
1011 if (sourceOk && haveModel(sourceId)) { | 1040 if (sourceOk && haveModel(sourceId)) { |
1012 m_currentTransformerSource = m_models[sourceId]; | 1041 m_currentTransformSource = m_models[sourceId]; |
1013 } else { | 1042 } else { |
1014 m_currentTransformerSource = m_document->getMainModel(); | 1043 m_currentTransformSource = m_document->getMainModel(); |
1015 } | 1044 } |
1016 | 1045 |
1017 m_currentTransformer = transform; | 1046 m_currentTransform = Transform(); |
1018 m_currentTransformerConfiguration = ""; | |
1019 | |
1020 m_currentTransformerContext = PluginTransformer::ExecutionContext(); | |
1021 | 1047 |
1022 bool ok = false; | 1048 bool ok = false; |
1023 int channel = attributes.value("channel").trimmed().toInt(&ok); | 1049 int channel = attributes.value("channel").trimmed().toInt(&ok); |
1024 if (ok) m_currentTransformerContext.channel = channel; | 1050 if (ok) m_currentTransformChannel = channel; |
1025 | 1051 else m_currentTransformChannel = -1; |
1026 int domain = attributes.value("domain").trimmed().toInt(&ok); | 1052 |
1027 if (ok) m_currentTransformerContext.domain = Vamp::Plugin::InputDomain(domain); | 1053 QString type = attributes.value("type"); |
1054 | |
1055 if (type == "transform") { | |
1056 m_currentTransformIsNewStyle = true; | |
1057 return true; | |
1058 } else { | |
1059 m_currentTransformIsNewStyle = false; | |
1060 std::cerr << "NOTE: SV-XML: Reading old-style derivation element" | |
1061 << std::endl; | |
1062 } | |
1063 | |
1064 QString transformId = attributes.value("transform"); | |
1065 | |
1066 m_currentTransform.setIdentifier(transformId); | |
1028 | 1067 |
1029 int stepSize = attributes.value("stepSize").trimmed().toInt(&ok); | 1068 int stepSize = attributes.value("stepSize").trimmed().toInt(&ok); |
1030 if (ok) m_currentTransformerContext.stepSize = stepSize; | 1069 if (ok) m_currentTransform.setStepSize(stepSize); |
1031 | 1070 |
1032 int blockSize = attributes.value("blockSize").trimmed().toInt(&ok); | 1071 int blockSize = attributes.value("blockSize").trimmed().toInt(&ok); |
1033 if (ok) m_currentTransformerContext.blockSize = blockSize; | 1072 if (ok) m_currentTransform.setBlockSize(blockSize); |
1034 | 1073 |
1035 int windowType = attributes.value("windowType").trimmed().toInt(&ok); | 1074 int windowType = attributes.value("windowType").trimmed().toInt(&ok); |
1036 if (ok) m_currentTransformerContext.windowType = WindowType(windowType); | 1075 if (ok) m_currentTransform.setWindowType(WindowType(windowType)); |
1076 | |
1077 if (!m_currentTransformSource) return true; | |
1037 | 1078 |
1038 QString startFrameStr = attributes.value("startFrame"); | 1079 QString startFrameStr = attributes.value("startFrame"); |
1039 QString durationStr = attributes.value("duration"); | 1080 QString durationStr = attributes.value("duration"); |
1040 | 1081 |
1041 size_t startFrame = 0; | 1082 size_t startFrame = 0; |
1048 if (durationStr != "") { | 1089 if (durationStr != "") { |
1049 duration = durationStr.trimmed().toInt(&ok); | 1090 duration = durationStr.trimmed().toInt(&ok); |
1050 if (!ok) duration = 0; | 1091 if (!ok) duration = 0; |
1051 } | 1092 } |
1052 | 1093 |
1053 m_currentTransformerContext.startFrame = startFrame; | 1094 m_currentTransform.setStartTime |
1054 m_currentTransformerContext.duration = duration; | 1095 (RealTime::frame2RealTime |
1096 (startFrame, m_currentTransformSource->getSampleRate())); | |
1097 | |
1098 m_currentTransform.setDuration | |
1099 (RealTime::frame2RealTime | |
1100 (duration, m_currentTransformSource->getSampleRate())); | |
1055 | 1101 |
1056 return true; | 1102 return true; |
1057 } | 1103 } |
1058 | 1104 |
1059 bool | 1105 bool |
1117 if (m_currentDerivedModelId < 0 && !m_currentPlayParameters) { | 1163 if (m_currentDerivedModelId < 0 && !m_currentPlayParameters) { |
1118 std::cerr << "WARNING: SV-XML: Plugin found outside derivation or play parameters" << std::endl; | 1164 std::cerr << "WARNING: SV-XML: Plugin found outside derivation or play parameters" << std::endl; |
1119 return false; | 1165 return false; |
1120 } | 1166 } |
1121 | 1167 |
1168 if (!m_currentPlayParameters && m_currentTransformIsNewStyle) { | |
1169 return true; | |
1170 } | |
1171 | |
1122 QString configurationXml = "<plugin"; | 1172 QString configurationXml = "<plugin"; |
1123 | 1173 |
1124 for (int i = 0; i < attributes.length(); ++i) { | 1174 for (int i = 0; i < attributes.length(); ++i) { |
1125 configurationXml += QString(" %1=\"%2\"") | 1175 configurationXml += QString(" %1=\"%2\"") |
1126 .arg(attributes.qName(i)) | 1176 .arg(attributes.qName(i)) |
1130 configurationXml += "/>"; | 1180 configurationXml += "/>"; |
1131 | 1181 |
1132 if (m_currentPlayParameters) { | 1182 if (m_currentPlayParameters) { |
1133 m_currentPlayParameters->setPlayPluginConfiguration(configurationXml); | 1183 m_currentPlayParameters->setPlayPluginConfiguration(configurationXml); |
1134 } else { | 1184 } else { |
1135 m_currentTransformerConfiguration += configurationXml; | 1185 TransformFactory::getInstance()-> |
1136 } | 1186 setParametersFromPluginConfigurationXml(m_currentTransform, |
1137 | 1187 configurationXml); |
1188 } | |
1189 | |
1190 return true; | |
1191 } | |
1192 | |
1193 bool | |
1194 SVFileReader::readTransform(const QXmlAttributes &attributes) | |
1195 { | |
1196 if (m_currentDerivedModelId < 0) { | |
1197 std::cerr << "WARNING: SV-XML: Transform found outside derivation" << std::endl; | |
1198 return false; | |
1199 } | |
1200 | |
1201 m_currentTransform = Transform(); | |
1202 m_currentTransform.setFromXmlAttributes(attributes); | |
1203 return true; | |
1204 } | |
1205 | |
1206 bool | |
1207 SVFileReader::readParameter(const QXmlAttributes &attributes) | |
1208 { | |
1209 if (m_currentDerivedModelId < 0) { | |
1210 std::cerr << "WARNING: SV-XML: Parameter found outside derivation" << std::endl; | |
1211 return false; | |
1212 } | |
1213 | |
1214 QString name = attributes.value("name"); | |
1215 if (name == "") { | |
1216 std::cerr << "WARNING: SV-XML: Ignoring nameless transform parameter" | |
1217 << std::endl; | |
1218 return false; | |
1219 } | |
1220 | |
1221 float value = attributes.value("value").trimmed().toFloat(); | |
1222 | |
1223 m_currentTransform.setParameter(name, value); | |
1138 return true; | 1224 return true; |
1139 } | 1225 } |
1140 | 1226 |
1141 bool | 1227 bool |
1142 SVFileReader::readSelection(const QXmlAttributes &attributes) | 1228 SVFileReader::readSelection(const QXmlAttributes &attributes) |