Skip to content

working on the generator code#167

Closed
webern wants to merge 27 commits into
masterfrom
placeholder
Closed

working on the generator code#167
webern wants to merge 27 commits into
masterfrom
placeholder

Conversation

@webern

@webern webern commented Jun 7, 2026

Copy link
Copy Markdown
Owner

No description provided.

webern and others added 27 commits June 3, 2026 05:18
Delete the project in which core roundtrip, or corert tests were
introduced.
Maintain AGENTS.md with fresh information. Also I had thought that
MusicXML 4.1 was released but it is just the unreleased working version
number, so fix references to it in instruction docs.
Add Jinja2 template rendering for the 101 simple-value
elements, replacing the fake-CT path through
generate_element_h/cpp. Templates and routing config
live in gen/cpp/. Jinja2 is pinned in a new /opt/gen-venv
Docker venv. New `make generate` target runs the
generator inside Docker.
Move mutable sets (SYNTHETIC_OPTIONAL_GROUPS, etc.), static
group dicts, WRAPPING_STREAMCONTENTS, and group_class_name()
into a dedicated module.
Move CORE_ROOT_ATTRS, ATTRS_TYPE_ALIAS, ELEMENTS_DIR_SHARED_ATTRS,
and resolve_attrs_name() into a dedicated module for attribute
struct naming logic.
GROUPS_WITH_REAL_FROM_X_ELEMENT -> group_config.py
DYNAMICS_MARKS, CHOICE_SKIP -> element_config.py
Move the 50-line SCORE_WRAPPER_FLAVOR_CONFIG dict (partwise vs
timewise behavioral knobs) into its own module.
Per-attribute default value overrides are now expressed as
nested TOML tables under [overrides.attr_default], loaded at
import time by overrides.py into the same tuple-keyed dict.
XMLNS_PRESERVING_ATTRS, CHILD_INIT_VALUE_OVERRIDE, and
ELEMENT_HAS_CONTENTS_ALWAYS_TRUE now live in TOML under
[overrides], loaded by overrides.py at import time.
Replace 55-line generate_group_h f-string body with a
group_h.j2 template, registered in config.toml under
[categories.group].
Replace 185-line generate_group_cpp f-string body with a
group_cpp.j2 template. Pre-renders ctor init list and
fromXElementImpl (complex line-wrapping logic) in Python,
passes the rest as structured data to the template.
Replace generate_attrs_h f-string body with attrs_h.j2 template,
registered in config.toml under [categories.attrs].
Replace 125-line generate_attrs_cpp f-string body with
attrs_cpp.j2 template. Pre-renders the ctor init list in
Python, passes attr metadata as structured data.
SCORE_WRAPPER_FLAVOR_CONFIG (partwise/timewise behavioral knobs)
now lives under [score_wrapper] in config.toml, loaded by
score_config.py at import time.
CORE_ROOT_ATTRS, ELEMENTS_DIR_SHARED_ATTRS, and ATTRS_TYPE_ALIAS
now live under [attrs] in config.toml, loaded by attrs_config.py.
OVERWRITE_FILE_STEMS, ELEMENT_CLASS_NAME_OVERRIDE,
ELEMENT_VALUE_TYPE_OVERRIDE, SKIP_ELEMENTS, BESPOKE_FAMILY_OWNED,
and TREE_ELEMENTS now live under [elements] in config.toml.
GENERATE_GROUPS, WRAPPING_STREAMCONTENTS, GROUPS_WITH_REAL_FROM_X,
NESTED_OPTIONAL_SEQUENCE_AS_GROUP, EXTENSION_OPTIONAL_GROUP_RENAME,
UNBOUNDED_SEQUENCE_AS_GROUP, and SYNTHETIC_UNBOUNDED_GROUP_IMPORT_-
GROUP_AFTER now live under [groups] in config.toml.
@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown

Core-dev coverage src/private/mx/core/

Metric Coverage Covered / Total
Lines 68.7% 23306 / 33936
Functions 60.8% 4624 / 7601
Branches 49.5% 17880 / 36118

Download HTML report - unzip and open index.html.

Commit d40f1a0db0f69d69f0166c1da1dfe8cbcbb3ff9d.

@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown

gen-quality gen/

gen-quality: 39.6 / 100   (floor 37.7, +1.9)

  structure     23.1  x0.50   [fn 35.4 / file 10.9]
  cyclomatic    63.2  x0.25
  cognitive     49.1  x0.25

  161 functions across 10 files, 13679 lines (largest file 12343)
  max cc 208  max cognitive 428  max fn loc 1085

Worst offenders (top 5 per axis; full lists in score.json):
  cyclomatic gen/generate.py:3954       generate_tree_parent_cpp           208
  cyclomatic gen/generate.py:578        generate_element_cpp               80
  cyclomatic gen/generate.py:12000      main                               72
  cyclomatic gen/generate.py:10698      generate_note_cpp                  71
  cyclomatic gen/generate.py:3699       generate_tree_parent_h             68
  cognitive  gen/generate.py:3954       generate_tree_parent_cpp           428
  cognitive  gen/generate.py:578        generate_element_cpp               226
  cognitive  gen/generate.py:12000      main                               170
  cognitive  gen/generate.py:3699       generate_tree_parent_h             101
  cognitive  gen/generate.py:10698      generate_note_cpp                  66
  size       gen/generate.py:3954       generate_tree_parent_cpp           1085
  size       gen/generate.py:10698      generate_note_cpp                  616
  size       gen/generate.py:578        generate_element_cpp               529
  size       gen/generate.py:8087       generate_harmony_cpp               376
  size       gen/generate.py:11536      _generate_direction_cpp            376

Commit d40f1a0db0f69d69f0166c1da1dfe8cbcbb3ff9d.

webern added a commit that referenced this pull request Jun 14, 2026
Initially I tried using AI to reverse-engineer the pseudo-hand-rolled
original codegen. It worked but resulted in a 12k lines of unredeemable
Python garbage with no room to maneuver from there. So, I started over
and developed a `gen/` program from the ground up using AI. I tried to
keep it agnostic as to language target, so I think targeting other
languages and use-cases is a real possibility now. Early on, I used Go
and C as language targets to force the AI to think about extensibility.
Those targets exist under `gen/test`, but are intended more as `gen/`
program regression tests than for actual MusicXML use.

For the replaced `mx::core` code, I prioritized compile time and better
use of C++ features like `variant` and `option`. AI wanted to drop the
`ezxml` abstraction and I guess it was time to let it go, so `pugixml`
is promoted to `mx::core` interaction.

A `test-core-dev` target was used to allow the the AI to innovate on
`mx::core` without worrying about `mx::impl` and `mx::api` (in fact, I
deleted those layers during code-gen). Then I replaced those layers and
burned tokens to preserve the `mx::impl` algorithms targeting the new
set of `mx::core` classes.

## References

- Closes #157
- Closes #158
- Progresses #58
- Closes PR #167
- Closes PR #168

## Follow-ups:
- surface more features in the `mx/api` layer. top priority is probably
SMuFL
- better packaging and distribution
@webern

webern commented Jun 14, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #169

@webern webern closed this Jun 14, 2026
@webern webern deleted the placeholder branch June 14, 2026 20:45
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