
    rhX                      % S r SSKJr  SSKJr  SSKrSSKJr  SSKrSSK	J
r
  SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKrSSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ r   SSK!J"r"  \RF                  (       a  SSKJ$r$  / SQr%\RL                  " S5      r'\RP                  " S\)\*-  S9r+ " S S\RX                  5      r- " S S\RX                  5      r. " S S\RX                  5      r/ " S S\RX                  5      r0 " S S5      r1 " S  S!5      r2\" 5       r3S"\4S#'   \" 5       r5S$\4S%'   S& r6SES' jr7\Rp                  " S(S)S*5          SES+ j5       r9    SFS, jr:\Rp                  " S(S)S-5          SES. j5       r; " S/ S05      r<   SG SHS2 jjr=  SI SHS3 jjr>SSS1S4. SHS5 jjr?S1SSS6.       SJS7 jjr@SKS8 jrASLSMS9 jjrBSNS: jrCSOS; jrDS< rESPS= jrF " S> S?\R                  5      rH " S@ SA\R                  5      rI " SB SC\R                  5      rJ\@\=\>\?\B\C\D\E\<\7\:/rK\LSD:X  a  SSKr\R                  " \J5        gg)Qa  
music21.converter contains tools for loading music from various file formats,
whether from disk, from the web, or from text, into
music21.stream.:class:`~music21.stream.Score` objects (or
other similar stream objects).

The most powerful and easy to use tool is the :func:`~music21.converter.parse`
function. Simply provide a filename, URL, or text string and, if the format
is supported, a :class:`~music21.stream.Score` will be returned.

This is the most general, public interface for all formats.  Programmers
adding their own formats to the system should provide an interface here to
their own parsers (such as humdrum, musicxml, etc.)

The second and subsequent times that a file is loaded it will likely be much
faster since we store a parsed version of each file as a "pickle" object in
the temp folder on the disk.

>>> #_DOCS_SHOW s = converter.parse('d:/myDocs/schubert.krn')
>>> s = converter.parse(humdrum.testFiles.schubert) #_DOCS_HIDE
>>> s
<music21.stream.Score ...>
    )annotations)dequeN)	responses)isclose)subConverters)	museScore)_version)common)environment)exceptions21)metadata)musedata)stream)bundles)base)r   r   ArchiveManagerExceptionPickleFilterExceptionConverterExceptionConverterFileExceptionArchiveManagerPickleFilterresetSubConvertersregisterSubConverterunregisterSubConverter	Converter	parseFile	parseDataparseURLparsefreezethaw	freezeStrthawStr	converter_StrOrBytes)boundc                      \ rS rSrSrg)r   W    N__name__
__module____qualname____firstlineno____static_attributes__r)       T/home/james-whalen/.local/lib/python3.13/site-packages/music21/converter/__init__.pyr   r   W       r0   r   c                      \ rS rSrSrg)r   [   r)   Nr*   r)   r0   r1   r   r   [   r2   r0   r   c                      \ rS rSrSrg)r   _   r)   Nr*   r)   r0   r1   r   r   _   r2   r0   r   c                      \ rS rSrSrg)r   c   r)   Nr*   r)   r0   r1   r   r   c   r2   r0   r   c                  b    \ rS rSrSrS
SS jjrSS jrSS jrSSS jjr S     SS jjr	Sr
g	)r   h   a  
Before opening a file path, this class can check if this is an
archived file collection, such as a .zip or .mxl file. This will return the
data from the archive.

>>> fnCorpus = corpus.getWork('bwv66.6', fileExtensions=('.xml',))

This is likely a unicode string

>>> #_DOCS_SHOW fnCorpus
>>> '/Users/cuthbert/git/music21base/music21/corpus/bach/bwv66.6.mxl' #_DOCS_HIDE
'/Users/cuthbert/git/music21base/music21/corpus/bach/bwv66.6.mxl'
>>> am = converter.ArchiveManager(fnCorpus)
>>> am.isArchive()
True
>>> am.getNames()
['bwv66.6.xml', 'META-INF/container.xml']
>>> data = am.getData()
>>> data[0:70]
'<?xml version="1.0" encoding="UTF-8"?>\r<!DOCTYPE score-partwise PUBLIC'

The only archive type supported now is zip. But .mxl is zip so that covers almost
everything.
c                D    [         R                  " USS9U l        X l        g NTreturnPathlib)r
   	cleanpathfparchiveType)selfr@   rA   s      r1   __init__ArchiveManager.__init__   s     & 0 04 H +r0   c                p   U R                   S:X  ad  U R                  R                  S;   a-   [        R                  " U R                  S5       n SSS5        gU R                  R                  S:X  a  g g[        SU R                    35      e! , (       d  f       g= f! [        R
                   a     gf = f)	zQ
Return True or False if the filepath is an
archive of the supplied archiveType.
zip).mxlz.mdrNFTz.zipzno support for archiveType: )rA   r@   suffixzipfileZipFile
BadZipfiler   )rB   unuseds     r1   	isArchiveArchiveManager.isArchive   s    
 u$ww~~0! #6& 7 6) *  *,HIYIYHZ*[\\ 76  )) ! !s/   !B BB 
BB B B54B5c                    / nU R                   S:X  aT  [        R                  " U R                  S5       nUR	                  5        H  nUR                  U5        M     SSS5        U$ U$ ! , (       d  f       U$ = f)z7
Return a list of all names contained in this archive.
rF   rH   N)rA   rJ   rK   r@   namelistappend)rB   postfsubFps       r1   getNamesArchiveManager.getNames   sg     u$#.!ZZ\EKK& * / t /. s   )A))
A8c                    SnU R                   S:w  a  [        SU R                    35      e[        R                  " U R                  S5       nU R                  X15      nSSS5        U$ ! , (       d  f       U$ = f)z
Return data from the archive.

For 'musedata' format this will be a list of strings.
For 'musicxml' this will be a single string.

* Changed in v8: name is not used.
NrF   zno support for extension: rH   )rA   r   rJ   rK   r@   _extractContents)rB   
dataFormatrS   rT   s       r1   getDataArchiveManager.getData   sq     u$),FtGWGWFX*YZZ__TWWc*a((7D +  +* s   A((
A7c                    S nUS:X  a  UR                  5        H  nSU;   a  M  [        R                  " U5      R                  S;  a  M1  UR	                  U5      n[        U[        5      (       aT  [        R                  " SUS S 5      nU(       a!  UR                  S5      R                  S5      nOSn UR                  US	9n  U$     U$ US:X  a  [        R                  " UR                  5       5      n/ nUR                  5        H]  n UR!                  US5       n[#        [$        R&                  " US S95      n	S S S 5        UR)                  SR+                  W	5      5        M_     U$ ! [         a*    UR                  S
S	9n[        R                  " SSU5      n Nf = f! , (       d  f       Nk= f! [         aP    UR!                  US5       n[#        [$        R&                  " US SS95      n	S S S 5         M  ! , (       d  f        N= ff = f)NmusicxmlzMETA-INF)z	.musicxmlz.xmlrG   s   encoding=[\'\"](\S*?)[\'\"]i     asciizUTF-8encodingz	utf-16-lezencoding=([\'\"]\S*?[\'\"])zencoding='UTF-8'r   rH   )newlinez
ISO-8859-1)rc   rb    )rQ   pathlibPathrI   read
isinstancebytesrematchgroupdecodeUnicodeDecodeErrorsubmusedataModuleMuseDataDirectorygetPathsopenlistioTextIOWrapperrR   join)
rB   rT   rZ   rS   rU   foundEncodingdefaultEncodingmddzipOpenliness
             r1   rY   ArchiveManager._extractContents   s    #  &<<&--5RRvve}dE**$&HH-LdSXTXk$ZM$*7*=*=a*@*G*G*P +2@#{{O{D B s &r ? :% !221::<@C D
Ns+w $R%5%5gt%L M , BGGEN+ (. M . @#{{K{@!vv&D&8$ @@* ,+) Ns+w $R%5%5gt?K&M !N ,+++NsZ   5E+F3F"=F3+1FF"
F0	,F30F33H G:/H:
H	H	H)rA   r@   N)rF   )r@   str | pathlib.Path)returnbool)r   z	list[str])r^   )r   t.Any)rT   zzipfile.ZipFilerZ   strr   r   )r+   r,   r-   r.   __doc__rC   rN   rV   r[   rY   r/   r)   r0   r1   r   r   h   sG    6,*	( ,6C+C%(C:?C Cr0   r   c                  d    \ rS rSrSr  S	     S
S jjr  S     SS jjrSS jrSS jrSr	g)r   i  aY  
Before opening a file path, this class checks to see if there is an up-to-date
version of the file pickled and stored in the scratch directory.

If forceSource is True, then a pickle path will not be created.

Provide a file path to check if there is pickled version.

If forceSource is True, pickled files, if available, will not be
returned.
Nc                \    [         R                  " USS9U l        X l        X0l        X@l        g r<   )r
   r?   r@   forceSourcenumberkeywords)rB   r@   r   r   r   s        r1   rC   PickleFilter.__init__  s(     !' 0 04 H!, &*2r0   c                (   Uc  [         R                  5       nO.[        U[        5      (       a  [        R
                  " U5      nOUnUc  SnOSnS[        [        R                  R                  5      -   S-   [        [        R                  R                  5      -   n[        U R                  5      n/ nSU R                  ;   a$  U R                  S   SL a  UR                  S5        OCSU R                  ;   a3  U R                  S    H   nUR                  S	[        U5      -   5        M"     S
R                  S[        R                  U/UQ[         R"                  " U5      P5      n	U R$                  b  U	S
[        U R$                  5      -   -  n	X-  n	X9-  $ )zQ
Returns the file path of the pickle file for this file.

Returns a pathlib.Path
z.pz.p.gzpy.quantizePostFnoQtzquarterLengthDivisorsqld-m21)environLocalgetRootTempDirrh   r   re   rf   sysversion_infomajorminorr@   r   rR   rw   r	   __version__r
   getMd5r   )
rB   	directoryzipTypepathLibDirectory	extensionpythonVersionpathNameToParsequantizationdivisorbaseNames
             r1   getPickleFpPickleFilter.getPickleFp  sc    +::<	3''&||I6(?IIs3#3#3#9#9::S@3sGWGWG]G]C^^dgg,"$T]]*t}}^/LPU/U($5==)@A##ECL$89 B 88UH$8$8- =, =#]]?;= > ;;"c$++...H**r0   c                z    U R                  SS9nUR                  5       (       a  [        R                  " U5        gg)z
If a compressed pickled file exists, remove it from disk.

Generally not necessary to call, since we can just overwrite obsolete pickles,
but useful elsewhere.
gzr   N)r   existsosremove)rB   pickleFps     r1   removePicklePickleFilter.removePickleD  s5     ##D#1??IIh r0   c                0   [         R                  5       n[        R                  " U R                  5      nUS:X  a-  U R
                  (       a  [        S5      eSnU R                  nSnOUb  U R
                  (       a  SnU R                  nSnOU R                  USS9nUR                  5       (       d  SnU R                  nOSU R                  R                  5       R                  UR                  5       R                  :  a  SnUnOSnU R                  nXCU4$ )a  
Given a file path specified with __init__, look for an up-to-date pickled
version of this file path. If it exists, return its fp, otherwise return the
original file path.

Return arguments are file path to load, boolean whether to write a pickle, and
the file path of the pickle.  All file paths can be pathlib.Path objects or None

Does not check that fp exists or create the pickle file.

>>> fp = '/Users/Cuthbert/Desktop/musicFile.mxl'
>>> pickFilter = converter.PickleFilter(fp)
>>> #_DOCS_SHOW pickFilter.status()
(PosixPath('/Users/Cuthbert/Desktop/musicFile.mxl'), True,
      PosixPath('/tmp/music21/m21-7.0.0-py3.9-18b8c5a5f07826bd67ea0f20462f0b8d.p.gz'))
picklezHcannot access source file when only given a file path to a pickled file.FNr   r   T)r   r   r
   findFormatFiler@   r   r   r   r   statst_mtime)rB   	fpScratch	m21FormatwritePicklefpLoadfpPickles         r1   statusPickleFilter.statusO  s    " !//1	))$''2	 +^` `KWWFH$"2"2KWWFH''	4'@H??$$"77<<>**X]]_-E-EE"'K%F"&K!WWFH,,r0   )r   r@   r   r   )FN)r@   r~   r   r   r   
