Modifier/Note Mixin Classes #1516
mscuthbert
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In #1513 at the (current) bottom, I noticed a bug that is a little bit hard to fix in TimeSigNote (because its glyph is stored pretty far down in the system). And I've realized that the same bugs take place anywhere there is a lot of shared code between a Modifier (or StaveModifier) and a Note. (For instance, Clef and ClefNote; KeySignature and KeySignatureNote). And the difficulty of writing a new Note is probably why we don't have XNote versions of every modifier/stavemodifier.
In other languages, like Python, the answer would be pretty simple: Create something like ClefBase which has all the information that is currently in the Clef (StaveModifier), and then do:
and voila! two related classes deriving from different superclasses but with their shared guts in one place.
The problem of course is that JS does not have multiple inheritance. It is possible to do so with Mixin functions that return classes:
I did this in a lot of projects in the past, and it was really helpful (especially in music21j where I had to port a lot of ideas from Python which has multiple inheritance).
I think that such mixin interfaces would go a long way to avoiding bugs in computing widths, collisions, etc.
It is, however, harder in TypeScript, so just in case we go in this direction, just to note how to set up a TypeScript happy mixin.
TypeScript version:
thoughts?
Beta Was this translation helpful? Give feedback.
All reactions