Skip to content

Commit cf5c02f

Browse files
--score-elements: remove options
1 parent f70be3c commit cf5c02f

File tree

10 files changed

+44
-130
lines changed

10 files changed

+44
-130
lines changed

src/app/internal/commandlineparser.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ void CommandLineParser::init()
109109
"Transpose the given score and export the data to a single JSON file, print it to stdout",
110110
"options"));
111111
m_parser.addOption(QCommandLineOption("score-elements",
112-
"Scan the given score and export elements to a single JSON file, print it to stdout",
113-
"options"));
112+
"Scan the given score and export elements to a single JSON file, print it to stdout"));
114113
m_parser.addOption(QCommandLineOption("source-update", "Update the source in the given score"));
115114

116115
m_parser.addOption(QCommandLineOption({ "S", "style" }, "Load style file", "style"));
@@ -373,7 +372,6 @@ void CommandLineParser::parse(int argc, char** argv)
373372
m_options.runMode = IApplication::RunMode::ConsoleApp;
374373
m_options.converterTask.type = ConvertType::ExportScoreElements;
375374
m_options.converterTask.inputFile = scorefiles[0];
376-
m_options.converterTask.params[CmdOptions::ParamKey::ScoreElementsOptions] = m_parser.value("score-elements");
377375
}
378376

