Previous topic

music21.midi.translate

Next topic

music21.musedata.base40

Table Of Contents

Table Of Contents

This Page

music21.musedata

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 ore more files.

MuseDataWork methods

MuseDataWork.addFile(fp)

Open and read this file path as

MuseDataWork.addString(input_str)

Add a string representation acting like a part file

>>> from music21.musedata import testFiles
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bach_cantata5_mvmt3)
MuseDataWork.getParts()

Get all parts contained in all files associated with this work. A list of MuseDataPart objects that were created in a MuseDataFile.

MuseDataDirectory

class music21.musedata.MuseDataDirectory(dirOrList)

This class manages finding musedata files stored in a directory, comparing file names and examining sub directories 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 methods

MuseDataDirectory.getPaths(group=None)

Return sorted paths for a group, or None

MuseDataDirectory.isMusedataFile(fp)

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 methods

MuseDataFile.close()
MuseDataFile.open(fp)
MuseDataFile.read()
MuseDataFile.readstr(input_str)

Read a string, dividing it into individual parts.

MuseDataMeasure

class music21.musedata.MuseDataMeasure(src=[], 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 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 lost of all records stored in this measure as MuseDataRecord.

MuseDataMeasure.hasNotes()

Return True of if this Measure return Notes

MuseDataMeasure.hasVoices()

Return True of if this Measure defines one or more ‘back’ indication.

Note: this does not instantiate MuseDataRecord instances.

MuseDataMeasureIterator

class music21.musedata.MuseDataMeasureIterator(src, boundaries, parent)

Create MuseDataMeasure objects on demand, in order

MuseDataMeasureIterator methods

MuseDataMeasureIterator.next()

MuseDataPart

class music21.musedata.MuseDataPart(src=[], stage=None)

A MuseData part is defined by collection of lines

MuseDataPart methods

MuseDataPart.getClefObject(voice=1)

Return a music21 clef object based on a two character clef definition.

>>> from music21.musedata import testFiles
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bach_cantata5_mvmt3)
>>> mdw.getParts()[0].getClefObject().sign
'C'
MuseDataPart.getDirective()

The directive field is generally used to store tempo indications.This indication, however, is frequently not provided.

>>> from music21.musedata import testFiles
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.hwv56_movement1_17)
>>> mdw.getParts()[3].getDirective()
'Largo e piano'
MuseDataPart.getDivisionsPerQuarterNote()
>>> from music21.musedata import testFiles
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bach_cantata5_mvmt3)
>>> mdw.getParts()[0].getDivisionsPerQuarterNote()
4
>>> mdw.getParts()[0].getDivisionsPerQuarterNote()
4
>>> mdw.getParts()[1].getDivisionsPerQuarterNote()
8
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bachContrapunctus1_part1)
>>> mdw.getParts()[0].getDivisionsPerQuarterNote()
4.0
MuseDataPart.getGroupMembershipNumber(membership='score')
>>> from music21.musedata import testFiles
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bach_cantata5_mvmt3)
>>> mdw.getParts()[0].getGroupMembershipNumber()
1
>>> mdw.getParts()[1].getGroupMembershipNumber()
2
>>> mdw.getParts()[2].getGroupMembershipNumber()
3
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bachContrapunctus1_part2)
>>> mdw.getParts()[0].getGroupMembershipNumber()
'2'
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bachContrapunctus1_part1)
>>> mdw.getParts()[0].getGroupMembershipNumber()
'1'
MuseDataPart.getGroupMemberships()
>>> from music21.musedata import testFiles
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bach_cantata5_mvmt3)
>>> mdw.getParts()[0].getGroupMemberships()
['score']
MuseDataPart.getGroupMembershipsTotal(membership='score')
>>> from music21.musedata import testFiles
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bach_cantata5_mvmt3)
>>> mdw.getParts()[0].getGroupMembershipsTotal()
3
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bachContrapunctus1_part2)
>>> mdw.getParts()[0].getGroupMembershipsTotal()
4
MuseDataPart.getKeySignature()
>>> from music21.musedata import testFiles
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bach_cantata5_mvmt3)
>>> mdw.getParts()[0].getKeySignature()
<music21.key.KeySignature of 3 flats>
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bachContrapunctus1_part1)
>>> mdw.getParts()[0].getKeySignature()
<music21.key.KeySignature of 1 flat>
MuseDataPart.getMeasures()

Return a list of all measures stored in this part as MuseDataMeasure objects.

MuseDataPart.getMovementNumber()
>>> from music21.musedata import testFiles
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bach_cantata5_mvmt3)
>>> mdw.getParts()[0].getMovementNumber()
'3'
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bachContrapunctus1_part2)
>>> mdw.getParts()[0].getMovementNumber()
'1'
MuseDataPart.getMovementTitle()
>>> from music21.musedata import testFiles
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bach_cantata5_mvmt3)
>>> mdw.getParts()[0].getMovementTitle()
'Aria'
MuseDataPart.getPartName()
>>> from music21.musedata import testFiles
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bach_cantata5_mvmt3)
>>> mdw.getParts()[0].getPartName()
'Viola Solo'
>>> mdw.getParts()[1].getPartName()
'TENORE'
MuseDataPart.getSource()
>>> from music21.musedata import testFiles
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bach_cantata5_mvmt3)
>>> mdw.getParts()[0].getSource()
'Bach Gesellschaft i'
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bachContrapunctus1_part2)
>>> mdw.getParts()[0].getSource()
'Bach Gesellschaft xxv,1'
MuseDataPart.getTimeSignatureObject()
>>> from music21.musedata import testFiles
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bach_cantata5_mvmt3)
>>> mdw.getParts()[0].getTimeSignatureObject()
<music21.meter.TimeSignature 3/4>
MuseDataPart.getTranspositionIntervalObject()

If this part defines a transposition, return a corresponding Interval object.

>>> import os.path
>>> fp1 = os.path.join(common.getSourceFilePath(), 'musedata', 'testPrimitive', 'test01', '01.md')
>>> fp2 = os.path.join(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()
>>> from music21.musedata import testFiles
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bach_cantata5_mvmt3)
>>> mdw.getParts()[0].getWorkNumber()
'5'
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bachContrapunctus1_part2)
>>> mdw.getParts()[0].getWorkNumber()
'1080'
MuseDataPart.getWorkTitle()
>>> from music21.musedata import testFiles
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bach_cantata5_mvmt3)
>>> mdw.getParts()[0].getWorkTitle()
'Wo soll ich fliehen hin'
>>> mdw = musedata.MuseDataWork()
>>> mdw.addString(testFiles.bachContrapunctus1_part2)
>>> mdw.getParts()[0].getWorkTitle()
'381'
MuseDataPart.update()

After setting the source string, this method must be called to configure the _measureNumberToLine method and set additional attributes.

MuseDataRecord

class music21.musedata.MuseDataRecord(src='', parent=None)

Object for extracting data from a Note or other related record, or a single line of musedata data.

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() == 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
MuseDataRecord.getQuarterLength(divisionsPerQuarterNote=None)
>>> mdr = musedata.MuseDataRecord('Ef4    1        s     d  ==')
>>> mdr.getQuarterLength(4)
0.25
>>> 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()

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

MuseDataRecordIterator

class music21.musedata.MuseDataRecordIterator(src, parent)

Create MuseDataRecord objects on demand, in order

MuseDataRecordIterator methods

MuseDataRecordIterator.next()