int | NoneNN)r   zpathlib.Path | str | Noner   
str | Noner   pathlib.Pathr   None)r   z.tuple[pathlib.Path, bool, pathlib.Path | None])
r+   r,   r-   r.   r   rC   r   r   r   r/   r)   r0   r1   r   r     s^    
 &+$(
3%
3"
3 "
3 8<(,'+4'+%'+1='+R	 ,-r0   r   z'deque[type[subConverters.SubConverter]]_registeredSubConvertersz:deque[type[subConverters.SubConverter] | t.Literal['all']]_deregisteredSubConvertersc                 T    [         R                  5         [        R                  5         g)zR
Reset state to default (removing all registered and deregistered subConverters).
N)r   clearr   r)   r0   r1   r   r     s     ""$$$&r0   c                .    [         R                  U 5        g)a  
Add a SubConverter to the list of registered subConverters.

Example, register a converter for the obsolete Amiga composition software Sonix (so fun!)

>>> class ConverterSonix(converter.subConverters.SubConverter):
...    registerFormats = ('sonix',)
...    registerInputExtensions = ('mus',)

>>> converter.registerSubConverter(ConverterSonix)
>>> scf = converter.Converter().getSubConverterFormats()
>>> for x in sorted(scf):
...     x, scf[x]
('abc', <class 'music21.converter.subConverters.ConverterABC'>)
...
('sonix', <class 'music21.ConverterSonix'>)
...

See `converter.qmConverter` for an example of an extended subConverter.

>>> converter.resetSubConverters() #_DOCS_HIDE

Changed in v.9 -- custom subConverters are registered above default subConverters.
N)r   
appendleftnewSubConverters    r1   r   r     s    2 ''8r0   v9v10z)use unregisterSubconverter with capital Cc                    [        U 5        g)z>
Deprecated: use registerSubConverter w/ capital "C" instead.
N)r   r   s    r1   registerSubconverterr     s     )r0   c                `   U S:X  a>  [         R                  5         [        R                  5         [        R                  S5        g [         R	                  U 5        g! [
         aG    [        5       nUR                  5       nX;   a  [        R                  U 5         g[        SU < S35      ef = f)a  
Remove a SubConverter from the list of registered subConverters.

>>> converter.resetSubConverters() #_DOCS_HIDE
>>> mxlConverter = converter.subConverters.ConverterMusicXML

>>> c = converter.Converter()
>>> mxlConverter in c.subConvertersList()
True
>>> converter.unregisterSubConverter(mxlConverter)
>>> mxlConverter in c.subConvertersList()
False

If there is no such subConverter registered, and it is not a default subConverter,
then a converter.ConverterException is raised:

>>> class ConverterSonix(converter.subConverters.SubConverter):
...    registerFormats = ('sonix',)
...    registerInputExtensions = ('mus',)
>>> converter.unregisterSubConverter(ConverterSonix)
Traceback (most recent call last):
music21.converter.ConverterException: Could not remove <class 'music21.ConverterSonix'> from
            registered subConverters

The special command "all" removes everything including the default converters:

>>> converter.unregisterSubConverter('all')
>>> c.subConvertersList()
[]

>>> converter.resetSubConverters() #_DOCS_HIDE
allNzCould not remove z from registered subConverters)	r   r   r   rR   r   
ValueErrorr   defaultSubConvertersr   )removeSubConvertercdscs      r1   r   r     s    H U" &&("((*"))%0	Z ''(:; ZK$$&$&--.@A$#$6#99WXZ ZZs   A >B-B-z)use unregisterSubConverter with capital Cc                    [        U 5        g)z@
Deprecated: use unregisterSubConverter w/ capital "C" instead.
N)r   r   s    r1   unregisterSubconverterr     s     ?+r0   c                  R   \ rS rSr% SrSS0rS\S'   S$S jr      S%S jr   S&       S'S jjr	S r
  S(S jr   S&   S)S jjrS	S	S
S.         S*S jjr\R                  " SSS5       S+   S,S jj5       r\ S+   S,S jj5       r\R                  " SSS5      S-S j5       r\S-S j5       r\R                  " SSS5        S.S j5       r\S.S j5       r\    S/S j5       r\R                  " SSS5      S0S j5       rS0S jr    S1S  jrS2S! jr\S3S" j5       rS#rg	)4r   i  z
A class used for converting all supported data formats into music21 objects.

Not a subclass, but a wrapper for different converter objects based on format.
subConverterz
            a :class:`~music21.converter.subConverters.SubConverter` object
            that will do the actual converting.
            zdict[str, str]	_DOC_ATTRc                     S U l         S U l        g N)r   _thawedStreamrB   s    r1   rC   Converter.__init__  s    =AHLr0   c                    [        U[        5      (       a  [        R                  " U5      nOUnS[        R
                  -   S-   [        R                  " U5      -   U-   nXE-  $ )Nzm21-r   )rh   r   re   rf   r	   r   r
   r   )rB   r   exturldirectoryPathlibfilenames         r1   _getDownloadFpConverter._getDownloadFp  sW     i%%&||I6(H00036s9KKcQ**r0   NFc                   [         R                  " USS9nUR                  5       (       d  [        SU 35      eUnUc  U R	                  U5      nU R                  U5        [        R                  (       a+  [        U R                  [        R                  5      (       d   eXPR                  l         U R                  R                  " U4SU0UD6  [        R                  (       a+  [        U R                  [        R                   5      (       d   eU R                  R"                  (       d$  ["        R$                  " 5       U R                  l        ['        U5      U R                  R"                  l        X R                  R"                  l        XpR                  R"                  l        g! [         a    [        SU 35      ef = f)z
Given a file path, parse and store a music21 Stream.

If format is None then look up the format from the file
extension using `common.findFormatFile`.

Does not use or store pickles in any circumstance.
Tr=   no such file exists: Nr   z!File is not in a correct format: )r
   r?   r   r   getFormatFromFileExtensionsetSubConverterFromFormattTYPE_CHECKINGrh   r   r   SubConverterr   r   NotImplementedErrorr   Streamr   Metadatar   filePath
fileNumber
fileFormat)rB   r@   r   formatr   r   	fpPathlib	useFormats           r1   parseFileNoPickleConverter.parseFileNoPickle  sd     #)"2"22T"J	!!(+@)EFF	77	BI&&y1??d//1K1KLLLL%-"	S''  ??dkk6==9999{{###+#4#4#6DKK (+I%*0'*3' # 	S(+LRD)QRR	Ss   1F( (Gc                    [         R                  " USS9nSnUR                  5       (       a  SnU$ [         R                  " U5      nUc  [	        SU 35      eU$ )z
gets the format from a file extension.

>>> fp = common.getSourceFilePath() / 'musedata' / 'testZip.zip'
>>> c = converter.Converter()
>>> c.getFormatFromFileExtension(fp)
'musedata'
Tr=   Nr   z%cannot find a format extensions for: )r
   r?   is_dirr   r   )rB   r@   r   s      r1   r   $Converter.getFormatFromFileExtensionH  sh     b5 	99;;"I
  --b1I ,/TUWTX-YZZr0   c                v   SSK Jn  [        R                  " USS9nUR	                  5       (       d  [        SU 35      eUnUc  U R                  U5      n[        XU40 UD6n	U	R                  5       u  pnUSL a  Ub  USL a  [        R                  S5         [        US	S
9U l        U R$                  R&                  (       d$  [&        R(                  " 5       U R$                  l        XR$                  R&                  l        X R$                  R&                  l        XR$                  R&                  l        g[        R                  S5        U R"                  " XX440 UD6  USL a  Ub  USL a  [        R                  S5        U R$                  nUR1                  USS9nUR3                  US	S9  [        R                  S5        [        US	S
9U l        U R$                  R&                  (       d$  [&        R(                  " 5       U R$                  l        XR$                  R&                  l        X R$                  R&                  l        XR$                  R&                  l        gggg! UR                   aG    [        R                  SU S35        [        R                   " U5        U R"                  " XX440 UD6   GNf = f)a  
Given a file path, parse and store a music21 Stream, set as self.stream.

If format is None then look up the format from the file
extension using `common.findFormatFile`.

Will load from a pickle unless forceSource is True
Will store as a pickle unless storePickle is False
r   
freezeThawTr=   r   NFzLoading Pickled versionzlibr   zCould not parse pickle, z.  RewritingzLoading original versionzFreezing PicklefastButUnsafe)r@   r   zReplacing self.stream)music21r   r
   r?   r   r   r   r   r   r   
printDebugr!   r   FreezeThawExceptionwarnr   r   r   r   r   r   r   r   r   StreamFreezerwrite)rB   r@   r   r   r   storePickler   r   r   pfObjunused_fpDstr   r   ssfs                  r1   r   Converter.parseFile_  sC    	'b5yy{{(+@)EFF	77;IRfAA.3lln+8%H$8[E=Q##$=>T%)(F%C" ;;'''/'8'8':$,.KK  ).4KK  +.7KK  +##$>?""2vOhOd"x';t@S''(9:KK--at-DHf5''(?@%)(F%C"{{+++3+<+<+>DKK(02$$-28$$/2;$$/ AT';" 11 T!!$<XJl"ST		(#&&r6S(STs   I! !AJ87J8c                   UnUGc  UR                  5       nU R                  U5      u  pa[        U[        5      (       a  UR	                  SS5      nOUnUb  GO{UR                  S5      (       a  SU;   a  SnGO[SnGOWUR                  S5      (       d$  UR                  5       R                  S5      (       a  SnGOUR                  5       R                  S	5      (       a  SnOUR                  S
5      (       d$  UR                  5       R                  S5      (       a  SnOUR                  S5      (       d:  UR                  S5      (       d$  UR                  5       R                  S5      (       a  SnObUR                  5       R                  S5      (       a  SnO;SU;   a	  SU;   a  SnO,SU;   a	  SU;   a  SnOSU;   a	  SU;   a  SnO[        SU-  5      eU R                  U5        [        R                  (       a+  [        U R                  [        R                  5      (       d   eXPR                  l        U R                  R                  XS9  g)zW
Given raw data, determine format and parse into a music21 Stream,
set as self.stream.
Nutf-8ignorez<?xmlz<meimeir^   zmei:z	musicxml:MThdzmidi:midiz!!!z**zhumdrum:humdrumztinynotation:tinyNotationzWK#:measurer   zM:zK:abczTime Signature:m1	romanTextz.File not found or no such format found for: %sr   )lstripformatFromHeaderrh   ri   rm   
startswithlowerr   r   r   r   r   r   r   r   r   )rB   dataStrr   r   r   r   r   dataStrMakeStrs           r1   r   Converter.parseData  s
    	nn&G!%!6!6w!?I'5))!(!B!($**733^+ %I *I**622n6J6J6L6W6WX^6_6_!	%%'22;??&	**622n6J6J6L6W6WX_6`6`"	 ++E22%0066%++-88DD%	%%'22?CC*	 >)i>.I&	'DN,B!	"n49O'	()Y)7*8 9 9 	&&y1??d//1K1KLLLL%-"##G#;r0   r   r   r   c          	        [         S   nUS;   a!  SU< S3nUS-  nUS-  nUS-  n[        U5      eUc*  [        R                  " U5      u  pUc  [        S	U 35      eO[        R                  " U5      u  pU	c  S
n	[         R                  5       nU R                  XU5      nUSL d  UR                  5       (       d  [         R                  SU 3/5        [        R                  " USSS9nUR                  S:w  a/  [        SU SUR                   S[        UR                      35      eUR                  UR                  5        O[         R                  SU 3/5        Uc  [        R                  " U5      nOUnUc  [        SU< 35      eU R!                  U5        ["        R$                  (       a+  ['        U R(                  [*        R,                  5      (       d   eXPR(                  l        U R(                  R1                  XS9  U R2                  c  [        S5      eXR2                  R4                  l        X0R2                  R4                  l        XR2                  R4                  l        g)a`  
Given a url, download and parse the file
into a music21 Stream stored in the `stream`
property of the converter object.

