Skip to content

Serialize last enums when writing#33197

Open
miiizen wants to merge 3 commits intomusescore:masterfrom
miiizen:serializeEnums
Open

Serialize last enums when writing#33197
miiizen wants to merge 3 commits intomusescore:masterfrom
miiizen:serializeEnums

Conversation

@miiizen
Copy link
Copy Markdown
Contributor

@miiizen miiizen commented Apr 29, 2026

This PR serializes the last couple of enums we were casting to int.
I've also removed the code reading and writing the subtype tag for ActionItems - 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.

@miiizen miiizen requested a review from mike-spa April 29, 2026 13:46
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 29, 2026

📝 Walkthrough

Walkthrough

This 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 ActionIcon, GuitarBend, and Harmony elements in the MuseScore file format, removing legacy ActionIcon subtype handling, and adding new conversion methods (toXml and fromXml overloads) for GuitarBendType and NoteCaseType in the TConv utility class. Correspondingly, all related test fixture files are updated to reflect the new text-based enum values instead of numeric codes.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: converting remaining enum serialization from integer casts to textual representation.
Description check ✅ Passed The description clearly explains the two main objectives and provides context, but omits several template sections including CLA signing, commit message verification, and testing information.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

❤️ Share
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 650927a and 4f6b24d.

📒 Files selected for processing (39)
  • src/engraving/rw/read500/tread.cpp
  • src/engraving/rw/write/twrite.cpp
  • src/engraving/tests/parts_data/part-spanners-parts.mscx
  • src/engraving/tests/parts_data/part-spanners.mscx
  • src/engraving/types/typesconv.cpp
  • src/engraving/types/typesconv.h
  • src/importexport/guitarpro/tests/data/basic-bend.gp-ref.mscx
  • src/importexport/guitarpro/tests/data/basic-bend.gp5-ref.mscx
  • src/importexport/guitarpro/tests/data/basic-bend.gpx-ref.mscx
  • src/importexport/guitarpro/tests/data/bend.gp-ref.mscx
  • src/importexport/guitarpro/tests/data/bend.gp3-ref.mscx
  • src/importexport/guitarpro/tests/data/bend.gp4-ref.mscx
  • src/importexport/guitarpro/tests/data/bend.gp5-ref.mscx
  • src/importexport/guitarpro/tests/data/bend.gpx-ref.mscx
  • src/importexport/guitarpro/tests/data/bend_and_glissando.gp-ref.mscx
  • src/importexport/guitarpro/tests/data/bend_and_glissando.gp5-ref.mscx
  • src/importexport/guitarpro/tests/data/bend_and_harmonic.gp-ref.mscx
  • src/importexport/guitarpro/tests/data/bend_and_harmonic.gp5-ref.mscx
  • src/importexport/guitarpro/tests/guitarbendimporter_data/bend_hold-gp.mscx
  • src/importexport/guitarpro/tests/guitarbendimporter_data/bend_on_tuplet-gp.mscx
  • src/importexport/guitarpro/tests/guitarbendimporter_data/bend_on_unequal_chords-gp.mscx
  • src/importexport/guitarpro/tests/guitarbendimporter_data/bend_release-gp.mscx
  • src/importexport/guitarpro/tests/guitarbendimporter_data/bends_release_grace_after-gp.mscx
  • src/importexport/guitarpro/tests/guitarbendimporter_data/bends_tied_1-gp.mscx
  • src/importexport/guitarpro/tests/guitarbendimporter_data/bends_tied_2-gp.mscx
  • src/importexport/guitarpro/tests/guitarbendimporter_data/bends_tied_3-gp.mscx
  • src/importexport/guitarpro/tests/guitarbendimporter_data/grace_chord_diff_bends-gp.mscx
  • src/importexport/guitarpro/tests/guitarbendimporter_data/prebend-gp.mscx
  • src/importexport/guitarpro/tests/guitarbendimporter_data/prebend-gp5.mscx
  • src/importexport/guitarpro/tests/guitarbendimporter_data/prebend_bend-gp.mscx
  • src/importexport/guitarpro/tests/guitarbendimporter_data/prebend_release_bend-gp.mscx
  • src/importexport/guitarpro/tests/guitarbendimporter_data/simple_bend-gp.mscx
  • src/importexport/guitarpro/tests/guitarbendimporter_data/simple_bend_chord-gp.mscx
  • src/importexport/guitarpro/tests/guitarbendimporter_data/slight_bend-gp.mscx
  • src/importexport/guitarpro/tests/guitarbendimporter_data/slight_bend-gp5.mscx
  • src/importexport/guitarpro/tests/guitarbendimporter_data/slight_bend_chord-gp.mscx
  • src/importexport/guitarpro/tests/guitarbendimporter_data/slight_bend_tied-gp.mscx
  • src/importexport/guitarpro/tests/guitarbendimporter_data/tied_bends_release_or_hold-gp.mscx
  • src/importexport/mei/tests/data/chord-label-01.mscx

Comment on lines +2060 to +2063
GuitarBendType TConv::fromXml(const AsciiStringView& tag, GuitarBendType def)
{
return findTypeByXmlTag(GUITAR_BEND_TYPES, tag, def);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant