Previous topic

music21.midi.translate

Next topic

music21.musedata.base40

Table Of Contents

Table Of Contents

This Page

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 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

>>> mdw = musedata.MuseDataWork()
>>> mdw.addString('WK#:581       MV#:3c\nBreitkopf & Hartel, Vol. 13\nClarinet Quintet\nTrio II\n$  K:0   Q:6   T:3/4   X:-11   C:4\nC5     3        e     d  [     (&0p\nE5     3        e     d  ]')
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.

>>> import os
>>> fp1 = os.path.join(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.

>>> import os
>>> fp1 = os.path.join(common.getSourceFilePath(), 'musedata', 'testPrimitive', 'test01', '01.md')
>>> mdw = musedata.MuseDataWork()
>>> mdw.addFile(fp1)
>>> mdw.getParts()[0].getDirective() is None
True
MuseDataPart.getDivisionsPerQuarterNote()
>>> import os
>>> fp1 = os.path.join(common.getSourceFilePath(), 'musedata', 'testPrimitive', 'test01', '01.md')
>>> mdw = musedata.MuseDataWork()
>>> mdw.addFile(fp1)
>>> mdw.getParts()[0].getDivisionsPerQuarterNote()
6
MuseDataPart.getGroupMembershipNumber(membership='score')
>>> import os
>>> fp1 = os.path.join(common.getSourceFilePath(), 'musedata', 'testPrimitive', 'test01', '01.md')
>>> mdw = musedata.MuseDataWork()
>>> mdw.addFile(fp1)
>>> mdw.getParts()[0].getGroupMembershipNumber()
1
MuseDataPart.getGroupMemberships()
>>> import os
>>> fp1 = os.path.join(common.getSourceFilePath(), 'musedata', 'testPrimitive', 'test01', '01.md')
>>> mdw = musedata.MuseDataWork()
>>> mdw.addFile(fp1)
>>> mdw.getParts()[0].getGroupMemberships()
['sound', 'score']
MuseDataPart.getGroupMembershipsTotal(membership='score')
>>> import os
>>> fp1 = os.path.join(common.getSourceFilePath(), 'musedata', 'testPrimitive', 'test01', '01.md')
>>> mdw = musedata.MuseDataWork()
>>> mdw.addFile(fp1)
>>> mdw.getParts()[0].getGroupMembershipsTotal()
5
MuseDataPart.getKeySignature()
>>> import os
>>> fp1 = os.path.join(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()
>>> import os
>>> fp1 = os.path.join(common.getSourceFilePath(), 'musedata', 'testPrimitive', 'test01', '01.md')
>>> mdw = musedata.MuseDataWork()
>>> mdw.addFile(fp1)
>>> mdw.getParts()[0].getMovementNumber()
'3'
MuseDataPart.getMovementTitle()
>>> import os
>>> fp1 = os.path.join(common.getSourceFilePath(), 'musedata', 'testPrimitive', 'test01', '01.md')
>>> mdw = musedata.MuseDataWork()
>>> mdw.addFile(fp1)
>>> mdw.getParts()[0].getMovementTitle()
'Trio II'
MuseDataPart.getPartName()
>>> import os
>>> fp1 = os.path.join(common.getSourceFilePath(), 'musedata', 'testPrimitive', 'test01', '01.md')
>>> mdw = musedata.MuseDataWork()
>>> mdw.addFile(fp1)
>>> mdw.getParts()[0].getPartName()
'Clarinet in A'
MuseDataPart.getSource()
>>> import os
>>> fp1 = os.path.join(common.getSourceFilePath(), 'musedata', 'testPrimitive', 'test01', '01.md')
>>> mdw = musedata.MuseDataWork()
>>> mdw.addFile(fp1)
>>> mdw.getParts()[0].getSource()
'Breitkopf & H...rtel, Vol. 13'
MuseDataPart.getTimeSignatureObject()
>>> import os
>>> fp1 = os.path.join(common.getSourceFilePath(), 'musedata', 'testPrimitive', 'test01', '01.md')
>>> mdw = musedata.MuseDataWork()
>>> mdw.addFile(fp1)
>>> 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()
>>> import os
>>> fp1 = os.path.join(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

>>> import os
>>> fp1 = os.path.join(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.

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

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()

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()