Note that this checks the user Environment
`autoDownload` setting before downloading.

Use `forceSource=True` to download every time rather than
re-reading from a cached file.

>>> joplinURL = ('https://github.com/cuthbertLab/music21/raw/master'
...              + '/music21/corpus/joplin/maple_leaf_rag.mxl')
>>> c = converter.Converter()
>>> #_DOCS_SHOW c.parseURL(joplinURL)
>>> #_DOCS_SHOW joplinStream = c.stream

* Changed in v7: made keyword-only and added `forceSource` option.
autoDownload)denyaskz2Automatic downloading of URLs is presently set to z; z5configure your Environment "autoDownload" setting to z)"allow" to permit automatic downloading: z(environment.set('autoDownload', 'allow')Nz%cannot determine file format of url: z.txtTzdownloading to:    )allow_redirectstimeout   zCould not download z	, error:  zusing already downloaded file: z'Cannot automatically find a format for r  z-Could not create a Stream via a subConverter.)r   r   r
   findFormatExtURL
findFormatr   r   r   r  requestsgetstatus_coder   write_bytescontentr   r   r   r   rh   r   r   r   r   r   r   r   r   r   r   )rB   r   r   r   r   r   r"  messageformatFromURLr   unused_formatTyper   r@   rH   r   s                  r1   r   Converter.parseURL  sF   8 $N3?*J<JZZ\]GNNGBBGAAG$W--
 >!'!8!8!=M$(+PQTPU)VWW % &,%6%6v%>"{ //1	  5$biikk##'7t%<$=>S$CA}}#()#ia	RSR_R_H`Gabd dNN199%##'Frd%K$LM >--b1II$'Nrf%UVV&&y1??d//1K1KLLLL%-"##B#6;;$%TUU(*%*0'*3'r0   r   r   z$use subConvertersList with capital Cc                $    U R                  U5      $ r   )subConvertersList)rB   converterTypes     r1   subconvertersListConverter.subconvertersList)  s    
 %%m44r0   c                   / n[          H  nUR                  U5        M     [        (       a  [        S   S:X  a  OJUR                  [        R                  5       5        [         H  nUS:X  a  M   UR                  U5        M     U S:X  a  U$ / nU HF  nU S:X  a  UR                  (       d  M  U S:X  a  UR                  (       d  M5  UR                  U5        MH     U$ ! [         a     M  f = f)a  
Gives a list of all the subConverter classes that are registered.

If converterType is 'any' (true), then input or output
subConverters are listed.

Otherwise, 'input', or 'output' can be used to filter.

>>> converter.resetSubConverters() #_DOCS_HIDE
>>> c = converter.Converter()
>>> scl = c.subConvertersList()
>>> defaultScl = c.defaultSubConverters()
>>> tuple(scl) == tuple(defaultScl)
True

>>> sclInput = c.subConvertersList('input')
>>> sclInput
[<class 'music21.converter.subConverters.ConverterABC'>,
 <class 'music21.converter.subConverters.ConverterCapella'>,
 <class 'music21.converter.subConverters.ConverterClercqTemperley'>,
 <class 'music21.converter.subConverters.ConverterHumdrum'>,
 <class 'music21.converter.subConverters.ConverterMEI'>,
 <class 'music21.converter.subConverters.ConverterMidi'>,
 <class 'music21.converter.subConverters.ConverterMuseData'>,
 <class 'music21.converter.subConverters.ConverterMusicXML'>,
 <class 'music21.converter.subConverters.ConverterNoteworthy'>,
 <class 'music21.converter.subConverters.ConverterNoteworthyBinary'>,
 <class 'music21.converter.subConverters.ConverterRomanText'>,
 <class 'music21.converter.subConverters.ConverterScala'>,
 <class 'music21.converter.subConverters.ConverterTinyNotation'>,
 <class 'music21.converter.subConverters.ConverterVolpiano'>]

Get those that can output (note that this is also a static method
on converter)

>>> sclOutput = converter.Converter.subConvertersList('output')
>>> sclOutput
[<class 'music21.converter.subConverters.ConverterBraille'>,
 <class 'music21.converter.subConverters.ConverterLilypond'>,
 <class 'music21.converter.subConverters.ConverterMidi'>,
 <class 'music21.converter.subConverters.ConverterMusicXML'>,
 <class 'music21.converter.subConverters.ConverterRomanText'>,
 <class 'music21.converter.subConverters.ConverterScala'>,
 <class 'music21.converter.subConverters.ConverterText'>,
 <class 'music21.converter.subConverters.ConverterTextLine'>,
 <class 'music21.converter.subConverters.ConverterVexflow'>,
 <class 'music21.converter.subConverters.ConverterVolpiano'>]

>>> class ConverterSonix(converter.subConverters.SubConverter):
...    registerFormats = ('sonix',)
...    registerInputExtensions = ('mus',)
>>> converter.registerSubConverter(ConverterSonix)
>>> ConverterSonix in c.subConvertersList()
True

Newly registered subConveters appear first, so they will be used instead
of any default subConverters that work on the same format or extension.

>>> class BadMusicXMLConverter(converter.subConverters.SubConverter):
...    registerFormats = ('musicxml',)
...    registerInputExtensions = ('xml', 'mxl', 'musicxml')
...    def parseData(self, strData, number=None):
...        self.stream = stream.Score(id='empty')

>>> converter.registerSubConverter(BadMusicXMLConverter)
>>> c.subConvertersList()
[<class 'music21.BadMusicXMLConverter'>,
 ...
 <class 'music21.converter.subConverters.ConverterMusicXML'>,
 ...]

Show that this musicxml file by Amy Beach is now parsed by BadMusicXMLConverter:

>>> #_DOCS_SHOW s = corpus.parse('beach/prayer_of_a_tired_child')
>>> #_DOCS_HIDE -- we cannot know if the piece is already parsed or not.
>>> s = corpus.parse('beach/prayer_of_a_tired_child', forceSource=True)  #_DOCS_HIDE
>>> s.id
'empty'
>>> len(s.parts)
0

Note that if the file has already been parsed by another subConverter format
the parameter `forceSource` is required to force the file to be parsed by the
newly registered subConverter:

>>> converter.unregisterSubConverter(BadMusicXMLConverter)
>>> #_DOCS_HIDE -- the forceSource will not have created a pickle.
>>> #_DOCS_SHOW s = corpus.parse('beach/prayer_of_a_tired_child')
>>> s.id
'empty'
>>> s = corpus.parse('beach/prayer_of_a_tired_child', forceSource=True)
>>> len(s.parts)
6

>>> converter.resetSubConverters() #_DOCS_HIDE
r   r   anyinputoutput)
r   rR   r   extendr   r   r   r   registerInputExtensionsregisterOutputExtensions)r7  subConverterListregunregisteredfilteredSubConvertersListscs         r1   r6  Converter.subConvertersList0  s    J +C##C( , &%*DQ*G5*P##I$B$B$DE :5($++L9	 !; E!##$&!"B'0J0J(1L1L%,,R0 # )( " s   /C
C*)C*z'use defaultSubConverters with capital Cc                "    U R                  5       $ r   )r   r   s    r1   defaultSubconvertersConverter.defaultSubconverters  s    ((**r0   c                 Z   / n [        [        R                  5       H  n[        [        U5      n[	        U5      (       d  M%  [        U[        R                  5      (       a  MF  [        US5      (       d  MY  [        U[        R                  5      (       d  Mz  U R                  U5        M     U $ )a  
return an alphabetical list of the default subConverters: those in converter.subConverters
with the class SubConverter.

Do not use generally.  Use Converter.subConvertersList()

>>> c = converter.Converter()
>>> for sc in c.defaultSubConverters():
...     print(sc)
<class 'music21.converter.subConverters.ConverterABC'>
<class 'music21.converter.subConverters.ConverterBraille'>
<class 'music21.converter.subConverters.ConverterCapella'>
<class 'music21.converter.subConverters.ConverterClercqTemperley'>
<class 'music21.converter.subConverters.ConverterHumdrum'>
<class 'music21.converter.subConverters.ConverterIPython'>
<class 'music21.converter.subConverters.ConverterLilypond'>
<class 'music21.converter.subConverters.ConverterMEI'>
<class 'music21.converter.subConverters.ConverterMidi'>
<class 'music21.converter.subConverters.ConverterMuseData'>
<class 'music21.converter.subConverters.ConverterMusicXML'>
<class 'music21.converter.subConverters.ConverterNoteworthy'>
<class 'music21.converter.subConverters.ConverterNoteworthyBinary'>
<class 'music21.converter.subConverters.ConverterRomanText'>
<class 'music21.converter.subConverters.ConverterScala'>
<class 'music21.converter.subConverters.ConverterText'>
<class 'music21.converter.subConverters.ConverterTextLine'>
<class 'music21.converter.subConverters.ConverterTinyNotation'>
<class 'music21.converter.subConverters.ConverterVexflow'>
<class 'music21.converter.subConverters.ConverterVolpiano'>
<class 'music21.converter.subConverters.SubConverter'>
__mro__)sortedr   __dict__getattrcallablerh   typesFunctionTypehasattr
issubclassr   rR   )r   ipossibleSubConverters      r1   r   Converter.defaultSubConverters  s    B HJ../A#*=!#< -..&';U=O=OPP 4i@@"#79S9STT$++,@A 0 $#r0   z)use getSubConverterFormats with capital Cc                "    U R                  5       $ r   )getSubConverterFormatsr   s    r1   getSubconverterFormats Converter.getSubconverterFormats  s     **,,r0   c                     0 n [         R                  5        HF  n[        US5      (       d  M  UR                  nU H  nUR	                  5       nX0;  d  M  XU'   M      MH     U $ )a	  
Get a dictionary of subConverters for various formats.

(staticmethod: call on an instance or the class itself)

>>> scf = converter.Converter.getSubConverterFormats()
>>> scf['abc']
<class 'music21.converter.subConverters.ConverterABC'>
>>> for x in sorted(scf):
...     x, scf[x]
('abc', <class 'music21.converter.subConverters.ConverterABC'>)
('braille', <class 'music21.converter.subConverters.ConverterBraille'>)
('capella', <class 'music21.converter.subConverters.ConverterCapella'>)
('clercqtemperley', <class 'music21.converter.subConverters.ConverterClercqTemperley'>)
('cttxt', <class 'music21.converter.subConverters.ConverterClercqTemperley'>)
('har', <class 'music21.converter.subConverters.ConverterClercqTemperley'>)
('humdrum', <class 'music21.converter.subConverters.ConverterHumdrum'>)
('ipython', <class 'music21.converter.subConverters.ConverterIPython'>)
('jupyter', <class 'music21.converter.subConverters.ConverterIPython'>)
('lily', <class 'music21.converter.subConverters.ConverterLilypond'>)
('lilypond', <class 'music21.converter.subConverters.ConverterLilypond'>)
('mei', <class 'music21.converter.subConverters.ConverterMEI'>)
('midi', <class 'music21.converter.subConverters.ConverterMidi'>)
('musedata', <class 'music21.converter.subConverters.ConverterMuseData'>)
('musicxml', <class 'music21.converter.subConverters.ConverterMusicXML'>)
('noteworthy', <class 'music21.converter.subConverters.ConverterNoteworthyBinary'>)
('noteworthytext', <class 'music21.converter.subConverters.ConverterNoteworthy'>)
('rntext', <class 'music21.converter.subConverters.ConverterRomanText'>)
('romantext', <class 'music21.converter.subConverters.ConverterRomanText'>)
('scala', <class 'music21.converter.subConverters.ConverterScala'>)
('t', <class 'music21.converter.subConverters.ConverterText'>)
('text', <class 'music21.converter.subConverters.ConverterText'>)
('textline', <class 'music21.converter.subConverters.ConverterTextLine'>)
('tinynotation', <class 'music21.converter.subConverters.ConverterTinyNotation'>)
('txt', <class 'music21.converter.subConverters.ConverterText'>)
('vexflow', <class 'music21.converter.subConverters.ConverterVexflow'>)
('volpiano', <class 'music21.converter.subConverters.ConverterVolpiano'>)
('xml', <class 'music21.converter.subConverters.ConverterMusicXML'>)
registerFormats)r   r6  rR  r\  r  )converterFormatsnameformatsTuplerT   s       r1   rX   Converter.getSubConverterFormats  sb    R //1Dt.//#33%A	A0.2+ & 2  r0   c                    U c  [        S5      eU R                  5       n [        R                  5       nX;  a  [        SU  35      eX   nU" 5       $ )a  
Return a particular subConverter class based on the format
of the converterFormat string.

Static method: call on the class itself or an instance:

>>> converter.Converter.getSubConverterFromFormat('musicxml')
<music21.converter.subConverters.ConverterMusicXML object at 0x...>
z*Did not find a format from the source filez#no converter available for format: )r   r  r   rX  )converterFormatscfsubConverterClasss      r1   getSubConverterFromFormat#Converter.getSubConverterFromFormat  s^     "$%QRR)//1..0%$'J?J[%\]]0 ""r0   z,use setSubConverterFromFormat with capital Cc                &    U R                  U5        g r   )r   rB   rb  s     r1   setSubconverterFromFormat#Converter.setSubconverterFromFormat2  s    &&7r0   c                8    [         R                  U5      U l        g)z
sets the .subConverter according to the format of `converterFormat`:

>>> convObj = converter.Converter()
>>> convObj.setSubConverterFromFormat('humdrum')
>>> convObj.subConverter
<music21.converter.subConverters.ConverterHumdrum object at 0x...>
N)r   re  r   rh  s     r1   r   #Converter.setSubConverterFromFormat6  s     &??Pr0   c           	         [        U[        5      (       a$  USS R                  SS5      R                  5       nOA[        U[        5      (       a  USS R                  5       nO[        S[        U5       S35      eSnU R                  5       nU Hz  nUR                   Hg  nUR                  UR                  5       S-   5      (       d  M,  Un[        R                  " [        U[        U5      S-   S R                  5       5      n  Mx     M|     X14$ )	a  
if dataStr begins with a text header such as  "tinyNotation:" then
return that format plus the dataStr with the head removed.

