mscxyz.Score

class mscxyz.Score(src: str | Path)[source]

Bases: object

This class holds basic file properties of the MuseScore score file.

Parameters:

src – The relative (or absolute) path of a MuseScore file.

__init__(src: str | Path) None[source]

Methods

__init__(src)

backup()

Make a copy of the MuseScore file.

change_path([suffix, extension, filename])

exists()

get_version()

Get the version number of the MuseScore file.

make_snapshot()

new([suffix, extension, filename])

print_diff()

read_as_text()

Read the MuseScore XML file as text.

reload([save])

Reload the MuseScore file.

save([new_dest, mscore])

Save the MuseScore file.

Attributes

backup_file

The absolute path of the backup file.

basename

The basename of the score file, for example: score.

dirname

The name of the containing directory of the MuseScore file, for example: /home/xyz/score_files.

export

extension

The extension (mscx or mscz) of the score file.

fields

filename

The filename of the MuseScore file, for example: score.mscz.

is_uncompressed

Whether the MuseScore file is uncompressed , i.e. it is a *.mscx file.

json_file

The absolute path of the JSON file in which the metadata can be exported.

lyrics

meta

program_revision

The revision number of the MuseScore program, for example: eb8d33c.

program_version

The semantic version number of the MuseScore program, for example: 4.2.0.

style

style_file

Score files created with MuseScore 4 have a separate style file.

version_major

The major MuseScore version, for example 2, 3 or 4

xml_string

zip_container

path

The absolute path of the MuseScore file, for example /home/xyz/score.mscz.

xml_file

The path of the uncompressed MuseScore file in XML format file.

xml_root

The root element of the XML tree.

xml

version

The MuseScore version as a floating point number, for example 2.03, 3.01 or 4.20.

path: Path

The absolute path of the MuseScore file, for example /home/xyz/score.mscz.

zip_container: ZipContainer | None = None
xml_file: str

The path of the uncompressed MuseScore file in XML format file. This path may be located in the temporary directory.

xml: XmlManipulator
xml_root: _Element

The root element of the XML tree. It is the <museScore version="X.X"> Tag. See the lxml API.

version: float

The MuseScore version as a floating point number, for example 2.03, 3.01 or 4.20.

style_file: Path | None = None

Score files created with MuseScore 4 have a separate style file.

property xml_string: str
property version_major: int

The major MuseScore version, for example 2, 3 or 4

property program_version: str

The semantic version number of the MuseScore program, for example: 4.2.0.

<programVersion>4.2.0</programVersion>
See:

MuseScore C++ source code: writer.cpp line 56

property program_revision: str

The revision number of the MuseScore program, for example: eb8d33c.

<programRevision>eb8d33c</programRevision>
See:

MuseScore C++ source code: writer.cpp line 57

property backup_file: Path

The absolute path of the backup file. The string _bak is appended to the file name before the extension.

property json_file: Path

The absolute path of the JSON file in which the metadata can be exported.

property dirname: str

The name of the containing directory of the MuseScore file, for example: /home/xyz/score_files.

property filename: str

The filename of the MuseScore file, for example: score.mscz.

property basename: str

The basename of the score file, for example: score.

property extension: str

The extension (mscx or mscz) of the score file.

property is_uncompressed: bool

Whether the MuseScore file is uncompressed , i.e. it is a *.mscx file

change_path(suffix: Any | None = None, extension: str | None = None, filename: str | None = None) Path[source]
property export: Export
property fields: FieldsManager
property lyrics: Lyrics
property meta: Meta
property style: Style
make_snapshot() None[source]
new(suffix: Any | None = None, extension: str | None = None, filename: str | None = None) Score[source]
exists() bool[source]
backup() None[source]

Make a copy of the MuseScore file.

get_version() float[source]

Get the version number of the MuseScore file.

Returns:

The version number as a float.

Raises:

ValueError – If the version number cannot be retrieved.

print_diff() None[source]
save(new_dest: str = '', mscore: bool = False) None[source]

Save the MuseScore file.

Parameters:
  • new_dest – Save the MuseScore file under a new name.

  • mscore – Save the MuseScore file by opening it with the MuseScore executable and save it there.

read_as_text() str[source]

Read the MuseScore XML file as text.

Returns:

The content of the MuseScore XML file as text.

reload(save: bool = False) Score[source]

Reload the MuseScore file.

Parameters:

save – Whether to save the changes before reloading. Default is False.

Returns:

The reloaded Score object.