Utilities for working with file formats.

almost everything here is deprecated.



Given a format defined either by a format name, abbreviation, or an extension, return the regularized format name as well as the output extensions.

DEPRECATED May 2014 – moving to converter

All but the first element of the tuple are deprecated for use, since the extension can vary by subConverter (e.g., lily.png)

>>> common.findFormat('.mxl')
('musicxml', '.musicxml')
>>> common.findFormat('musicxml')
('musicxml', '.musicxml')
>>> common.findFormat('lily')
('lilypond', '.ly')
>>> common.findFormat('lily.png')
('lilypond', '.ly')
>>> common.findFormat('humdrum')
('humdrum', '.krn')
>>> common.findFormat('txt')
('text', '.txt')
>>> common.findFormat('textline')
('textline', '.txt')
>>> common.findFormat('midi')
('midi', '.mid')
>>> common.findFormat('abc')
('abc', '.abc')
>>> common.findFormat('scl')
('scala', '.scl')
>>> common.findFormat('braille')
('braille', '.txt')
>>> common.findFormat('vexflow')
('vexflow', '.html')
>>> common.findFormat('capx')
('capella', '.capx')

Works the same whether you have a leading dot or not:

>>> common.findFormat('md')
('musedata', '.md')
>>> common.findFormat('.md')
('musedata', '.md')

If you give something we can’t deal with, returns a Tuple of None, None:

>>> common.findFormat('wpd')
(None, None)

These don’t work but should eventually:

# >>> common.findFormat(‘png’) # (‘musicxml.png’, ‘.png’)

# >>> common.findFormat(‘ipython’) # (‘ipython’, ‘.png’) # >>> common.findFormat(‘ipython.png’) # (‘ipython’, ‘.png’)

# >>> common.findFormat(‘musicxml.png’) # (‘musicxml.png’, ‘.png’)


Given a file path (relative or absolute) find format and extension used (not the output extension)

DEPRECATED May 2014 – moving to converter

>>> common.findFormatExtFile('test.mxl')
('musicxml', '.mxl')
>>> common.findFormatExtFile('long/file/path/test-2009.03.02.xml')
('musicxml', '.xml')
>>> common.findFormatExtFile('long/file/path.intermediate.png/test-2009.03.xml')
('musicxml', '.xml')
>>> common.findFormatExtFile('test')
(None, None)

Windows drive >>> common.findFormatExtFile(‘d:/long/file/path/test.xml’) (‘musicxml’, ‘.xml’)

On a windows networked filesystem >>> common.findFormatExtFile(r’\longfilepathtest.krn’) (‘humdrum’, ‘.krn’)


Given a URL, attempt to find the extension. This may scrub arguments in a URL, or simply look at the last characters.

DEPRECATED May 2014 – moving to converter

>>> urlA = ''
>>> urlB = ''
>>> urlC = ''
>>> urlF = 'https://junk'
>>> urlM = ''
>>> common.findFormatExtURL(urlA)
('musicxml', '.xml')
>>> common.findFormatExtURL(urlB)
('humdrum', '.krn')
>>> common.findFormatExtURL(urlC)
('musicxml', '.xml')
>>> common.findFormatExtURL(urlF)
(None, None)
>>> common.findFormatExtURL(urlM)
('midi', '.mid')

Given a file path (relative or absolute) return the format

DEPRECATED May 2014 – moving to converter

>>> common.findFormatFile('test.xml')
>>> common.findFormatFile('long/file/path/test-2009.03.02.xml')
>>> common.findFormatFile('long/file/path.intermediate.png/test-2009.03.xml')

On a windows networked filesystem >>> common.findFormatFile(r’\longfilepathtest.krn’) ‘humdrum’

music21.common.formats.findSubConverterForFormat(fmt: str) type[SubConverter] | None

return a converter.subConverter.SubConverter subclass for a given format – this is a music21 format name, not a file extension. Or returns None

>>> common.findSubConverterForFormat('musicxml')
<class 'music21.converter.subConverters.ConverterMusicXML'>
>>> common.findSubConverterForFormat('text')
<class 'music21.converter.subConverters.ConverterText'>
>>> common.findSubConverterForFormat('romantext')
<class 'music21.converter.subConverters.ConverterRomanText'>

Some subConverters have format aliases

>>> common.findSubConverterForFormat('t')
<class 'music21.converter.subConverters.ConverterText'>