o cc@s0ddlZddlZGdddeZdZdZdZdZdZd Z d Z d Z d Z d Z dZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ d Z!d!Z"d"Z#d#Z$dZ%d$Z&d%d&Z'd'd(Z(d)d*Z)d+d,Z*d-d.Z+d/d0Z,e(ddddddde*e*e*e*e)e)e*e,fZ-d1d2Z.d3d4Z/d5d6Z0d;d7d8Z1d;d9d:Z2dS)<Nc@s eZdZdS)errorN)__name__ __module__ __qualname__rrS/home/lily/lilypond-2.24.1/release/binaries/lilypond/lilypond-2.24.1/python/midi.pyr-srxyz{|}~ !/QTXY`cCs2d}|dkr||d@d>}|}|dks||S)Nrrrrr)nextbytegetbytesumrrr_get_variable_length_number_s r,cCstd)Nz/the first midi command in the track is a repeat)rstatusr)r*rrr_first_command_is_repeatgr/cCs||fSNrr-rrr_read_two_byteskr0r2cCs |||fSr1rr-rrr_read_three_bytesos r3cs&t|}dfddt|DS)Nc3s|]}tVqdSr1)chr).0ir*rr usz_read_string..)r,joinrange)r)r*lengthrr8r _read_stringss r=cCs(|dkr ||t||fS|t||fS)Nr()r=r-rrr _read_f0_bytexsr>ccsttd|}|j}d}d}z2|D],}|t||7}|r&||kr&WdS|}|dkr2|}|}|t|d?|||fVqWdStyUttt|t dw)NBrrrz-a track ended in the middle of a MIDI command) iterarray__next__r,_read_midi_event StopIterationprintlenlistr)data clocks_maxZdataiterr*timer.r)rrr_parse_track_bodys(  rKcCs|||d|krtd||||dfztd||d|d\}Wntjy7td|w|d|}||d|}t||krRtd|||fS)Nrzexpected %r, got %rz>Irz:the %s header is truncated (may be an incomplete download)z3the %s is truncated (may be an incomplete download))rstructunpackrF)rHpostypemagicr<endposrrr _parse_hunks "  rRccsJ|dkr td|t|D]}t||dd\}}tt||VqdS)Nztoo many tracks: %dtrackMTrk)rr;rRrGrK)midirN num_tracksrIr7Z trackdatarrr _parse_trackss  rXcCs t|ddd\}}tt||S)NrrTrU)rRrGrK)rTrIZ track_bodyendrrr parse_tracksrZcCslt|ddd\}}ztd|dd\}}}Wn tjy$tdwtt||||}||df|fS)NrfilesMThdz>3Hrzthe file header is too shortr)rRrLrMrrGrX)rVrIheaderZfirst_track_posformatrWZdivisionZtracksrrrparsesr^r1)3rArL ExceptionrZNOTE_OFFZNOTE_ONZPOLYPHONIC_KEY_PRESSUREZCONTROLLER_CHANGEZPROGRAM_CHANGEZCHANNEL_KEY_PRESSUREZ PITCH_BENDZ ALL_SOUND_OFFZRESET_ALL_CONTROLLERSZ LOCAL_CONTROLZ ALL_NOTES_OFFZ OMNI_MODE_OFFZ OMNI_MODE_ONZ MONO_MODE_ONZ POLY_MODE_ONZSEQUENCE_NUMBERZ TEXT_EVENTZCOPYRIGHT_NOTICEZSEQUENCE_TRACK_NAMEZINSTRUMENT_NAMEZLYRICZMARKERZ CUE_POINTZ PROGRAM_NAMEZ DEVICE_NAMEZMIDI_CHANNEL_PREFIXZ MIDI_PORTZ END_OF_TRACKZ SET_TEMPOZ SMTPE_OFFSETZTIME_SIGNATUREZ KEY_SIGNATUREZXMF_PATCH_TYPE_PREFIXZSEQUENCER_SPECIFIC_META_EVENTZ META_EVENTr,r/r2r3r=r>rCrKrRrXrZr^rrrrs(