|
MNX Document Model
|
Provides type-safe ID-based lookup for elements in an MNX document. More...
#include <EntityMap.h>
Classes | |
| struct | MappedPosition |
| Canonical position value used by EntityMap for measure-relative comparisons and caches. More... | |
Public Member Functions | |
| EntityMap (std::weak_ptr< json > documentRoot, const std::optional< ErrorHandler > &errorHandler=std::nullopt) | |
| Constructs the index for a given document. | |
| template<typename T > | |
| std::optional< T > | tryGet (const std::string &id, const std::optional< Base > &errorLocation=std::nullopt) const |
| Attempts to look up an object by string ID. | |
| template<typename T > | |
| T | get (const std::string &id, const std::optional< Base > &errorLocation=std::nullopt) const |
| Looks up an object by string ID. | |
| template<typename T > | |
| size_t | getIndexOf (const std::string &id, const std::optional< Base > &errorLocation=std::nullopt) const |
| Returns the array index of an object identified by ID. | |
| template<typename T > | |
| bool | exists (const std::string &id) const |
Returns whether the specified ID exists in the mapping with type T. | |
| std::optional< part::Beam > | tryGetBeam (const sequence::Event &event) const |
| Get the beam for an event, if it is mapped. | |
| std::optional< int > | tryGetBeamStartLevel (const std::string &eventId) const |
| Return the secondary beam depth that starts at an event ID, if any. | |
| int | getBeamStartLevel (const std::string &eventId) const |
| Return the beam start level for an event ID or 0 if none. | |
| void | clear () |
| Clears all mapped items. | |
| std::optional< int > | tryGetOttavaShift (const sequence::Event &event) const |
| Retrieve the ottava shift for an event (if known). | |
| int | getOttavaShift (const sequence::Event &event) const |
| Retrieve the ottava shift for an event. Returns 0 if not cached. | |
| std::optional< MappedPosition > | tryGetEventPosition (const sequence::Event &event) const |
| Retrieve the cached mapped position for an event (if known). | |
| MappedPosition | getEventPosition (const sequence::Event &event) const |
| Retrieve the cached mapped position for an event. | |
| int | comparePositions (const MappedPosition &lhs, const MappedPosition &rhs, bool rhsIncludesTrailingGrace=false) const |
| Compare two mapped positions using global measure order and grace-note targeting. | |
| const std::vector< std::string > & | getLyricLineOrder () const |
| Retrieve the lyric line order. | |
Friends | |
| class | mnx::Document |
Provides type-safe ID-based lookup for elements in an MNX document.
Constructed from an mnx::Document, the EntityMap scans the document to index all identifiable elements by ID. Supports lookup by type.
|
inlineexplicit |
Constructs the index for a given document.
| documentRoot | Shared pointer to the document's JSON root. |
| errorHandler | A optional callback function for handling errors. |
| int mnx::util::EntityMap::comparePositions | ( | const MappedPosition & | lhs, |
| const MappedPosition & | rhs, | ||
| bool | rhsIncludesTrailingGrace = false |
||
| ) | const |
Compare two mapped positions using global measure order and grace-note targeting.
The inputs may be native MappedPosition values or regular document-backed MeasureRhythmicPosition objects converted implicitly to MappedPosition, provided their measureId values refer to global measure IDs already present in this EntityMap.
| lhs | The left-hand position to compare. |
| rhs | The right-hand position to compare. |
| rhsIncludesTrailingGrace | When true, a right-hand position with graceIndex == 0 is treated as also including trailing grace notes at the same fractional position, so those grace positions compare equal to rhs rather than later than it. |
lhs is earlier, 1 if later, or 0 if equivalent for the requested policy.
|
inline |
Looks up an object by string ID.
| T | The expected type (e.g., mnx::Part, mnx::Layout, mnx::sequence::Note). |
| id | The ID to search for. |
| errorLocation | The location in the document for error reporting purposes. |
| mapping_error | if the ID is not found. |
|
inline |
Returns the array index of an object identified by ID.
Looks up an object of type T by its ID and returns the index of that object within its owning array. This is equivalent to calling get<T>() followed by ArrayElementObject::calcArrayIndex().
| T | The expected object type. Must derive from ArrayElementObject. |
| id | The ID of the object to locate. |
| errorLocation | Optional document location used for error reporting. |
| mapping_error | if the ID is not found or does not refer to an object of type T. |
|
inline |
Attempts to look up an object by string ID.
| T | The expected type (e.g., mnx::Part, mnx::Layout, mnx::sequence::Note). |
| id | The ID to search for. |
| errorLocation | The location in the document for error reporting purposes. |
| mapping_error | if the ID is found but has a different type than T (release builds only; debug builds assert instead). |
|
inline |
Get the beam for an event, if it is mapped.
| event | The event to search for. |