Mercurial > hg > sonic-annotator
comparison runner/FeatureExtractionManager.cpp @ 112:0c2d8c945bbf multiplex
Merge from default branch
author | Chris Cannam |
---|---|
date | Thu, 02 Oct 2014 15:23:25 +0100 |
parents | ca565b18ba3e 74f7ad72fee6 |
children | 297f9e415e39 |
comparison
equal
deleted
inserted
replaced
110:ca565b18ba3e | 112:0c2d8c945bbf |
---|---|
39 using Vamp::HostExt::PluginWrapper; | 39 using Vamp::HostExt::PluginWrapper; |
40 | 40 |
41 #include "data/fileio/FileSource.h" | 41 #include "data/fileio/FileSource.h" |
42 #include "data/fileio/AudioFileReader.h" | 42 #include "data/fileio/AudioFileReader.h" |
43 #include "data/fileio/AudioFileReaderFactory.h" | 43 #include "data/fileio/AudioFileReaderFactory.h" |
44 #include "data/fileio/PlaylistFileReader.h" | |
45 #include "base/TempDirectory.h" | 44 #include "base/TempDirectory.h" |
46 #include "base/ProgressPrinter.h" | 45 #include "base/ProgressPrinter.h" |
47 #include "transform/TransformFactory.h" | 46 #include "transform/TransformFactory.h" |
48 #include "rdf/RDFTransformFactory.h" | 47 #include "rdf/RDFTransformFactory.h" |
49 #include "transform/FeatureWriter.h" | 48 #include "transform/FeatureWriter.h" |
433 return addFeatureExtractor(transform, writers); | 432 return addFeatureExtractor(transform, writers); |
434 } | 433 } |
435 | 434 |
436 void FeatureExtractionManager::addSource(QString audioSource, bool willMultiplex) | 435 void FeatureExtractionManager::addSource(QString audioSource, bool willMultiplex) |
437 { | 436 { |
438 if (QFileInfo(audioSource).suffix().toLower() == "m3u") { | |
439 ProgressPrinter retrievalProgress("Opening playlist file..."); | |
440 FileSource source(audioSource, &retrievalProgress); | |
441 if (!source.isAvailable()) { | |
442 cerr << "ERROR: File or URL \"" << audioSource.toStdString() | |
443 << "\" could not be located" << endl; | |
444 throw FileNotFound(audioSource); | |
445 } | |
446 source.waitForData(); | |
447 PlaylistFileReader reader(source); | |
448 if (reader.isOK()) { | |
449 vector<QString> files = reader.load(); | |
450 for (int i = 0; i < (int)files.size(); ++i) { | |
451 addSource(files[i], willMultiplex); | |
452 } | |
453 return; | |
454 } else { | |
455 cerr << "ERROR: Playlist \"" << audioSource.toStdString() | |
456 << "\" could not be opened" << endl; | |
457 throw FileNotFound(audioSource); | |
458 } | |
459 } | |
460 | |
461 std::cerr << "Have audio source: \"" << audioSource.toStdString() << "\"" << std::endl; | 437 std::cerr << "Have audio source: \"" << audioSource.toStdString() << "\"" << std::endl; |
462 | 438 |
463 // We don't actually do anything with it here, unless it's the | 439 // We don't actually do anything with it here, unless it's the |
464 // first audio source and we need it to establish default channel | 440 // first audio source and we need it to establish default channel |
465 // count and sample rate | 441 // count and sample rate |
511 | 487 |
512 m_readyReaders[audioSource] = reader; | 488 m_readyReaders[audioSource] = reader; |
513 } | 489 } |
514 } | 490 } |
515 | 491 |
516 void FeatureExtractionManager::extractFeatures(QString audioSource, bool force) | 492 void FeatureExtractionManager::extractFeatures(QString audioSource) |
517 { | 493 { |
518 if (m_plugins.empty()) return; | 494 if (m_plugins.empty()) return; |
519 | |
520 if (QFileInfo(audioSource).suffix().toLower() == "m3u") { | |
521 //!!! This shouldn't happen here, it should be done in | |
522 //!!! main.cpp when assembling the sources list | |
523 FileSource source(audioSource); | |
524 PlaylistFileReader reader(source); | |
525 if (reader.isOK()) { | |
526 vector<QString> files = reader.load(); | |
527 for (int i = 0; i < (int)files.size(); ++i) { | |
528 try { | |
529 extractFeatures(files[i], force); | |
530 } catch (const std::exception &e) { | |
531 if (!force) throw; | |
532 cerr << "ERROR: Feature extraction failed for playlist entry \"" | |
533 << files[i].toStdString() | |
534 << "\": " << e.what() << endl; | |
535 // print a note only if we have more files to process | |
536 if (++i != (int)files.size()) { | |
537 cerr << "NOTE: \"--force\" option was provided, continuing (more errors may occur)" << endl; | |
538 } | |
539 } | |
540 } | |
541 return; | |
542 } else { | |
543 cerr << "ERROR: Playlist \"" << audioSource.toStdString() | |
544 << "\" could not be opened" << endl; | |
545 throw FileNotFound(audioSource); | |
546 } | |
547 } | |
548 | 495 |
549 testOutputFiles(audioSource); | 496 testOutputFiles(audioSource); |
550 | 497 |
551 if (m_sampleRate == 0) { | 498 if (m_sampleRate == 0) { |
552 throw FileOperationFailed | 499 throw FileOperationFailed |