Else, return (None, dataStr) where dataStr is the original untouched.

The header is not detected case-sensitive.

>>> c = converter.Converter()
>>> c.formatFromHeader('tinynotation: C4 E2')
('tinynotation', 'C4 E2')

Note that the format is always returned in lower case:

>>> c.formatFromHeader('romanText: m1: a: I b2 V')
('romantext', 'm1: a: I b2 V')

If there is no header then the format is None and the original is
returned unchanged:

>>> c.formatFromHeader('C4 E2')
(None, 'C4 E2')
>>> c.formatFromHeader(b'binary-data')
(None, b'binary-data')


New formats can register new headers, like this old Amiga format:

>>> class ConverterSonix(converter.subConverters.SubConverter):
...    registerFormats = ('sonix',)
...    registerInputExtensions = ('mus',)
>>> converter.registerSubConverter(ConverterSonix)
>>> c.formatFromHeader('sonix: AIFF data')
('sonix', 'AIFF data')
>>> converter.resetSubConverters() #_DOCS_HIDE

If bytes are passed in, the data is returned as bytes, but the
header format is still converted to a string:

>>> c.formatFromHeader(b'romanText: m1: a: I b2 V')
('romantext', b'm1: a: I b2 V')

Anything except string or bytes raises a ValueError:

