implemented --trim-image and --score-update options
This commit is contained in:
parent
ddc211d8c3
commit
35c3e5fdd2
|
@ -229,6 +229,7 @@ int AppShell::processConverter(const CommandLineController::ConverterTask& task)
|
|||
|
||||
io::path highlightConfigPath = task.params[CommandLineController::ParamKey::HighlightConfigPath].toString();
|
||||
io::path stylePath = task.params[CommandLineController::ParamKey::StylePath].toString();
|
||||
QString scoreSource = task.params[CommandLineController::ParamKey::ScoreSource].toString();
|
||||
|
||||
switch (task.type) {
|
||||
case CommandLineController::ConvertType::Batch:
|
||||
|
@ -249,6 +250,9 @@ int AppShell::processConverter(const CommandLineController::ConverterTask& task)
|
|||
case CommandLineController::ConvertType::ExportScorePartsPdf:
|
||||
ret = converter()->exportScorePartsPdfs(task.inputFile, task.outputFile, stylePath);
|
||||
break;
|
||||
case CommandLineController::ConvertType::SourceUpdate:
|
||||
ret = converter()->updateSource(task.inputFile, scoreSource);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
|
|
|
@ -40,6 +40,7 @@ void CommandLineController::parse(const QStringList& args)
|
|||
m_parser.addOption(QCommandLineOption({ "d", "debug" }, "Debug mode"));
|
||||
|
||||
m_parser.addOption(QCommandLineOption({ "D", "monitor-resolution" }, "Specify monitor resolution", "DPI"));
|
||||
m_parser.addOption(QCommandLineOption({ "T", "trim-image" }, "Use with '-o <file>.png' and '-o <file.svg>'. Trim exported image with specified margin (in pixels)", "margin"));
|
||||
|
||||
// Converter mode
|
||||
m_parser.addOption(QCommandLineOption({ "r", "image-resolution" }, "Set output resolution for image export", "DPI"));
|
||||
|
@ -55,7 +56,9 @@ void CommandLineController::parse(const QStringList& args)
|
|||
m_parser.addOption(QCommandLineOption("score-parts", "Generate parts data for the given score and save them to separate mscz files"));
|
||||
m_parser.addOption(QCommandLineOption("score-parts-pdf",
|
||||
"Generate parts data for the given score and export the data to a single JSON file, print it to stdout"));
|
||||
m_parser.addOption(QCommandLineOption({"S", "style"}, "Load style file", "style"));
|
||||
m_parser.addOption(QCommandLineOption("source-update", "Update the source in the given score"));
|
||||
|
||||
m_parser.addOption(QCommandLineOption({ "S", "style" }, "Load style file", "style"));
|
||||
|
||||
m_parser.process(args);
|
||||
}
|
||||
|
@ -63,7 +66,7 @@ void CommandLineController::parse(const QStringList& args)
|
|||
void CommandLineController::apply()
|
||||
{
|
||||
auto floatValue = [this](const QString& name) -> std::optional<float> {
|
||||
bool ok;
|
||||
bool ok = true;
|
||||
float val = m_parser.value(name).toFloat(&ok);
|
||||
if (ok) {
|
||||
return val;
|
||||
|
@ -71,6 +74,15 @@ void CommandLineController::apply()
|
|||
return std::nullopt;
|
||||
};
|
||||
|
||||
auto intValue = [this](const QString& name) -> std::optional<int> {
|
||||
bool ok = true;
|
||||
int val = m_parser.value(name).toInt(&ok);
|
||||
if (ok) {
|
||||
return val;
|
||||
}
|
||||
return std::nullopt;
|
||||
};
|
||||
|
||||
// Common
|
||||
// TODO: Open these files at launch if RunMode is Editor
|
||||
QStringList scorefiles = m_parser.positionalArguments();
|
||||
|
@ -93,6 +105,15 @@ void CommandLineController::apply()
|
|||
}
|
||||
}
|
||||
|
||||
if (m_parser.isSet("T")) {
|
||||
std::optional<int> val = intValue("T");
|
||||
if (val) {
|
||||
imagesExportConfiguration()->setTrimMarginPixelSize(val);
|
||||
} else {
|
||||
LOGE() << "Option: -T not recognized trim value: " << m_parser.value("T");
|
||||
}
|
||||
}
|
||||
|
||||
// Converter mode
|
||||
if (m_parser.isSet("r")) {
|
||||
std::optional<float> val = floatValue("r");
|
||||
|
@ -149,6 +170,13 @@ void CommandLineController::apply()
|
|||
m_converterTask.inputFile = scorefiles[0];
|
||||
}
|
||||
|
||||
if (m_parser.isSet("source-update")) {
|
||||
application()->setRunMode(IApplication::RunMode::Converter);
|
||||
m_converterTask.type = ConvertType::SourceUpdate;
|
||||
m_converterTask.inputFile = scorefiles[0];
|
||||
m_converterTask.params[CommandLineController::ParamKey::ScoreSource] = m_parser.value("source-update");
|
||||
}
|
||||
|
||||
if (m_parser.isSet("F") || m_parser.isSet("R")) {
|
||||
configuration()->revertToFactorySettings(m_parser.isSet("R"));
|
||||
}
|
||||
|
|
|
@ -48,12 +48,14 @@ public:
|
|||
ExportScoreMedia,
|
||||
ExportScoreMeta,
|
||||
ExportScoreParts,
|
||||
ExportScorePartsPdf
|
||||
ExportScorePartsPdf,
|
||||
SourceUpdate
|
||||
};
|
||||
|
||||
enum class ParamKey {
|
||||
HighlightConfigPath,
|
||||
StylePath
|
||||
StylePath,
|
||||
ScoreSource
|
||||
};
|
||||
|
||||
struct ConverterTask {
|
||||
|
|
|
@ -39,6 +39,7 @@ public:
|
|||
virtual Ret exportScoreMeta(const io::path& in, const io::path& out, const io::path& stylePath) = 0;
|
||||
virtual Ret exportScoreParts(const io::path& in, const io::path& out, const io::path& stylePath) = 0;
|
||||
virtual Ret exportScorePartsPdfs(const io::path& in, const io::path& out, const io::path& stylePath) = 0;
|
||||
virtual Ret updateSource(const io::path& in, const QString& newSource) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -550,3 +550,18 @@ QByteArray BackendApi::scorePartJson(Ms::Score* score)
|
|||
|
||||
return scoreData.toBase64();
|
||||
}
|
||||
|
||||
Ret BackendApi::updateSource(const io::path& in, const QString& newSource)
|
||||
{
|
||||
RetVal<IMasterNotationPtr> notation = openScore(in);
|
||||
if (!notation.ret) {
|
||||
return notation.ret;
|
||||
}
|
||||
|
||||
Meta meta = notation.val->metaInfo();
|
||||
meta.source = newSource;
|
||||
|
||||
notation.val->setMetaInfo(meta);
|
||||
|
||||
return notation.val->save();
|
||||
}
|
||||
|
|
|
@ -49,11 +49,12 @@ public:
|
|||
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 QString& newSource);
|
||||
|
||||
private:
|
||||
static Ret openOutputFile(QFile& file, const io::path& out);
|
||||
|
||||
static RetVal<notation::IMasterNotationPtr> openScore(const io::path& path, const io::path& stylePath);
|
||||
static RetVal<notation::IMasterNotationPtr> openScore(const io::path& path, const io::path& stylePath = io::path());
|
||||
|
||||
static notation::PageList pages(const notation::INotationPtr notation);
|
||||
|
||||
|
|
|
@ -153,3 +153,10 @@ mu::Ret ConverterController::exportScorePartsPdfs(const mu::io::path& in, const
|
|||
|
||||
return BackendApi::exportScorePartsPdfs(in, out, stylePath);
|
||||
}
|
||||
|
||||
mu::Ret ConverterController::updateSource(const io::path& in, const QString& newSource)
|
||||
{
|
||||
TRACEFUNC;
|
||||
|
||||
return BackendApi::updateSource(in, newSource);
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
Ret exportScoreMeta(const io::path& in, const io::path& out, const io::path& stylePath) override;
|
||||
Ret exportScoreParts(const io::path& in, const io::path& out, const io::path& stylePath) override;
|
||||
Ret exportScorePartsPdfs(const io::path& in, const io::path& out, const io::path& stylePath) override;
|
||||
Ret updateSource(const io::path& in, const QString& newSource) override;
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -46,6 +46,9 @@ public:
|
|||
|
||||
virtual bool exportPngWithTransparentBackground() const = 0;
|
||||
virtual void setExportPngWithTransparentBackground(bool transparent) = 0;
|
||||
|
||||
virtual int trimMarginPixelSize() const = 0;
|
||||
virtual void setTrimMarginPixelSize(std::optional<int> pixelSize) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -72,3 +72,13 @@ void ImagesExportConfiguration::setExportPngWithTransparentBackground(bool trans
|
|||
{
|
||||
settings()->setValue(EXPORT_PNG_USE_TRANSPARENCY_KEY, Val(transparent));
|
||||
}
|
||||
|
||||
int ImagesExportConfiguration::trimMarginPixelSize() const
|
||||
{
|
||||
return m_trimMarginPixelSize ? m_trimMarginPixelSize.value() : 0;
|
||||
}
|
||||
|
||||
void ImagesExportConfiguration::setTrimMarginPixelSize(std::optional<int> pixelSize)
|
||||
{
|
||||
m_trimMarginPixelSize = pixelSize;
|
||||
}
|
||||
|
|
|
@ -39,8 +39,11 @@ public:
|
|||
bool exportPngWithTransparentBackground() const override;
|
||||
void setExportPngWithTransparentBackground(bool transparent) override;
|
||||
|
||||
private:
|
||||
int trimMarginPixelSize() const override;
|
||||
void setTrimMarginPixelSize(std::optional<int> pixelSize) override;
|
||||
|
||||
private:
|
||||
std::optional<int> m_trimMarginPixelSize;
|
||||
std::optional<float> m_customExportPngDpi;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ mu::Ret PngWriter::write(INotationPtr notation, Device& destinationDevice, const
|
|||
|
||||
Ms::Page* page = pages[PAGE_NUMBER];
|
||||
|
||||
const int TRIM_MARGIN_SIZE = options.value(OptionKey::TRIM_MARGINS_SIZE, Val(0)).toInt();
|
||||
const int TRIM_MARGIN_SIZE = configuration()->trimMarginPixelSize();
|
||||
RectF pageRect = page->abbox();
|
||||
|
||||
if (TRIM_MARGIN_SIZE >= 0) {
|
||||
|
|
|
@ -75,7 +75,7 @@ mu::Ret SvgWriter::write(INotationPtr notation, Device& destinationDevice, const
|
|||
printer.setTitle(pages.size() > 1 ? QString("%1 (%2)").arg(title).arg(PAGE_NUMBER + 1) : title);
|
||||
printer.setOutputDevice(&destinationDevice);
|
||||
|
||||
const int TRIM_MARGINS_SIZE = options.value(OptionKey::TRIM_MARGINS_SIZE, Val(0)).toInt();
|
||||
const int TRIM_MARGINS_SIZE = configuration()->trimMarginPixelSize();
|
||||
|
||||
RectF pageRect = page->abbox();
|
||||
if (TRIM_MARGINS_SIZE >= 0) {
|
||||
|
|
|
@ -25,9 +25,14 @@
|
|||
|
||||
#include "notation/abstractnotationwriter.h"
|
||||
|
||||
#include "modularity/ioc.h"
|
||||
#include "iimagesexportconfiguration.h"
|
||||
|
||||
namespace mu::iex::imagesexport {
|
||||
class SvgWriter : public notation::AbstractNotationWriter
|
||||
{
|
||||
INJECT(iex, IImagesExportConfiguration, configuration)
|
||||
|
||||
public:
|
||||
std::vector<notation::INotationWriter::UnitType> supportedUnitTypes() const override;
|
||||
Ret write(notation::INotationPtr notation, io::Device& destinationDevice, const Options& options = Options()) override;
|
||||
|
|
|
@ -48,7 +48,6 @@ public:
|
|||
UNIT_TYPE,
|
||||
PAGE_NUMBER,
|
||||
TRANSPARENT_BACKGROUND,
|
||||
TRIM_MARGINS_SIZE,
|
||||
NOTES_COLORS
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue