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)

Note that .mxl and .mx are only considered MusicXML input formats.

>>> common.findFormat('mx')
('musicxml', '.xml')
>>> common.findFormat('.mxl')
('musicxml', '.xml')
>>> common.findFormat('musicxml')
('musicxml', '.xml')
>>> 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')
>>> common.findFormat('mx')
('musicxml', '.xml')

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('')
('musicxml', '.mx')
>>> 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 = 'http://junk'
>>> common.findFormatExtURL(urlA)
('musicxml', '.xml')
>>> common.findFormatExtURL(urlB)
('humdrum', '.krn')
>>> common.findFormatExtURL(urlC)
('musicxml', '.xml')
>>> common.findFormatExtURL(urlF)
(None, None)

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’


Will be fully deprecated when there’s an exact equivalent in converter…

Given an input format or music21 format, find and return all possible input extensions.

>>> a = common.findInputExtension('musicxml')
>>> a
('.xml', '.mxl', '.mx', '.musicxml')
>>> a = common.findInputExtension('humdrum')
>>> a
>>> common.findInputExtension('musedata')
('.md', '.musedata', '.zip')

mx is not a music21 format but it is a file format

>>> common.findInputExtension('mx')
('.xml', '.mxl', '.mx', '.musicxml')

Leading dots don’t matter…

>>> common.findInputExtension('.mx')
('.xml', '.mxl', '.mx', '.musicxml')

blah is neither

>>> common.findInputExtension('blah') is 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'>

Some subconverters have format aliases

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