Serialize last enums when writing#33197
Conversation
Palettes are versioned now, so this is safe
📝 WalkthroughWalkthroughThis pull request converts enum serialization in XML files from integer-based representation to human-readable ASCII-text representation. Changes include modifying the read/write logic for 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/engraving/types/typesconv.cpp`:
- Around line 2060-2063: In fromXml(), the new text-only enum lookup can
silently return the default ("def") for legacy files that store numeric enum
values; after the existing string/name-based lookup, add a numeric fallback: if
the lookup result is the default, attempt to parse the element text as an
integer (e.g., with QString::toInt or std::stoi) and convert that integer to the
enum via the same enum cast/mapping used elsewhere (static_cast or the project's
int->enum helper), then use that value instead of the default; apply the same
change to the second occurrence of the lookup in fromXml() so both name and
numeric legacy encodings are supported.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 6f944fe1-4d4a-485b-8544-1fd37c749ac8
📒 Files selected for processing (39)
src/engraving/rw/read500/tread.cppsrc/engraving/rw/write/twrite.cppsrc/engraving/tests/parts_data/part-spanners-parts.mscxsrc/engraving/tests/parts_data/part-spanners.mscxsrc/engraving/types/typesconv.cppsrc/engraving/types/typesconv.hsrc/importexport/guitarpro/tests/data/basic-bend.gp-ref.mscxsrc/importexport/guitarpro/tests/data/basic-bend.gp5-ref.mscxsrc/importexport/guitarpro/tests/data/basic-bend.gpx-ref.mscxsrc/importexport/guitarpro/tests/data/bend.gp-ref.mscxsrc/importexport/guitarpro/tests/data/bend.gp3-ref.mscxsrc/importexport/guitarpro/tests/data/bend.gp4-ref.mscxsrc/importexport/guitarpro/tests/data/bend.gp5-ref.mscxsrc/importexport/guitarpro/tests/data/bend.gpx-ref.mscxsrc/importexport/guitarpro/tests/data/bend_and_glissando.gp-ref.mscxsrc/importexport/guitarpro/tests/data/bend_and_glissando.gp5-ref.mscxsrc/importexport/guitarpro/tests/data/bend_and_harmonic.gp-ref.mscxsrc/importexport/guitarpro/tests/data/bend_and_harmonic.gp5-ref.mscxsrc/importexport/guitarpro/tests/guitarbendimporter_data/bend_hold-gp.mscxsrc/importexport/guitarpro/tests/guitarbendimporter_data/bend_on_tuplet-gp.mscxsrc/importexport/guitarpro/tests/guitarbendimporter_data/bend_on_unequal_chords-gp.mscxsrc/importexport/guitarpro/tests/guitarbendimporter_data/bend_release-gp.mscxsrc/importexport/guitarpro/tests/guitarbendimporter_data/bends_release_grace_after-gp.mscxsrc/importexport/guitarpro/tests/guitarbendimporter_data/bends_tied_1-gp.mscxsrc/importexport/guitarpro/tests/guitarbendimporter_data/bends_tied_2-gp.mscxsrc/importexport/guitarpro/tests/guitarbendimporter_data/bends_tied_3-gp.mscxsrc/importexport/guitarpro/tests/guitarbendimporter_data/grace_chord_diff_bends-gp.mscxsrc/importexport/guitarpro/tests/guitarbendimporter_data/prebend-gp.mscxsrc/importexport/guitarpro/tests/guitarbendimporter_data/prebend-gp5.mscxsrc/importexport/guitarpro/tests/guitarbendimporter_data/prebend_bend-gp.mscxsrc/importexport/guitarpro/tests/guitarbendimporter_data/prebend_release_bend-gp.mscxsrc/importexport/guitarpro/tests/guitarbendimporter_data/simple_bend-gp.mscxsrc/importexport/guitarpro/tests/guitarbendimporter_data/simple_bend_chord-gp.mscxsrc/importexport/guitarpro/tests/guitarbendimporter_data/slight_bend-gp.mscxsrc/importexport/guitarpro/tests/guitarbendimporter_data/slight_bend-gp5.mscxsrc/importexport/guitarpro/tests/guitarbendimporter_data/slight_bend_chord-gp.mscxsrc/importexport/guitarpro/tests/guitarbendimporter_data/slight_bend_tied-gp.mscxsrc/importexport/guitarpro/tests/guitarbendimporter_data/tied_bends_release_or_hold-gp.mscxsrc/importexport/mei/tests/data/chord-label-01.mscx
| GuitarBendType TConv::fromXml(const AsciiStringView& tag, GuitarBendType def) | ||
| { | ||
| return findTypeByXmlTag(GUITAR_BEND_TYPES, tag, def); | ||
| } |
There was a problem hiding this comment.
Preserve legacy numeric read compatibility in fromXml().
At Line 2062 and Line 2079, the new lookup is text-only. Older files written before this change may still store numeric enum values; those would now resolve to def and silently alter semantics on load.
Proposed fix (add numeric fallback after tag lookup)
GuitarBendType TConv::fromXml(const AsciiStringView& tag, GuitarBendType def)
{
- return findTypeByXmlTag(GUITAR_BEND_TYPES, tag, def);
+ const GuitarBendType parsed = findTypeByXmlTag(GUITAR_BEND_TYPES, tag, def);
+ if (parsed != def) {
+ return parsed;
+ }
+
+ bool ok = false;
+ const int legacy = toInt(tag, &ok);
+ return ok ? static_cast<GuitarBendType>(legacy) : def;
}
@@
NoteCaseType TConv::fromXml(const AsciiStringView& tag, NoteCaseType def)
{
- return findTypeByXmlTag(NOTE_CASE_TYPES, tag, def);
+ const NoteCaseType parsed = findTypeByXmlTag(NOTE_CASE_TYPES, tag, def);
+ if (parsed != def) {
+ return parsed;
+ }
+
+ bool ok = false;
+ const int legacy = toInt(tag, &ok);
+ return ok ? static_cast<NoteCaseType>(legacy) : def;
}Also applies to: 2077-2080
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/engraving/types/typesconv.cpp` around lines 2060 - 2063, In fromXml(),
the new text-only enum lookup can silently return the default ("def") for legacy
files that store numeric enum values; after the existing string/name-based
lookup, add a numeric fallback: if the lookup result is the default, attempt to
parse the element text as an integer (e.g., with QString::toInt or std::stoi)
and convert that integer to the enum via the same enum cast/mapping used
elsewhere (static_cast or the project's int->enum helper), then use that value
instead of the default; apply the same change to the second occurrence of the
lookup in fromXml() so both name and numeric legacy encodings are supported.
This PR serializes the last couple of enums we were casting to
int.I've also removed the code reading and writing the
subtypetag forActionItems- see #24060 (comment). Now that we read palette file version properly and are not supporting backwards compatibility between MU5 and MU4, this code can go.