>>> c.formatFromHeader(23)
Traceback (most recent call last):
ValueError: Cannot parse a format from <class 'int'>.
Nr%  r  r  zCannot parse a format from r   :r_   )rh   ri   rm   r  r   r   typer6  r\  r  r   castr%   lenr  )rB   r  dataStrStartLowerfoundFormatrA  rE  possibleFormats          r1   r  Converter.formatFromHeaderA  s    j gu%% ' 3 3GX F L L N%% ' 2 2 4:4=/KLL113"B"$"4"4$//0D0D0F0LMM"0Kff[%,S-=-A-B%C%J%J%L'G  #5 # %%r0   c                V   UR                  5       R                  5       nUR                  S5      (       a  USS nSnUR                  S5      nUS   n[	        U5      S:  a  USS nO/ nU R                  5       nU H&  nUR                  nU H  nX:X  d  M
  Un  O   Uc  M&    O   Uc,  U H&  nUR                  n	U	 H  n
X:X  d  M
  Un  O   Uc  M&    O   Uc,  U H&  nUR                  n	U	 H  n
X:X  d  M
  Un  O   Uc  M&    O   U(       a   UR                  (       a  UR                  S   $ g)a<  
Take in a string representing a format, a file extension (w/ or without leading dot)
etc. and find the format string that best represents the format that should be used.

Searches SubConverter.registerFormats first, then SubConverter.registerInputExtensions,
then SubConverter.registerOutputExtensions

Returns None if no format applies:

>>> c = converter.Converter()
>>> c.regularizeFormat('mxl')
'musicxml'
>>> c.regularizeFormat('t')
'text'
>>> c.regularizeFormat('abc')
'abc'
>>> c.regularizeFormat('lily.png')
'lilypond'
>>> c.regularizeFormat('blah') is None
True
r   r_   Nr   )r  stripr  splitrq  r6  r\  r?  )rB   fmtfoundSc
formatListunused_subformatssclrE  formatsscFormat
extensionsr   s              r1   regularizeFormatConverter.regularizeFormat  sM   . iik!>>#ab'CYYs^
mz?Q *12 "$$&B((G#? G $ "  ?77
%Cz"$ & &  ?77
%Cz"$ & &  w..**1--r0   c                |    U R                   b  U R                   $ U R                  b  U R                  R                  $ g)z*
Returns the .subConverter.stream object.
N)r   r   r   r   s    r1   r   Converter.stream  s=    
 )%%%*$$+++r0   )r   r   r   )r   pathlib.Path | strr   r   r   r   NNF)r@   r  r   r   r   r   r   r   )NNFT)r  str | bytesr   r   )
r   r   r   r   r   r   r   r   r   r   )r;  )r7  z#t.Literal['any', 'input', 'output']r   &list[type[subConverters.SubConverter]])r   r  )r   z+dict[str, type[subConverters.SubConverter]])rb  r   r   zsubConverters.SubConverter)rb  r   )r  r%   r   ztuple[str | None, _StrOrBytes])ry  r   r   r   )r   z/stream.Score | stream.Part | stream.Opus | None)r+   r,   r-   r.   r   r   __annotations__rC   r   r   r   r   r   r   r
   
deprecatedr8  staticmethodr6  rH  r   rY  rX  re  ri  r   r  r  propertyr   r/   r)   r0   r1   r   r     sd    	!I~ M
+#+ + 	+(  !-4-4 -4 	-4
 -4^. $(>B6<v ;<;< 
;<B  !P4P4 	P4
 P4 P4 
P4j tU$JK >C5:5 
05 L5 =B@):@)	/@) @)D tU$MN+ O+ )$ )$V tU$OP-	4- Q-
 0  0 d ##	## #* tU$RS8 T8	QF&F& 