379377
if (m_parser.isSet("source-update")) {

src/app/internal/consoleapp.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,7 @@ int ConsoleApp::processConverter(const CmdOptions::ConverterTask& task)
331331
ret = converter()->exportScoreTranspose(task.inputFile, task.outputFile, scoreTranspose, openParams);
332332
} break;
333333
case ConvertType::ExportScoreElements: {
334-
std::string options = task.params[CmdOptions::ParamKey::ScoreElementsOptions].toString().toStdString();
335-
ret = converter()->exportScoreElements(task.inputFile, task.outputFile, options, openParams);
334+
ret = converter()->exportScoreElements(task.inputFile, task.outputFile, openParams);
336335
} break;
337336
case ConvertType::ExportScoreVideo: {
338337
ret = converter()->exportScoreVideo(task.inputFile, task.outputFile, openParams);

src/converter/iconvertercontroller.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ class IConverterController : MODULE_EXPORT_INTERFACE
6161
virtual muse::Ret exportScoreTranspose(const muse::io::path_t& in, const muse::io::path_t& out, const std::string& optionsJson,
6262
const OpenParams& openParams = {}) = 0;
6363

64-
virtual muse::Ret exportScoreElements(const muse::io::path_t& in, const muse::io::path_t& out, const std::string& optionsJson,
65-
const OpenParams& openParams = {}) = 0;
64+
virtual muse::Ret exportScoreElements(const muse::io::path_t& in, const muse::io::path_t& out, const OpenParams& openParams = {}) = 0;
6665

6766
virtual muse::Ret exportScoreVideo(const muse::io::path_t& in, const muse::io::path_t& out, const OpenParams& openParams = {}) = 0;
6867

src/converter/internal/compat/backendapi.cpp

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -69,40 +69,6 @@ static const std::string DEV_INFO_NAME = "devinfo";
6969
static constexpr bool ADD_SEPARATOR = true;
7070
static constexpr auto NO_STYLE = "";
7171

72-
static ScoreElementScanner::Options parseScoreElementScannerOptions(const std::string& json)
73-
{
74-
if (json.empty()) {
75-
return {};
76-
}
77-
78-
QJsonParseError parseError;
79-
const QJsonDocument doc = QJsonDocument::fromJson(QByteArray::fromStdString(json), &parseError);
80-
if (parseError.error != QJsonParseError::NoError) {
81-
LOGE() << "JSON parse error:" << parseError.errorString();
82-
return {};
83-
}
84-
85-
const QJsonObject obj = doc.object();
86-
87-
ScoreElementScanner::Options options;
88-
options.avoidDuplicates = obj.value("avoidDuplicates").toBool();
89-
90-
const QJsonArray typeArray = obj.value("types").toArray();
91-
for (const auto typeObj : typeArray) {
92-
if (!typeObj.isString()) {
93-
continue;
94-
}
95-
96-
const std::string typeStr = typeObj.toString().toStdString();
97-
const ElementType type = TConv::fromXml(typeStr, ElementType::INVALID);
98-
if (type != ElementType::INVALID) {
99-
options.acceptedTypes.insert(type);
100-
}
101-
}
102-
103-
return options;
104-
}
105-
10672
Ret BackendApi::exportScoreMedia(const muse::io::path_t& in, const muse::io::path_t& out, const muse::io::path_t& highlightConfigPath,
10773
const muse::io::path_t& stylePath,
10874
bool forceMode,
@@ -231,7 +197,7 @@ Ret BackendApi::exportScoreTranspose(const muse::io::path_t& in, const muse::io:
231197
return result ? make_ret(Ret::Code::Ok) : make_ret(Ret::Code::InternalError);
232198
}
233199

234-
Ret BackendApi::exportScoreElements(const muse::io::path_t& in, const muse::io::path_t& out, const std::string& optionsJson,
200+
Ret BackendApi::exportScoreElements(const muse::io::path_t& in, const muse::io::path_t& out,
235201
const muse::io::path_t& stylePath, bool forceMode)
236202
{
237203
TRACEFUNC;
@@ -246,7 +212,7 @@ Ret BackendApi::exportScoreElements(const muse::io::path_t& in, const muse::io::
246212
QFile outputFile;
247213
openOutputFile(outputFile, out);
248214

249-
return doExportScoreElements(notation, optionsJson, outputFile);
215+
return doExportScoreElements(notation, outputFile);
250216
}
251217

252218
Ret BackendApi::openOutputFile(QFile& file, const muse::io::path_t& out)
@@ -686,11 +652,10 @@ Ret BackendApi::doExportScoreTranspose(const INotationPtr notation, BackendJsonW
686652
return ret;
687653
}
688654

689-
muse::Ret BackendApi::doExportScoreElements(const notation::INotationPtr notation, const std::string& optionsJson, QIODevice& out)
655+
muse::Ret BackendApi::doExportScoreElements(const notation::INotationPtr notation, QIODevice& out)
690656
{
691657
mu::engraving::Score* score = notation->elements()->msScore();
692-
ScoreElementScanner::Options options = parseScoreElementScannerOptions(optionsJson);
693-
ElementMap elements = ScoreElementScanner::scanElements(score, options);
658+
ElementMap elements = ScoreElementScanner::scanElements(score);
694659

695660
QJsonArray rootArray;
696661

src/converter/internal/compat/backendapi.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ class BackendApi
5959
static muse::Ret exportScoreTranspose(const muse::io::path_t& in, const muse::io::path_t& out, const std::string& optionsJson,
6060
const muse::io::path_t& stylePath, bool forceMode = false, bool unrollRepeats = false);
6161

62-
static muse::Ret exportScoreElements(const muse::io::path_t& in, const muse::io::path_t& out, const std::string& optionsJson,
63-
const muse::io::path_t& stylePath, bool forceMode = false);
62+
static muse::Ret exportScoreElements(const muse::io::path_t& in, const muse::io::path_t& out, const muse::io::path_t& stylePath,
63+
bool forceMode = false);
6464

6565
static muse::Ret updateSource(const muse::io::path_t& in, const std::string& newSource, bool forceMode = false);
6666

@@ -95,7 +95,7 @@ class BackendApi
9595
static muse::Ret doExportScoreTranspose(const notation::INotationPtr notation, BackendJsonWriter& jsonWriter,
9696
bool addSeparator = false);
9797

98-
static muse::Ret doExportScoreElements(const notation::INotationPtr notation, const std::string& optionsJson, QIODevice& out);
98+
static muse::Ret doExportScoreElements(const notation::INotationPtr notation, QIODevice& out);
9999

100100
static muse::RetVal<QByteArray> scorePartJson(mu::engraving::Score* score, const std::string& fileName);
101101

src/converter/internal/compat/scoreelementsscanner.cpp

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,16 @@ using namespace mu::converter;
3232
using namespace mu::engraving;
3333

3434
struct ScannerData {
35-
using ElementKey = std::pair<ElementType, int /*subtype*/>;
36-
3735
// in
38-
ScoreElementScanner::Options options;
3936
size_t measures = 0;
4037

4138
// out
4239
ElementMap elements;
4340
std::set<Chord*> chords;
4441
std::set<Spanner*> spanners;
45-
std::map<InstrumentTrackId, std::map<ElementKey, std::set<muse::String> > > uniqueNames;
4642
};
4743

48-
static bool itemAccepted(const EngravingItem* item, const ElementTypeSet& acceptedTypes)
44+
static bool itemAccepted(const EngravingItem* item)
4945
{
5046
// Ignore temporary / invalid elements and elements that cannot be interacted with
5147
if (!item || !item->part() || !item->selectable() || !item->isInteractionAvailable()) {
@@ -68,26 +64,7 @@ static bool itemAccepted(const EngravingItem* item, const ElementTypeSet& accept
6864
return false;
6965
}
7066

71-
if (!item->visible() && !item->score()->isShowInvisible()) {
72-
return false;
73-
}
74-
75-
if (acceptedTypes.empty()) {
76-
return true;
77-
}
78-
79-
ElementType type = item->type();
80-
81-
if (item->isNote()) {
82-
const Chord* chord = toNote(item)->chord();
83-
if (chord->notes().size() > 1) {
84-
type = chord->type();
85-
}
86-
} else if (item->isSpannerSegment()) {
87-
type = toSpannerSegment(item)->spanner()->type();
88-
}
89-
90-
return muse::contains(acceptedTypes, type);
67+
return true;
9168
}
9269

9370
static bool isChordArticulation(const EngravingItem* item)
@@ -97,7 +74,7 @@ static bool isChordArticulation(const EngravingItem* item)
9774
return false;
9875
}
9976

100-
static const std::unordered_set<ElementType> CHORD_ARTICULATION_TYPES {
77+
static const ElementTypeSet CHORD_ARTICULATION_TYPES {
10178
ElementType::ARPEGGIO,
10279
ElementType::TREMOLO_SINGLECHORD,
10380
ElementType::ORNAMENT,
@@ -125,7 +102,7 @@ static muse::String chordToNotes(const Chord* chord)
125102

126103
static void addElementInfoIfNeed(ScannerData* scannerData, EngravingItem* item)
127104
{
128-
if (!itemAccepted(item, scannerData->options.acceptedTypes)) {
105+
if (!itemAccepted(item)) {
129106
return;
130107
}
131108

@@ -210,18 +187,6 @@ static void addElementInfoIfNeed(ScannerData* scannerData, EngravingItem* item)
210187
part->instrumentId(item->tick())
211188
};
212189

213-
if (scannerData->options.avoidDuplicates) {
214-
const muse::String& name = !info.name.empty() ? info.name : info.notes;
215-
const ScannerData::ElementKey key = std::make_pair(type, item->subtype());
216-
std::set<muse::String>& uniqueNames = scannerData->uniqueNames[trackId][key];
217-
218-
if (muse::contains(uniqueNames, name)) {
219-
return;
220-
}
221-
222-
uniqueNames.insert(name);
223-
}
224-
225190
if (!locationIsSet) {
226191
const EngravingItem::BarBeat barbeat = item->barbeat();
227192
info.start.staffIdx = item->staffIdx();
@@ -242,12 +207,11 @@ static void addElementInfoIfNeed(ScannerData* scannerData, EngravingItem* item)
242207
scannerData->elements[trackId].emplace_back(std::move(info));
243208
}
244209

245-
ElementMap ScoreElementScanner::scanElements(Score* score, const Options& options)
210+
ElementMap ScoreElementScanner::scanElements(Score* score)
246211
{
247212
TRACEFUNC;
248213

249214
ScannerData data;
250-
data.options = options;
251215
data.measures = score->nmeasures();
252216

253217
score->scanElements([&](mu::engraving::EngravingItem* item) { addElementInfoIfNeed(&data, item); });

src/converter/internal/compat/scoreelementsscanner.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,6 @@ namespace mu::converter {
3232
class ScoreElementScanner
3333
{
3434
public:
35-
struct Options {
36-
Options() {}
37-
38-
mu::engraving::ElementTypeSet acceptedTypes;
39-
bool avoidDuplicates = false;
40-
};
41-
42-
static ElementMap scanElements(mu::engraving::Score* score, const Options& options = {});
35+
static ElementMap scanElements(mu::engraving::Score* score);
4336
};
4437
}

src/converter/internal/convertercontroller.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,12 @@ Ret ConverterController::exportScoreTranspose(const muse::io::path_t& in, const
584584
return BackendApi::exportScoreTranspose(in, out, optionsJson, openParams.stylePath, openParams.forceMode, openParams.unrollRepeats);
585585
}
586586

587-
Ret ConverterController::exportScoreElements(const muse::io::path_t& in, const muse::io::path_t& out, const std::string& optionsJson,
587+
Ret ConverterController::exportScoreElements(const muse::io::path_t& in, const muse::io::path_t& out,
588588
const OpenParams& openParams)
589589
{
590590
TRACEFUNC;
591591

592-
return BackendApi::exportScoreElements(in, out, optionsJson, openParams.stylePath, openParams.forceMode);
592+
return BackendApi::exportScoreElements(in, out, openParams.stylePath, openParams.forceMode);
593593
}
594594

595595
Ret ConverterController::exportScoreVideo(const muse::io::path_t& in, const muse::io::path_t& out, const OpenParams& openParams)

src/converter/internal/convertercontroller.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ class ConverterController : public IConverterController, public muse::Injectable
6666
muse::Ret exportScoreTranspose(const muse::io::path_t& in, const muse::io::path_t& out, const std::string& optionsJson,
6767
const OpenParams& openParams = {}) override;
6868

69-
muse::Ret exportScoreElements(const muse::io::path_t& in, const muse::io::path_t& out, const std::string& optionsJson,
70-
const OpenParams& openParams = {}) override;
69+
muse::Ret exportScoreElements(const muse::io::path_t& in, const muse::io::path_t& out, const OpenParams& openParams = {}) override;
7170

7271
muse::Ret exportScoreVideo(const muse::io::path_t& in, const muse::io::path_t& out, const OpenParams& openParams = {}) override;
7372

src/converter/tests/scoreelementsscanner_tests.cpp

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static const muse::String CONVERTER_DATA_DIR("data/");
3434
class Converter_ScoreElementsTests : public ::testing::Test
3535
{
3636
public:
37-
ElementInfo makeInfo(ElementType type, const String& name, const String& notes = u"") const
37+
ElementInfo makeInfo(ElementType type, const String& name = u"", const String& notes = u"") const
3838
{
3939
ElementInfo info;
4040
info.type = type;
@@ -51,56 +51,53 @@ TEST_F(Converter_ScoreElementsTests, ScanElements)
5151
Score* score = ScoreRW::readScore(CONVERTER_DATA_DIR + "score_elements.mscx");
5252
ASSERT_TRUE(score);
5353

54-
// [GIVEN] Scanner options
55-
ScoreElementScanner::Options options;
56-
options.avoidDuplicates = true;
57-
options.acceptedTypes = {
58-
// 1st measure
59-
ElementType::KEYSIG,
60-
ElementType::TIMESIG,
61-
ElementType::ARPEGGIO,
62-
ElementType::CHORD,
63-
ElementType::TREMOLO_SINGLECHORD,
64-
65-
// 2nd measure
66-
ElementType::ORNAMENT,
67-
68-
// 3rd measure
69-
ElementType::TRILL,
70-
71-
// 4th measure
72-
ElementType::GRADUAL_TEMPO_CHANGE,
73-
ElementType::HAIRPIN,
74-
75-
// 5th measure
76-
ElementType::PLAYTECH_ANNOTATION,
77-
};
78-
7954
// [WHEN] Scan the score
80-
ElementMap result = ScoreElementScanner::scanElements(score, options);
55+
ElementMap result = ScoreElementScanner::scanElements(score);
8156

8257
// [THEN] The list matches the expected one
8358
ElementInfoList expectedList;
8459

8560
// 1st measure
61+
expectedList.emplace_back(makeInfo(ElementType::CLEF, u"Treble clef"));
8662
expectedList.emplace_back(makeInfo(ElementType::KEYSIG, u"C major / A minor"));
8763
expectedList.emplace_back(makeInfo(ElementType::TIMESIG, u"4/4 time"));
8864
expectedList.emplace_back(makeInfo(ElementType::ARPEGGIO, u"Up arpeggio", u"C5 E5 G5 B5"));
8965
expectedList.emplace_back(makeInfo(ElementType::CHORD, u"", u"C5 E5 G5 B5"));
9066
expectedList.emplace_back(makeInfo(ElementType::TREMOLO_SINGLECHORD, u"32nd through stem", u"F4 A4 C5"));
67+
expectedList.emplace_back(makeInfo(ElementType::REST, u"Rest(s)"));
9168

9269
// 2nd measure
93-
expectedList.emplace_back(makeInfo(ElementType::ORNAMENT, u"Turn", u"A4 E5")); // skip duplicates
70+
expectedList.emplace_back(makeInfo(ElementType::BAR_LINE, u"Single barline"));
71+
expectedList.emplace_back(makeInfo(ElementType::ORNAMENT, u"Turn", u"A4 E5"));
72+
expectedList.emplace_back(makeInfo(ElementType::ORNAMENT, u"Turn", u"A4 E5"));
73+
expectedList.emplace_back(makeInfo(ElementType::NOTE, u"C5"));
74+
expectedList.emplace_back(makeInfo(ElementType::REST, u"Rest(s)"));
9475

9576
// 3rd measure
77+
expectedList.emplace_back(makeInfo(ElementType::BAR_LINE, u"Single barline"));
78+
expectedList.emplace_back(makeInfo(ElementType::NOTE, u"A4"));
9679
expectedList.emplace_back(makeInfo(ElementType::TRILL, u"Trill line"));
80+
expectedList.emplace_back(makeInfo(ElementType::NOTE, u"C5"));
81+
expectedList.emplace_back(makeInfo(ElementType::NOTE, u"B4"));
82+
expectedList.emplace_back(makeInfo(ElementType::NOTE, u"D5"));
9783

9884
// 4th measure
85+
expectedList.emplace_back(makeInfo(ElementType::BAR_LINE, u"Single barline"));
86+
expectedList.emplace_back(makeInfo(ElementType::NOTE, u"A4"));
9987
expectedList.emplace_back(makeInfo(ElementType::HAIRPIN, u"Crescendo hairpin"));
10088
expectedList.emplace_back(makeInfo(ElementType::GRADUAL_TEMPO_CHANGE, u"accel."));
89+
expectedList.emplace_back(makeInfo(ElementType::NOTE, u"B4"));
90+
expectedList.emplace_back(makeInfo(ElementType::NOTE, u"A4"));
91+
expectedList.emplace_back(makeInfo(ElementType::NOTE, u"B4"));
10192

10293
// 5th measure
94+
expectedList.emplace_back(makeInfo(ElementType::BAR_LINE, u"Single barline"));
95+
expectedList.emplace_back(makeInfo(ElementType::NOTE, u"A4"));
10396
expectedList.emplace_back(makeInfo(ElementType::PLAYTECH_ANNOTATION, u"Pizzicato"));
97+
expectedList.emplace_back(makeInfo(ElementType::BAR_LINE, u"Final barline"));
98+
expectedList.emplace_back(makeInfo(ElementType::NOTE, u"B4"));
99+
expectedList.emplace_back(makeInfo(ElementType::NOTE, u"A4"));
100+
expectedList.emplace_back(makeInfo(ElementType::NOTE, u"B4"));
104101

105102
ASSERT_EQ(result.size(), 1);
106103
const mu::engraving::InstrumentTrackId expectedTrackId { muse::ID(1), u"piano" };

0 commit comments

Comments
 (0)