comparison transform/FileFeatureWriter.cpp @ 1013:6370575a812c

Merge
author Chris Cannam
date Mon, 17 Nov 2014 17:10:29 +0000
parents 694301cc71cc
children d74ebd2d2c49
comparison
equal deleted inserted replaced
1012:ee9f4477f65b 1013:6370575a812c
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 }
102 if (m_support & SupportStdOut) {
101 p.name = "stdout"; 103 p.name = "stdout";
102 p.description = "Write all transform results directly to standard output."; 104 p.description = "Write all transform results directly to standard output.";
103 p.hasArg = false; 105 p.hasArg = false;
104 pl.push_back(p); 106 pl.push_back(p);
105 } 107 }
147 m_singleFileName = i->second.c_str(); 149 m_singleFileName = i->second.c_str();
148 // } 150 // }
149 } 151 }
150 } 152 }
151 } else if (i->first == "stdout") { 153 } else if (i->first == "stdout") {
152 if (m_support & SupportOneFileTotal) { 154 if (m_support & SupportStdOut) {
153 if (m_singleFileName != "") { 155 if (m_singleFileName != "") {
154 SVDEBUG << "FileFeatureWriter::setParameters: WARNING: Both stdout and one-file provided, ignoring stdout" << endl; 156 SVDEBUG << "FileFeatureWriter::setParameters: WARNING: Both stdout and one-file provided, ignoring stdout" << endl;
155 } else { 157 } else {
156 m_stdout = true; 158 m_stdout = true;
157 } 159 }
163 } 165 }
164 } 166 }
165 } 167 }
166 168
167 QString 169 QString
168 FileFeatureWriter::getOutputFilename(QString trackId, 170 FileFeatureWriter::createOutputFilename(QString trackId,
169 TransformId transformId) 171 TransformId transformId)
170 { 172 {
171 if (m_singleFileName != "") { 173 if (m_singleFileName != "") {
172 if (QFileInfo(m_singleFileName).exists() && !(m_force || m_append)) { 174 if (QFileInfo(m_singleFileName).exists() && !(m_force || m_append)) {
173 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;
174 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;
175 return ""; 177 return "";
176 } 178 }
177 return m_singleFileName; 179 return m_singleFileName;
178 } 180 }
179 181
180 if (m_stdout) return ""; 182 if (m_stdout) {
183 return "";
184 }
181 185
182 QUrl url(trackId, QUrl::StrictMode); 186 QUrl url(trackId, QUrl::StrictMode);
183 QString scheme = url.scheme().toLower(); 187 QString scheme = url.scheme().toLower();
184 bool local = (scheme == "" || scheme == "file" || scheme.length() == 1); 188 bool local = (scheme == "" || scheme == "file" || scheme.length() == 1);
185 189
233 // subsequent input files (because the file would already exist). 237 // subsequent input files (because the file would already exist).
234 // getOutputFile does the right thing in this case, so we just 238 // getOutputFile does the right thing in this case, so we just
235 // leave it to it 239 // leave it to it
236 if (m_stdout || m_singleFileName != "") return; 240 if (m_stdout || m_singleFileName != "") return;
237 241
238 QString filename = getOutputFilename(trackId, transformId); 242 QString filename = createOutputFilename(trackId, transformId);
239 if (filename == "") { 243 if (filename == "") {
240 throw FailedToOpenOutputStream(trackId, transformId); 244 throw FailedToOpenOutputStream(trackId, transformId);
241 } 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];
242 } 274 }
243 275
244 QFile * 276 QFile *
245 FileFeatureWriter::getOutputFile(QString trackId, 277 FileFeatureWriter::getOutputFile(QString trackId,
246 TransformId transformId) 278 TransformId transformId)
247 { 279 {
248 pair<QString, TransformId> key; 280 TrackTransformPair key = getFilenameKey(trackId, transformId);
249
250 if (m_singleFileName != "") {
251 key = pair<QString, TransformId>("", "");
252 } else if (m_manyFiles) {
253 key = pair<QString, TransformId>(trackId, transformId);
254 } else {
255 key = pair<QString, TransformId>(trackId, "");
256 }
257 281
258 if (m_files.find(key) == m_files.end()) { 282 if (m_files.find(key) == m_files.end()) {
259 283
260 QString filename = getOutputFilename(trackId, transformId); 284 QString filename = createOutputFilename(trackId, transformId);
261 285
262 if (filename == "") { // stdout or failure 286 if (filename == "") { // stdout or failure
263 return 0; 287 return 0;
264 } 288 }
265 289