comparison transform/FileFeatureWriter.cpp @ 999:694301cc71cc

Add MIDI destinations tests and fix feature writer bugs resulting from them
author Chris Cannam
date Tue, 14 Oct 2014 10:07:02 +0100
parents 2104ea2204d2
children d74ebd2d2c49
comparison
equal deleted inserted replaced
998:e25dc8d57565 999:694301cc71cc
73 { 73 {
74 ParameterList pl; 74 ParameterList pl;
75 Parameter p; 75 Parameter p;
76 76
77 p.name = "basedir"; 77 p.name = "basedir";
78 p.description = "Base output directory path. (The default is the same directory as the input file.)"; 78 p.description = "Base output directory path. (The default is the same directory as the input file.) The directory must exist already.";
79 p.hasArg = true; 79 p.hasArg = true;
80 pl.push_back(p); 80 pl.push_back(p);
81 81
82 if (m_support & SupportOneFilePerTrackTransform && 82 if (m_support & SupportOneFilePerTrackTransform &&
83 m_support & SupportOneFilePerTrack) { 83 m_support & SupportOneFilePerTrack) {
84 p.name = "many-files"; 84 p.name = "many-files";
85 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.)"; 85 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.)";
86 p.hasArg = false; 86 p.hasArg = false;
87 pl.push_back(p); 87 pl.push_back(p);
88 } 88 }
89 89
90 if (m_support & SupportOneFileTotal) { 90 if (m_support & SupportOneFileTotal) {
91 if (m_support & ~SupportOneFileTotal) { // not only option 91 if (m_support & ~SupportOneFileTotal) { // not only option
92 p.name = "one-file"; 92 p.name = "one-file";
93 if (m_support & SupportOneFilePerTrack) { 93 if (m_support & SupportOneFilePerTrack) {
94 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.)"; 94 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.)";
95 } else { 95 } else {
96 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.)"; 96 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.)";
97 } 97 }
98 p.hasArg = true; 98 p.hasArg = true;
99 pl.push_back(p); 99 pl.push_back(p);
100 } 100 }
101 } 101 }
165 } 165 }
166 } 166 }
167 } 167 }
168 168
169 QString 169 QString
170 FileFeatureWriter::getOutputFilename(QString trackId, 170 FileFeatureWriter::createOutputFilename(QString trackId,
171 TransformId transformId) 171 TransformId transformId)
172 { 172 {
173 if (m_singleFileName != "") { 173 if (m_singleFileName != "") {
174 if (QFileInfo(m_singleFileName).exists() && !(m_force || m_append)) { 174 if (QFileInfo(m_singleFileName).exists() && !(m_force || m_append)) {
175 cerr << endl << "FileFeatureWriter: ERROR: Specified output file \"" << m_singleFileName << "\" exists and neither --" << getWriterTag() << "-force nor --" << getWriterTag() << "-append flag is specified -- not overwriting" << endl; 175 cerr << endl << "FileFeatureWriter: ERROR: Specified output file \"" << m_singleFileName << "\" exists and neither --" << getWriterTag() << "-force nor --" << getWriterTag() << "-append flag is specified -- not overwriting" << endl;
176 SVDEBUG << "NOTE: To find out how to fix this problem, read the help for the --" << getWriterTag() << "-force" << endl << "and --" << getWriterTag() << "-append options" << endl; 176 SVDEBUG << "NOTE: To find out how to fix this problem, read the help for the --" << getWriterTag() << "-force" << endl << "and --" << getWriterTag() << "-append options" << endl;
177 return ""; 177 return "";
178 } 178 }
179 return m_singleFileName; 179 return m_singleFileName;
180 } 180 }
181 181
182 if (m_stdout) return ""; 182 if (m_stdout) {
183 return "";
184 }
183 185
184 QUrl url(trackId, QUrl::StrictMode); 186 QUrl url(trackId, QUrl::StrictMode);
185 QString scheme = url.scheme().toLower(); 187 QString scheme = url.scheme().toLower();
186 bool local = (scheme == "" || scheme == "file" || scheme.length() == 1); 188 bool local = (scheme == "" || scheme == "file" || scheme.length() == 1);
187 189
235 // subsequent input files (because the file would already exist). 237 // subsequent input files (because the file would already exist).
236 // getOutputFile does the right thing in this case, so we just 238 // getOutputFile does the right thing in this case, so we just
237 // leave it to it 239 // leave it to it
238 if (m_stdout || m_singleFileName != "") return; 240 if (m_stdout || m_singleFileName != "") return;
239 241
240 QString filename = getOutputFilename(trackId, transformId); 242 QString filename = createOutputFilename(trackId, transformId);
241 if (filename == "") { 243 if (filename == "") {
242 throw FailedToOpenOutputStream(trackId, transformId); 244 throw FailedToOpenOutputStream(trackId, transformId);
243 } 245 }
246 }
247
248 FileFeatureWriter::TrackTransformPair
249 FileFeatureWriter::getFilenameKey(QString trackId,
250 TransformId transformId)
251 {
252 TrackTransformPair key;
253
254 if (m_singleFileName != "") {
255 key = TrackTransformPair("", "");
256 } else if (m_manyFiles) {
257 key = TrackTransformPair(trackId, transformId);
258 } else {
259 key = TrackTransformPair(trackId, "");
260 }
261
262 return key;
263 }
264
265 QString
266 FileFeatureWriter::getOutputFilename(QString trackId,
267 TransformId transformId)
268 {
269 TrackTransformPair key = getFilenameKey(trackId, transformId);
270 if (m_filenames.find(key) == m_filenames.end()) {
271 m_filenames[key] = createOutputFilename(trackId, transformId);
272 }
273 return m_filenames[key];
244 } 274 }
245 275
246 QFile * 276 QFile *
247 FileFeatureWriter::getOutputFile(QString trackId, 277 FileFeatureWriter::getOutputFile(QString trackId,
248 TransformId transformId) 278 TransformId transformId)
249 { 279 {
250 pair<QString, TransformId> key; 280 TrackTransformPair key = getFilenameKey(trackId, transformId);
251
252 if (m_singleFileName != "") {
253 key = pair<QString, TransformId>("", "");
254 } else if (m_manyFiles) {
255 key = pair<QString, TransformId>(trackId, transformId);
256 } else {
257 key = pair<QString, TransformId>(trackId, "");
258 }
259 281
260 if (m_files.find(key) == m_files.end()) { 282 if (m_files.find(key) == m_files.end()) {
261 283
262 QString filename = getOutputFilename(trackId, transformId); 284 QString filename = createOutputFilename(trackId, transformId);
263 285
264 if (filename == "") { // stdout or failure 286 if (filename == "") { // stdout or failure
265 return 0; 287 return 0;
266 } 288 }
267 289