Mercurial > hg > sonic-annotator
diff runner/FeatureExtractionManager.cpp @ 109:78a7c77ba432
A more general solution (I hope) to the problem of making sure transforms are always run in a consistent order
author | Chris Cannam |
---|---|
date | Thu, 02 Oct 2014 14:54:09 +0100 |
parents | fae326c22df5 |
children | ca565b18ba3e 74f7ad72fee6 |
line wrap: on
line diff
--- a/runner/FeatureExtractionManager.cpp Thu Oct 02 14:31:47 2014 +0100 +++ b/runner/FeatureExtractionManager.cpp Thu Oct 02 14:54:09 2014 +0100 @@ -350,6 +350,10 @@ plugin = m_transformPluginMap[transform]; } + if (m_plugins.find(plugin) == m_plugins.end()) { + m_orderedPlugins.push_back(plugin); + } + m_plugins[plugin][transform] = writers; return true; @@ -613,12 +617,11 @@ int latestEndFrame = frameCount; bool haveExtents = false; - for (PluginMap::iterator pi = m_plugins.begin(); - pi != m_plugins.end(); ++pi) { + foreach (Plugin *plugin, m_orderedPlugins) { - Plugin *plugin = pi->first; + PluginMap::iterator pi = m_plugins.find(plugin); -// std::cerr << "Calling reset on " << plugin << std::endl; + std::cerr << "Calling reset on " << plugin << std::endl; plugin->reset(); for (TransformWriterMap::iterator ti = pi->second.begin(); @@ -641,6 +644,11 @@ latestEndFrame = startFrame + duration; } + cerr << "startFrame for transform " << startFrame << endl; + cerr << "duration for transform " << duration << endl; + cerr << "earliestStartFrame becomes " << earliestStartFrame << endl; + cerr << "latestEndFrame becomes " << latestEndFrame << endl; + haveExtents = true; string outputId = transform.getOutput().toStdString(); @@ -672,8 +680,9 @@ int startFrame = earliestStartFrame; int endFrame = latestEndFrame; - for (PluginMap::iterator pi = m_plugins.begin(); - pi != m_plugins.end(); ++pi) { + foreach (Plugin *plugin, m_orderedPlugins) { + + PluginMap::iterator pi = m_plugins.find(plugin); for (TransformWriterMap::const_iterator ti = pi->second.begin(); ti != pi->second.end(); ++ti) { @@ -745,10 +754,9 @@ Vamp::RealTime timestamp = Vamp::RealTime::frame2RealTime (i, m_sampleRate); - for (PluginMap::iterator pi = m_plugins.begin(); - pi != m_plugins.end(); ++pi) { + foreach (Plugin *plugin, m_orderedPlugins) { - Plugin *plugin = pi->first; + PluginMap::iterator pi = m_plugins.find(plugin); Plugin::FeatureSet featureSet = plugin->process(data, timestamp); if (!m_summariesOnly) { @@ -765,41 +773,9 @@ lifemgr.destroy(); // deletes reader, data - // In order to ensure our results are written to the output in a - // fixed order (and not one that depends on the pointer value of - // each plugin on the heap in any given run of the program) we - // take the plugins' entries from the plugin map and sort them - // into a new, temporary map that is indexed by the first - // transform for each plugin. We then iterate over than instead of - // over m_plugins in order to get the right ordering. + foreach (Plugin *plugin, m_orderedPlugins) { - // This is not the most elegant way to do this -- it would be more - // elegant to impose an ordering directly on the plugins that are - // used as keys to m_plugins. But the plugin type comes from the - // Vamp SDK, so this change is more localised. - - // Thanks to Matthias for this. - - typedef map<Transform, PluginMap::value_type> OrderedPluginMap; - OrderedPluginMap orderedPlugins; - - for (PluginMap::iterator pi = m_plugins.begin(); - pi != m_plugins.end(); ++pi) { - Transform firstForPlugin = (pi->second).begin()->first; - orderedPlugins.insert(OrderedPluginMap::value_type(firstForPlugin, *pi)); - } - - for (OrderedPluginMap::iterator superPi = orderedPlugins.begin(); - superPi != orderedPlugins.end(); ++superPi) { - - // The value we extract from this map is just the same as the - // value_type we get from iterating over our PluginMap - // directly -- but we happen to get them in the right order - // now because the map iterator is ordered by the Transform - // key type ordering - PluginMap::value_type pi = superPi->second; - - Plugin *plugin = pi.first; + PluginMap::iterator pi = m_plugins.find(plugin); Plugin::FeatureSet featureSet = plugin->getRemainingFeatures(); if (!m_summariesOnly) { @@ -942,8 +918,9 @@ void FeatureExtractionManager::finish() { - for (PluginMap::iterator pi = m_plugins.begin(); - pi != m_plugins.end(); ++pi) { + foreach (Plugin *plugin, m_orderedPlugins) { + + PluginMap::iterator pi = m_plugins.find(plugin); for (TransformWriterMap::iterator ti = pi->second.begin(); ti != pi->second.end(); ++ti) {