mung.node_class module

NOTE: This file should become obsolete. The list of classes will be implemented as a sub-JSON from SMuFL.

This module implements the NodeClass, which represents one possible Node class, such as a notehead or a time signature. Aside from defining the “vocabulary” of available object classes for annotation, it also contains some information about how objects of the given class should be displayed in the MUSCIMarker annotation software (ordering related object classes together in menus, implementing a sensible color scheme, etc.). There is nothing interesting about this class, we pulled it into the mung package because the object grammar (i.e. which relationships are allowed and which are not) depends on having NodeClass object as its “vocabulary”, and you will probably want to manipulate the data somehow based on the objects’ relationships (like reassembling notes from notation primitives: notehead plus stem plus flags…), and the grammar file is a reference for doing that.

NodeClass is a plain old data class, nothing interesting about it. The only catch is that colors for rendering in MUSCIMarker are kept as a #RRGGBB string in the XML file, but represented in the NodeClass.color attribute as a triplet of floats between 0 (00) and 255 (ff).

The ___str__() method of the class will output the correct XML representation.

XML example

This is what a single NodeClass element might look like:

<NodeClass>
    <Id>1</Id>
    <Name>notehead-empty</Name>
    <GroupName>note-primitive/notehead-empty</GroupName>
    <Color>#FF7566</Color>
</NodeClass>

See e.g. test/test_data/mff-muscima-classes-annot.xml, which is incidentally the real NodeClass list used for annotating MUSCIMA++.

class mung.node_class.NodeClass(class_id, name, group_name, color)[source]

Bases: object

Information about the annotation class. We’re using it mostly to get the color of rendered Node.

NodeClass is a Plain Old Data class, there is no other functionality beyond simply existing and writing itself out in the appropriate XML format.

mung.node_class.hex2rgb(hstr)[source]

Parse a hex-coded color like ‘#AA0202’ into a floating-point representation.

>>> hex2rgb('#abe822')
(0.6705882352941176, 0.9098039215686274, 0.13333333333333333)
mung.node_class.parse_hex(hstr)[source]

Convert a hexadecimal number string to integer.

>>> parse_hex('33')
51
>>> parse_hex('abe8')
44008
mung.node_class.rgb2hex(rgb)[source]

Convert a floating-point representation of R, G, B values between 0 and 1 (inclusive) to a hex string (strating with a hashmark). Will use uppercase letters for 10 - 15.

>>> rgb = (0.6705882352941176, 0.9098039215686274, 0.13333333333333333)
>>> rgb2hex(rgb)
'#ABE822'