# HG changeset patch # User Chris Cannam # Date 1413277622 -3600 # Node ID 694301cc71ccb10c8cc5a729c9ffb861891589c2 # Parent e25dc8d575656f0409233b29a3f621eb225bbd52 Add MIDI destinations tests and fix feature writer bugs resulting from them diff -r e25dc8d57565 -r 694301cc71cc transform/FileFeatureWriter.cpp --- a/transform/FileFeatureWriter.cpp Mon Oct 13 14:44:51 2014 +0100 +++ b/transform/FileFeatureWriter.cpp Tue Oct 14 10:07:02 2014 +0100 @@ -75,14 +75,14 @@ Parameter p; p.name = "basedir"; - p.description = "Base output directory path. (The default is the same directory as the input file.)"; + p.description = "Base output directory path. (The default is the same directory as the input file.) The directory must exist already."; p.hasArg = true; pl.push_back(p); if (m_support & SupportOneFilePerTrackTransform && m_support & SupportOneFilePerTrack) { p.name = "many-files"; - p.description = "Create a separate output file for every combination of input file and transform. The output file names will be based on the input file names. (The default is to create one output file per input audio file, and write all transform results for that input into it.)"; + p.description = "Create a separate output file for every combination of input file and transform. The output file names will be based on the input file names. (The default is to create one output file per input audio file, and write all transform results for that input into it.)"; p.hasArg = false; pl.push_back(p); } @@ -91,9 +91,9 @@ if (m_support & ~SupportOneFileTotal) { // not only option p.name = "one-file"; if (m_support & SupportOneFilePerTrack) { - p.description = "Write all transform results for all input files into the single named output file. (The default is to create one output file per input audio file, and write all transform results for that input into it.)"; + p.description = "Write all transform results for all input files into the single named output file. (The default is to create one output file per input audio file, and write all transform results for that input into it.)"; } else { - p.description = "Write all transform results for all input files into the single named output file. (The default is to create a separate output file for each combination of input audio file and transform.)"; + p.description = "Write all transform results for all input files into the single named output file. (The default is to create a separate output file for each combination of input audio file and transform.)"; } p.hasArg = true; pl.push_back(p); @@ -167,8 +167,8 @@ } QString -FileFeatureWriter::getOutputFilename(QString trackId, - TransformId transformId) +FileFeatureWriter::createOutputFilename(QString trackId, + TransformId transformId) { if (m_singleFileName != "") { if (QFileInfo(m_singleFileName).exists() && !(m_force || m_append)) { @@ -179,7 +179,9 @@ return m_singleFileName; } - if (m_stdout) return ""; + if (m_stdout) { + return ""; + } QUrl url(trackId, QUrl::StrictMode); QString scheme = url.scheme().toLower(); @@ -237,29 +239,49 @@ // leave it to it if (m_stdout || m_singleFileName != "") return; - QString filename = getOutputFilename(trackId, transformId); + QString filename = createOutputFilename(trackId, transformId); if (filename == "") { throw FailedToOpenOutputStream(trackId, transformId); } } +FileFeatureWriter::TrackTransformPair +FileFeatureWriter::getFilenameKey(QString trackId, + TransformId transformId) +{ + TrackTransformPair key; + + if (m_singleFileName != "") { + key = TrackTransformPair("", ""); + } else if (m_manyFiles) { + key = TrackTransformPair(trackId, transformId); + } else { + key = TrackTransformPair(trackId, ""); + } + + return key; +} + +QString +FileFeatureWriter::getOutputFilename(QString trackId, + TransformId transformId) +{ + TrackTransformPair key = getFilenameKey(trackId, transformId); + if (m_filenames.find(key) == m_filenames.end()) { + m_filenames[key] = createOutputFilename(trackId, transformId); + } + return m_filenames[key]; +} + QFile * FileFeatureWriter::getOutputFile(QString trackId, TransformId transformId) { - pair key; - - if (m_singleFileName != "") { - key = pair("", ""); - } else if (m_manyFiles) { - key = pair(trackId, transformId); - } else { - key = pair(trackId, ""); - } + TrackTransformPair key = getFilenameKey(trackId, transformId); if (m_files.find(key) == m_files.end()) { - QString filename = getOutputFilename(trackId, transformId); + QString filename = createOutputFilename(trackId, transformId); if (filename == "") { // stdout or failure return 0; diff -r e25dc8d57565 -r 694301cc71cc transform/FileFeatureWriter.h --- a/transform/FileFeatureWriter.h Mon Oct 13 14:44:51 2014 +0100 +++ b/transform/FileFeatureWriter.h Tue Oct 14 10:07:02 2014 +0100 @@ -58,13 +58,26 @@ QTextStream *getOutputStream(QString, TransformId); typedef pair TrackTransformPair; + typedef map FileNameMap; typedef map FileMap; typedef map FileStreamMap; FileMap m_files; + FileNameMap m_filenames; FileStreamMap m_streams; QTextStream *m_prevstream; + TrackTransformPair getFilenameKey(QString, TransformId); + + // Come up with a suitable output filename for the given track ID - + // transform ID combo. Fail if it already exists, etc. + QString createOutputFilename(QString, TransformId); + + // Look up and return the output filename for the given track ID - + // transform ID combo. QString getOutputFilename(QString, TransformId); + + // Look up and return the output file handle for the given track + // ID - transform ID combo. Return 0 if it could not be opened. QFile *getOutputFile(QString, TransformId); // subclass can implement this to be called before file is opened for append