MuseScore/src/appshell/commandlinecontroller.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

89 lines
3 KiB
C++
Raw Normal View History

//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2020 MuseScore BVBA and others
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================
#include "commandlinecontroller.h"
#include "log.h"
using namespace mu::appshell;
using namespace mu::framework;
void CommandLineController::parse(const QStringList& args)
{
// Common
m_parser.addHelpOption(); // -?, -h, --help
m_parser.addVersionOption(); // -v, --version
m_parser.addOption(QCommandLineOption({ "D", "monitor-resolution" }, "Specify monitor resolution", "DPI"));
// Converter mode
2020-12-26 12:57:43 +01:00
m_parser.addOption(QCommandLineOption({ "r", "image-resolution" }, "Set output resolution for image export", "DPI"));
m_parser.addOption(QCommandLineOption({ "j", "job" }, "Process a conversion job", "file"));
m_parser.addOption(QCommandLineOption({ "o", "export-to" }, "Export to 'file'. Format depends on file's extension", "file"));
m_parser.process(args);
}
void CommandLineController::apply()
{
2020-12-26 12:57:43 +01:00
auto floatValue = [this](const QString& name) -> std::optional<float> {
bool ok;
2020-12-26 12:57:43 +01:00
float val = m_parser.value(name).toFloat(&ok);
if (ok) {
2020-12-26 12:57:43 +01:00
return val;
}
2020-12-28 11:52:09 +01:00
return std::nullopt;
2020-12-26 12:57:43 +01:00
};
// Common
if (m_parser.isSet("D")) {
std::optional<float> val = floatValue("D");
if (val) {
uiConfiguration()->setPhysicalDotsPerInch(val);
} else {
2020-12-26 14:12:52 +01:00
LOGE() << "Option: -D not recognized DPI value: " << m_parser.value("D");
}
}
// Converter mode
2020-12-26 12:57:43 +01:00
if (m_parser.isSet("r")) {
std::optional<float> val = floatValue("r");
if (val) {
importexportConfiguration()->setExportPngDpiResolution(val);
2020-12-28 11:52:09 +01:00
} else {
2020-12-26 12:57:43 +01:00
LOGE() << "Option: -r not recognized DPI value: " << m_parser.value("r");
}
}
if (m_parser.isSet("o")) {
application()->setRunMode(IApplication::RunMode::Converter);
m_converterTask.exportFile = m_parser.value("o");
}
if (m_parser.isSet("j")) {
application()->setRunMode(IApplication::RunMode::Converter);
m_converterTask.isBatchMode = true;
m_converterTask.batchJobFile = m_parser.value("j");
}
}
CommandLineController::ConverterTask CommandLineController::converterTask() const
{
return m_converterTask;
}