implemented the --force option

This commit is contained in:
Roman Pudashkin 2021-06-21 15:10:27 +02:00
parent 39711be1b5
commit e84c94196a
8 changed files with 90 additions and 71 deletions

View file

@ -227,35 +227,36 @@ int AppShell::processConverter(const CommandLineController::ConverterTask& task)
{
Ret ret = make_ret(Ret::Code::Ok);
io::path stylePath = task.params[CommandLineController::ParamKey::StylePath].toString();
bool forceMode = task.params[CommandLineController::ParamKey::ForceMode].toBool();
switch (task.type) {
case CommandLineController::ConvertType::Batch:
ret = converter()->batchConvert(task.inputFile, stylePath);
ret = converter()->batchConvert(task.inputFile, stylePath, forceMode);
break;
case CommandLineController::ConvertType::File:
ret = converter()->fileConvert(task.inputFile, task.outputFile, stylePath);
ret = converter()->fileConvert(task.inputFile, task.outputFile, stylePath, forceMode);
break;
case CommandLineController::ConvertType::ExportScoreMedia: {
io::path highlightConfigPath = task.params[CommandLineController::ParamKey::HighlightConfigPath].toString();
ret = converter()->exportScoreMedia(task.inputFile, task.outputFile, highlightConfigPath, stylePath);
ret = converter()->exportScoreMedia(task.inputFile, task.outputFile, highlightConfigPath, stylePath, forceMode);
} break;
case CommandLineController::ConvertType::ExportScoreMeta:
ret = converter()->exportScoreMeta(task.inputFile, task.outputFile, stylePath);
ret = converter()->exportScoreMeta(task.inputFile, task.outputFile, stylePath, forceMode);
break;
case CommandLineController::ConvertType::ExportScoreParts:
ret = converter()->exportScoreParts(task.inputFile, task.outputFile, stylePath);
ret = converter()->exportScoreParts(task.inputFile, task.outputFile, stylePath, forceMode);
break;
case CommandLineController::ConvertType::ExportScorePartsPdf:
ret = converter()->exportScorePartsPdfs(task.inputFile, task.outputFile, stylePath);
ret = converter()->exportScorePartsPdfs(task.inputFile, task.outputFile, stylePath, forceMode);
break;
case CommandLineController::ConvertType::ExportScoreTranspose: {
std::string scoreTranspose = task.params[CommandLineController::ParamKey::ScoreTransposeOptions].toString().toStdString();
ret = converter()->exportScoreTranspose(task.inputFile, task.outputFile, scoreTranspose, stylePath, forceMode);
} break;
case CommandLineController::ConvertType::SourceUpdate: {
std::string scoreSource = task.params[CommandLineController::ParamKey::ScoreSource].toString().toStdString();
ret = converter()->updateSource(task.inputFile, scoreSource);
ret = converter()->updateSource(task.inputFile, scoreSource, forceMode);
} break;
case CommandLineController::ConvertType::ExportScoreTranspose:
std::string scoreTranspose = task.params[CommandLineController::ParamKey::ScoreTransposeOptions].toString().toStdString();
ret = converter()->exportScoreTranspose(task.inputFile, task.outputFile, scoreTranspose, stylePath);
break;
}
if (!ret) {

View file

@ -50,6 +50,7 @@ void CommandLineController::parse(const QStringList& args)
m_parser.addOption(QCommandLineOption({ "o", "export-to" }, "Export to 'file'. Format depends on file's extension", "file"));
m_parser.addOption(QCommandLineOption({ "F", "factory-settings" }, "Use factory settings"));
m_parser.addOption(QCommandLineOption({ "R", "revert-settings" }, "Revert to factory settings, but keep default preferences"));
m_parser.addOption(QCommandLineOption({ "f", "force" }, "Use with '-o <file>', ignore warnings reg. score being corrupted or from wrong version"));
m_parser.addOption(QCommandLineOption("score-media",
"Export all media (excepting mp3) for a given score in a single JSON file and print it to stdout"));
@ -198,6 +199,10 @@ void CommandLineController::apply()
configuration()->revertToFactorySettings(m_parser.isSet("R"));
}
if (m_parser.isSet("f")) {
m_converterTask.params[CommandLineController::ParamKey::ForceMode] = m_parser.value("f");
}
if (m_parser.isSet("S")) {
m_converterTask.params[CommandLineController::ParamKey::StylePath] = m_parser.value("S");
}

View file

@ -59,7 +59,8 @@ public:
HighlightConfigPath,
StylePath,
ScoreSource,
ScoreTransposeOptions
ScoreTransposeOptions,
ForceMode
};
struct ConverterTask {

View file

@ -33,16 +33,18 @@ class IConverterController : MODULE_EXPORT_INTERFACE
public:
virtual ~IConverterController() = default;
virtual Ret fileConvert(const io::path& in, const io::path& out, const io::path& stylePath = io::path()) = 0;
virtual Ret batchConvert(const io::path& batchJobFile, const io::path& stylePath = io::path()) = 0;
virtual Ret fileConvert(const io::path& in, const io::path& out, const io::path& stylePath = io::path(), bool forceMode = false) = 0;
virtual Ret batchConvert(const io::path& batchJobFile, const io::path& stylePath = io::path(), bool forceMode = false) = 0;
virtual Ret exportScoreMedia(const io::path& in, const io::path& out,
const io::path& highlightConfigPath = io::path(), const io::path& stylePath = io::path()) = 0;
virtual Ret exportScoreMeta(const io::path& in, const io::path& out, const io::path& stylePath = io::path()) = 0;
virtual Ret exportScoreParts(const io::path& in, const io::path& out, const io::path& stylePath = io::path()) = 0;
virtual Ret exportScorePartsPdfs(const io::path& in, const io::path& out, const io::path& stylePath = io::path()) = 0;
const io::path& highlightConfigPath = io::path(), const io::path& stylePath = io::path(), bool forceMode = false) = 0;
virtual Ret exportScoreMeta(const io::path& in, const io::path& out, const io::path& stylePath = io::path(), bool forceMode = false) = 0;
virtual Ret exportScoreParts(const io::path& in, const io::path& out, const io::path& stylePath = io::path(), bool forceMode = false) = 0;
virtual Ret exportScorePartsPdfs(const io::path& in, const io::path& out, const io::path& stylePath = io::path(), bool forceMode = false) = 0;
virtual Ret exportScoreTranspose(const io::path& in, const io::path& out, const std::string& optionsJson,
const io::path& stylePath = io::path()) = 0;
virtual Ret updateSource(const io::path& in, const std::string& newSource) = 0;
const io::path& stylePath = io::path(), bool forceMode = false) = 0;
virtual Ret updateSource(const io::path& in, const std::string& newSource, bool forceMode = false) = 0;
};
}

