muscima.cropobject_class module

This module implements the CropObjectClass, which represents one possible CropObject 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 muscima package because the object grammar (i.e. which relationships are allowed and which are not) depends on having CropObjectClass 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.

CropObjectClass 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 CropObjectClass.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 CropObjectClass element might look like:


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

class muscima.cropobject_class.CropObjectClass(clsid, name, group_name, color)[source]

Bases: object

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

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


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

>>> hex2rgb('#abe822')
(0.6705882352941176, 0.9098039215686274, 0.13333333333333333)

Convert a hexadecimal number string to integer.

>>> parse_hex('33')
>>> parse_hex('abe8')

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)