Replies: 10 comments 8 replies
-
|
Just to make sure I understand your proposal and we're talking about the same thing, would you mind writing out one of our example docs with your proposed typing included? When you say you need typing information, that term is a bit ambiguous. The new global To be brutally honest, I would probably never agree to requiring type information. It would be 100% derivable information, completely redundant, inviting only opportunities for errors. It goes against the MNX philosophy of "when possible, use one and only one way to encode things, and use the smallest number of data elements as possible, to avoid opportunities for encoding conflicting information." Finally: I'm not a C++ programmer, but doesn't the JSON Schema give you a machine-readable way of "knowing" which type each object is? (Here I mean "type" in the sense of "MNX type.") Isn't that one of the main benefits of having a JSON Schema in the first place? |
Beta Was this translation helpful? Give feedback.
-
|
The proposal is to add an optional "type" field to {
"mnx": {"version": 1},
"global": {
"measures": [
{
"id": "gm1",
"barline": {"type": "regular"}, // naming conflict here with "type"
"time": {"count": 4, "unit": 4},
"type": "globalMeasure"
}
]
},
"parts": [
{
"id": "p1",
"type": "part"
"measures": [
{
"id": "p1m1",
"type": "measure",
"clefs": [
{"clef": {"sign": "G", "staffPosition": -2}}
],
"sequences": [
{
"content": [
{
"id": "ev1",
"type": "event", // optional: (default is "event")
"duration": {"base": "whole"},
"notes": [
{
"id": "n1",
"type": "note",
"pitch": {"step": "C", "octave": 4}
}
]
}
]
}
]
}
]
}
]
}I'm not aware of a C++ tool that would allow it to infer a type from an arbitrary json location (aka Given your reaction, I'm not expecting it to happen. But if it did, there are some naming conflicts with |
Beta Was this translation helpful? Give feedback.
-
|
Another way to do it would be to turn the ID field itself into a dictionary that included the type. |
Beta Was this translation helpful? Give feedback.
-
|
This discussion was brought up in the proposal to change from XML to MNX. I'm not sure it's really been addressed. "duck typing" in music data is pretty hard. For example, I see that "note" in MNX has You can also say that they will be distinguished by where they appear -- their parent context; i.e., "notes" will only ever appear in an array of notes. But you then only know their type if you also reference the schema -- your software needs to be "schema-aware" and needs to parse a given document and interpret it through the lens of that schema, if you want to give a type to an arbitrary object. Reading arbitrary JSON and making sense of it is not possible in this scenario. Fundamentally, it seems a bit strange to me to leave such a critical component of data understanding to implicit behaviours. The second principle of the "Zen of Python" says "Explicit is better than implicit." Given the choice between stating something directly, and hoping that the right answer emerges from a collection of properties and contexts, I would tend to favour the former. It seems the gain in clarity far outweighs some amount of redundancy. |
Beta Was this translation helpful? Give feedback.
-
|
I don't find appeals to "beauty/ugliness" convincing. The computer that consumes a file does not care about aesthetics. What I care about is making the file as easy to consume as possible. We have introduced a mechanism for universal object lookup by adding a universal |
Beta Was this translation helpful? Give feedback.
-
That's exactly why I could use an explicit type specifier in the data. My work with MNX has been mostly as exporter. But I have been concurrently developing a program that semantically validates an input MNX file. One if those checks is to check the existence and validity of Currently, because Now, suppose I need to validate the One of the attractions of the new universal
But think back to the task of validating a If we end up with a standard where the data does not explicitly name its type, I will probably go the hard-coding route. So I can solve the problem. But it seems like a design flaw, which is why I brought it up. |
Beta Was this translation helpful? Give feedback.
-
|
My proposal (repeated):
or To my mind, it makes sense to either have the type listed inside every object (a view Adrian has rejected and has been settled for some time in my mind) or to have the type specified outside the object -- generally by the schema saying that only Object-Type-X (or null) can go here or with an external type specifier for the few cases such as sequences' "content" where multiple object types can be used (and unlike with To generally not have the type specified in the object but occasionally have it done except with some defaults seems to me the worst choice to make. Unlike MusicXML, I expect the same object type/class to reappear in different parts of the standard—e.g., we will single rhythmic value object used wherever rhythms are needed and not have to have |
Beta Was this translation helpful? Give feedback.
-
|
I guess my question comes back to, why did we move As it is, I am reduced to deciding ahead of time (i.e., at compile time) which IDs I will map and what their types are. This seems to defeat the purpose of moving |
Beta Was this translation helpful? Give feedback.
-
|
Adrian wrote:
I'll reveal myself as one of those talking a lot about how MNX is making itself useful not just as a complete-sheet-music encoding format but as a set of micro-formats for encoding musical concepts such as notes or metronome marks or (here) keys/key-signatures. I don't think that MNX needs to worry about specifying a larger container format (or conversely constrain the user) unless these microformats end up used within MNX. I can imagine referencing this as Apparently a recent change (which I didn't know about when I started #448) really helps this system, as now every Object-Class has its own entry in |
Beta Was this translation helpful? Give feedback.
-
|
Regarding explicit vs implicit type with respect to consuming MNX: Currently, this requires tracking state:
I believe that makes the difference between deserializing and parsing. That bit me when trying simple deserializing with Rust's serde and using data types generated from With an initial naive approach, With An explicit type on |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am a big proponent of
json. The fact that MNX switched tojsonis why I became interested in the project. But one disadvantage ofjsoncompared toxmlis that a json object has no built-in mechanism that says what type an object is. Withxml, the node name can be designed to serve this purpose.With the introduction of universal object IDs into MNX, it becomes possible to create a cross-reference lookup for every object in the document that has an ID. (Up till now I have been creating separate lookup tables per type-with-ID. So I had a note-lookup table, an event-lookup table, a layout-lookup table, etc.) However, a single lookup table provides an easy way to detect duplicate ID errors and reduces code complexity.
The drawback is, a single lookup cannot identify the type of object it finds from the data. I am using C++, so for me this lookup table is going to be something like
That means that if I am going to bind the data in the
json_pointerback to a type (which is the whole point of the lookup), I will have track the type externally to the data. However, if we added an optionaltypeto every object with anid, then it would be embodied in the data. We already have this for content arrays, of course. I'm just suggesting that we consider expanding it to the other objects.As I write this down, I am realizing that external type tracking is actually fairly workable. Still, it requires the program to hard-code the types and that means the program only captures the types it knows about. I thought I would toss this idea out for discussion. Two counter-arguments that do not sway me much are
typevalue would not add that much more, especially if we stick with"event"as the default. Having teethed on 1980s microcomputers, I am continually astonished at how instantaneously a moderately priced 2025 PC can chew through a text file with millions of lines.Beta Was this translation helpful? Give feedback.
All reactions