diff --git a/src/importexport/mei/internal/meiconverter.cpp b/src/importexport/mei/internal/meiconverter.cpp index 79f74fe39145d..2fe6d90881bac 100644 --- a/src/importexport/mei/internal/meiconverter.cpp +++ b/src/importexport/mei/internal/meiconverter.cpp @@ -1258,6 +1258,9 @@ void Convert::dynamFromMEI(engraving::Dynamic* dynamic, const StringList& meiLin dynamic->setDynamicType(meiLines.at(0)); } + // @layer + Convert::layerIdentFromMEI(dynamic, meiDynam); + // text content StringList lines; // For each line in the dynamic text @@ -1307,6 +1310,12 @@ libmei::Dynam Convert::dynamToMEI(const engraving::Dynamic* dynamic, StringList& meiDynam.SetPlace(Convert::directionToMEI(dynamic->direction())); } + // @layer + Convert::layerIdentToMEI(dynamic, meiDynam); + + // @staff + Convert::staffIdentToMEI(dynamic, meiDynam); + // @label if (dynamic->dynamicType() != engraving::DynamicType::OTHER) { meiDynam.SetLabel(engraving::TConv::toXml(dynamic->dynamicType()).ascii()); @@ -1605,6 +1614,9 @@ void Convert::hairpinFromMEI(engraving::Hairpin* hairpin, const libmei::Hairpin& // @color Convert::colorlineFromMEI(hairpin, meiHairpin); + + // @layer + Convert::layerIdentFromMEI(hairpin, meiHairpin); } libmei::Hairpin Convert::hairpinToMEI(const engraving::Hairpin* hairpin) @@ -1631,6 +1643,12 @@ libmei::Hairpin Convert::hairpinToMEI(const engraving::Hairpin* hairpin) // @color Convert::colorlineToMEI(hairpin, meiHairpin); + // @layer + Convert::layerIdentToMEI(hairpin, meiHairpin); + + // @staff + Convert::staffIdentToMEI(hairpin, meiHairpin); + return meiHairpin; } @@ -2296,6 +2314,9 @@ libmei::Octave Convert::octaveToMEI(const engraving::Ottava* ottava) // @color Convert::colorlineToMEI(ottava, meiOctave); + // @staff + Convert::staffIdentToMEI(ottava, meiOctave); + return meiOctave; } @@ -2946,6 +2967,9 @@ libmei::Tempo Convert::tempoToMEI(const engraving::TempoText* tempoText, StringL // text content - only split lines meiLines = String(tempoText->plainText()).split(u"\n"); + // @staff + Convert::staffIdentToMEI(tempoText, meiTempo); + return meiTempo; } @@ -3333,6 +3357,53 @@ std::list Convert::getTypeValuesWithPrefix(const std::string& typeS return values; } +void Convert::layerIdentFromMEI(engraving::EngravingItem* item, const libmei::Element& meiElement) +{ + if (!item->hasVoiceAssignmentProperties()) { + return; + } + + const libmei::AttLayerIdent* layerAtt = dynamic_cast(&meiElement); + + IF_ASSERT_FAILED(layerAtt) { + return; + } + + if (layerAtt->HasLayer()) { + // without further check we assume the layer to match + item->setProperty(engraving::Pid::VOICE_ASSIGNMENT, engraving::VoiceAssignment::CURRENT_VOICE_ONLY); + } +} + +void Convert::layerIdentToMEI(const engraving::EngravingItem* item, libmei::Element& meiElement) +{ + libmei::AttLayerIdent* layerAtt = dynamic_cast(&meiElement); + + IF_ASSERT_FAILED(layerAtt) { + return; + } + + if (item->hasVoiceAssignmentProperties() + && (item->getProperty(engraving::Pid::VOICE_ASSIGNMENT).value() + == engraving::VoiceAssignment::CURRENT_VOICE_ONLY)) { + layerAtt->SetLayer(item->voice() + 1); + } +} + +void Convert::staffIdentToMEI(const engraving::EngravingItem* item, libmei::Element& meiElement) +{ + libmei::AttStaffIdent* staffAtt = dynamic_cast(&meiElement); + + IF_ASSERT_FAILED(staffAtt) { + return; + } + + libmei::xsdPositiveInteger_List staffList; + staffList.push_back(item->staff()->idx() + 1); + // TODO: add staff number if centered between staves + staffAtt->SetStaff(staffList); +} + double Convert::tstampFromFraction(const engraving::Fraction& fraction, const engraving::Fraction& timesig) { return (double)fraction.numerator() / fraction.denominator() * timesig.denominator() + 1.0; diff --git a/src/importexport/mei/internal/meiconverter.h b/src/importexport/mei/internal/meiconverter.h index 8d16360c9ce63..b90f2f15b461d 100644 --- a/src/importexport/mei/internal/meiconverter.h +++ b/src/importexport/mei/internal/meiconverter.h @@ -223,6 +223,9 @@ class Convert static void harmFromMEI(engraving::Harmony* harmony, const muse::StringList& meiLines, const libmei::Harm& meiHarm, bool& warning); static libmei::Harm harmToMEI(const engraving::Harmony* harmony, muse::StringList& meiLines); + static void layerIdentFromMEI(engraving::EngravingItem* item, const libmei::Element& meiElement); + static void layerIdentToMEI(const engraving::EngravingItem* item, libmei::Element& meiElement); + static void lvFromMEI(engraving::Articulation* lv, const libmei::Lv& meiLv, bool& warning); static libmei::Lv lvToMEI(const engraving::Articulation* lv); @@ -281,6 +284,8 @@ class Convert static StaffStruct staffFromMEI(const libmei::StaffDef& meiStaffDef, bool& warning); static libmei::StaffDef staffToMEI(const engraving::Staff* staff); + static void staffIdentToMEI(const engraving::EngravingItem* item, libmei::Element& meiElement); + static std::pair stemFromMEI(const libmei::AttStems& meiStemsAtt, bool& warning); static std::pair stemToMEI(const engraving::DirectionV direction, bool noStem); diff --git a/src/importexport/mei/internal/meiexporter.cpp b/src/importexport/mei/internal/meiexporter.cpp index c6c8f6af4a8e5..e00459fee5a1e 100644 --- a/src/importexport/mei/internal/meiexporter.cpp +++ b/src/importexport/mei/internal/meiexporter.cpp @@ -1183,7 +1183,7 @@ bool MeiExporter::writeChord(const Chord* chord, const Staff* staff) meiChord.SetDots(chord->dots()); } this->writeBeamTypeAtt(chord, meiChord); - this->writeStaffIdenAtt(chord, staff, meiChord); + this->writeStaffIdentAtt(chord, staff, meiChord); this->writeStemAtt(chord, meiChord); this->writeArtics(chord); this->writeVerses(chord); @@ -1273,7 +1273,7 @@ bool MeiExporter::writeNote(const Note* note, const Chord* chord, const Staff* s meiNote.SetDots(chord->dots()); } this->writeBeamTypeAtt(chord, meiNote); - this->writeStaffIdenAtt(chord, staff, meiNote); + this->writeStaffIdentAtt(chord, staff, meiNote); this->writeStemAtt(chord, meiNote); this->writeArtics(chord); this->writeVerses(chord); @@ -1343,7 +1343,7 @@ bool MeiExporter::writeRest(const Rest* rest, const Staff* staff) } Convert::colorToMEI(rest, meiRest); this->writeBeamTypeAtt(rest, meiRest); - this->writeStaffIdenAtt(rest, staff, meiRest); + this->writeStaffIdentAtt(rest, staff, meiRest); // this->writeVerses(rest); const char prefix = (rest->visible()) ? 'r' : 's'; std::string xmlId = this->getXmlIdFor(rest, prefix); @@ -2053,7 +2053,7 @@ bool MeiExporter::writeBeamTypeAtt(const ChordRest* chordRest, libmei::AttTyped& * Write the cross-staff attribute (@staff) for a ChordRest (i.e., chord, note, rest or space). */ -bool MeiExporter::writeStaffIdenAtt(const ChordRest* chordRest, const Staff* staff, libmei::AttStaffIdent& staffIdentAtt) +bool MeiExporter::writeStaffIdentAtt(const ChordRest* chordRest, const Staff* staff, libmei::AttStaffIdent& staffIdentAtt) { if (chordRest->staffMove() != 0) { staff_idx_t staffN = staff->idx() + chordRest->staffMove() + 1; diff --git a/src/importexport/mei/internal/meiexporter.h b/src/importexport/mei/internal/meiexporter.h index 3f1d61326aa8b..706fa8f9e1f6f 100644 --- a/src/importexport/mei/internal/meiexporter.h +++ b/src/importexport/mei/internal/meiexporter.h @@ -147,7 +147,7 @@ class MeiExporter * Methods for writing specific MEI attribute classes within elements */ bool writeBeamTypeAtt(const engraving::ChordRest* chordRest, libmei::AttTyped& typeAtt); - bool writeStaffIdenAtt(const engraving::ChordRest* chordRest, const engraving::Staff* staff, libmei::AttStaffIdent& staffIdentAtt); + bool writeStaffIdentAtt(const engraving::ChordRest* chordRest, const engraving::Staff* staff, libmei::AttStaffIdent& staffIdentAtt); bool writeStemAtt(const engraving::Chord* chord, libmei::AttStems& stemsAtt); /** diff --git a/src/importexport/mei/tests/data/color-01.mei b/src/importexport/mei/tests/data/color-01.mei index a2a9d1926aceb..599d550b905f5 100644 --- a/src/importexport/mei/tests/data/color-01.mei +++ b/src/importexport/mei/tests/data/color-01.mei @@ -88,8 +88,8 @@ - - + + diff --git a/src/importexport/mei/tests/data/dynamic-01.mei b/src/importexport/mei/tests/data/dynamic-01.mei index b2b4a0bdf2f69..de9ca3cb67dda 100644 --- a/src/importexport/mei/tests/data/dynamic-01.mei +++ b/src/importexport/mei/tests/data/dynamic-01.mei @@ -54,11 +54,11 @@ - p - mp - sffz - sfz - pp + p + mp + sffz + sfz + pp @@ -76,9 +76,9 @@ - sempre mp e dolce - p e sempredolce - molto ff + sempre mp e dolce + p e sempredolce + molto ff diff --git a/src/importexport/mei/tests/data/dynamic-01.mscx b/src/importexport/mei/tests/data/dynamic-01.mscx index 385a7de6bcfba..0d173df2da8d4 100644 --- a/src/importexport/mei/tests/data/dynamic-01.mscx +++ b/src/importexport/mei/tests/data/dynamic-01.mscx @@ -104,6 +104,7 @@ sfz 112 + currentVoiceOnly eighth diff --git a/src/importexport/mei/tests/data/ending-01.mei b/src/importexport/mei/tests/data/ending-01.mei index fb1743472374f..ff66724657503 100644 --- a/src/importexport/mei/tests/data/ending-01.mei +++ b/src/importexport/mei/tests/data/ending-01.mei @@ -57,7 +57,7 @@ - + = 160 diff --git a/src/importexport/mei/tests/data/hairpin-01.mei b/src/importexport/mei/tests/data/hairpin-01.mei index bf9b65390edeb..17ac53df82c55 100644 --- a/src/importexport/mei/tests/data/hairpin-01.mei +++ b/src/importexport/mei/tests/data/hairpin-01.mei @@ -58,7 +58,7 @@ - + @@ -74,8 +74,8 @@ - f - + f + @@ -121,7 +121,7 @@ - f + f dim. @@ -166,7 +166,7 @@ - + @@ -182,7 +182,7 @@ - + @@ -212,7 +212,7 @@ - + diff --git a/src/importexport/mei/tests/data/octave-01.mei b/src/importexport/mei/tests/data/octave-01.mei index 20d75ac6f10ba..29987fab49ff8 100644 --- a/src/importexport/mei/tests/data/octave-01.mei +++ b/src/importexport/mei/tests/data/octave-01.mei @@ -58,7 +58,7 @@ - + @@ -74,7 +74,7 @@ - + @@ -104,7 +104,7 @@ - + @@ -120,7 +120,7 @@ - + @@ -149,8 +149,8 @@ - - + + diff --git a/src/importexport/mei/tests/data/tempo-01.mei b/src/importexport/mei/tests/data/tempo-01.mei index 9f05a34bac8f7..577e87d173ecd 100644 --- a/src/importexport/mei/tests/data/tempo-01.mei +++ b/src/importexport/mei/tests/data/tempo-01.mei @@ -61,7 +61,7 @@ - + = 80 @@ -79,7 +79,7 @@ - + = 120 @@ -97,7 +97,7 @@ - + = 80 @@ -115,7 +115,7 @@ - Vivace + Vivace @@ -132,7 +132,7 @@ - Presto + Presto @@ -149,7 +149,7 @@ - + = @@ -168,7 +168,7 @@ - + = @@ -187,7 +187,7 @@ - Andante ( = 120) + Andante ( = 120) @@ -268,7 +268,7 @@ - Allegromolto + Allegromolto @@ -285,7 +285,7 @@ - Vivace + Vivace