&F&PCN 	 	r0   r   Fc                B   [        5       n[        R                  " U SS9n UR                  " U 4XUS.UD6  [        R
                  (       aJ  [        UR                  [        R                  [        R                  [        R                  45      (       d   eUR                  $ )z=
Given a file path, attempt to parse the file into a Stream.
Tr=   r   r   r   )r   r
   r?   r   r   r   rh   r   ScorePartOpus)r@   r   r   r   r   vs         r1   r   r     so     	A			"D	1BKKV6kVXV!((V\\6;;$LMMMM88Or0   c                   [        5       nUR                  " U 4XS.UD6  [        R                  (       aJ  [	        UR
                  [
        R                  [
        R                  [
        R                  45      (       d   eUR
                  $ )za
Given musical data represented within a Python string, attempt to parse the
data into a Stream.
r   r   )	r   r   r   r   rh   r   r  r  r  )r  r   r   r   r  s        r1   r   r     s[     	AKKBBB!((V\\6;;$LMMMM88Or0   r   c                  [        5       nUR                  " U 4XS.UD6  [        R                  (       aJ  [	        UR
                  [
        R                  [
        R                  [
        R                  45      (       d   eUR
                  $ )z
Given a URL, attempt to download and parse the file into a Stream. Note:
URL downloading will not happen automatically unless the user has set their
Environment "autoDownload" preference to "allow".

* Changed in v7: made keyword-only.
)r   r   )	r   r   r   r   rh   r   r  r  r  )r   r   r   r   r   r  s         r1   r   r     s[     	AJJsG6GhG!((V\\6;;$LMMMM88Or0   )r   r   r   c                  [        U [        5      (       a  U R                  SS5      n[        U [        R                  5      (       a  [        U 5      nO[        U [        R                  5      (       aa  U R                  R                  5       (       a  [        U R                  5      nOF[        [        R                  " 5       U R                  -  5      nO[        U [
        5      (       a  U nOSn[        R                  " U 5      (       aB  [        U 5      S:X  a3  U S   c-  [        [        U S   5      5      (       a  [        U S   4SU0UD6$ [        R                  " U 5      (       a  [        U 5      S:X  a  [        [        U S   5      5      (       a  [        U S   [
        5      (       d  [!        SU S   < 35      e[        U S   ["        5      (       d  [!        S	U S   < 35      e[        U S   4SU0UD6n[        U[$        R&                  5      (       a  UR)                  U S   5      $ U$ [        U [        5      (       d$  UR+                  S
5      (       a  [-        U 4X#S.UD6$ [        U [        5      (       d  [        U5      (       a  [        U4X#US.UD6$ [        U [        5      (       dG  [        [        R.                  " U5      5      (       a#  [        [        R.                  " U5      4X#US.UD6$ [        U[        5      (       d;  UR+                  S5      (       d  UR+                  S5      (       a  [1        U 4X#US.UD6$ [        U [        R                  5      (       a  [3        S[        U 5       35      e[        U [
        5      (       a.  [        R4                  " U 5      b  [3        S[        U 5       35      e[-        U 4X#S.UD6$ )a4  
Given a file path, encoded data in a Python string, or a URL, attempt to
parse the item into a Stream.  Note: URL downloading will not happen
automatically unless the user has set their Environment "autoDownload"
preference to "allow".

Keywords can include `number` which specifies a piece number in a file of
multi-piece file. (Otherwise, a particular score from an
:class:`~music21.stream.Opus` can also be extracted by providing a
two-element list or tuple of the form (path, number) to the `value` argument.)

`format` specifies the format to parse the line of text or the file as.

`quantizePost` specifies whether to quantize a stream resulting from MIDI conversion.
By default, MIDI streams are quantized to the nearest sixteenth or triplet-eighth
(i.e. smaller durations will not be preserved).
`quarterLengthDivisors` sets the quantization units explicitly.

A string of text is first checked to see if it is a filename that exists on
disk.  If not it is searched to see if it looks like a URL.  If not it is
processed as data.

PC File:

>>> #_DOCS_SHOW s = converter.parse(r'c:\users\myke\desktop\myFile.xml')

Mac File:

>>> #_DOCS_SHOW s = converter.parse('/Users/cuthbert/Desktop/myFile.xml')

URL:

>>> #_DOCS_SHOW s = converter.parse('https://midirepository.org/file220/file.mid')


Data is preceded by an identifier such as "tinynotation:"

>>> s = converter.parse("tinyNotation: 3/4 E4 r f# g=lastG trip{b-8 a g} c", makeNotation=False)
>>> s[meter.TimeSignature].first()
<music21.meter.TimeSignature 3/4>

or the format can be passed directly:

>>> s = converter.parse("2/16 E4 r f# g=lastG trip{b-8 a g} c", format='tinyNotation')
>>> s[meter.TimeSignature].first()
<music21.meter.TimeSignature 2/16>

* Changed in v8: passing a list of tinyNotation strings was never documented as a
    possibility and has been removed.
r  r  rd      r_   r   r   zCIf using a two-element list, the first value must be a string, not zMIf using a two-element list, the second value must be an integer number, not r  r  r  zhttp://zhttps://zCannot find file in )rh   ri   rm   re   rf   r   r   MetadataEntry
sourcePathis_absoluter
   getCorpusFilePath
isListLikerq  
_osCanLoadr   r   intr   r  getScoreByNumberr  r   r?   r   FileNotFoundErrorr   )valuer   r   r   r   valueStrrE  s          r1   r   r     sN   v %<<2%&&u:	E700	1	1''))5++,H63358H8HHIH	E3		%  E
aa 3uQx=))q=&=H==


E
"
"%jAoU1X''%(C(($UV[\]V^Uab  %(C(($Qxl$  uQx;;(;b&++&&&&uQx00Iu%%(*=*=f*E*EIvIII&&"" >&%0>4<> 	>&&))(344))(3 >F%0>4<> 	>%((h.A.A).L.L191D1DZ1P1P =f$/=3;= 	=	E7<<	(	("6s5zl CDD	E3		F$9$9%$@$L"6s5zl CDD IvIIIr0   c                H   UR                  S5      (       a  USS n[        R                  " U5      u  p4Uc  [        SU 35      eUR	                  S5      nUS   nUSS n[        R
                  " U5      nUc  [        SU 35      eU" 5       nUR                  " U 4UUS.UD6$ )a  
Convert `obj` to the given format `fmt` and return the information retrieved.

Currently, this is somewhat inefficient: it calls SubConverter.toData which
calls `write()` on the object and reads back the value of the file.

>>> tiny = converter.parse('tinyNotation: 4/4 C4 D E F G1')
>>> data = converter.toData(tiny, 'braille.ascii')
>>> type(data)
<class 'str'>
>>> print(data)
    #D4
#A _?:$] (<K
r   r_   Nz*cannot support output in this format yet: r   )ry  
subformats)r  r
   r+  r   rx  findSubConverterForFormattoData)	objry  r   regularizedConverterFormat
unused_ext
formatSubsr  scClassformatWriters	            r1   r  r    s     ~~c!"g-3->->s-C*!) #McU!STT3J
Q-CABJ../IJG #McU!STT9L& 	 r0   c                L    SSK Jn  UR                  XS9nUR                  XUS9$ )al  
Given a StreamObject and a file path, serialize and store the Stream to a file.

This function is based on the :class:`~music21.converter.StreamFreezer` object.

The serialization format is defined by the `fmt` argument; 'pickle' (the default) is only one
presently supported.  'json' or 'jsonnative' will be used once jsonpickle is good enough.

If no file path is given, a temporary file is used.

The file path is returned.

>>> c = converter.parse('tinynotation: 4/4 c4 d e f')
>>> c.show('text')
{0.0} <music21.stream.Measure 1 offset=0.0>
    {0.0} <music21.clef.TrebleClef>
    {0.0} <music21.meter.TimeSignature 4/4>
    {0.0} <music21.note.Note C>
    {1.0} <music21.note.Note D>
    {2.0} <music21.note.Note E>
    {3.0} <music21.note.Note F>
    {4.0} <music21.bar.Barline type=final>
>>> fp = converter.freeze(c, fmt='pickle')
>>> #_DOCS_SHOW fp
PosixPath('/tmp/music21/sjiwoe.p.gz')

The file can then be "thawed" back into a Stream using the
:func:`~music21.converter.thaw` method.

>>> d = converter.thaw(fp)
>>> d.show('text')
{0.0} <music21.stream.Measure 1 offset=0.0>
    {0.0} <music21.clef.TrebleClef>
    {0.0} <music21.meter.TimeSignature 4/4>
    {0.0} <music21.note.Note C>
    {1.0} <music21.note.Note D>
    {2.0} <music21.note.Note E>
    {3.0} <music21.note.Note F>
    {4.0} <music21.bar.Barline type=final>

OMIT_FROM_DOCS

>>> import os
>>> os.remove(fp)
r   r   r   )ry  r@   r   )r   r   r  r  )	streamObjry  r@   r   r   r   r  s          r1   r    r      s.    ^ #   HA77s7733r0   c                d    SSK Jn  UR                  5       nUR                  XS9  UR                  $ )z
Given a file path of a serialized Stream, defrost the file into a Stream.

This function is based on the :class:`~music21.converter.StreamFreezer` object.

See the documentation for :meth:`~music21.converter.freeze` for demos.
r   r   r   )r   r   StreamThawerrs   r   )r@   r   r   r  s       r1   r!   r!     s,     #!AFF2F88Or0   c                N    SSK Jn  UR                  U 5      nUR                  US9$ )a;  
Given a StreamObject
serialize and return a serialization string.

This function is based on the
:class:`~music21.converter.StreamFreezer` object.

The serialization format is defined by
the `fmt` argument; 'pickle' (the default),
is the only one presently supported.


>>> c = converter.parse('tinyNotation: 4/4 c4 d e f', makeNotation=False)
>>> c.show('text')
{0.0} <music21.meter.TimeSignature 4/4>
{0.0} <music21.note.Note C>
{1.0} <music21.note.Note D>
{2.0} <music21.note.Note E>
{3.0} <music21.note.Note F>
>>> data = converter.freezeStr(c, fmt='pickle')
>>> len(data) > 20  # pickle implementation dependent
True
>>> d = converter.thawStr(data)
>>> d.show('text')
{0.0} <music21.meter.TimeSignature 4/4>
{0.0} <music21.note.Note C>
{1.0} <music21.note.Note D>
{2.0} <music21.note.Note E>
{3.0} <music21.note.Note F>

r   r   )ry  )r   r   r  writeStr)r  ry  r   r  s       r1   r"   r"     s)    @ #  +A::#:r0   c                h    SSK Jn  UR                  5       nUR                  U 5        UR                  $ )z
Given a serialization string, defrost into a Stream.

This function is based on the :class:`~music21.converter.StreamFreezer` object.
r   r   )r   r   r  openStrr   )strDatar   r  s      r1   r#   r#     s*     #!AIIg88Or0   c                b     [         R                  R                  U 5      $ ! [         a     gf = f)a  
Return os.path.exists, but catch `ValueError` and return False.

os.path.exists raises ValueError for paths over 260 chars
on all versions of Windows lacking the `LongPathsEnabled` setting,
which is absent below Windows 10.1607 and opt-in on higher versions.
F)r   pathr   r   )r@   s    r1   r  r  *  s,    ww~~b!! s   ! 
..c                      \ rS rSrS rSrg)TestSlowi9  c                    SSK Jn  UR                   H)  n[        R                  " 5       nUR                  U5        M+     g )Nr   	testFiles)music21.musicxmlr  ALLr   ConverterMusicXMLr   )rB   r  mxStringas       r1   testMusicXMLConversionTestSlow.testMusicXMLConversion;  s-    .!H//1AKK! &r0   r)   N)r+   r,   r-   r.   r  r/   r)   r0   r1   r  r  9  s    "r0   r  c                  *    \ rS rSrSrS rS rS rSrg)TestExternaliB  Tc                *   [         R                  " 5       nSSKJn  UR                  n[        U5      nUR                  n[        U5      nUR                  US   5        UR                  US   5        U R                  (       a  UR                  5         g g )Nr   testPrimitive)	r   r  r  r  chordsThreeNotesDuration21cr   beams01rR   show)rB   r   r  r  r  bs         r1   testConversionMusicXml#TestExternal.testConversionMusicXmlE  so    LLN2 <<h ((h 	
1	199FFH r0   c                    SSK Jn  UR                  S5      n[        U5      n[	        U5      nU R
                  (       a  UR                  5         [        R                  " U5        g )Nr   corpuszbach/bwv66.6.xml)r   r  r   r    r!   r  r   r   )rB   r  r	  r@   s2s        r1   testFreezerTestExternal.testFreezerV  sA    "LL+,AY"X99GGI
		"r0   c                    SSK Jn  UR                  S   n[        R                  " 5       nUR                  U5        [        U5      nU R                  (       a"  UR                  S5        UR                  5         g g )Nr   r     text)r  r  r  r   r  r   r  )rB   r  r  r  r  s        r1   testMusicXMLTabConversion&TestExternal.testMusicXMLTabConversion_  sW    .==#++-	Hh99FF6NFFH r0   r)   N)	r+   r,   r-   r.   r  r  r  r  r/   r)   r0   r1   r  r  B  s    D"
r0   r  c                      \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rSr g) Testix  c                2    SSK Jn  U" U [        5       5        g )Nr   )testCopyAll)music21.test.commonTestr  globals)rB   r  s     r1   testCopyAndDeepcopyTest.testCopyAndDeepcopyz  s    7D')$r0   c                   SSK Jn  SSKJn  SSKJn  UR
                  n[        U5      nUR                  5       nUR                  UR                  5      nU R                  [        U5      S5        UR                  n[        U5      nUR                  5       nUR                  UR                  5      nU R                  [        U5      S5        UR                  UR                  5      nU R                  [        U5      S5        UR                  UR                  5      nU R                  [        U5      S5        UR                  n[        U5      nUR                  5       nUR                  UR                  5      n/ n	U H'  n
U
R                    H  nU	R#                  U5        M     M)     U R                  [        U	5      S	5        UR$                  n[        U5      nUR                  5       nUR                  UR&                  5      nU R                  [        U5      S
5        UR(                  n[        U5      nUR                  5       nUR                  UR                  5      nUR*                  n[        U5      nU R                  [        U5      S5        UR                  [,        R.                  5       H  nU R                  [        U5      S5        UR                  [,        R0                  5      nU R                  [3        US   R4                  5      S5        U R                  [3        US   R4                  5      S5        M     g )Nr   r  )dynamicsnotef      5   r           r_   )r  r  r   r  r  
pitches01ar   flattengetElementsByClassNoteassertEqualrq  directions31aDynamicDynamicWedgelyricsMelisma61dlyricsrR   restsDurations02aRestnotations32arhythmDurations03ar   r  Measurer  r   )rB   r  r  r  r  r  r  r   dfoundnoteObjr  partmeasuress                 r1   testConversionMXTest.testConversionMX~  s   2$  ++(OIIK  +Q% !..(OIIK  !1!12Q$  +Q$   !6!67Q# !11(OIIK  +G~~S! &  	UQ' !22(OIIK  +Q$ !--(OIIK  + 33(OQ#((5DSY*..v~~>HS!!3!34a8S"!4!45q9	 6r0   c           	     x   SSK Jn  SSKJn  UR                  n[        U5      nUR                  [        R                  5       Ht  nXQR                     nU R                  [        U5      S5        / SQn[        [        U5      5       H,  nU R                  Xx   [        Xh   R                  5      5        M.     Mv     g )Nr   chordr  r  )r  r  r  r  r  r  r  )r   r  r  r  r  r   r  r   r  Chordr  rq  rangepitches)	rB   r  r  r  r  r  chords	knownSizerT  s	            r1   testConversionMXChordsTest.testConversionMXChords  s    !2 <<(O((5D++&FS[!,-I3y>*  s693D3D/EF +	 6r0   c                P   SSK Jn  SSKJn  UR                  n[        U5      nUR                  S   nUR                  5       R                  n/ nU H7  n[        XR                  5      (       d  M  XxR                  R                  -  nM9     U R                  [        U5      S5        g )Nr   r  r     )r   r  r  r  r  r   partsrecursenotesAndRestsrh   r  beams	beamsListr  rq  )	rB   r  r  r  r  r  notesr  ns	            r1   testConversionMXBeamsTest.testConversionMXBeams  s     2 (((Owwqz,,A!YY''***  	US)r0   c                   SSK Jn  UR                  n[        U5      nUR                  S   nUR
                  n[        U5      nUR                  S   nUR                  5       R                  nU R                  [        U5      S5        g )Nr   r     )
r  r  timeSignatures11cr   r  timeSignatures11dr  r  r  rq  )rB   r  r  r  unused_partr  r  s          r1   testConversionMXTimeTest.testConversionMXTime  sl    2 22(Oggaj 22(Owwqz,,UR(r0   c                    SSK Jn  SSKJn  UR                  n[        U5      nUR                  S   nXQR                     nU R                  [        U5      S5        g )Nr   clefr     )
r   r!  r  r  clefs12ar   r  Clefr  rq  )rB   r!  r  r  r  r  clefss          r1   testConversionMXClefPrimitive"Test.testConversionMXClefPrimitive  sH     2 ))(OwwqzYYUR(r0   c                   SSK Jn  SSK Jn  SSK Jn  UR	                  S5      nUR
                  S   UR                     nU R                  [        U5      S5        U R                  US   R                  S5        UR
                  S   UR                     nU R                  [        U5      S5        U R                  US   R                  S5        U R                  [        US   5      R                  S	5        UR
                  S
   UR                     nU R                  [        U5      S5        UR
                  S   UR                     nU R                  [        U5      S5        g )Nr   r  r   meterlucar_   Gr  Treble8vbClefr     )r   r  r!  r*  r   r  r$  r  rq  signoctaveChangero  r+   TimeSignature)rB   r  r!  r*  r  r%  tss          r1   testConversionMXClefTimeCorpus#Test.testConversionMXClefTimeCorpus  s   " !LL  
499%UQ'q, 
499%UQ'q..3eAh00/B 
499%UQ' WWQZ++,R!$r0   c                   SSK Jn  SSKJn  UR                  n[        U5      nUR                  S   nUR                  5       R                  UR                  5      nU R                  [        U5      S5        / n/ SQn[        [        U5      5       H6  n	UR                  [        Xi   R                  S   R                   5      5        M8     U R                  Xx5        g )Nr   r  r  r.  )z-<class 'music21.articulations.Staccatissimo'>z&<class 'music21.articulations.Accent'>z(<class 'music21.articulations.Staccato'>z&<class 'music21.articulations.Tenuto'>)r   r  r  r  articulations01r   r  r  r  r  r  rq  r  rR   r   articulations	__class__)
rB   r  r  r  r  r  r  rS   rk   rT  s
             r1   testConversionMXArticulations"Test.testConversionMXArticulations  s     2 00(Owwqz11$))<UQ'; s5z"AKKEH2215??@A #%r0   c                    SSK Jn  SSKJn  UR                  n[        U5      nUR                  S   nXQR                     nU R                  [        U5      S5        g )Nr   keyr  .   )
r   r=  r  r  keySignatures13ar   r  KeySignaturer  rq  )rB   r=  r  r  r  r  keyLists          r1   testConversionMXKeyTest.testConversionMXKey,  sK    2 11(Owwqz''(Wr*r0   c                   SSK Jn  [        UR                  5      nU R	                  UR
                  R                  S5        U R	                  UR
                  R                  S5        U R	                  UR
                  R                  S5        [        UR                  5      nU R	                  UR
                  R                  S5        U R	                  UR
                  R                  S5        g )Nr   r  zWolfgang Amadeus Mozartz Quintet for Clarinet and Stringsz#Menuetto (Excerpt from Second Trio)zGilles Binchoisz$Excerpt from Magnificat secundi toni)r  r  r   mozartTrioK581Excerptr  r   composertitlemovementNamebinchoisMagnificat	bestTitle)rB   r  r  s      r1   testConversionMXMetadataTest.testConversionMXMetadata6  s    .)112,,.GH))+MN002WX)../,,.?@--/UVr0   c                    SSK Jn  SSKJn  [	        UR
                  5      nUR                  S   nXAR                     nU R                  [        U5      S5        g )Nr   barr  r  )
r   rO  r  r  r   barlines46ar  Barliner  rq  )rB   rO  r  r  r  barlineLists         r1   testConversionMXBarlinesTest.testConversionMXBarlinesC  sF    2-++,wwqz;;'[)2.r0   c                f   SSK Jn  SSKJn  [	        UR
                  5      nUR                  [        R                  5      R                  5       nXBR                     n/ nU H  nUR                  UR                  5        M      U R                  U/ SQ5        U R                  [        U5      S5        g )Nr   r  )layout)r_   r  r.  r  r        )r  r  r   rV  r   systemLayoutTwoPartr  r   r  firstSystemLayoutrR   measureNumberr  rq  )rB   r  rV  r  r  systemLayoutListmeasuresWithSLes           r1   testConversionXMLayoutTest.testConversionXMLayoutK  s    2"-334 ##FKK0668 3 34!A!!!//2 ");<-.2r0   c                
   SSK Jn  SSKJn  [	        UR
                  5      nSnSnUR                   H  nUR                  5       R                  S   R                  UR                  5      nU R                  XrR                  5        UR                  5       R                   H8  nUR                  c  M  US-  nUR                  R                  S;   d  M3  US-  nM:     M     U R                  US5        U R                  US5        g )Nr   r  r   r_   )startcontinue9   (   )r  r  r   r!  r   multiMeasureTiesr  r  r  getContextByClassr$  assertIsInstance	TenorCleftiero  r  )	rB   r  r!  r  	countTiescountStartTiesprS   r  s	            r1   testConversionMXTiesTest.testConversionMXTies[  s    2 -001 	A99;$$Q'99$))DD!!$7YY[&&55$NIuuzz%::&!+	 '  	B',r0   c                   SSK Jn  SSK Jn  UR                  SS5      nUR                  S   UR
                     nU R                  [        U5      S5        UR                  S   UR
                     nU R                  [        U5      S5        UR                  S   UR
                     nU R                  [        U5      S5        g )Nr   r  )
instrumentzschumann_clara/opus17r  r_   r  )r   r  rr  r   r  
Instrumentr  rq  )rB   r  rr  r	  is1is2is3s          r1   testConversionMXInstrumentTest.testConversionMXInstrumentq  s    "&LL0!4ggaj../S1%ggaj../S1%ggaj../S1%r0   c                   [         R                  " 5       S-  S-  nUS-  n[        U5      n[        U5      n[        R
                  " 5       nUR                  U5        UR                  S5       nUR                  5       nS S S 5        UR                  W5        [        U5        [        U5        g ! , (       d  f       N6= f)Nr  r  
test01.midrb)	r
   getSourceFilePathr   r   r   ConverterMidirs   rg   r   )rB   dirLibr@   unused_sr   rT   datas          r1   testConversionMidiBasicTest.testConversionMidiBasic  s    ))+f4Fl" R=9'')	B WWT]a668D  	
D 	$d ]s   .B//
B=c                   SSK Jn  SSK Jn  SSK Jn  SSK Jn  [
        R                  " 5       S-  S-  S-  n[        U5      nU R                  [        XdR                     5      S	5        [
        R                  " 5       S-  S-  S
-  n[        U5      nU R                  [        XdR                     5      S5        U R                  [        XcR                     5      S5        U R                  [        XaR                     5      S5        U R                  [        XbR                     5      S5        [
        R                  " 5       S-  S-  S-  n[        U5      nSSKJn  UR!                  5       R"                  S S  Vs/ s H  oR$                  PM     n	nSSSSSSSSSSSSSSSSSSSSSSSSU" SS5      U" SS5      U" SS5      SSS/n
U R                  X5        U R                  [        XaR                     5      S5        U R                  [        XbR                     5      S5        [
        R                  " 5       S-  S-  S-  n[        U5      nU R                  [        XaR                     5      S5        U R                  [        XbR                     5      S5        [
        R                  " 5       S-  S-  S-  n[        U5      nU R                  [        XaR                     5      S5        XbR                     nU R                  [        U5      S5        U R                  US   R&                  S5        U R                  US   R&                  S5        U R                  US   R&                  S5        g s  snf )Nr   r)  r<  r  r  r  r  rz  r"  z
test05.midr  r  r_   z
test06.mid)Fraction         ?g      ?r  z
test07.midz
test08.midr  )r   r*  r=  r  r  r
   r|  r   r  rq  r  r  r1  r@  	fractionsr  r  r  quarterLengthsharps)rB   r*  r=  r  r  r@   r	  Fr  dListrk   r  s               r1   testConversionMidiNotesTest.testConversionMidiNotes  s   !! %%'&0?B\Q bMQyy\*B/ %%'&0?B\QbM 	Qyy\*A.Q{{^,a0 	Q2234a8Q//0115 %%'&0?B\QbM 	,*+))+*C*CCR*HI*HQ*HIc3S#sCcc3S#sCcc3Qq!Wa1gqAwS#O 	&Q2234a8Q//0115
 %%'&0?B\QbMQ2234a8Q//0115 %%'&0?B\QbMQ2234a8""#UQ'q"-q!,q"-= Js   <M5c                   SSK Jn  SSKJn  UR                  n[        U5      nUR                  S   nUR                  [        R                  5      nU R                  US   R                  S 5        U R                  US   R                  R                  S5        U R                  US   R                  S 5        U R                  US   R                  R                  S5        UR                  n[        U5      nU R                  [        XAR                      5      S5        UR                  S   nUR                  [        R                  5      ng )Nr   rN  r  finalr_   r.  )r   rO  r  r  simpleRepeat45ar   r  r  r   r  r  leftBarlinerightBarlinero  repeatMultipleTimes45crq  rQ  )rB   rO  r  r  r	  r  r   s          r1   testConversionMXRepeatsTest.testConversionMXRepeats  s   2 00(Owwqz**6>>:!00$7!1166@!00$7!1166@ 77(OQ{{^,a0wwqz**6>>:r0   c           	     $   SSK Jn  SSKJn  [	        UR
                  5      nU R                  U[        R                  5        U R                  U[        R                  5        U R                  [        UR                  5       R                  5      S5        UR	                  S5      nU R                  U[        R                  5        U R                  UR                   Vs/ s H&  n[        UR                  5       R                  5      PM(     sn/ SQ5        UR	                  SSS9nU R                  U[        R                  5        U R                  U[        R                  5        U R                  UR                   R"                  S	5        g s  snf )
Nr   r  r  B   zessenFolksong/teste)!   3   ;   r        C   X   rX  r  zMoli hua)music21.abcFormatr  r   r  r   theAleWifesDaughterri  r   r  assertNotIsInstancer  r  rq  r  r  scoresr   rG  )rB   r  r  r	  ops        r1   testConversionABCOpusTest.testConversionABCOpus  s   /")//0a.  FKK0QYY[667< \\/0 	b&++."))L)Q#aiik778)L:	<
 LL.qL9a.  FKK0)):6 Ms   -Fc                V   SSK Jn  UR                  SSS9nU R                  U[        R
                  5        U R                  UR                  R                  S5        U R                  [        UR                  S   R                  5       R                  S   R                  5      S5        g )	Nr   r  zessenFolksong/han1rX  r  zYi gan hongqi kongzhong piaor.  zL<music21.beam.Beams <music21.beam.Beam 1/start>/<music21.beam.Beam 2/start>>)r   r  r   ri  r   r  r  r   rG  r   r  r  r  r  )rB   r  r	  s      r1   testConversionABCWorkFromOpus"Test.testConversionABCWorkFromOpus  s    "LL-aL8a.))+IJ
""$2215;;<Z	\r0   c                   [         R                  " 5       S-  S-  S-  n[        [        U5      S 45      nU R	                  U[
        R                  5        U R                  [        5         [        US45        S S S 5        U R                  [        5         [        [        U5      S45        S S S 5        [        [        U5      S45      nU R	                  U[
        R                  5        g ! , (       d  f       Ny= f! , (       d  f       NV= f)Nr  essenFolksongz	testd.abcrW  )rW  )
r
   r|  r   r   ri  r   r  assertRaisesr   r  rB   r@   r	  s      r1   +testConversionABCWorkFromOpusWithoutKeyword0Test.testConversionABCWorkFromOpusWithoutKeyword  s    %%'(2_D{R3r7D/"a-122q'N 3 123r7D/" 3 3r7A,a. 32 32s   *C+C<+
C9<
D
c                    [         R                  " 5       S-  S-  S-  n[        U5      nU R                  [	        UR
                  5      S5        g )Nr   r  test01r  )r
   r|  r   r  rq  r  r  s      r1   testConversionMusedataTest.testConversionMusedata(  s@    %%'*4FQ"IQWWq)r0   c                   [         R                  " 5       S-  S-  n[        U5      nU R                  UR                  S5        U R                  UR                  5       5        UR                  5       nU R                  USS S5        U R                  UR                  5       / SQ5        [         R                  " 5       S-  S	-  S
-  n[        R                  " 5       nUR                  U5        g)z:
Test getting data out of musedata or musicxml zip files.
r^   ztestMxl.mxlrF   N&   z&<?xml version="1.0" encoding="UTF-8"?>)zmusicXML.xmlz	META-INF/zMETA-INF/container.xmlr   r  r  )r
   r|  r   r  rA   
assertTruerN   r[   rV   r   ConverterMuseDatar   )rB   r@   afrS   cmds        r1   testMixedArchiveHandlingTest.testMixedArchiveHandling.  s     %%'*4}DB/' zz|cr$LM(_`6 %%'*4FQ--/br0   c                `    SnSSK Jn  [        5       nU R                  X#R                  U5        g)z
Ensure Converter.parseData() distinguishes between a string with MEI data and a string with
MusicXML data. The "subConverter" module is mocked out because we don't actually need to
test the conversion process in this unit test.
z8<?xml version="1.0" encoding="UTF-8"?><mei><note/></mei>r   )MeiElementErrorN)music21.mei.baser  r   r  r   )rB   	meiStringr  testConvs       r1   testMEIvsMXTest.testMEIvsMXZ  s,     O	 	5;/+=+=yIr0   c           	         SSK Jn  SSK Jn  UR                  R                  [
        R                  -   S-   n[        USSSS9nXAR                      H*  nU R                  [        UR                  S	-  S
SS95        M,     g)zS
Checks quantization when parsing a stream. Here everything snaps to the 8th note.
r   r  )omrzk525short.midTFr  )r   r  r   r  g        gHz>)abs_tolN)r   r  r  
correctorspathNamer   sepr   r  r  r   r  )rB   r  r  midiFp
midiStreamr  s         r1   testParseMidiQuantizeTest.testParseMidiQuantizes  sg     	!((2661OC6t^bc
II&AOOGAOOc$93MN 'r0   c                B   [         R                  " 5       S-  S-  S-  n[        U5      nU R                  SUR	                  5       R                  5       5        [        USS9nU R                  SUR	                  5       R                  5       5        [        USS9nU R                  S	UR	                  5       R                  5       5        UR                  S
5       nUR                  5       nSSS5        U R                  W[        5        [        USS9nU R                  SUR	                  5       R                  5       5        [        U5      nUR                  5         [        USS9n	U	R                  5         [        USS9n
U
R                  5         g! , (       d  f       N= f)z~
Checks that quantization is not performed if quantizePost=False.
Source MIDI file contains only: 3 16th notes, 2 32nd notes.
r  r  z
test15.midg      ?F)r   r  )r   g      ?r{  N)r
   r|  r   assertNotInr  _uniqueOffsetsAndEndTimesassertInrs   rg   ri  ri   r   r   )rB   r@   streamFpQuantizedstreamFpNotQuantizedstreamFpCustomQuantizedrT   r  streamDataNotQuantizedpf1pf2pf3s              r1   testParseMidiNoQuantizeTest.testParseMidiNoQuantize  s[   
 %%'&0?B\Q ""I 1 9 9 ; U U WX$Re<e199;UUWX"'$"G6>>@ZZ\] WWT]a668D dE*!&t%!@e3;;=WWYZ 22E22T: ]s   F
Fc                R   SSK Jn  [        R                  " 5       S-  S-  n[	        U5      nUR                  5         U R                  [        5         [        U5        SSS5        [        USS9nU R                  [        XAR                     5      S5        g! , (       d  f       N@= f)	zv
Here is a filename with an incorrect extension (.txt for .rnText).  Make sure that
it is not cached the second time.
r   )harmonyr$   zincorrectExtension.txtN	romantext)r   r_   )r   r  r
   r|  r   r   r  r   r   r  rq  Harmony)rB   r  r@   pfr   s        r1   testIncorrectNotCachedTest.testIncorrectNotCached  s    
 	$%%'+58PP"
56"I 7 "[)Q/0!4	 76s   B
B&c                8   [         R                  " 5       S-  S-  S-  n[        U5      nU R                  SUR                  5        [         R                  " 5       S-  S-  S-  nU R                  [        5         [        U5        S S S 5        U R                  [        5         [        [        U5      5        S S S 5        U R                  [        5         [        S5        S S S 5        g ! , (       d  f       Nj= f! , (       d  f       NI= f! , (       d  f       g = f)Nr  bachzbwv66.6.mxlr   zbwv66.6z5nonexistent_path_ending_in_correct_extension.musicxml)	r
   r|  r   r  classesr  r  r   r   r  s      r1   testConverterFromPathTest.testConverterFromPath  s    %%'(2V;mK"Ih		*%%'(2V;iG01"I 212 #b'N 3 01IJ 21 2122 21s$   9C)"C:D)
C7:
D
Dc                   SSK Jn  SnUS-   n[        R                  " 5       nSUS'   [	        U5      nU R                  [        UR                  5      S5        [        5       R                  UR                  5       SU5      n[        US	S
S9 nUR                  S5        SSS5        U R                  U5         [	        USS9nSSS5        [	        USS9nU R                  [        UR                  5      S5        [        U5      nU R                  [        UR                  5      S5        [        R                   " U5        g! , (       d  f       N= f! , (       d  f       N= f)zD
This should be the only test that requires an internet connection.
r   )HumdrumExceptionz<https://raw.githubusercontent.com/craigsapp/chopin-preludes/z>f8fb01f09d717e84929fb8b2950f96dd6bc05686/kern/prelude28-20.krnallowr"  r  z.krnr  r  ra   z.all sorts of garbage that Humdrum cannot parseNF)r   T)music21.humdrum.spineParserr  r   Environmentr   r  rq  r  r   r   r   rs   r  r  r   r   r   )rB   r  urlBaser   r_  r	  destFpr@   s           r1   testParseURLTest.testParseURL  s    	APXX##%#.SMQWWq) ++A,<,<,>L&#0BHHEF 1 /0%0A 1 Sd+QWWq) #JQWWq)
		& 10 10s   E 7E 
E
Er)   N)!r+   r,   r-   r.   r  r  r  r  r  r&  r3  r9  rB  rK  rS  r`  ro  rw  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r/   r)   r0   r1   r  r  x  s    %::XG*))%2&(+W/3 -,&,A.F;076
\/**XJ2O@5"K r0   r  __main__)r   z type[subConverters.SubConverter]r   r   )r   z3t.Literal['all'] | type[subConverters.SubConverter]r   r   r  )r   (stream.Score | stream.Part | stream.Opusr   )
r  zAbundles.MetadataEntry | bytes | str | pathlib.Path | list | tupler   r   r   r   r   r   r   r  )r  zbase.Music21Objectry  r   r   r  )NNFr   )r   r   )r   r   )r@   r   r   r   )Nr   
__future__r   collectionsr   copyhttp.clientr   ru   mathr   r   rj   re   r   rP  typingr   unittestrJ   r,  music21.converterr   r   r   r	   r
   r   r   r   r   rp   r   music21.metadatar   r   r   __all__r  r   TypeVarr   ri   r%   Music21Exceptionr   r   r   r   r   r   r   r  r   r   r   r  r   r   r   r   r   r   r   r   r  r    r!   r"   r#   r  TestCaser  r  r  
_DOC_ORDERr+   mainTestr)   r0   r1   <module>r     s  . #   ! 	  	 	  
      + '       .  $ ??	 &&{3iiSY7	l;; 		L99 		66 		\:: 	
U Urz- z-~ EJG A K
 
G   
'96 4 KL*5*	* M*3ZI3Z	3Zl 4 KL,5,	, M,e e`  B	$  B$ 	
 A, $!!	xJxJ xJ 	xJ
 >xJt!H14h"J	"x   "'8$$ 'lh	8 h	Z Y	8VT9g-/EG
 zT r0   