View file

@ -51,13 +51,14 @@ static const std::string MIDI_WRITER_NAME = "midi";
static const std::string MUSICXML_WRITER_NAME = "mxml";
static const std::string META_DATA_NAME = "metadata";
static const bool ADD_SEPARATOR = true;
static constexpr bool ADD_SEPARATOR = true;
static constexpr auto NO_STYLE = "";
Ret BackendApi::exportScoreMedia(const io::path& in, const io::path& out, const io::path& highlightConfigPath, const io::path& stylePath)
Ret BackendApi::exportScoreMedia(const io::path& in, const io::path& out, const io::path& highlightConfigPath, const io::path& stylePath, bool forceMode)
{
TRACEFUNC
RetVal<IMasterNotationPtr> openScoreRetVal = openScore(in, stylePath);
RetVal<IMasterNotationPtr> openScoreRetVal = openScore(in, stylePath, forceMode);
if (!openScoreRetVal.ret) {
return openScoreRetVal.ret;
}
@ -83,11 +84,11 @@ Ret BackendApi::exportScoreMedia(const io::path& in, const io::path& out, const
return result ? make_ret(Ret::Code::Ok) : make_ret(Ret::Code::InternalError);
}
Ret BackendApi::exportScoreMeta(const io::path& in, const io::path& out, const io::path& stylePath)
Ret BackendApi::exportScoreMeta(const io::path& in, const io::path& out, const io::path& stylePath, bool forceMode)
{
TRACEFUNC
RetVal<IMasterNotationPtr> openScoreRetVal = openScore(in, stylePath);
RetVal<IMasterNotationPtr> openScoreRetVal = openScore(in, stylePath, forceMode);
if (!openScoreRetVal.ret) {
return openScoreRetVal.ret;
}
@ -104,11 +105,11 @@ Ret BackendApi::exportScoreMeta(const io::path& in, const io::path& out, const i
return result ? make_ret(Ret::Code::Ok) : make_ret(Ret::Code::InternalError);
}
Ret BackendApi::exportScoreParts(const io::path& in, const io::path& out, const io::path& stylePath)
Ret BackendApi::exportScoreParts(const io::path& in, const io::path& out, const io::path& stylePath, bool forceMode)
{
TRACEFUNC
RetVal<IMasterNotationPtr> openScoreRetVal = openScore(in, stylePath);
RetVal<IMasterNotationPtr> openScoreRetVal = openScore(in, stylePath, forceMode);
if (!openScoreRetVal.ret) {
return openScoreRetVal.ret;
}
@ -125,11 +126,11 @@ Ret BackendApi::exportScoreParts(const io::path& in, const io::path& out, const
return ret;
}
Ret BackendApi::exportScorePartsPdfs(const io::path& in, const io::path& out, const io::path& stylePath)
Ret BackendApi::exportScorePartsPdfs(const io::path& in, const io::path& out, const io::path& stylePath, bool forceMode)
{
TRACEFUNC
RetVal<IMasterNotationPtr> openScoreRetVal = openScore(in, stylePath);
RetVal<IMasterNotationPtr> openScoreRetVal = openScore(in, stylePath, forceMode);
if (!openScoreRetVal.ret) {
return openScoreRetVal.ret;
}
@ -146,11 +147,11 @@ Ret BackendApi::exportScorePartsPdfs(const io::path& in, const io::path& out, co
return ret;
}
Ret BackendApi::exportScoreTranspose(const io::path& in, const io::path& out, const std::string& optionsJson, const io::path& stylePath)
Ret BackendApi::exportScoreTranspose(const io::path& in, const io::path& out, const std::string& optionsJson, const io::path& stylePath, bool forceMode)
{
TRACEFUNC
RetVal<IMasterNotationPtr> openScoreRetVal = openScore(in, stylePath);
RetVal<IMasterNotationPtr> openScoreRetVal = openScore(in, stylePath, forceMode);
if (!openScoreRetVal.ret) {
return openScoreRetVal.ret;
}
@ -184,7 +185,7 @@ Ret BackendApi::openOutputFile(QFile& file, const io::path& out)
return ok ? make_ret(Ret::Code::Ok) : make_ret(Ret::Code::InternalError);
}
RetVal<notation::IMasterNotationPtr> BackendApi::openScore(const io::path& path, const io::path& stylePath)
RetVal<notation::IMasterNotationPtr> BackendApi::openScore(const io::path& path, const io::path& stylePath, bool forceMode)
{
TRACEFUNC
@ -193,7 +194,7 @@ RetVal<notation::IMasterNotationPtr> BackendApi::openScore(const io::path& path,
return make_ret(Ret::Code::InternalError);
}
Ret ret = masterNotation->load(path, stylePath);
Ret ret = masterNotation->load(path, stylePath, forceMode);
if (!ret) {
LOGE() << "failed load: " << path << ", ret: " << ret.toString();
return make_ret(Ret::Code::InternalError);
@ -695,9 +696,9 @@ Ret BackendApi::applyTranspose(const INotationPtr notation, const std::string& o
return ok ? make_ret(Ret::Code::Ok) : make_ret(Ret::Code::InternalError);
}
Ret BackendApi::updateSource(const io::path& in, const std::string& newSource)
Ret BackendApi::updateSource(const io::path& in, const std::string& newSource, bool forceMode)
{
RetVal<IMasterNotationPtr> notation = openScore(in);
RetVal<IMasterNotationPtr> notation = openScore(in, NO_STYLE, forceMode);
if (!notation.ret) {
return notation.ret;
}

View file

@ -45,17 +45,18 @@ class BackendApi
INJECT_STATIC(converter, notation::INotationWritersRegister, writers)
public:
static Ret exportScoreMedia(const io::path& in, const io::path& out, const io::path& highlightConfigPath, const io::path& stylePath);
static Ret exportScoreMeta(const io::path& in, const io::path& out, const io::path& stylePath);
static Ret exportScoreParts(const io::path& in, const io::path& out, const io::path& stylePath);
static Ret exportScorePartsPdfs(const io::path& in, const io::path& out, const io::path& stylePath);
static Ret updateSource(const io::path& in, const std::string& newSource);
static Ret exportScoreTranspose(const io::path& in, const io::path& out, const std::string& optionsJson, const io::path& stylePath);
static Ret exportScoreMedia(const io::path& in, const io::path& out, const io::path& highlightConfigPath, const io::path& stylePath = "", bool forceMode = false);
static Ret exportScoreMeta(const io::path& in, const io::path& out, const io::path& stylePath, bool forceMode = false);
static Ret exportScoreParts(const io::path& in, const io::path& out, const io::path& stylePath, bool forceMode = false);
static Ret exportScorePartsPdfs(const io::path& in, const io::path& out, const io::path& stylePath, bool forceMode = false);
static Ret exportScoreTranspose(const io::path& in, const io::path& out, const std::string& optionsJson, const io::path& stylePath, bool forceMode = false);
static Ret updateSource(const io::path& in, const std::string& newSource, bool forceMode = false);
private:
static Ret openOutputFile(QFile& file, const io::path& out);
static RetVal<notation::IMasterNotationPtr> openScore(const io::path& path, const io::path& stylePath = io::path());
static RetVal<notation::IMasterNotationPtr> openScore(const io::path& path, const io::path& stylePath = io::path(), bool forceMode = false);
static notation::PageList pages(const notation::INotationPtr notation);

View file

@ -34,8 +34,10 @@
using namespace mu::converter;
mu::Ret ConverterController::batchConvert(const io::path& batchJobFile, const io::path& stylePath)
mu::Ret ConverterController::batchConvert(const io::path& batchJobFile, const io::path& stylePath, bool forceMode)
{
TRACEFUNC;
RetVal<BatchJob> batchJob = parseBatchJob(batchJobFile);
if (!batchJob.ret) {
LOGE() << "failed parse batch job file, err: " << batchJob.ret.toString();
@ -44,7 +46,7 @@ mu::Ret ConverterController::batchConvert(const io::path& batchJobFile, const io
Ret ret = make_ret(Ret::Code::Ok);
for (const Job& job : batchJob.val) {
ret = fileConvert(job.in, job.out, stylePath);
ret = fileConvert(job.in, job.out, stylePath, forceMode);
if (!ret) {
LOGE() << "failed convert, err: " << ret.toString() << ", in: " << job.in << ", out: " << job.out;
break;
@ -54,9 +56,10 @@ mu::Ret ConverterController::batchConvert(const io::path& batchJobFile, const io
return ret;
}
mu::Ret ConverterController::fileConvert(const io::path& in, const io::path& out, const io::path& stylePath)
mu::Ret ConverterController::fileConvert(const io::path& in, const io::path& out, const io::path& stylePath, bool forceMode)
{
TRACEFUNC;
LOGI() << "in: " << in << ", out: " << out;
auto masterNotation = notationCreator()->newMasterNotation();
IF_ASSERT_FAILED(masterNotation) {
@ -69,7 +72,7 @@ mu::Ret ConverterController::fileConvert(const io::path& in, const io::path& out
return make_ret(Err::ConvertTypeUnknown);
}
Ret ret = masterNotation->load(in, stylePath);
Ret ret = masterNotation->load(in, stylePath, forceMode);
if (!ret) {
LOGE() << "failed load notation, err: " << ret.toString() << ", path: " << in;
return make_ret(Err::InFileFailedLoad);
@ -93,6 +96,8 @@ mu::Ret ConverterController::fileConvert(const io::path& in, const io::path& out
mu::RetVal<ConverterController::BatchJob> ConverterController::parseBatchJob(const io::path& batchJobFile) const
{
TRACEFUNC;
RetVal<BatchJob> rv;
QFile file(batchJobFile.toQString());
if (!file.open(QIODevice::ReadOnly)) {
@ -127,45 +132,46 @@ mu::RetVal<ConverterController::BatchJob> ConverterController::parseBatchJob(con
}
mu::Ret ConverterController::exportScoreMedia(const mu::io::path& in, const mu::io::path& out, const mu::io::path& highlightConfigPath,
const io::path& stylePath)
const io::path& stylePath, bool forceMode)
{
TRACEFUNC;
return BackendApi::exportScoreMedia(in, out, highlightConfigPath, stylePath);
return BackendApi::exportScoreMedia(in, out, highlightConfigPath, stylePath, forceMode);
}
mu::Ret ConverterController::exportScoreMeta(const mu::io::path& in, const mu::io::path& out, const io::path& stylePath)
mu::Ret ConverterController::exportScoreMeta(const mu::io::path& in, const mu::io::path& out, const io::path& stylePath, bool forceMode)
{
TRACEFUNC;
return BackendApi::exportScoreMeta(in, out, stylePath);
return BackendApi::exportScoreMeta(in, out, stylePath, forceMode);
}
mu::Ret ConverterController::exportScoreParts(const mu::io::path& in, const mu::io::path& out, const io::path& stylePath)
mu::Ret ConverterController::exportScoreParts(const mu::io::path& in, const mu::io::path& out, const io::path& stylePath, bool forceMode)
{
TRACEFUNC;
return BackendApi::exportScoreParts(in, out, stylePath);
return BackendApi::exportScoreParts(in, out, stylePath, forceMode);
}
mu::Ret ConverterController::exportScorePartsPdfs(const mu::io::path& in, const mu::io::path& out, const io::path& stylePath)
mu::Ret ConverterController::exportScorePartsPdfs(const mu::io::path& in, const mu::io::path& out, const io::path& stylePath, bool forceMode)
{
TRACEFUNC;
return BackendApi::exportScorePartsPdfs(in, out, stylePath);
}
mu::Ret ConverterController::updateSource(const io::path& in, const std::string& newSource)
{
TRACEFUNC;
return BackendApi::updateSource(in, newSource);
return BackendApi::exportScorePartsPdfs(in, out, stylePath, forceMode);
}
mu::Ret ConverterController::exportScoreTranspose(const mu::io::path& in, const mu::io::path& out, const std::string& optionsJson,
const io::path& stylePath)
const io::path& stylePath, bool forceMode)
{
TRACEFUNC;
return BackendApi::exportScoreTranspose(in, out, optionsJson, stylePath);
return BackendApi::exportScoreTranspose(in, out, optionsJson, stylePath, forceMode);
}
mu::Ret ConverterController::updateSource(const io::path& in, const std::string& newSource, bool forceMode)
{
TRACEFUNC;
return BackendApi::updateSource(in, newSource, forceMode);
}

View file

@ -41,16 +41,18 @@ class ConverterController : public IConverterController
public:
ConverterController() = default;
Ret fileConvert(const io::path& in, const io::path& out, const io::path& stylePath = io::path()) override;
Ret batchConvert(const io::path& batchJobFile, const io::path& stylePath = io::path()) override;
Ret fileConvert(const io::path& in, const io::path& out, const io::path& stylePath = io::path(), bool forceMode = false) override;
Ret batchConvert(const io::path& batchJobFile, const io::path& stylePath = io::path(), bool forceMode = false) override;
Ret exportScoreMedia(const io::path& in, const io::path& out,
const io::path& highlightConfigPath = io::path(), const io::path& stylePath = io::path()) override;
Ret exportScoreMeta(const io::path& in, const io::path& out, const io::path& stylePath = io::path()) override;
Ret exportScoreParts(const io::path& in, const io::path& out, const io::path& stylePath = io::path()) override;
Ret exportScorePartsPdfs(const io::path& in, const io::path& out, const io::path& stylePath = io::path()) override;
const io::path& highlightConfigPath = io::path(), const io::path& stylePath = io::path(), bool forceMode = false) override;
Ret exportScoreMeta(const io::path& in, const io::path& out, const io::path& stylePath = io::path(), bool forceMode = false) override;
Ret exportScoreParts(const io::path& in, const io::path& out, const io::path& stylePath = io::path(), bool forceMode = false) override;
Ret exportScorePartsPdfs(const io::path& in, const io::path& out, const io::path& stylePath = io::path(), bool forceMode = false) override;
Ret exportScoreTranspose(const io::path& in, const io::path& out, const std::string& optionsJson,
const io::path& stylePath = io::path()) override;
Ret updateSource(const io::path& in, const std::string& newSource) override;
const io::path& stylePath = io::path(), bool forceMode = false) override;
Ret updateSource(const io::path& in, const std::string& newSource, bool forceMode = false) override;
private: