music21.musedata¶
N.B. in Dec. 2014 MuseData access was removed from music21 because the rights conflicted with access computationally from music21. This module is retained for anyone who has such access, however it is completely untested now and errors cannot and will not be fixed.
Objects and resources for processing MuseData.
MuseData conversion from a file or URL to a Stream
is available through
the music21 converter module’s parse()
function.
>>> from music21 import *
>>> abcScore = converter.parse('d:/data/musedata/myScore.stage2')
Low level MuseData conversion is facilitated by the objects in this module and
music21.musedata.translate.museDataToStreamScore()
.
MuseDataWork¶
- class music21.musedata.MuseDataWork¶
A work might consist of one or more files.
MuseDataWork
bases
MuseDataWork
read-only properties
Read-only properties inherited from ProtoM21Object
:
MuseDataWork
methods
- MuseDataWork.addFile(fp: str | Iterable[str]) None ¶
Open and read this file path or list of paths as MuseDataFile objects and set self.files
- MuseDataWork.addString(input_str)¶
Add a string representation acting like a part file
>>> mdw = musedata.MuseDataWork() >>> mdw.addString('WK#:581 MV#:3c\nBreitkopf & Hartel, Vol. 13\n' + ... 'Clarinet Quintet\n' + ... 'Trio II\n' + ... '$ K:0 Q:6 T:3/4 X:-11 C:4\n' + ... 'C5 3 e d [ (&0p\n' + ... 'E5 3 e d ]')
# TODO: Okay, so what? did we test this or demo anything?
- MuseDataWork.getParts()¶
Get all parts contained in all files associated with this work. A list of MuseDataPart objects that were created in a MuseDataFile.
Methods inherited from ProtoM21Object
:
MuseDataDirectory¶
- class music21.musedata.MuseDataDirectory(dirOrList)¶
This class manages finding musedata files stored in a directory, comparing file names and examining subdirectories to determine which files are parts.
Once found, a MuseDataWork, or a list of paths, can be returned
A directory, or a list of file path stubs, such as that obtained within a zip file, can both be provided.
MuseDataDirectory
bases
MuseDataDirectory
read-only properties
Read-only properties inherited from ProtoM21Object
:
MuseDataDirectory
methods
- MuseDataDirectory.getPaths(group=None)¶
Return sorted paths for a group, or None
- MuseDataDirectory.isMusedataFile(fp)¶
Methods inherited from ProtoM21Object
:
MuseDataFile¶
- class music21.musedata.MuseDataFile¶
A MuseDataFile file may describe one or more MuseDataPart; a Score might need multiple files for complete definition. A MuseDataFile object can be created from a string.
When read, one or more MuseDataPart objects are created and stored on self.parts.
MuseDataFile
bases
MuseDataFile
read-only properties
Read-only properties inherited from ProtoM21Object
:
MuseDataFile
methods
- MuseDataFile.close()¶
- MuseDataFile.open(fp)¶
- MuseDataFile.read()¶
- MuseDataFile.readstr(input_str)¶
Read a string, dividing it into individual parts.
Methods inherited from ProtoM21Object
:
MuseDataMeasure¶
- class music21.musedata.MuseDataMeasure(src=None, parent=None)¶
A MuseDataMeasure is an abstraction of the data contained within a measure definitions.
This needs to be an object to gracefully handle the following cases. Some Measures do not have any notes, for example, and the end of encoding where a final bar line is defined. Some measures do not have numbers or barlin definitions, such as pickup notes. Some measures define barline characteristics. Backup and forward presumably only is contained within a measure.
MuseDataMeasure
bases
MuseDataMeasure
read-only properties
Read-only properties inherited from ProtoM21Object
:
MuseDataMeasure
methods
- MuseDataMeasure.getBarObject()¶
Return a configured music21 bar object. This can be used with the current Measure or applied to a previous Measure.
- MuseDataMeasure.getMeasureObject()¶
Return a configured music21
Measure
.
- MuseDataMeasure.getRecords()¶
Return a list of all records stored in this measure as MuseDataRecord.
- MuseDataMeasure.hasNotes()¶
Return True of if this Measure has Notes
- MuseDataMeasure.hasVoices()¶
Return True of if this Measure defines one or more ‘back’ indication.
Note: this does not instantiate MuseDataRecord instances.
Methods inherited from ProtoM21Object
:
MuseDataMeasureIterator¶
- class music21.musedata.MuseDataMeasureIterator(src, boundaries, parent)¶
Create MuseDataMeasure objects on demand, in order
MuseDataPart¶
- class music21.musedata.MuseDataPart(src=None, stage=None)¶
A MuseData part is defined by collection of lines
MuseDataPart
bases
MuseDataPart
read-only properties
Read-only properties inherited from ProtoM21Object
:
MuseDataPart
methods
- MuseDataPart.getClefObject(voice=1)¶
Return a music21 clef object based on a two character clef definition.
>>> fp1 = (common.getSourceFilePath() / 'musedata' / 'testPrimitive' ... / 'test01' / '01.md') >>> mdw = musedata.MuseDataWork() >>> mdw.addFile(fp1) >>> mdw.getParts()[0].getClefObject().sign 'G'
- MuseDataPart.getDirective()¶
The directive field is generally used to store tempo indications. This indication, however, is frequently not provided.
>>> fp1 = (common.getSourceFilePath() / 'musedata' / 'testPrimitive' ... / 'test01' / '01.md') >>> mdw = musedata.MuseDataWork() >>> mdw.addFile(fp1) >>> mdw.getParts()[0].getDirective() is None True
- MuseDataPart.getDivisionsPerQuarterNote()¶
>>> fp1 = (common.getSourceFilePath() / 'musedata' / 'testPrimitive' ... / 'test01' / '01.md') >>> mdw = musedata.MuseDataWork() >>> mdw.addFile(fp1) >>> mdw.getParts()[0].getDivisionsPerQuarterNote() 6
- MuseDataPart.getGroupMembershipNumber(membership='score')¶
>>> fp1 = (common.getSourceFilePath() / 'musedata' / 'testPrimitive' ... / 'test01' / '01.md') >>> mdw = musedata.MuseDataWork() >>> mdw.addFile(fp1) >>> mdw.getParts()[0].getGroupMembershipNumber() 1
- MuseDataPart.getGroupMemberships()¶
>>> fp1 = (common.getSourceFilePath() / 'musedata' / 'testPrimitive' ... / 'test01' / '01.md') >>> mdw = musedata.MuseDataWork() >>> mdw.addFile(fp1) >>> mdw.getParts()[0].getGroupMemberships() ['sound', 'score']
- MuseDataPart.getGroupMembershipsTotal(membership='score')¶
>>> fp1 = str(common.getSourceFilePath() /'musedata' / 'testPrimitive' ... / 'test01' / '01.md') >>> mdw = musedata.MuseDataWork() >>> mdw.addFile(fp1) >>> mdw.getParts()[0].getGroupMembershipsTotal() 5
- MuseDataPart.getKeyParameters()¶
>>> fp1 = (common.getSourceFilePath() / 'musedata' / 'testPrimitive' ... / 'test01' / '01.md') >>> mdw = musedata.MuseDataWork() >>> mdw.addFile(fp1) >>> mdw.getParts()[0].getKeyParameters() 0
- MuseDataPart.getKeySignature()¶
>>> fp1 = (common.getSourceFilePath() / 'musedata' / 'testPrimitive' ... / 'test01' / '01.md') >>> mdw = musedata.MuseDataWork() >>> mdw.addFile(fp1) >>> mdw.getParts()[0].getKeySignature() <music21.key.KeySignature of no sharps or flats>
- MuseDataPart.getMeasures()¶
Return a list of all measures stored in this part as MuseDataMeasure objects.
- MuseDataPart.getMovementNumber()¶
Returns a string, not an int.
>>> fp1 = (common.getSourceFilePath() / 'musedata' / 'testPrimitive' ... / 'test01' / '01.md') >>> mdw = musedata.MuseDataWork() >>> mdw.addFile(fp1) >>> mdw.getParts()[0].getMovementNumber() '3'
- MuseDataPart.getMovementTitle()¶
>>> fp1 = (common.getSourceFilePath() / 'musedata' / 'testPrimitive' ... / 'test01' / '01.md') >>> mdw = musedata.MuseDataWork() >>> mdw.addFile(fp1) >>> mdw.getParts()[0].getMovementTitle() 'Trio II'
- MuseDataPart.getPartName()¶
>>> fp1 = (common.getSourceFilePath() / 'musedata' / 'testPrimitive' ... / 'test01' / '01.md') >>> mdw = musedata.MuseDataWork() >>> mdw.addFile(fp1) >>> mdw.getParts()[0].getPartName() 'Clarinet in A'
- MuseDataPart.getSource()¶
Return the source (original print encoding) for the score.
>>> fp1 = (common.getSourceFilePath() / 'musedata' / 'testPrimitive' ... / 'test01' / '03.md') >>> mdw = musedata.MuseDataWork() >>> mdw.addFile(fp1) >>> mdw.getParts()[0].getSource() 'Breitkopf & Härtel, Vol. 13'
Note that the publisher is Härtel. MuseData predates the standardization of encoding as UTF-8, so many MuseData files are in Windows (ISO-8859-1) encodings. Music21 tries first in utf-8 and if there are errors will try again in ISO-8859-1, and if it fails it will try to read ignoring any errors (leaving “Hrtel”). In this case, both UTF-8 and ISO-8859-1 support this character (Latin-1 space in Unicode).
If you know the encoding you can pass that to MuseDataWork or MuseDataFile. It is not yet a property you can specify in converter.
>>> mdw = musedata.MuseDataWork() >>> mdw.encoding = 'ISO-8859-1' >>> mdw.addFile(fp1) >>> mdw.getParts()[0].getSource() 'Breitkopf & Härtel, Vol. 13'
- MuseDataPart.getTimeSignatureObject()¶
>>> fp1 = (common.getSourceFilePath() / 'musedata' / 'testPrimitive' ... / 'test01' / '01.md') >>> mdw = musedata.MuseDataWork() >>> mdw.addFile(fp1) >>> mdw.getParts()[0].getTimeSignatureObject() <music21.meter.TimeSignature 3/4>
- MuseDataPart.getTimeSignatureParameters()¶
>>> fp1 = (common.getSourceFilePath() / 'musedata' / 'testPrimitive' ... / 'test01' / '01.md') >>> mdw = musedata.MuseDataWork() >>> mdw.addFile(fp1) >>> mdw.getParts()[0].getTimeSignatureParameters() '3/4'
- MuseDataPart.getTranspositionIntervalObject()¶
If this part defines a transposition, return a corresponding Interval object.
>>> fp1 = (common.getSourceFilePath() / 'musedata' / 'testPrimitive' ... / 'test01' / '01.md') >>> fp2 = (common.getSourceFilePath() / 'musedata' / 'testPrimitive' ... / 'test01' / '02.md') >>> mdw = musedata.MuseDataWork() >>> mdw.addFile(fp1) >>> mdw.addFile(fp2) >>> mdw.getParts()[0].getTranspositionIntervalObject() <music21.interval.Interval m-3>
- MuseDataPart.getWorkNumber()¶
Returns a String not an int, representing an opus number
>>> fp1 = (common.getSourceFilePath() / 'musedata' / 'testPrimitive' ... / 'test01' / '01.md') >>> mdw = musedata.MuseDataWork() >>> mdw.addFile(fp1) >>> mdw.getParts()[0].getWorkNumber() '581'
- MuseDataPart.getWorkTitle()¶
For stage 1 just gets the catalogue number
>>> fp1 = (common.getSourceFilePath() / 'musedata' / 'testPrimitive' ... / 'test01' / '01.md') >>> mdw = musedata.MuseDataWork() >>> mdw.addFile(fp1) >>> mdw.getParts()[0].getWorkTitle() 'Clarinet Quintet'
- MuseDataPart.update()¶
After setting the source string, this method must be called to configure the _measureNumberToLine method and set additional attributes.
Methods inherited from ProtoM21Object
:
MuseDataRecord¶
- class music21.musedata.MuseDataRecord(src: str = '', parent=None)¶
Object for extracting data from a Note or other related record, or a single line of musedata data.
MuseDataRecord
bases
MuseDataRecord
read-only properties
Read-only properties inherited from ProtoM21Object
:
MuseDataRecord
methods
- MuseDataRecord.getArticulationObjects()¶
Return a list of 0 or more music21 Articulation objects
>>> mdr = musedata.MuseDataRecord('C4 12 e u [ .p') >>> mdr.getArticulationObjects() [<music21.articulations.Staccato>]
>>> mdr = musedata.MuseDataRecord('C4 12 e u [ .p>') >>> mdr.getArticulationObjects() [<music21.articulations.Staccato>, <music21.articulations.Accent>]
- MuseDataRecord.getBeams()¶
Return complete span of characters defining beams.
>>> mdr = musedata.MuseDataRecord('E2 1 s u =') >>> mdr.getBeams() '=' >>> mdr = musedata.MuseDataRecord('E2 1 s u ]') >>> mdr.getBeams() ']' >>> mdr = musedata.MuseDataRecord('E2 4 q u') >>> mdr.getBeams() is None True
- MuseDataRecord.getDots()¶
- MuseDataRecord.getDynamicObjects()¶
Return a list of 0 or more music21 Dynamic objects
>>> mdr = musedata.MuseDataRecord('C5 12 e u ff') >>> mdr.getDynamicObjects() [<music21.dynamics.Dynamic ff>]
>>> mdr = musedata.MuseDataRecord('E4 48 h u (pp') >>> mdr.getDynamicObjects() [<music21.dynamics.Dynamic pp>]
- MuseDataRecord.getExpressionObjects()¶
Return a list of 0 or more music21 Articulation objects
>>> mdr = musedata.MuseDataRecord('C4 12 e u [ t') >>> mdr.getExpressionObjects() [<music21.expressions.Trill>]
>>> mdr = musedata.MuseDataRecord('C4 12 e u [ .p>F') >>> mdr.getExpressionObjects() [<music21.expressions.Fermata>]
- MuseDataRecord.getLyrics()¶
Return lyrics as a list.
>>> mdr = musedata.MuseDataRecord('D4 2 e u con-') >>> mdr.stage = 2 >>> mdr.getLyrics() ['con-']
- MuseDataRecord.getPitchObject()¶
Get the Pitch object defined by this record. This may be a note, chord, or grace pitch.
>>> mdr = musedata.MuseDataRecord('Ef4 1 s d ==') >>> p = mdr.getPitchObject() >>> p.nameWithOctave 'E-4' >>> mdr = musedata.MuseDataRecord('F#4 1 s # d ==') >>> p = mdr.getPitchObject() >>> p.nameWithOctave 'F#4' >>> p.accidental.displayStatus True
Double sharps were giving octave problems.
>>> mdr = musedata.MuseDataRecord('F##5 2 e x d') >>> p = mdr.getPitchObject() >>> p.nameWithOctave 'F##5'
- MuseDataRecord.getQuarterLength(divisionsPerQuarterNote=None)¶
Gets the quarterLength of the note given the prevailing divisionsPerQuarterNote
Here there is one division:
>>> mdr = musedata.MuseDataRecord('Ef4 1 s d ==') >>> mdr.getQuarterLength(4) 0.25 >>> mdr.getQuarterLength(8) 0.125
>>> mdr = musedata.MuseDataRecord('Ef4 6 s d ==') >>> mdr.getQuarterLength(4) 1.5
>>> mdr = musedata.MuseDataRecord('back 4') >>> mdr.getQuarterLength(4) 1.0
- MuseDataRecord.hasCautionaryAccidental()¶
Return a boolean if this note has a cautionary accidental.
>>> mdr = musedata.MuseDataRecord('F5 3 t n d ==[ (+') >>> mdr.hasCautionaryAccidental() True
>>> mdr = musedata.MuseDataRecord('C4 12 e u [') >>> mdr.hasCautionaryAccidental() False
- MuseDataRecord.isBack()¶
>>> mdr = musedata.MuseDataRecord('back 4') >>> mdr.isBack() True
- MuseDataRecord.isChord()¶
Chords are specified as additional note records following a main chord tone. The blank space defines this as chord tone.
- MuseDataRecord.isCueOrGrace()¶
- MuseDataRecord.isNote()¶
- MuseDataRecord.isRest() bool ¶
Return a boolean if this record is a rest.
>>> mdr = musedata.MuseDataRecord('D4 1 s d ]]') >>> mdr.isRest() False >>> mdr = musedata.MuseDataRecord('measure 1 A') >>> mdr.isRest() False
- MuseDataRecord.isTied()¶
Return a boolean if this record is tied.
>>> mdr = musedata.MuseDataRecord('D4 8- h d -') >>> mdr.isTied() True
>>> mdr = musedata.MuseDataRecord('C4 1 s u [[') >>> mdr.isTied() False
Methods inherited from ProtoM21Object
:
MuseDataRecordIterator¶
- class music21.musedata.MuseDataRecordIterator(src, parent)¶
Create MuseDataRecord objects on demand, in order