Skip to content

Commit

Permalink
Fix * placeholder not on end of filename
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Cal committed Jan 8, 2025
1 parent f13b7d7 commit 2dc2178
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 46 deletions.
52 changes: 21 additions & 31 deletions src/converter/internal/convertercontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Ret ConverterController::fileConvert(const muse::io::path_t& in, const muse::io:

// Check if this is a part conversion job
QString baseName = QString::fromStdString(io::completeBasename(out).toStdString());
if (baseName.endsWith('*')) {
if (baseName.contains('*')) {
return convertScoreParts(in, out, stylePath, forceMode);
}

Expand Down Expand Up @@ -235,7 +235,7 @@ Ret ConverterController::convertScoreParts(const muse::io::path_t& in, const mus
return make_ret(Ret::Code::Ok);
}

RetVal<ConverterController::BatchJob> ConverterController::parseBatchJob(const muse::io::path_t& batchJobFile)
RetVal<ConverterController::BatchJob> ConverterController::parseBatchJob(const muse::io::path_t& batchJobFile) const
{
TRACEFUNC;

Expand Down Expand Up @@ -265,7 +265,6 @@ RetVal<ConverterController::BatchJob> ConverterController::parseBatchJob(const m

Job job;
job.in = correctUserInputPath(obj["in"].toString());
job.out = correctUserInputPath(obj["out"].toString());

QJsonObject transposeOptionsObj = obj["transpose"].toObject();
if (!transposeOptionsObj.isEmpty()) {
Expand All @@ -274,29 +273,26 @@ RetVal<ConverterController::BatchJob> ConverterController::parseBatchJob(const m
rv.ret = transposeOptions.ret;
return rv;
}

job.transposeOptions = transposeOptions.val;
}

if (!job.in.empty() && !job.out.empty()) {
QJsonValue outValue = obj["out"];
if (outValue.isString()) {
job.out = correctUserInputPath(outValue.toString());
rv.val.push_back(std::move(job));
} else if (outValue.isArray()) {
QJsonArray outArray = outValue.toArray();
for (const QJsonValue& outItem : outArray) {
Job partJob = job; // Copy the input path
if (outItem.isString()) {
partJob.out = correctUserInputPath(outItem.toString());
} else if (outItem.isArray() && outItem.toArray().size() == 2) {
QJsonArray partOutArray = outItem.toArray();
QString prefix = correctUserInputPath(partOutArray[0].toString());
QString suffix = partOutArray[1].toString();
partJob.out = prefix + "*" + suffix; // Use "*" as a placeholder for part names
}
rv.val.push_back(std::move(partJob));
QJsonValue outValue = obj["out"];
if (outValue.isString()) {
job.out = correctUserInputPath(outValue.toString());
rv.val.push_back(std::move(job));
} else if (outValue.isArray()) {
QJsonArray outArray = outValue.toArray();
for (const QJsonValue& outItem : outArray) {
Job partJob = job; // Copy the input path
if (outItem.isString()) {
partJob.out = correctUserInputPath(outItem.toString());
} else if (outItem.isArray() && outItem.toArray().size() == 2) {
QJsonArray partOutArray = outItem.toArray();
QString prefix = correctUserInputPath(partOutArray[0].toString());
QString suffix = partOutArray[1].toString();
partJob.out = prefix + "*" + suffix; // Use "*" as a placeholder for part names
}
rv.val.push_back(std::move(partJob));
}
}
}
Expand Down Expand Up @@ -406,9 +402,7 @@ Ret ConverterController::convertScorePartsToPdf(INotationWriterPtr writer, IMast
for (size_t i = 0; i < notations.size(); ++i) {
QString partName = notations[i]->name();
QString baseName = QString::fromStdString(io::completeBasename(out).toStdString());
baseName.chop(1); // Remove the * placeholder

muse::io::path_t partOut = io::dirpath(out) + "/" + baseName.toStdString() + partName.toStdString() + ".pdf";
muse::io::path_t partOut = io::dirpath(out) + "/" + baseName.replace("*", partName).toStdString() + ".pdf";

File file(partOut);
if (!file.open(File::WriteOnly)) {
Expand Down Expand Up @@ -436,7 +430,6 @@ Ret ConverterController::convertScorePartsToPngs(INotationWriterPtr writer, mu::
{
TRACEFUNC;

INotationPtrList notations;
INotationPtrList notations;
for (IExcerptNotationPtr e : masterNotation->excerpts()) {
notations.push_back(e->notation());
Expand All @@ -445,8 +438,7 @@ Ret ConverterController::convertScorePartsToPngs(INotationWriterPtr writer, mu::
for (size_t i = 0; i < notations.size(); i++) {
QString partName = notations[i]->name();
QString baseName = QString::fromStdString(io::completeBasename(out).toStdString());
baseName.chop(1); // Remove the * placeholder
muse::io::path_t pngFilePath = io::dirpath(out) + "/" + baseName.toStdString() + partName.toStdString() + ".png";
muse::io::path_t pngFilePath = io::dirpath(out) + "/" + baseName.replace("*", partName).toStdString() + ".png";
Ret ret2 = convertPageByPage(writer, notations[i], pngFilePath);
if (!ret2) {
return ret2;
Expand All @@ -469,9 +461,7 @@ Ret ConverterController::convertScorePartsToMp3(INotationWriterPtr writer, IMast
for (size_t i = 0; i < notations.size(); ++i) {
QString partName = notations[i]->name();
QString baseName = QString::fromStdString(io::completeBasename(out).toStdString());
baseName.chop(1); // Remove the * placeholder

muse::io::path_t partOut = io::dirpath(out) + "/" + baseName.toStdString() + partName.toStdString() + ".mp3";
muse::io::path_t partOut = io::dirpath(out) + "/" + baseName.replace("*", partName).toStdString() + ".mp3";

File file(partOut);
if (!file.open(File::WriteOnly)) {
Expand Down
24 changes: 9 additions & 15 deletions src/converter/internal/convertercontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,14 @@ class ConverterController : public IConverterController, public muse::Injectable
ConverterController(const muse::modularity::ContextPtr& iocCtx)
: muse::Injectable(iocCtx) {}

muse::Ret fileConvert(const muse::io::path_t& in, const muse::io::path_t& out, const muse::io::path_t& stylePath = muse::io::path_t(),
bool forceMode = false, const muse::String& soundProfile = muse::String(),
muse::Ret fileConvert(const muse::io::path_t& in, const muse::io::path_t& out, const muse::io::path_t& stylePath = muse::io::path_t(),
bool forceMode = false, const muse::String& soundProfile = muse::String(),
const muse::UriQuery& extensionUri = muse::UriQuery()) override;

muse::Ret batchConvert(const muse::io::path_t& batchJobFile, const muse::io::path_t& stylePath = muse::io::path_t(),
bool forceMode = false, const muse::String& soundProfile = muse::String(),
muse::Ret batchConvert(const muse::io::path_t& batchJobFile, const muse::io::path_t& stylePath = muse::io::path_t(),
bool forceMode = false, const muse::String& soundProfile = muse::String(),
muse::Ret fileConvert(const muse::io::path_t& in, const muse::io::path_t& out,
const muse::io::path_t& stylePath = muse::io::path_t(), bool forceMode = false,
const muse::String& soundProfile = muse::String(),
const muse::UriQuery& extensionUri = muse::UriQuery(), const std::string& transposeOptionsJson = {}) override;

muse::Ret batchConvert(const muse::io::path_t& batchJobFile,
const muse::io::path_t& stylePath = muse::io::path_t(), bool forceMode = false,
const muse::String& soundProfile = muse::String(),
const muse::UriQuery& extensionUri = muse::UriQuery(), muse::ProgressPtr progress = nullptr) override;

muse::Ret convertScoreParts(const muse::io::path_t& in, const muse::io::path_t& out,
Expand Down Expand Up @@ -108,8 +106,4 @@ class ConverterController : public IConverterController, public muse::Injectable
muse::Ret convertScorePartsToMp3(project::INotationWriterPtr writer, notation::IMasterNotationPtr masterNotation,
const muse::io::path_t& out) const;
};
}
<<<<<<< HEAD
=======

#endif // MU_CONVERTER_CONVERTERCONTROLLER_H
}

0 comments on commit 2dc2178

Please sign in to comment.