Added --quiet mode
This commit is contained in:
parent
fa0aff0012
commit
14969afab7
|
@ -25,7 +25,7 @@ unique_ptr<AudioClip> createWaveAudioClip(path filePath) {
|
||||||
try {
|
try {
|
||||||
return std::make_unique<WaveFileReader>(filePath);
|
return std::make_unique<WaveFileReader>(filePath);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
std::throw_with_nested(std::runtime_error(fmt::format("Could not open sound file '{0}'.", filePath.string())));
|
std::throw_with_nested(std::runtime_error(fmt::format("Could not open sound file {}.", filePath)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
39
src/main.cpp
39
src/main.cpp
|
@ -20,6 +20,8 @@
|
||||||
#include "TsvExporter.h"
|
#include "TsvExporter.h"
|
||||||
#include "XmlExporter.h"
|
#include "XmlExporter.h"
|
||||||
#include "JsonExporter.h"
|
#include "JsonExporter.h"
|
||||||
|
#include <boost/iostreams/stream.hpp>
|
||||||
|
#include <boost/iostreams/device/null.hpp>
|
||||||
|
|
||||||
using std::exception;
|
using std::exception;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
@ -80,10 +82,8 @@ unique_ptr<Exporter> createExporter(ExportFormat exportFormat) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
#ifdef _DEBUG
|
|
||||||
auto pausableStderrSink = addPausableStdErrSink(logging::Level::Warn);
|
auto pausableStderrSink = addPausableStdErrSink(logging::Level::Warn);
|
||||||
pausableStderrSink->pause();
|
pausableStderrSink->pause();
|
||||||
#endif
|
|
||||||
|
|
||||||
// Define command-line parameters
|
// Define command-line parameters
|
||||||
const char argumentValueSeparator = ' ';
|
const char argumentValueSeparator = ' ';
|
||||||
|
@ -94,6 +94,7 @@ int main(int argc, char *argv[]) {
|
||||||
tclap::ValuesConstraint<logging::Level> logLevelConstraint(logLevels);
|
tclap::ValuesConstraint<logging::Level> logLevelConstraint(logLevels);
|
||||||
tclap::ValueArg<logging::Level> logLevel("", "logLevel", "The minimum log level to log", false, logging::Level::Debug, &logLevelConstraint, cmd);
|
tclap::ValueArg<logging::Level> logLevel("", "logLevel", "The minimum log level to log", false, logging::Level::Debug, &logLevelConstraint, cmd);
|
||||||
tclap::ValueArg<string> logFileName("", "logFile", "The log file path.", false, string(), "string", cmd);
|
tclap::ValueArg<string> logFileName("", "logFile", "The log file path.", false, string(), "string", cmd);
|
||||||
|
tclap::SwitchArg quietMode("q", "quiet", "Suppresses all output to stderr except for error messages.", cmd, false);
|
||||||
tclap::ValueArg<int> maxThreadCount("", "threads", "The maximum number of worker threads to use.", false, getProcessorCoreCount(), "number", cmd);
|
tclap::ValueArg<int> maxThreadCount("", "threads", "The maximum number of worker threads to use.", false, getProcessorCoreCount(), "number", cmd);
|
||||||
tclap::ValueArg<string> dialogFile("d", "dialogFile", "A file containing the text of the dialog.", false, string(), "string", cmd);
|
tclap::ValueArg<string> dialogFile("d", "dialogFile", "A file containing the text of the dialog.", false, string(), "string", cmd);
|
||||||
auto exportFormats = vector<ExportFormat>(ExportFormatConverter::get().getValues());
|
auto exportFormats = vector<ExportFormat>(ExportFormatConverter::get().getValues());
|
||||||
|
@ -101,20 +102,24 @@ int main(int argc, char *argv[]) {
|
||||||
tclap::ValueArg<ExportFormat> exportFormat("f", "exportFormat", "The export format.", false, ExportFormat::Tsv, &exportFormatConstraint, cmd);
|
tclap::ValueArg<ExportFormat> exportFormat("f", "exportFormat", "The export format.", false, ExportFormat::Tsv, &exportFormatConstraint, cmd);
|
||||||
tclap::UnlabeledValueArg<string> inputFileName("inputFile", "The input file. Must be a sound file in WAVE format.", true, "", "string", cmd);
|
tclap::UnlabeledValueArg<string> inputFileName("inputFile", "The input file. Must be a sound file in WAVE format.", true, "", "string", cmd);
|
||||||
|
|
||||||
|
std::ostream* infoStream = &std::cerr;
|
||||||
|
boost::iostreams::stream<boost::iostreams::null_sink> nullStream((boost::iostreams::null_sink()));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto resumeLogging = gsl::finally([&]() {
|
auto resumeLogging = gsl::finally([&]() {
|
||||||
std::cerr << std::endl << std::endl;
|
*infoStream << std::endl << std::endl;
|
||||||
#ifdef _DEBUG
|
|
||||||
pausableStderrSink->resume();
|
pausableStderrSink->resume();
|
||||||
#endif
|
|
||||||
std::cerr << std::endl;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Parse command line
|
// Parse command line
|
||||||
cmd.parse(argc, argv);
|
cmd.parse(argc, argv);
|
||||||
|
if (quietMode.getValue()) {
|
||||||
|
infoStream = &nullStream;
|
||||||
|
}
|
||||||
if (maxThreadCount.getValue() < 1) {
|
if (maxThreadCount.getValue() < 1) {
|
||||||
throw std::runtime_error("Thread count must be 1 or higher.");
|
throw std::runtime_error("Thread count must be 1 or higher.");
|
||||||
}
|
}
|
||||||
|
path inputFilePath(inputFileName.getValue());
|
||||||
|
|
||||||
// Set up log file
|
// Set up log file
|
||||||
if (logFileName.isSet()) {
|
if (logFileName.isSet()) {
|
||||||
|
@ -124,43 +129,45 @@ int main(int argc, char *argv[]) {
|
||||||
logging::infoFormat("Application startup. Command line: {}", join(
|
logging::infoFormat("Application startup. Command line: {}", join(
|
||||||
vector<char*>(argv, argv + argc) | transformed([](char* arg) { return fmt::format("\"{}\"", arg); }), " "));
|
vector<char*>(argv, argv + argc) | transformed([](char* arg) { return fmt::format("\"{}\"", arg); }), " "));
|
||||||
|
|
||||||
std::cerr << "Processing input file. ";
|
try {
|
||||||
|
*infoStream << fmt::format("Generating lip-sync data for {}.", inputFilePath) << std::endl;
|
||||||
|
*infoStream << "Processing. ";
|
||||||
JoiningContinuousTimeline<Shape> animation(TimeRange::zero(), Shape::X);
|
JoiningContinuousTimeline<Shape> animation(TimeRange::zero(), Shape::X);
|
||||||
{
|
{
|
||||||
ProgressBar progressBar;
|
ProgressBar progressBar(*infoStream);
|
||||||
|
|
||||||
// Animate the recording
|
// Animate the recording
|
||||||
animation = animateWaveFile(
|
animation = animateWaveFile(
|
||||||
inputFileName.getValue(),
|
inputFilePath,
|
||||||
dialogFile.isSet() ? readUtf8File(path(dialogFile.getValue())) : boost::optional<u32string>(),
|
dialogFile.isSet() ? readUtf8File(path(dialogFile.getValue())) : boost::optional<u32string>(),
|
||||||
maxThreadCount.getValue(),
|
maxThreadCount.getValue(),
|
||||||
progressBar);
|
progressBar);
|
||||||
}
|
}
|
||||||
std::cerr << "Done." << std::endl << std::endl;
|
*infoStream << "Done." << std::endl << std::endl;
|
||||||
|
|
||||||
// Export animation
|
// Export animation
|
||||||
unique_ptr<Exporter> exporter = createExporter(exportFormat.getValue());
|
unique_ptr<Exporter> exporter = createExporter(exportFormat.getValue());
|
||||||
exporter->exportShapes(path(inputFileName.getValue()), animation, std::cout);
|
exporter->exportShapes(inputFilePath, animation, std::cout);
|
||||||
|
|
||||||
logging::info("Exiting application normally.");
|
logging::info("Exiting application normally.");
|
||||||
|
} catch (...) {
|
||||||
|
std::throw_with_nested(std::runtime_error(fmt::format("Error processing file {}.", inputFilePath)));
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} catch (tclap::ArgException& e) {
|
} catch (tclap::ArgException& e) {
|
||||||
// Error parsing command-line args.
|
// Error parsing command-line args.
|
||||||
cmd.getOutput()->failure(cmd, e);
|
cmd.getOutput()->failure(cmd, e);
|
||||||
std::cerr << std::endl;
|
logging::error("Invalid command line. Exiting application.");
|
||||||
logging::error("Invalid command line. Exiting application with error code.");
|
|
||||||
return 1;
|
return 1;
|
||||||
} catch (tclap::ExitException&) {
|
} catch (tclap::ExitException&) {
|
||||||
// A built-in TCLAP command (like --help) has finished. Exit application.
|
// A built-in TCLAP command (like --help) has finished. Exit application.
|
||||||
std::cerr << std::endl;
|
|
||||||
logging::info("Exiting application after help-like command.");
|
logging::info("Exiting application after help-like command.");
|
||||||
return 0;
|
return 0;
|
||||||
} catch (const exception& e) {
|
} catch (const exception& e) {
|
||||||
// Generic error
|
// Generic error
|
||||||
string message = getMessage(e);
|
string message = getMessage(e);
|
||||||
std::cerr << "An error occurred.\n" << message << std::endl;
|
logging::fatalFormat("Exiting application with error:\n{}", message);
|
||||||
logging::errorFormat("Exiting application with error: {}", message);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,9 @@ void ProgressMerger::report() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ProgressBar::ProgressBar() {
|
ProgressBar::ProgressBar(std::ostream& stream) :
|
||||||
|
stream(stream)
|
||||||
|
{
|
||||||
updateLoopFuture = std::async(std::launch::async, &ProgressBar::updateLoop, this);
|
updateLoopFuture = std::async(std::launch::async, &ProgressBar::updateLoop, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,6 +110,6 @@ void ProgressBar::updateText(const string& text) {
|
||||||
output.append(overlapCount, '\b');
|
output.append(overlapCount, '\b');
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cerr << output;
|
stream << output;
|
||||||
currentText = text;
|
currentText = text;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
class ProgressSink {
|
class ProgressSink {
|
||||||
public:
|
public:
|
||||||
|
@ -43,7 +44,7 @@ private:
|
||||||
|
|
||||||
class ProgressBar : public ProgressSink {
|
class ProgressBar : public ProgressSink {
|
||||||
public:
|
public:
|
||||||
ProgressBar();
|
ProgressBar(std::ostream& stream = std::cerr);
|
||||||
~ProgressBar();
|
~ProgressBar();
|
||||||
void reportProgress(double value) override;
|
void reportProgress(double value) override;
|
||||||
|
|
||||||
|
@ -55,6 +56,7 @@ private:
|
||||||
std::atomic<double> currentProgress { 0 };
|
std::atomic<double> currentProgress { 0 };
|
||||||
std::atomic<bool> done { false };
|
std::atomic<bool> done { false };
|
||||||
|
|
||||||
|
std::ostream& stream;
|
||||||
std::string currentText;
|
std::string currentText;
|
||||||
int animationIndex = 0;
|
int animationIndex = 0;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue