Previous topic

music21.abcFormat

Next topic

music21.analysis.correlate

Table Of Contents

Table Of Contents

This Page

music21.abcFormat.translate

Functions for translating music21 objects and ABCHandler instances. Mostly, these functions are for advanced, low level usage. For basic importing of ABC files from a file or URL to a Stream, use the music21 converter module’s parse() function.

Functions

music21.abcFormat.translate.abcToStreamOpus(abcHandler, inputM21=None, number=None)

Convert a multi-work stream into one or more complete works packed into a an Opus Stream.

If a number argument is given, and a work is defined by that number, that work is returned.

music21.abcFormat.translate.abcToStreamPart(abcHandler, inputM21=None, spannerBundle=None)

Handler conversion of a single Part of a multi-part score. Results are added into the provided inputM21 object or a newly created Part object

The part object is then returned.

music21.abcFormat.translate.abcToStreamScore(abcHandler, inputM21=None)

Given an abcHandler object, build into a multi-part Score with metadata.

This assumes that this ABCHandler defines a single work (with 1 or fewer reference numbers).

if the optional parameter inputM21 is given a music21 Stream subclass, it will use that object as the outermost object. However, inner parts will always be made Part objects.

music21.abcFormat.translate.reBar(music21Part, inPlace=True)

Re-bar overflow measures using the last known time signature.

>>> from music21 import corpus
>>> irl = corpus.parse("irl")
>>> music21Part = irl[1][1]

The whole part is in 2/4 time, but there are some measures expressed in 4/4 time without an explicit time signature change, an error in abc parsing due to the omission of barlines. The method will split those measures such that they conform to the last time signature, in this case 2/4. The default is to reBar in place. The measure numbers are updated accordingly. (NOTE: reBar is called automatically in abcToStreamPart)

The key signature and clef are assumed to be the same in the second measure after the split, so both are omitted. If the time signature is not the same in the second measure, the new time signature is indicated, and the measure following returns to the last time signature, except in the case that a new time signature is indicated.

>>> music21Part.measure(15).show("text")
{0.0} <music21.note.Note A>
{1.0} <music21.note.Note A>
>>> music21Part.measure(16).show("text")
{0.0} <music21.note.Note A>
{0.5} <music21.note.Note B->
{1.0} <music21.note.Note A>
{1.5} <music21.note.Note G>

An example where the time signature wouldn’t be the same. This score is mistakenly marked as 4/4, but has some measures that are longer.

>>> music21Part2 = irl[14][1] # 4/4 time signature
>>> music21Part2.measure(1).show("text")
{0.0} <music21.note.Note C>
{1.0} <music21.note.Note A>
{1.5} <music21.note.Note G>
{2.0} <music21.note.Note E>
{2.5} <music21.note.Note G>
>>> music21Part2.measure(2).show("text")
{0.0} <music21.meter.TimeSignature 1/8>
{0.0} <music21.note.Note E>