Mercurial > hg > svapp
comparison framework/SVFileReader.cpp @ 101:89a689720ee9 spectrogram-cache-rejig
* Merge from trunk
author | Chris Cannam |
---|---|
date | Wed, 27 Feb 2008 11:59:42 +0000 |
parents | de2b3c6479c8 |
children |
comparison
equal
deleted
inserted
replaced
59:bf1a53489ccc | 101:89a689720ee9 |
---|---|
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) { |
849 float value = 0.0; | 880 float value = 0.0; |
850 value = attributes.value("value").trimmed().toFloat(&ok); | 881 value = attributes.value("value").trimmed().toFloat(&ok); |
851 size_t duration = 0; | 882 size_t duration = 0; |
852 duration = attributes.value("duration").trimmed().toUInt(&ok); | 883 duration = attributes.value("duration").trimmed().toUInt(&ok); |
853 QString label = attributes.value("label"); | 884 QString label = attributes.value("label"); |
854 nm->addPoint(NoteModel::Point(frame, value, duration, label)); | 885 float level = attributes.value("level").trimmed().toFloat(&ok); |
886 if (!ok) { // level is optional | |
887 level = 1.f; | |
888 ok = true; | |
889 } | |
890 nm->addPoint(NoteModel::Point(frame, value, duration, level, label)); | |
855 return ok; | 891 return ok; |
856 } | 892 } |
857 | 893 |
858 TextModel *tm = dynamic_cast<TextModel *>(m_currentDataset); | 894 TextModel *tm = dynamic_cast<TextModel *>(m_currentDataset); |
859 | 895 |
986 if (!modelOk) { | 1022 if (!modelOk) { |
987 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; |
988 return false; | 1024 return false; |
989 } | 1025 } |
990 | 1026 |
991 QString transform = attributes.value("transform"); | |
992 | |
993 if (haveModel(modelId)) { | 1027 if (haveModel(modelId)) { |
994 m_currentDerivedModel = m_models[modelId]; | 1028 m_currentDerivedModel = m_models[modelId]; |
995 } else { | 1029 } else { |
996 // we'll regenerate the model when the derivation element ends | 1030 // we'll regenerate the model when the derivation element ends |
997 m_currentDerivedModel = 0; | 1031 m_currentDerivedModel = 0; |
1002 int sourceId = 0; | 1036 int sourceId = 0; |
1003 bool sourceOk = false; | 1037 bool sourceOk = false; |
1004 sourceId = attributes.value("source").trimmed().toInt(&sourceOk); | 1038 sourceId = attributes.value("source").trimmed().toInt(&sourceOk); |
1005 | 1039 |
1006 if (sourceOk && haveModel(sourceId)) { | 1040 if (sourceOk && haveModel(sourceId)) { |
1007 m_currentTransformerSource = m_models[sourceId]; | 1041 m_currentTransformSource = m_models[sourceId]; |
1008 } else { | 1042 } else { |
1009 m_currentTransformerSource = m_document->getMainModel(); | 1043 m_currentTransformSource = m_document->getMainModel(); |
1010 } | 1044 } |
1011 | 1045 |
1012 m_currentTransformer = transform; | 1046 m_currentTransform = Transform(); |
1013 m_currentTransformerConfiguration = ""; | |
1014 | |
1015 m_currentTransformerContext = PluginTransformer::ExecutionContext(); | |
1016 | 1047 |
1017 bool ok = false; | 1048 bool ok = false; |
1018 int channel = attributes.value("channel").trimmed().toInt(&ok); | 1049 int channel = attributes.value("channel").trimmed().toInt(&ok); |
1019 if (ok) m_currentTransformerContext.channel = channel; | 1050 if (ok) m_currentTransformChannel = channel; |
1020 | 1051 else m_currentTransformChannel = -1; |
1021 int domain = attributes.value("domain").trimmed().toInt(&ok); | 1052 |
1022 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); | |
1023 | 1067 |
1024 int stepSize = attributes.value("stepSize").trimmed().toInt(&ok); | 1068 int stepSize = attributes.value("stepSize").trimmed().toInt(&ok); |
1025 if (ok) m_currentTransformerContext.stepSize = stepSize; | 1069 if (ok) m_currentTransform.setStepSize(stepSize); |
1026 | 1070 |
1027 int blockSize = attributes.value("blockSize").trimmed().toInt(&ok); | 1071 int blockSize = attributes.value("blockSize").trimmed().toInt(&ok); |
1028 if (ok) m_currentTransformerContext.blockSize = blockSize; | 1072 if (ok) m_currentTransform.setBlockSize(blockSize); |
1029 | 1073 |
1030 int windowType = attributes.value("windowType").trimmed().toInt(&ok); | 1074 int windowType = attributes.value("windowType").trimmed().toInt(&ok); |
1031 if (ok) m_currentTransformerContext.windowType = WindowType(windowType); | 1075 if (ok) m_currentTransform.setWindowType(WindowType(windowType)); |
1076 | |
1077 if (!m_currentTransformSource) return true; | |
1032 | 1078 |
1033 QString startFrameStr = attributes.value("startFrame"); | 1079 QString startFrameStr = attributes.value("startFrame"); |
1034 QString durationStr = attributes.value("duration"); | 1080 QString durationStr = attributes.value("duration"); |
1035 | 1081 |
1036 size_t startFrame = 0; | 1082 size_t startFrame = 0; |
1043 if (durationStr != "") { | 1089 if (durationStr != "") { |
1044 duration = durationStr.trimmed().toInt(&ok); | 1090 duration = durationStr.trimmed().toInt(&ok); |
1045 if (!ok) duration = 0; | 1091 if (!ok) duration = 0; |
1046 } | 1092 } |
1047 | 1093 |
1048 m_currentTransformerContext.startFrame = startFrame; | 1094 m_currentTransform.setStartTime |
1049 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())); | |
1050 | 1101 |
1051 return true; | 1102 return true; |
1052 } | 1103 } |
1053 | 1104 |
1054 bool | 1105 bool |
1112 if (m_currentDerivedModelId < 0 && !m_currentPlayParameters) { | 1163 if (m_currentDerivedModelId < 0 && !m_currentPlayParameters) { |
1113 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; |
1114 return false; | 1165 return false; |
1115 } | 1166 } |
1116 | 1167 |
1168 if (!m_currentPlayParameters && m_currentTransformIsNewStyle) { | |
1169 return true; | |
1170 } | |
1171 | |
1117 QString configurationXml = "<plugin"; | 1172 QString configurationXml = "<plugin"; |
1118 | 1173 |
1119 for (int i = 0; i < attributes.length(); ++i) { | 1174 for (int i = 0; i < attributes.length(); ++i) { |
1120 configurationXml += QString(" %1=\"%2\"") | 1175 configurationXml += QString(" %1=\"%2\"") |
1121 .arg(attributes.qName(i)) | 1176 .arg(attributes.qName(i)) |
1125 configurationXml += "/>"; | 1180 configurationXml += "/>"; |
1126 | 1181 |
1127 if (m_currentPlayParameters) { | 1182 if (m_currentPlayParameters) { |
1128 m_currentPlayParameters->setPlayPluginConfiguration(configurationXml); | 1183 m_currentPlayParameters->setPlayPluginConfiguration(configurationXml); |
1129 } else { | 1184 } else { |
1130 m_currentTransformerConfiguration += configurationXml; | 1185 TransformFactory::getInstance()-> |
1131 } | 1186 setParametersFromPluginConfigurationXml(m_currentTransform, |
1132 | 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); | |
1133 return true; | 1224 return true; |
1134 } | 1225 } |
1135 | 1226 |
1136 bool | 1227 bool |
1137 SVFileReader::readSelection(const QXmlAttributes &attributes) | 1228 SVFileReader::readSelection(const QXmlAttributes &attributes) |