Skip to content

Conversation

@simonchatts
Copy link
Contributor

Currently plugins cannot access voltas, since these are in the Score's spannerMap. This PR exposes both the spannerMap and the Volta class to the API. Plugins can either iterate all Score-level spanners using curScore.spanners, or filter down using, eg:

for (const volta of curScore.spannersOfType(Element.VOLTA)) {
    volta.lineColor = "#ff0000";
}

I've tested plugins using this sort of thing and they seem to work fine.

I've tried to follow the existing conventions: just safely expose the DOM directly with a minimal API layer. In particular, iterating the spannerMap from a plugin is quadratic (spannerListCount() and spannerListAt() both are O(n)) but the alternative seems to be building some sort of cache and knowing when to invalidate it, which is opening a can of worms. The scores I've tested have only had a small number of voltas, ties etc, and so exhibited no performance issues whatsoever.

I've assumed this will be a 4.7 thing in the new \since declarations.

The compiler warning fix 9da9c63 becomes an error with the other changes, hence its inclusion here.

  • I signed the CLA
  • The title of the PR describes the problem it addresses
  • Each commit's message describes its purpose and effects, and references the issue it resolves
  • If changes are extensive, there is a sequence of easily reviewable commits
  • The code in the PR follows the coding rules
  • There are no unnecessary changes
  • The code compiles and runs on my machine, preferably after each commit individually
  • I created a unit test or vtest to verify the changes I made (if applicable)

@simonchatts simonchatts changed the title Voltas after crash Expose voltas and Score spannerMap to plugins Nov 14, 2025
Copy link
Contributor

@XiaoMigros XiaoMigros left a comment

Choose a reason for hiding this comment

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

I am opposed to exposing voltas as a separate element in the API. All the newly added properties are retrievable with the API already (and if they aren't, then that is due to more systemic issues that should be solved by other means).
Exposing the spanner map is a welcome change, as those are some of the last elements that plugins have (up to now) had no easy way of finding.

@simonchatts
Copy link
Contributor Author

I am opposed to exposing voltas as a separate element in the API.

Makes sense. I'll drop the voltas, and the separate spannersOfType method, and force-push an update. Thanks for the speedy comments!

@XiaoMigros
Copy link
Contributor

For the record, volta endings can be accessed by the volta_ending property, listed in elements.h. beginText as well as endHookType cover all the remaining properties.

@simonchatts
Copy link
Contributor Author

Changes pushed - should resolve all review comments so far. I've also updated the title to be more accurate. The updated example to turn voltas red is:

for (const spanner of curScore.spanners) {
    if (spanner.type === Element.VOLTA)) {
        spanner.lineColor = "#ff0000";
    }
}

@simonchatts simonchatts changed the title Expose voltas and Score spannerMap to plugins Expose Score spannerMap to plugins Nov 14, 2025
Copy link
Contributor

@XiaoMigros XiaoMigros left a comment

Choose a reason for hiding this comment

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

After testing locally, this is great! A very useful addition to the API.

@manolo
Copy link
Contributor

manolo commented Nov 16, 2025

This fixes: #31061

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.

3 participants