
    3jl                      d Z ddlmZ ddlmZ ddlmZ ddlZddlZddl	Z
ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ e
j,                  rddlmZ  ej0                  d      Zdd	 ddZdd	 ddZ G d dej8                        Z G d de      Z G d de      Z G d de      Z  G d de      Z! G d de      Z" G d  d!e      Z# G d" d#e      Z$ G d$ d%e      Z% G d& d'e%      Z& G d( d)e%      Z' G d* d+e%      Z( G d, d-e%      Z) G d. d/e      Z* G d0 d1e      Z+ G d2 d3e+      Z, G d4 d5e+      Z- G d6 d7e+      Z. G d8 d9e+      Z/ G d: d;e+      Z0 G d< d=e+      Z1 G d> d?e1      Z2 G d@ dAe1      Z3 G dB dCe1      Z4 G dD dEe1      Z5 G dF dGe1      Z6 G dH dIe+      Z7 G dJ dKe+      Z8 G dL dMe+      Z9 G dN dOe+      Z: G dP dQe+      Z; G dR dSe+      Z< G dT dUe+      Z= G dV dWe      Z> G dX dYe>      Z? G dZ d[e?      Z@ G d\ d]e?      ZA G d^ d_e?      ZB G d` dae?      ZC G db dce?      ZD G dd dee?      ZE G df dge>      ZF G dh die>      ZG G dj dke>      ZH G dl dmeH      ZI G dn doe>      ZJ G dp dqeJ      ZK G dr dse>      ZL G dt dueL      ZM G dv dweL      ZN G dx dyeL      ZO G dz d{eL      ZP G d| d}e>      ZQ G d~ de>      ZR G d de      ZS G d deS      ZT G d deS      ZU G d deS      ZV G d deV      ZW G d deS      ZX G d de      ZY G d deY      ZZ G d deY      Z[ G d deZ      Z\ G d deZ      Z] G d deZ      Z^ G d deZ      Z_ G d deZ      Z` G d deZ      Za G d deZ      Zb G d deZ      Zc G d deZ      Zd G d deZ      Ze G d deZ      Zf G d deZ      Zg G d de[      Zh G d de[      Zi G d de[      Zj G d de[      Zk G d de[      Zl G d de[      Zm G d dem      Zn G d dem      Zo G d dem      Zp G d dem      Zq G d dem      Zr G d dem      Zs G d dem      Zt G dĄ de[      Zu G dƄ de[      Zv G dȄ de[      Zw G dʄ de[      Zx G d̄ de[      Zy G d΄ de[      Zz G dЄ de[      Z{ G d҄ de[      Z| G dԄ de[      Z} G dք de[      Z~ G d؄ de[      Z G dڄ de[      Z G d܄ de[      Z G dބ de[      Z G d de[      Z G d de[      Z G d de[      Z G d de[      Z G d de[      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zg dZd ZdddZi deded e$dede$de$de de!de"de_de_d	e\d
e]de^deadedde'i de'de'de&de(de)de*de)de2de2de3de3de3de3de3de3de4de5i d e5d!e6d"e5d#e5d$e5d%e5d&e,d'e-d(e.d)e/d*e+d+e+d,e0d-efd.e+d/e+d0e+i d1e+d2ed3ed4ed5e#d6eUd7eVd8eXd9eUd:eTd;eSd<eSd=eSd>eMd?eNd@eOdAePi dBeFdCeGdDeJdEeHdFe@dGe?dHeAdIeBdJeBdKeCdLeDdMeEdNe#dOe#dPe#dQe#dRe#i dSe#dTe#dUe#dVe#dWe#dXe#dYe#dZe#d[e#d\e#d]e#d^e#d_e#d`e#dae#dbe#dce#i dde#dee#dfe;dge9dhe<die=djegdkeQdle,dmeRdne_doewdpeedqehdredse}dte#e#e#e#e#e#e#e#e#e#du	ZddvZddwZdx Z G dy dzej0                  j2                        Zej6                  f	 dd{Zej6                  f	 dd|Zej6                  f	 dd}Z G d~ dej>                        Z G d dej>                        ZegZedk(  rddlZ ejH                  e       yy(  a  
This module represents instruments through objects that contain general information
such as Metadata for instrument names, classifications, transpositions and default
MIDI program numbers.  It also contains information specific to each instrument
or instrument family, such as string pitches, etc.  Information about instrumental
ensembles is also included here though it may later be separated out into its own
ensemble.py module.
    )annotations)OrderedDict)IterableN)base)common)environment)InstrumentException)interval)note)pitch)
OffsetTreestream
instrumentFinPlacec                   |du r| }n| j                  d      }|D ]J  }t        |t        j                        s|j                  }|-|j
                  }|j                  ||       L |du r|S y)a  
    takes a :class:`~music21.stream.Stream` that has :class:`~music21.note.NotRest` objects
    and moves their `.storedInstrument` attributes to a new Stream (unless inPlace=True)

    >>> up1 = note.Unpitched()
    >>> up1.storedInstrument = instrument.BassDrum()
    >>> up2 = note.Unpitched()
    >>> up2.storedInstrument = instrument.Cowbell()
    >>> s = stream.Stream()
    >>> s.append(up1)
    >>> s.append(up2)
    >>> s2 = instrument.unbundleInstruments(s)
    >>> s2.show('text')
    {0.0} <music21.instrument.BassDrum 'Bass Drum'>
    {0.0} <music21.note.Unpitched 'Bass Drum'>
    {1.0} <music21.instrument.Cowbell 'Cowbell'>
    {1.0} <music21.note.Unpitched 'Cowbell'>
    TunbundleInstrumentsNF)coreCopyAsDerivation
isinstancer   NotReststoredInstrumentoffsetinsert)streamInr   sthisObjioffs         ?/DATA/.local/lib/python3.12/site-packages/music21/instrument.pyr   r   .   st    , $))*?@gt||,((A}nna   %     c                   |du r| }n| j                  d      }d}|D ]F  }d|j                  v r|}|j                  |       %t        |t        j
                        s@||_        H |du r|S y)a  
    >>> up1 = note.Unpitched()
    >>> up1.storedInstrument = instrument.BassDrum()
    >>> upUnknownInstrument = note.Unpitched()

    >>> up2 = note.Unpitched()
    >>> up2.storedInstrument = instrument.Cowbell()
    >>> s = stream.Stream()
    >>> s.append(up1)
    >>> s.append(upUnknownInstrument)
    >>> s.append(up2)
    >>> s2 = instrument.unbundleInstruments(s)
    >>> s3 = instrument.bundleInstruments(s2)
    >>> for test in s3:
    ...     print(test.storedInstrument)
    Bass Drum
    Bass Drum
    Cowbell

    TbundleInstrumentsN
InstrumentF)r   classesremover   r   r   r   )r   r   r   lastInstrumentr   s        r    r#   r#   U   sw    0 $))*=>N7??*$NHHW.'5G$  % r!   c                  \     e Zd ZdZdZdd fdZd Zd ZddZddZ	d Z
d	 Zddd
Z xZS )r$   a  
    Base class for all musical instruments.  Designed
    for subclassing, though usually a more specific
    instrument class (such as StringInstrument) would
    be better to subclass.

    Some defined attributes for instruments include:

    * partId
    * partName
    * partAbbreviation
    * instrumentId
    * instrumentName
    * instrumentAbbreviation
    * midiProgram (0-indexed)
    * midiChannel (0-indexed)
    * lowestNote (a note object or a string for _written_ pitch)
    * highestNote (a note object or a string for _written_ pitch)
    * transposition (an interval object)
    * inGMPercMap (bool -- if it uses the GM percussion map)
    * soundfontFn (filepath to a sound font, optional)
    ic                    t        |   di | d | _        d| _        d | _        d | _        d | _        d | _        d | _        d| _	        || _
        d | _        d | _        d | _        d | _        d | _        d | _        d | _        d| _        d | _        y )NF )super__init__partId_partIdIsRandompartNamepartAbbreviationprintPartNameprintPartAbbreviationinstrumentId_instrumentIdIsRandominstrumentNameinstrumentAbbreviationmidiProgrammidiChannelinstrumentSound
lowestNotehighestNotetranspositioninGMPercMapsoundfontFn)selfr5   keywords	__class__s      r    r,   zInstrument.__init__   s    $8$ $$"&*.(,04"&*%*"(604#%)%))-,0-1 6: r!   c                P   g }| j                   |j                  | j                    d       | j                  7| j                  | j                  k7  r|j                  | j                   d       | j                  |j                  | j                         dj	                  |      S )Nz:  )r-   appendr/   r5   join)r?   msgs     r    __str__zInstrument.__str__   s    ;;"JJ$++b)*==$$:M:M)MJJ$--+,*JJt**+wws|r!   c                *    t        t        |             S N)reprstrr?   s    r    _reprInternalzInstrument._reprInternal   s    CIr!   c                    t        j                  | |      }| j                  r|j                          | j                  r|j                          |S rI   )r   defaultDeepcopyr.   partIdRandomizer4   instrumentIdRandomize)r?   memonews      r    __deepcopy__zInstrument.__deepcopy__   sC    $$T40!%%%%'
r!   c                    | j                   | j                   S | j                  | j                  S | j                  | j                  S | j                  | j                  S y)zi
        Find a viable name, looking first at instrument, then part, then
        abbreviations.
        N)r/   r0   r5   r6   rL   s    r    bestNamezInstrument.bestName   sc    
 ==$== "".(((  ,&&&((4...r!   c                N    dt        j                          }|| _        d| _        y)3
        Force a unique id by using an MD5
        PTN)r   getMd5r-   r.   r?   idNews     r    rP   zInstrument.partIdRandomize   s(     FMMO$% #r!   c                N    dt        j                          }|| _        d| _        y)rX   ITN)r   rZ   r3   r4   r[   s     r    rQ   z Instrument.instrumentIdRandomize   s)     FMMO$% "%)"r!   c                *   t        |      }d| j                  v rd|vrd| _        | j                  S |sd| _        | j                  S t        |      |dz
  k\  rt	        d      t        |      D ]$  }||v r|dz  dk(  r|| _        | j                  c S  y)a  
        Assign an unused midi channel given a list of
        used channels.  Music21 uses 0-indexed MIDI channels.

        assigns the number to self.midiChannel and returns
        it as an int.

        Note that the Percussion MIDI channel (9 in music21, 10 in 1-16 numbering) is special,
        and thus is skipped.

        >>> used = [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11]
        >>> i = instrument.Violin()
        >>> i.autoAssignMidiChannel(used)
        12
        >>> i.midiChannel
        12

        Note that used is unchanged after calling this and would need to be updated manually

        >>> used
        [0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11]

        Unpitched percussion will be set to 9, so long as it's not in the filter list:

        >>> used = [0]
        >>> i = instrument.Maracas()
        >>> i.autoAssignMidiChannel(used)
        9
        >>> i.midiChannel
        9

        >>> used = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        >>> i = instrument.Woodblock()
        >>> i.autoAssignMidiChannel(used)
        11
        >>> i.midiChannel
        11

        If all 16 channels are used, an exception is raised:

        >>> used2 = range(16)
        >>> i = instrument.Instrument()
        >>> i.autoAssignMidiChannel(used2)
        Traceback (most recent call last):
        music21.exceptions21.InstrumentException: we are out of midi channels! help!

        Get around this by assinging higher channels:

        >>> i.autoAssignMidiChannel(used2, maxMidi=32)
        16
        >>> i.midiChannel
        16

        * Changed in v.9 -- usedChannelList is required, add maxMidi as an optional parameter.
            various small tweaks for corner cases.
        UnpitchedPercussion	   r      z"we are out of midi channels! help!   )	frozensetr%   r8   lenr	   range)r?   usedChannelsmaxMidichannelFilterchs        r    autoAssignMidiChannelz Instrument.autoAssignMidiChannel   s    t ",/ DLL0Qm5K D### D###7Q;.%&JKKGn&"W\')D$+++ % r!   rI   )r5   
str | None)returnrl   )rc   )rg   z	list[int])__name__
__module____qualname____doc__classSortOrderr,   rG   rM   rT   rV   rP   rQ   rk   __classcell__rA   s   @r    r$   r$      s>    , N < $*N Nr!   r$   c                       e Zd Z fdZ xZS )KeyboardInstrumentc                N    t        |   di | d| _        d| _        d| _        y )NKeyboardKbzkeyboard.pianor*   r+   r,   r5   r6   r9   r?   r@   rA   s     r    r,   zKeyboardInstrument.__init__F  s+    $8$(&*#/r!   rn   ro   rp   r,   rs   rt   s   @r    rv   rv   D  s    0 0r!   rv   c                  "     e Zd ZdZ fdZ xZS )Pianozf

    >>> p = instrument.Piano()
    >>> p.instrumentName
    'Piano'
    >>> p.midiProgram
    0
    c                    t        |   di | d| _        d| _        d| _        t        j                  d      | _        t        j                  d      | _        y )Nr~   Pnor   A0C8r*   	r+   r,   r5   r6   r7   r   Pitchr:   r;   r{   s     r    r,   zPiano.__init__W  sL    $8$%&+#++d+ ;;t,r!   rn   ro   rp   rq   r,   rs   rt   s   @r    r~   r~   M  s    - -r!   r~   c                       e Zd Z fdZ xZS )Harpsichordc                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        t        j                  d      | _	        y )Nr   Hpschd   zkeyboard.harpsichordF1F6r*   
r+   r,   r5   r6   r7   r9   r   r   r:   r;   r{   s     r    r,   zHarpsichord.__init__c  sT    $8$+&.#5++d+ ;;t,r!   r|   rt   s   @r    r   r   b      	- 	-r!   r   c                       e Zd Z fdZ xZS )
Clavichordc                \    t        |   di | d| _        d| _        d| _        d| _        y )Nr   Clv   zkeyboard.clavichordr*   r+   r,   r5   r6   r7   r9   r{   s     r    r,   zClavichord.__init__p  s3    $8$*&+#4r!   r|   rt   s   @r    r   r   o  s    5 5r!   r   c                       e Zd Z fdZ xZS )Celestac                \    t        |   di | d| _        d| _        d| _        d| _        y )Nr   Clst   zkeyboard.celestar*   r   r{   s     r    r,   zCelesta.__init__}  s3    $8$'&,#1r!   r|   rt   s   @r    r   r   |  s    2 2r!   r   c                       e Zd Z fdZ xZS )Samplerc                N    t        |   di | d| _        d| _        d| _        y )Nr   Samp7   r*   r+   r,   r5   r6   r7   r{   s     r    r,   zSampler.__init__  s+    $8$'&,#r!   r|   rt   s   @r    r   r     s     r!   r   c                  "     e Zd ZdZ fdZ xZS )ElectricPianozw

    >>> p = instrument.ElectricPiano()
    >>> p.instrumentName
    'Electric Piano'
    >>> p.midiProgram
    2
    c                N    t        |   di | d| _        d| _        d| _        y )NzElectric PianozE.Pno   r*   r   r{   s     r    r,   zElectricPiano.__init__  s+    $8$.&-#r!   r   rt   s   @r    r   r     s     r!   r   c                       e Zd Z fdZ xZS )Organc                N    t        |   di | d| _        d| _        d| _        y )Nr      zkeyboard.organr*   )r+   r,   r5   r7   r9   r{   s     r    r,   zOrgan.__init__  s+    $8$%/r!   r|   rt   s   @r    r   r     s    0 0r!   r   c                       e Zd Z fdZ xZS )	PipeOrganc                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        t        j                  d      | _	        y )Nz
Pipe OrganzP Orgr   zkeyboard.organ.pipeC2C6r*   r   r{   s     r    r,   zPipeOrgan.__init__  sT    $8$*&-#4++d+ ;;t,r!   r|   rt   s   @r    r   r         - -r!   r   c                       e Zd Z fdZ xZS )ElectricOrganc                    t        |   di | d| _        d| _        d| _        t        j                  d      | _        t        j                  d      | _        y )NzElectric OrganzElec Orgrc   r   r   r*   r   r{   s     r    r,   zElectricOrgan.__init__  sL    $8$.&0#++d+ ;;t,r!   r|   rt   s   @r    r   r     r   r!   r   c                       e Zd Z fdZ xZS )	ReedOrganc                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        t        j                  d      | _	        y )Nz
Reed OrganzR Org   zkeyboard.organ.reedr   r   r*   r   r{   s     r    r,   zReedOrgan.__init__  sT    $8$*&-#4++d+ ;;t,r!   r|   rt   s   @r    r   r     r   r!   r   c                       e Zd Z fdZ xZS )	Accordionc                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        t        j                  d      | _	        y )Nr   Acc   zkeyboard.accordionF3A6r*   r   r{   s     r    r,   zAccordion.__init__  sT    $8$)&+#3++d+ ;;t,r!   r|   rt   s   @r    r   r     r   r!   r   c                       e Zd Z fdZ xZS )	Harmonicac                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        t        j                  d      | _	        y )Nr   Hmca   zwind.reed.harmonicaC3r   r*   r   r{   s     r    r,   zHarmonica.__init__  sT    $8$)&,#4++d+ ;;t,r!   r|   rt   s   @r    r   r     r   r!   r   c                  @     e Zd Z fdZd Zd Z eeed      Z xZS )StringInstrumentc                j    t        |   di | d | _        d | _        d| _        d| _        d| _        y )Nr   Str0   r*   )r+   r,   _stringPitches_cachedPitchesr5   r6   r7   r{   s     r    r,   zStringInstrument.__init__  s;    $8$""0&+#r!   c                    t        | d      r| j                  | j                  S t        | d      st        d      | j                  D cg c]  }t	        j
                  |       c}| _        | j                  S c c}w )Nr   r   z.cannot get stringPitches for these instruments)hasattrr   r	   r   r   r   )r?   xs     r    _getStringPitchesz"StringInstrument._getStringPitches  st    4)*t/B/B/N&&&/0%&VWW;?;N;N"O;Na5;;q>;N"OD&&& #Ps   
A:c                j    |r#t        |d   d      s|d   || _        || _        y d | _        || _        y )Nr   step)r   r   r   )r?   
newPitchess     r    _setStringPitchesz"StringInstrument._setStringPitches   s;    7:a=&9Z]=R",D",D"&D",Dr!   a  
            stringPitches is a property that stores a list of Pitches (or pitch names,
            such as "C4") that represent the pitch of the open strings from lowest to
            highest.[*]

            >>> vln1 = instrument.Violin()
            >>> [str(p) for p in vln1.stringPitches]
            ['G3', 'D4', 'A4', 'E5']

            instrument.stringPitches are full pitch objects, not just names:

            >>> [x.octave for x in vln1.stringPitches]
            [3, 4, 4, 5]

            Scordatura for Scelsi's violin concerto *Anahit*.
            (N.B. that string to pitch conversion is happening automatically)

            >>> vln1.stringPitches = ['G3', 'G4', 'B4', 'D4']

            (`[*]In some tuning methods such as reentrant tuning on the ukulele,
            lute, or five-string banjo the order might not strictly be from lowest to
            highest.  The same would hold true for certain violin scordatura pieces, such
            as some of Biber's *Mystery Sonatas*`)
            doc)	rn   ro   rp   r,   r   r   propertystringPitchesrs   rt   s   @r    r   r     s*    '- .0A H Mr!   r   c                       e Zd Z fdZ xZS )Violinc                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        g d| _	        y )Nr   Vln(   zstrings.violinG3r   D4A4E5r*   
r+   r,   r5   r6   r7   r9   r   r   r:   r   r{   s     r    r,   zViolin.__init__$  sK    $8$&&+#/++d+6r!   r|   rt   s   @r    r   r   #      	7 	7r!   r   c                       e Zd Z fdZ xZS )Violac                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        g d| _	        y )Nr   Vla)   zstrings.violar   r   r   r   r   r*   r   r{   s     r    r,   zViola.__init__1  sK    $8$%&+#.++d+6r!   r|   rt   s   @r    r   r   0  r   r!   r   c                       e Zd Z fdZ xZS )Violoncelloc                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        g d| _	        y )Nr   Vc*   zstrings.cellor   )r   G2D3A3r*   r   r{   s     r    r,   zVioloncello.__init__>  sK    $8$+&*#.++d+6r!   r|   rt   s   @r    r   r   =  r   r!   r   c                  "     e Zd ZdZ fdZ xZS )
Contrabassz
    For the Contrabass (or double bass), the stringPitches attribute refers to the sounding pitches
    of each string; whereas the lowestNote attribute refers to the lowest written note.
    c                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        g d| _	        t        j                  d      | _        y )	Nr   Cb+   zstrings.contrabassE2E1A1D2r   P-8r*   )r+   r,   r5   r6   r7   r9   r   r   r:   r   r
   Intervalr<   r{   s     r    r,   zContrabass.__init__P  s^    $8$*&*#3++d+6%..u5r!   r   rt   s   @r    r   r   J  s    

6 
6r!   r   c                       e Zd Z fdZ xZS )Harpc                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        t        j                  d      | _	        y )Nr   Hp.   z
pluck.harpC1zG#7r*   r   r{   s     r    r,   zHarp.__init__^  sT    $8$$&*#+++d+ ;;u-r!   r|   rt   s   @r    r   r   ]  s    	. 	.r!   r   c                       e Zd Z fdZ xZS )Guitarc                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        g d| _	        y )Nr  Gtr   zpluck.guitarr   )r   A2r   r   B3E4r*   r   r{   s     r    r,   zGuitar.__init__k  sK    $8$&&+#-++d+Br!   r|   rt   s   @r    r  r  j  s    	C 	Cr!   r  c                       e Zd Z fdZ xZS )AcousticGuitarc                \    t        |   di | d| _        d| _        d| _        d| _        y )NAcoustic GuitarzAc Gtrr  zpluck.guitar.acousticr*   r   r{   s     r    r,   zAcousticGuitar.__init__x  s3    $8$/&.#6r!   r|   rt   s   @r    r
  r
  w      7 7r!   r
  c                       e Zd Z fdZ xZS )ElectricGuitarc                \    t        |   di | d| _        d| _        d| _        d| _        y )NzElectric GuitarzElec Gtr   zpluck.guitar.electricr*   r   r{   s     r    r,   zElectricGuitar.__init__  s3    $8$/&0#6r!   r|   rt   s   @r    r  r    r  r!   r  c                       e Zd Z fdZ xZS )AcousticBassc                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        g d| _	        y )NzAcoustic BasszAc b    zpluck.bass.acousticr   r   r*   r   r{   s     r    r,   zAcousticBass.__init__  sK    $8$-&,#4++d+6r!   r|   rt   s   @r    r  r    r   r!   r  c                       e Zd Z fdZ xZS )ElectricBassc                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        g d| _	        y )NzElectric BasszElec b!   zpluck.bass.electricr   r   r*   r   r{   s     r    r,   zElectricBass.__init__  sK    $8$-&.#4++d+6r!   r|   rt   s   @r    r  r    r   r!   r  c                       e Zd Z fdZ xZS )FretlessBassc                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        g d| _	        y )NzFretless BasszFretl b#   zpluck.bass.fretlessr   r   r*   r   r{   s     r    r,   zFretlessBass.__init__  sK    $8$-&/#4++d+6r!   r|   rt   s   @r    r  r    r   r!   r  c                       e Zd Z fdZ xZS )Mandolinc                    t        |   di | d| _        d| _        d| _        t        j                  d      | _        g d| _        y )Nr  Mdlnzpluck.mandolinr   r   r*   	r+   r,   r5   r6   r9   r   r   r:   r   r{   s     r    r,   zMandolin.__init__  sC    $8$(&,#/++d+6r!   r|   rt   s   @r    r  r        7 7r!   r  c                       e Zd Z fdZ xZS )Ukulelec                    t        |   di | d| _        d| _        d| _        t        j                  d      | _        g d| _        y )Nr%  Ukezpluck.ukuleleC4)G4r(  r  r   r*   r"  r{   s     r    r,   zUkulele.__init__  sC    $8$'&+#.++d+6r!   r|   rt   s   @r    r%  r%    r#  r!   r%  c                       e Zd Z fdZ xZS )Banjoc                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        g d| _	        t        j                  d      | _        y )	Nr+  Bjozpluck.banjoi   r   r   r   r*   )r+   r,   r5   r6   r9   r7   r   r   r:   r   r
   r   r<   r{   s     r    r,   zBanjo.__init__  s^    $8$%&+#,++d+6%..u5r!   r|   rt   s   @r    r+  r+    s    
6 
6r!   r+  c                       e Zd Z fdZ xZS )Lutec                \    t        |   di | d| _        d| _        d| _        d| _        y )Nr0  Ltez
pluck.luter  r*   r+   r,   r5   r6   r9   r7   r{   s     r    r,   zLute.__init__  s3    $8$$&+#+r!   r|   rt   s   @r    r0  r0         r!   r0  c                       e Zd Z fdZ xZS )Sitarc                \    t        |   di | d| _        d| _        d| _        d| _        y )Nr6  Sitzpluck.sitarh   r*   r3  r{   s     r    r,   zSitar.__init__  s3    $8$%&+#,r!   r|   rt   s   @r    r6  r6         r!   r6  c                       e Zd Z fdZ xZS )Shamisenc                \    t        |   di | d| _        d| _        d| _        d| _        y )Nr<  Shmsnzpluck.shamisenj   r*   r3  r{   s     r    r,   zShamisen.__init__  s3    $8$(&-#/r!   r|   rt   s   @r    r<  r<    r:  r!   r<  c                       e Zd Z fdZ xZS )Kotoc                \    t        |   di | d| _        d| _        d| _        d| _        y )NrA  z
pluck.kotok   r*   r3  r{   s     r    r,   zKoto.__init__  s3    $8$$&,#+r!   r|   rt   s   @r    rA  rA    r:  r!   rA  c                       e Zd Z fdZ xZS )WoodwindInstrumentc                @    t        |   di | d| _        d| _        y )NWoodwindWwr*   r+   r,   r5   r6   r{   s     r    r,   zWoodwindInstrument.__init__  s#    $8$(&*#r!   r|   rt   s   @r    rE  rE    s    + +r!   rE  c                       e Zd Z fdZ xZS )Flutec                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        y )NrK  Flzwind.flutes.fluteI   r(  r*   	r+   r,   r5   r6   r9   r7   r   r   r:   r{   s     r    r,   zFlute.__init__  sC    $8$%&*#2++d+r!   r|   rt   s   @r    rK  rK  
      , ,r!   rK  c                       e Zd Z fdZ xZS )Piccoloc                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        t        j                  d      | _        y )NrR  Picczwind.flutes.piccoloH   r   P8r*   r+   r,   r5   r6   r9   r7   r   r   r:   r
   r   r<   r{   s     r    r,   zPiccolo.__init__  sV    $8$'&,#4++d+%..t4r!   r|   rt   s   @r    rR  rR    s    	5 	5r!   rR  c                       e Zd Z fdZ xZS )Recorderc                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        y )NrY  Reczwind.flutes.recorderJ   F4r*   rO  r{   s     r    r,   zRecorder.__init__$  sC    $8$(&+#5++d+r!   r|   rt   s   @r    rY  rY  #  rP  r!   rY  c                       e Zd Z fdZ xZS )PanFlutec                \    t        |   di | d| _        d| _        d| _        d| _        y )Nz	Pan FlutezP Flzwind.flutes.panpipesK   r*   r3  r{   s     r    r,   zPanFlute.__init__0  s3    $8$)&,#5r!   r|   rt   s   @r    r_  r_  /  r4  r!   r_  c                       e Zd Z fdZ xZS )
Shakuhachic                \    t        |   di | d| _        d| _        d| _        d| _        y )Nrc  zShk Flzwind.flutes.shakuhachiM   r*   r3  r{   s     r    r,   zShakuhachi.__init__:  s3    $8$*&.#7r!   r|   rt   s   @r    rc  rc  9  r4  r!   rc  c                       e Zd Z fdZ xZS )Whistlec                x    t        |   di | d| _        d| _        d| _        d| _        d| _        d| _        y )Nrg  Whszwind.flutes.whistleTG   N   r*   r+   r,   r5   r6   r9   r=   percMapPitchr7   r{   s     r    r,   zWhistle.__init__D  sC    $8$'&+#4r!   r|   rt   s   @r    rg  rg  C  s    	 	r!   rg  c                       e Zd Z fdZ xZS )Ocarinac                \    t        |   di | d| _        d| _        d| _        d| _        y )Nro  Oczwind.flutes.ocarinaO   r*   r3  r{   s     r    r,   zOcarina.__init__Q  s3    $8$'&*#4r!   r|   rt   s   @r    ro  ro  P  r4  r!   ro  c                       e Zd Z fdZ xZS )Oboec                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        y )Nrt  Obzwind.reed.oboeD   B-3r*   rO  r{   s     r    r,   zOboe.__init__[  sC    $8$$&*#/++e,r!   r|   rt   s   @r    rt  rt  Z  r   r!   rt  c                       e Zd Z fdZ xZS )EnglishHornc                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        t        j                  d      | _        y )NzEnglish HornzEng Hnzwind.reed.english-hornE   r  P-5r*   rW  r{   s     r    r,   zEnglishHorn.__init__g  sV    $8$,&.#7++d+%..u5r!   r|   rt   s   @r    rz  rz  f      	6 	6r!   rz  c                       e Zd Z fdZ xZS )Clarinetc                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        t        j                  d      | _        y )Nr  Clzwind.reed.clarinetrj  E3M-2r*   rW  r{   s     r    r,   zClarinet.__init__t  sV    $8$(&*#3++d+%..u5r!   r|   rt   s   @r    r  r  s  r~  r!   r  c                  "     e Zd ZdZ fdZ xZS )BassClarinetz
    >>> bcl = instrument.BassClarinet()
    >>> bcl.instrumentName
    'Bass clarinet'
    >>> bcl.midiProgram
    71
    >>> 'WoodwindInstrument' in bcl.classes
    True
    c                    t        |   di | d| _        d| _        d| _        t        j                  d      | _        t        j                  d      | _
        y )NzBass clarinetzBs Clzwind.reed.clarinet.basszE-3M-9r*   )r+   r,   r5   r6   r9   r   r   r:   r
   r   r<   r{   s     r    r,   zBassClarinet.__init__  sN    $8$-&-#8++e,%..u5r!   r   rt   s   @r    r  r    s    6 6r!   r  c                       e Zd Z fdZ xZS )Bassoonc                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        y )Nr  Bsnwind.reed.bassoonF   B-1r*   rO  r{   s     r    r,   zBassoon.__init__  sC    $8$'&+#2++e,r!   r|   rt   s   @r    r  r    r   r!   r  c                       e Zd Z fdZ xZS )Contrabassoonc                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        y )Nr  zC Bsnr  r  r  r*   rO  r{   s     r    r,   zContrabassoon.__init__  sC    $8$-&-#2++e,r!   r|   rt   s   @r    r  r    r   r!   r  c                       e Zd Z fdZ xZS )	Saxophonec                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        y )Nr  Saxzwind.reed.saxophoneA   rx  r*   rO  r{   s     r    r,   zSaxophone.__init__  sC    $8$)&+#4++e,r!   r|   rt   s   @r    r  r    r   r!   r  c                       e Zd Z fdZ xZS )SopranoSaxophonec                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        y )NzSoprano SaxophonezS Saxzwind.reed.saxophone.soprano@   r  r*   	r+   r,   r5   r6   r9   r7   r
   r   r<   r{   s     r    r,   zSopranoSaxophone.__init__  sF    $8$1&-#<%..u5r!   r|   rt   s   @r    r  r        6 6r!   r  c                       e Zd Z fdZ xZS )AltoSaxophonec                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        y )NzAlto SaxophonezA Saxzwind.reed.saxophone.altor  zM-6r*   r  r{   s     r    r,   zAltoSaxophone.__init__  sF    $8$.&-#9%..u5r!   r|   rt   s   @r    r  r    r  r!   r  c                       e Zd Z fdZ xZS )TenorSaxophonec                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        y )NzTenor SaxophonezT Saxzwind.reed.saxophone.tenorB   r  r*   r  r{   s     r    r,   zTenorSaxophone.__init__  sF    $8$/&-#:%..u5r!   r|   rt   s   @r    r  r    r  r!   r  c                       e Zd Z fdZ xZS )BaritoneSaxophonec                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        y )NzBaritone SaxophonezBar Saxzwind.reed.saxophone.baritoneC   zM-13r*   r  r{   s     r    r,   zBaritoneSaxophone.__init__  sF    $8$2&/#=%..v6r!   r|   rt   s   @r    r  r    r#  r!   r  c                       e Zd Z fdZ xZS )Bagpipesc                \    t        |   di | d| _        d| _        d| _        d| _        y )Nr  Bagzwind.pipes.bagpipesm   r*   r3  r{   s     r    r,   zBagpipes.__init__  s3    $8$(&+#4r!   r|   rt   s   @r    r  r    r:  r!   r  c                       e Zd Z fdZ xZS )Shehnaic                \    t        |   di | d| _        d| _        d| _        d| _        y )Nr  Shnzwind.reed.shenaio   r*   r3  r{   s     r    r,   zShehnai.__init__  s3    $8$'&+#1r!   r|   rt   s   @r    r  r         r!   r  c                       e Zd Z fdZ xZS )BrassInstrumentc                N    t        |   di | d| _        d| _        d| _        y )NBrassBrs=   r*   r   r{   s     r    r,   zBrassInstrument.__init__  s+    $8$%&+#r!   r|   rt   s   @r    r  r    s     r!   r  c                  "     e Zd ZdZ fdZ xZS )Hornz
    >>> hn = instrument.Horn()
    >>> hn.instrumentName
    'Horn'
    >>> hn.midiProgram
    60
    >>> 'BrassInstrument' in hn.classes
    True
    c                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        t        j                  d      | _        y )Nr  Hnzbrass.french-horn<   r   r}  r*   rW  r{   s     r    r,   zHorn.__init__  sV    $8$$&*#2++d+%..u5r!   r   rt   s   @r    r  r  
  s    	6 	6r!   r  c                       e Zd Z fdZ xZS )Trumpetc                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        t        j                  d      | _        y )Nr  Tptzbrass.trumpet8   zF#3r  r*   rW  r{   s     r    r,   zTrumpet.__init__"  sV    $8$'&+#.++e,%..u5r!   r|   rt   s   @r    r  r  !  r~  r!   r  c                       e Zd Z fdZ xZS )Trombonec                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        y )Nr  Trbzbrass.trombone9   r   r*   rO  r{   s     r    r,   zTrombone.__init__/  sC    $8$(&+#/++d+r!   r|   rt   s   @r    r  r  .  rP  r!   r  c                       e Zd Z fdZ xZS )BassTrombonec                    t        |   di | d| _        d| _        d| _        t        j                  d      | _        y )NzBass TromboneBTrbzbrass.trombone.bassr  r*   )r+   r,   r5   r6   r9   r   r   r:   r{   s     r    r,   zBassTrombone.__init__;  s;    $8$-&,#4++e,r!   r|   rt   s   @r    r  r  :  s    - -r!   r  c                       e Zd Z fdZ xZS )Tubac                    t        |   di | d| _        d| _        d| _        d| _        t        j                  d      | _        y )Nr  Tbaz
brass.tuba:   D1r*   rO  r{   s     r    r,   zTuba.__init__F  sC    $8$$&+#+++d+r!   r|   rt   s   @r    r  r  E  rP  r!   r  c                       e Zd Z fdZ xZS )
Percussionc                \    t        |   di | d| _        d | _        d| _        d| _        y )NFr  Percr*   )r+   r,   r=   rm  r5   r6   r{   s     r    r,   zPercussion.__init__T  s3    $8$  *&,#r!   r|   rt   s   @r    r  r  S      - -r!   r  c                      e Zd Zy)PitchedPercussionNrn   ro   rp   r*   r!   r    r  r  \      r!   r  c                  @     e Zd Z fdZd Zd Z eeed      Z xZS )r`   c                \    t        |   di | d | _        i | _        i | _        d| _        y )Nra   r*   )r+   r,   	_modifier_modifierToPercMapPitch_percMapPitchToModifierr8   r{   s     r    r,   zUnpitchedPercussion.__init__a  s2    $8$')$')$r!   c                    | j                   S rI   )r  rL   s    r    _getModifierz UnpitchedPercussion._getModifierh  s    ~~r!   c                H   |j                         j                         }| j                  du ro|j                         | j                  v rS| j                  |j                            | _        | j                  | j
                  v r| j
                  | j                     }|| _        y )NT)lowerstripr=   r  rm  r  r  )r?   modifiers     r    _setModifierz UnpitchedPercussion._setModifierk  s    >>#))+ t#(8D<X<X(X $ < <X^^=M ND   D$@$@@778I8IJ!r!   a  
    Returns or sets the modifier for this instrument.  A modifier could
    be something like "low-floor" for a TomTom or "rimshot" for a SnareDrum.

    If the modifier is in the object's ._modifierToPercMapPitch dictionary
    then changing the modifier also changes the .percMapPitch for the object


    >>> bd = instrument.BongoDrums()
    >>> bd.modifier
    'high'

    >>> bd.percMapPitch
    60
    >>> bd.modifier = 'low'
    >>> bd.percMapPitch
    61

    Variations on modifiers can also be used and they get normalized:

    >>> wb1 = instrument.Woodblock()
    >>> wb1.percMapPitch
    76
    >>> wb1.modifier = 'LO'
    >>> wb1.percMapPitch
    77
    >>> wb1.modifier  # n.b. -- not LO
    'low'
    r   )	rn   ro   rp   r,   r  r  r   r  rs   rt   s   @r    r`   r`   `  s'    " l 9 	Hr!   r`   c                       e Zd Z fdZ xZS )
Vibraphonec                \    t        |   di | d| _        d| _        d| _        d| _        y )Nr  Vbpzpitched-percussion.vibraphone   r*   r3  r{   s     r    r,   zVibraphone.__init__  s3    $8$*&+#>r!   r|   rt   s   @r    r  r    r4  r!   r  c                       e Zd Z fdZ xZS )Marimbac                \    t        |   di | d| _        d| _        d| _        d| _        y )Nr  Marzpitched-percussion.marimba   r*   r3  r{   s     r    r,   zMarimba.__init__  s3    $8$'&+#;r!   r|   rt   s   @r    r  r    r4  r!   r  c                       e Zd Z fdZ xZS )	Xylophonec                \    t        |   di | d| _        d| _        d| _        d| _        y )Nr  zXyl.zpitched-percussion.xylophone   r*   r3  r{   s     r    r,   zXylophone.__init__  s3    $8$)&,#=r!   r|   rt   s   @r    r  r    r4  r!   r  c                       e Zd Z fdZ xZS )Glockenspielc                \    t        |   di | d| _        d| _        d| _        d| _        y )Nr  Gspzpitched-percussion.glockenspielra   r*   r3  r{   s     r    r,   zGlockenspiel.__init__  s3    $8$,&+#@r!   r|   rt   s   @r    r  r    s     r!   r  c                       e Zd Z fdZ xZS )ChurchBellsc                \    t        |   di | d| _        d| _        d| _        d| _        y )NzChurch BellsBellszmetal.bells.church   r*   r3  r{   s     r    r,   zChurchBells.__init__  s3    $8$,&-#3r!   r|   rt   s   @r    r  r    r4  r!   r  c                       e Zd Z fdZ xZS )TubularBellsc                \    t        |   di | d| _        d| _        d| _        d| _        y )NzTubular BellsTbellsz pitched-percussion.tubular-bellsr  r*   r3  r{   s     r    r,   zTubularBells.__init__  s3    $8$-&.#Ar!   r|   rt   s   @r    r   r     r4  r!   r   c                       e Zd Z fdZ xZS )Gongc                N    t        |   di | d| _        d| _        d| _        y )Nr  Gngz
metal.gongr*   rz   r{   s     r    r,   zGong.__init__  s+    $8$$&+#+r!   r|   rt   s   @r    r  r        , ,r!   r  c                       e Zd Z fdZ xZS )	Handbellsc                N    t        |   di | d| _        d| _        d| _        y )Nr	  Hbellszpitched-percussion.handbellsr*   rz   r{   s     r    r,   zHandbells.__init__  s+    $8$)&.#=r!   r|   rt   s   @r    r	  r	    s    > >r!   r	  c                       e Zd Z fdZ xZS )Dulcimerc                \    t        |   di | d| _        d| _        d| _        d| _        y )Nr  Dlczpluck.dulcimer   r*   r3  r{   s     r    r,   zDulcimer.__init__  s3    $8$(&+#/r!   r|   rt   s   @r    r  r    r4  r!   r  c                       e Zd Z fdZ xZS )	SteelDrumc                \    t        |   di | d| _        d| _        d| _        d| _        y )Nz
Steel DrumzSt Drzmetal.steel-drumsr   r*   r3  r{   s     r    r,   zSteelDrum.__init__  s3    $8$*&-#2r!   r|   rt   s   @r    r  r    r:  r!   r  c                       e Zd Z fdZ xZS )Timpanic                \    t        |   di | d| _        d| _        d| _        d| _        y )Nr  Timpzdrum.timpani/   r*   r3  r{   s     r    r,   zTimpani.__init__  s3    $8$'&,#-r!   r|   rt   s   @r    r  r    r4  r!   r  c                       e Zd Z fdZ xZS )Kalimbac                \    t        |   di | d| _        d| _        d| _        d| _        y )Nr  Kalzpitched-percussion.kalimbal   r*   r3  r{   s     r    r,   zKalimba.__init__  s3    $8$'&+#;r!   r|   rt   s   @r    r  r    r:  r!   r  c                       e Zd Z fdZ xZS )	Woodblockc                    t        |   di | d| _        d| _        d| _        d| _        d| _        d| _        ddddd	| _        dd
d| _	        | j                  | j                     | _
        y )Nr   zWd Blzwood.wood-blockTs   highL   re  )r#  lowhilor%  )r$  re  r*   )r+   r,   r5   r6   r9   r=   r7   r  r  r  rm  r{   s     r    r,   zWoodblock.__init__  sw    $8$)&-#0022Rr'R$,2'>$ 88Hr!   r|   rt   s   @r    r   r         I Ir!   r   c                       e Zd Z fdZ xZS )TempleBlockc                N    t        |   di | d| _        d| _        d| _        y )NzTemple BlockzTemp Blzwood.temple-blockr*   rz   r{   s     r    r,   zTempleBlock.__init__  s+    $8$,&/#2r!   r|   rt   s   @r    r*  r*        3 3r!   r*  c                       e Zd Z fdZ xZS )	Castanetsc                N    t        |   di | d| _        d| _        d| _        y )Nr.  Caszwood.castanetsr*   rz   r{   s     r    r,   zCastanets.__init__'  s+    $8$)&+#/r!   r|   rt   s   @r    r.  r.  &      0 0r!   r.  c                       e Zd Z fdZ xZS )Maracasc                j    t        |   di | d| _        d| _        d| _        d| _        d| _        y )Nr3  Tr  Mrcszrattle.maracar*   )r+   r,   r5   r=   rm  r6   r9   r{   s     r    r,   zMaracas.__init__0  s;    $8$'&,#.r!   r|   rt   s   @r    r3  r3  /  s    / /r!   r3  c                       e Zd Z fdZ xZS )	Vibraslapc                j    t        |   di | d| _        d| _        d| _        d| _        d| _        y )Nr7  Vbslpzrattle.vibraslapTr  r*   r+   r,   r5   r6   r9   r=   rm  r{   s     r    r,   zVibraslap.__init__;  s;    $8$)&-#1r!   r|   rt   s   @r    r7  r7  :  r  r!   r7  c                       e Zd Z fdZ xZS )Cymbalsc                @    t        |   di | d| _        d| _        y )Nr<  Cymr*   rI  r{   s     r    r,   zCymbals.__init__I  s#    $8$'&+#r!   r|   rt   s   @r    r<  r<  H  s    , ,r!   r<  c                       e Zd Z fdZ xZS )FingerCymbalsc                N    t        |   di | d| _        d| _        d| _        y )NzFinger CymbalszFing Cymzmetal.cymbal.fingerr*   rz   r{   s     r    r,   zFingerCymbals.__init__P  s+    $8$.&0#4r!   r|   rt   s   @r    r@  r@  O      5 5r!   r@  c                       e Zd Z fdZ xZS )CrashCymbalsc                    t        |   di | d| _        d| _        d| _        d| _        d| _        ddd| _        dd	d
| _        | j                  | j                     | _	        y )NzCrash Cymbalsr>  zmetal.cymbal.crashT11   r  )rF  2rH  )rG  r  r*   
r+   r,   r5   r6   r9   r=   r  r  r  rm  r{   s     r    r,   zCrashCymbals.__init__Y  su    $8$-&+#3-/-/(*$ -0,/(*$ !88Hr!   r|   rt   s   @r    rD  rD  X      I Ir!   rD  c                       e Zd Z fdZ xZS )SuspendedCymbalc                N    t        |   di | d| _        d| _        d| _        y )NzSuspended CymbalzSus Cymzmetal.cymbal.suspendedr*   rz   r{   s     r    r,   zSuspendedCymbal.__init__l  s+    $8$0&/#7r!   r|   rt   s   @r    rL  rL  k  s    8 8r!   rL  c                       e Zd Z fdZ xZS )SizzleCymbalc                N    t        |   di | d| _        d| _        d| _        y )NzSizzle CymbalzSiz Cymzmetal.cymbal.sizzler*   rz   r{   s     r    r,   zSizzleCymbal.__init__u  s+    $8$-&/#4r!   r|   rt   s   @r    rO  rO  t  rB  r!   rO  c                       e Zd Z fdZ xZS )SplashCymbalsc                N    t        |   di | d| _        d| _        d| _        y )NzSplash CymbalszSpl Cymzmetal.cymbal.splashr*   rz   r{   s     r    r,   zSplashCymbals.__init__~  s+    $8$.&/#4r!   r|   rt   s   @r    rR  rR  }  rB  r!   rR  c                       e Zd Z fdZ xZS )RideCymbalsc                N    t        |   di | d| _        d| _        d| _        y )NzRide CymbalszRide Cymzmetal.cymbal.rider*   rz   r{   s     r    r,   zRideCymbals.__init__  s+    $8$,&0#2r!   r|   rt   s   @r    rU  rU    r,  r!   rU  c                       e Zd Z fdZ xZS )HiHatCymbalc                    t        |   di | d| _        d| _        d| _        d| _        dddd| _        dd	d
d| _        | j                  | j
                     | _        d| _	        y )NzHi-Hat Cymbalzmetal.hi-hatTpedal,   r   r   )rZ  openclosedr\  r]  )r[  r   r   zHi-Hatr*   )
r+   r,   r5   r9   r=   r  r  r  rm  r6   r{   s     r    r,   zHiHatCymbal.__init__  s{    $8$-- 130224(*$ -4,2,4(*$ !88H&.#r!   r|   rt   s   @r    rX  rX    s    / /r!   rX  c                       e Zd Z fdZ xZS )Trianglec                    t        |   di | d| _        d| _        d| _        d| _        d| _        ddd| _        d	dd
| _        | j                  | j                     | _	        y )Nr_  Trizmetal.triangleTr\  Q   P   )r\  muterd  )rc  rb  r*   rI  r{   s     r    r,   zTriangle.__init__  su    $8$(&+#/0202(*$ -3,2(*$ !88Hr!   r|   rt   s   @r    r_  r_    rJ  r!   r_  c                       e Zd Z fdZ xZS )Cowbellc                j    t        |   di | d| _        d| _        d| _        d| _        d| _        y )Nrf  Cwbzmetal.bells.cowbellTr  r*   r:  r{   s     r    r,   zCowbell.__init__  s;    $8$'&+#4r!   r|   rt   s   @r    rf  rf    r  r!   rf  c                       e Zd Z fdZ xZS )Agogoc                x    t        |   di | d| _        d| _        d| _        d| _        d| _        d| _        y )Nrj  Agozmetal.bells.agogoTr  q   r*   rl  r{   s     r    r,   zAgogo.__init__  sC    $8$%&+#2r!   r|   rt   s   @r    rj  rj    s     r!   rj  c                       e Zd Z fdZ xZS )TamTamc                N    t        |   di | d| _        d| _        d| _        y )NzTam-TamzTam-tzmetal.tamtamr*   rz   r{   s     r    r,   zTamTam.__init__  s+    $8$'&-#-r!   r|   rt   s   @r    ro  ro        . .r!   ro  c                       e Zd Z fdZ xZS )SleighBellsc                N    t        |   di | d| _        d| _        d| _        y )NzSleigh BellszSlgh Blzmetal.bells.sleigh-bellsr*   rz   r{   s     r    r,   zSleighBells.__init__  s+    $8$,&/#9r!   r|   rt   s   @r    rs  rs    s    : :r!   rs  c                       e Zd Z fdZ xZS )	SnareDrumc                    t        |   di | d| _        d| _        d| _        d| _        d| _        dddd	| _        dd
dd| _        | j                  | j                     | _	        y )Nz
Snare DrumzSn Drzdrum.snare-drumTacoustic&   %   r   )rx  sideelectricr{  r|  )ry  rz  r   r*   rI  r{   s     r    r,   zSnareDrum.__init__  s{    $8$*&-#0#460246(*$ -7,2,6(*$ !88Hr!   r|   rt   s   @r    rv  rv    s    I Ir!   rv  c                       e Zd Z fdZ xZS )	TenorDrumc                N    t        |   di | d| _        d| _        d| _        y )Nz
Tenor DrumzTen Drzdrum.tenor-drumr*   rz   r{   s     r    r,   zTenorDrum.__init__  s+    $8$*&.#0r!   r|   rt   s   @r    r~  r~        1 1r!   r~  c                       e Zd Z fdZ xZS )
BongoDrumsc                    t        |   di | d| _        d| _        d| _        d| _        d| _        ddd| _        dd	d
| _        | j                  | j                     | _	        y )NzBongo DrumszBgo Drz
drum.bongoTr#  r  r  r#  r%  r%  )r  r  r*   rI  r{   s     r    r,   zBongoDrums.__init__   sk    $8$+&.#+022'>$,2'>$ 88Hr!   r|   rt   s   @r    r  r    s    I Ir!   r  c                       e Zd Z fdZ xZS )TomTomc                    t        |   di | d| _        d| _        d| _        d| _        d| _        dddd	d
dd| _        ddddddd| _        | j                  | j                     | _	        y )NzTom-TomTomzdrum.tom-tomT	low floorr   r   -   r  r   2   )r  
high floorr%  low-midhigh-midr#  r  r%  r  r  r#  )r   r   r  r  r   r  r*   rI  r{   s     r    r,   zTomTom.__init__  s    $8$'&+#-$57rRT352r(S$,7\u,5:6(S$ 88Hr!   r|   rt   s   @r    r  r    r(  r!   r  c                       e Zd Z fdZ xZS )Timbalesc                    t        |   di | d| _        d| _        d| _        d| _        d| _        ddd| _        dd	d
| _        | j                  | j                     | _	        y )Nr  Timzdrum.timbaleTr#  r  r  r  r%  )r  r  r*   rI  r{   s     r    r,   zTimbales.__init__  sk    $8$(&+#-022'>$,2'>$ 88Hr!   r|   rt   s   @r    r  r        
I 
Ir!   r  c                       e Zd Z fdZ xZS )	CongaDrumc                    t        |   di | d| _        d| _        d| _        d| _        d| _        dddd	| _        dd
dd| _        | j                  | j                     | _	        y )Nz
Conga DrumzCga Drz
drum.congaTr%  r  >   ?   )r%  	mute high	open highr  r  )r  r  r  r*   rI  r{   s     r    r,   zCongaDrum.__init__-  sp    $8$*&.#+/1QS'T$,1{'T$ 88Hr!   r|   rt   s   @r    r  r  ,  r  r!   r  c                       e Zd Z fdZ xZS )BassDrumc                    t        |   di | d| _        d| _        d| _        d| _        d| _        ddd| _        dd	d
| _        | j                  | j                     | _	        y )Nz	Bass DrumzB Drzdrum.bass-drumTrx  r  $   )rx  rF  rF  )r  r  r*   rI  r{   s     r    r,   zBassDrum.__init__;  sk    $8$)&,#/#46R'@$,6C'@$ 88Hr!   r|   rt   s   @r    r  r  :  r  r!   r  c                       e Zd Z fdZ xZS )Taikoc                \    t        |   di | d| _        d| _        d| _        d| _        y )Nr  Tkoz
drum.taikot   r*   r3  r{   s     r    r,   zTaiko.__init__I  s3    $8$%&+#+r!   r|   rt   s   @r    r  r  H  r:  r!   r  c                       e Zd Z fdZ xZS )
Tambourinec                j    t        |   di | d| _        d| _        d| _        d| _        d| _        y )Nr  Tmbnzdrum.tambourineT6   r*   r:  r{   s     r    r,   zTambourine.__init__S  s;    $8$*&,#0r!   r|   rt   s   @r    r  r  R  r  r!   r  c                       e Zd Z fdZ xZS )Whipc                N    t        |   di | d| _        d| _        d| _        y )Nr  zeffect.whipr*   rz   r{   s     r    r,   zWhip.__init__^  s+    $8$$&,#,r!   r|   rt   s   @r    r  r  ]  r  r!   r  c                       e Zd Z fdZ xZS )Ratchetc                N    t        |   di | d| _        d| _        d| _        y )Nr  Ratczrattle.ratchetr*   rz   r{   s     r    r,   zRatchet.__init__g  s+    $8$'&,#/r!   r|   rt   s   @r    r  r  f  r1  r!   r  c                       e Zd Z fdZ xZS )Sirenc                N    t        |   di | d| _        d| _        d| _        y )Nr  zeffect.sirenr*   rz   r{   s     r    r,   zSiren.__init__p  s+    $8$%&-#-r!   r|   rt   s   @r    r  r  o  rq  r!   r  c                       e Zd Z fdZ xZS )SandpaperBlocksc                N    t        |   di | d| _        d| _        d| _        y )NzSandpaper BlockszSand Blzwood.sand-blockr*   rz   r{   s     r    r,   zSandpaperBlocks.__init__y  s+    $8$0&/#0r!   r|   rt   s   @r    r  r  x  r  r!   r  c                       e Zd Z fdZ xZS )WindMachinec                N    t        |   di | d| _        d| _        d| _        y )NzWind Machinez	Wind Machzeffect.windr*   rz   r{   s     r    r,   zWindMachine.__init__  s+    $8$,&1#,r!   r|   rt   s   @r    r  r    r  r!   r  c                  "     e Zd ZdZ fdZ xZS )VocalistzC
    n.b. called Vocalist to not be confused with stream.Voice
    c                N    t        |   di | d| _        d| _        d| _        y )NVoiceV5   r*   r   r{   s     r    r,   zVocalist.__init__  s+    $8$%&)#r!   r   rt   s   @r    r  r    s     r!   r  c                       e Zd Z fdZ xZS )Sopranoc                N    t        |   di | d| _        d| _        d| _        y )Nr  Szvoice.sopranor*   rz   r{   s     r    r,   zSoprano.__init__  s+    $8$'&)#.r!   r|   rt   s   @r    r  r    s    / /r!   r  c                       e Zd Z fdZ xZS )MezzoSopranoc                N    t        |   di | d| _        d| _        d| _        y )NzMezzo-SopranoMezzvoice.mezzo-sopranor*   rz   r{   s     r    r,   zMezzoSoprano.__init__  s+    $8$-&+#4r!   r|   rt   s   @r    r  r    rB  r!   r  c                       e Zd Z fdZ xZS )Altoc                N    t        |   di | d| _        d| _        d| _        y )Nr  Az
voice.altor*   rz   r{   s     r    r,   zAlto.__init__  +    $8$$&)#+r!   r|   rt   s   @r    r  r    r  r!   r  c                       e Zd Z fdZ xZS )Tenorc                N    t        |   di | d| _        d| _        d| _        y )Nr  Tzvoice.tenorr*   rz   r{   s     r    r,   zTenor.__init__  s+    $8$%&)#,r!   r|   rt   s   @r    r  r    r  r!   r  c                       e Zd Z fdZ xZS )Baritonec                N    t        |   di | d| _        d| _        d| _        y )Nr  Barzvoice.baritoner*   rz   r{   s     r    r,   zBaritone.__init__  s+    $8$(&+#/r!   r|   rt   s   @r    r  r    r1  r!   r  c                       e Zd Z fdZ xZS )Bassc                N    t        |   di | d| _        d| _        d| _        y )Nr  Bz
voice.bassr*   rz   r{   s     r    r,   zBass.__init__  r  r!   r|   rt   s   @r    r  r    r  r!   r  c                       e Zd Z fdZ xZS )Choirc                \    t        |   di | d| _        d| _        d| _        d| _        y )Nr  Chzvoice.choir4   r*   r3  r{   s     r    r,   zChoir.__init__  s3    $8$%&*#,r!   r|   rt   s   @r    r  r    r4  r!   r  c                  "     e Zd ZdZ fdZ xZS )	Conductorzt
    Presently used only for tracking the MIDI track containing tempo,
    key signature, and related metadata.
    c                (    t        |   dddi| y )Nr5   r  r*   )r+   r,   r{   s     r    r,   zConductor.__init__  s    @@x@r!   r   rt   s   @r    r  r    s    
A Ar!   r  )ezno performerssoloduettrioquartetquintetsextetseptetoctetnonetdectetundectet	duodectet	tredectetquattuordectet
quindectet	sexdectetseptendectet
octodectetnovemdectetvigetet	unvigetet
duovigetet
trevigetetquattuorvigetetquinvigetet
sexvigetetseptenvigetetoctovigetetnovemvigetettrigetet
untrigetetduotrigetettretrigetetquottuortrigetetquintrigetetsextrigetetseptentrigetetoctotrigetetnovemtrigetetquadragetetunquadragetetduoquadragetettrequadragetetquattuorquadragetetquinquadragetetsexquadragetetoctoquadragetetr  novemquadragetetquinquagetetunquinquagetetduoquinquagetettrequinguagetetquattuorquinquagetetquinquinquagetetsexquinquagetetseptenquinquagetetoctoquinquagetetnovemquinquagetet	sexagetetundexagetetduosexagetettresexagetetquoattuorsexagetetquinsexagetetsexsexagetetseptensexagetetoctosexagetetnovemsexagetetseptuagetetunseptuagetetduoseptuagetettreseptuagetetquattuorseptuagetetquinseptuagetetsexseptuagetetseptenseptuagetetoctoseptuagetetnovemseptuagetet	octogetetunoctogetetduooctogetettreoctogetetquattuoroctogetetquinoctogetetsexoctogetetseptoctogetetoctooctogetetnovemoctogetet	nonagetetunnonagetetduononagetettrenonagetetquattuornonagetetquinnonagetetsexnonagetetseptennonagetetoctononagetetnovemnonagetetcentetc                R    | dkD  ry| dk  rt        d      t        t        |          S )z
    return the name of a generic ensemble with "number" players:

    >>> instrument.ensembleNameBySize(4)
    'quartet'
    >>> instrument.ensembleNameBySize(1)
    'solo'
    >>> instrument.ensembleNameBySize(83)
    'treoctogetet'
    d   zlarge ensembler   z,okay, you are on your own for this one buddy)r	   ensembleNamesBySizeint)numbers    r    ensembleNameBySizerH    s0     |	!!"PQQ"3v;//r!   c                t   ddl m} |r| }n| j                  d      }|j                         s|g}n|j	                  |j
                        }|D ]W  }t        |t           j                               }|D ].  }t        |      dk(  r|D ch c]  }|j                  |j                   }	}|D ch c]  }|j                  |j                   }
}t        |	      dkD  st        |
      dkD  r|d}|	D ]  }|} d}|
D ]  }|} |D ch c]  }|j                   }}t        |      dk(  r:d}|D ]  }||_	        ||_
        |} n |D ]  }||u r|j                  |d        |D ]7  }|j                  t        k(  r|j                  |d       *||_	        ||_
        9 1 Z |S c c}w c c}w c c}w )a  
    Check every offset in `s` for multiple instrument instances.
    If the `.partName` can be standardized across instances,
    i.e. if each instance has the same value or `None`,
    and likewise for `.instrumentName`, standardize the attributes.
    Further, and only if the above conditions are met,
    if there are two instances of the same class, remove all but one;
    if at least one generic `Instrument` instance is found at the same
    offset as one or more specific instruments, remove the generic `Instrument` instances.

    Two `Instrument` instances:

    >>> i1 = instrument.Instrument(instrumentName='Semi-Hollow Body')
    >>> i2 = instrument.Instrument()
    >>> i2.partName = 'Electric Guitar'
    >>> s1 = stream.Stream()
    >>> s1.insert(4, i1)
    >>> s1.insert(4, i2)
    >>> list(s1.getInstruments())
    [<music21.instrument.Instrument 'Semi-Hollow Body'>,
        <music21.instrument.Instrument 'Electric Guitar: '>]
    >>> post = instrument.deduplicate(s1)
    >>> list(post.getInstruments())
    [<music21.instrument.Instrument 'Electric Guitar: Semi-Hollow Body'>]

    One `Instrument` instance and one subclass instance, with `inPlace` and parts:

    >>> from music21.stream import Score, Part
    >>> i3 = instrument.Instrument()
    >>> i3.partName = 'Piccolo'
    >>> i4 = instrument.Piccolo()
    >>> s2 = stream.Score()
    >>> p1 = stream.Part()
    >>> p1.append([i3, i4])
    >>> p2 = stream.Part()
    >>> p2.append([instrument.Flute(), instrument.Flute()])
    >>> s2.insert(0, p1)
    >>> s2.insert(0, p2)
    >>> list(p1.getInstruments())
    [<music21.instrument.Instrument 'Piccolo: '>, <music21.instrument.Piccolo 'Piccolo'>]
    >>> list(p2.getInstruments())
    [<music21.instrument.Flute 'Flute'>, <music21.instrument.Flute 'Flute'>]
    >>> s2 = instrument.deduplicate(s2, inPlace=True)
    >>> list(p1.getInstruments())
    [<music21.instrument.Piccolo 'Piccolo'>]
    >>> list(p2.getInstruments())
    [<music21.instrument.Flute 'Flute'>]
    r   r   zinstrument.deduplicaterb   NT)recurse)music21r   r   hasPartLikeStreamsgetElementsByClassStreamr   r$   re   r/   r5   rA   r&   )r   r   r   	returnObj
substreamssuboTreeor   notNonePartNamesnotNoneInstNamesr/   pNamer5   iNameinstr%   	survivings                     r    deduplicaterZ    s   b 	**+CD	'')/8k
11&--@
3z?1134A1v{45PAq9O

AP:;\!Qq?O?O?[ 0 0!\ #$q(C0@,AA,EH)  *!N)!& * 344!$t~~!G47|q  	D$,DM*8D' $I	  Dy( JJtTJ2  D~~3

4
6(0.<+ G  X O  Q\ 5s   F+F+1F0F0
F5rb   r            r   r   r   ra   
   r  r  r  r  r  rc         r   r   r   r      r     r                 r  r  "   r  r  rz  ry  '   r   r   r   r   r[  r  r   r  r   rG  r  3   r  r  r  r   r  r  r  ;   r  r  r  r  r  r  r  r  rw  r|  r  rj  rU  rN  r\  ra  r$  re  rk  rr  rc  rb  R   S   T   U   V   W   X   Y   Z   [   \   ]   ^   _   `   a   b   c   rD  e   f   g   r9  r.  r?  rC  r  r  n   r  p   rm  r  r"  r  u   v   )	w   x   y   z   {   |   }   ~      c                    	 t         |    } |       }| |_        |S # t        $ r<}t        | t              st        dt        |              |t        d|        |d}~ww xY w)a  
    Return the instrument with "number" as its assigned MIDI program.
    Notice any of the values 0-5 will return Piano.

    Lookups are performed against `instrument.MIDI_PROGRAM_TO_INSTRUMENT`.

    >>> instrument.instrumentFromMidiProgram(4)
    <music21.instrument.ElectricPiano 'Electric Piano'>
    >>> instrument.instrumentFromMidiProgram(21)
    <music21.instrument.Accordion 'Accordion'>
    >>> instrument.instrumentFromMidiProgram(500)
    Traceback (most recent call last):
    music21.exceptions21.InstrumentException: No instrument found for MIDI program 500
    >>> instrument.instrumentFromMidiProgram('43')
    Traceback (most recent call last):
    TypeError: Expected int, got <class 'str'>
    zExpected int, got z%No instrument found for MIDI program N)MIDI_PROGRAM_TO_INSTRUMENTr7   KeyErrorr   rF  	TypeErrortyper	   )rG  class_rX  es       r    instrumentFromMidiProgramr    su    &	[+F3x! K	  [&#&0f?@aG!$I&"RSYZZ[s    	A 7AA c           	     F   ddl m} | j                         s2 |j                         }|j	                  d| j                                nQ |j                         }| j                  |j                        D ]"  }|j	                  d|j                                $ |j                  |j                        D ]  }|j                  dd        |t           }|s|S t               }|D ]&  }|j                  |vsd|i||j                  xs d<   (  |j                         }|D ]L  } |j                         }	||	_        |	j	                  d||   d          |	||   d<   |j	                  d|	       N |D ]  }
|
j                  s|j	                  |
j                  |
       |
}|j                  t              D ]  }|j                  }|j                  |j                   j"                  z   }||j                  xs d   d   }	|j%                  ||ddd	      }|j'                  t              D ]$  }	 |	j	                  |j)                  |      |       &   |j-                         j                  t              D ]  }d|j                   _         |S # |j*                  $ r Y ww xY w)
a  
    Given a single Stream, or a Score or similar multi-part structure,
    partition into a Part for each unique Instrument, joining events
    possibly from different parts.

    >>> p1 = converter.parse("tinynotation: 4/4 c4  d  e  f  g  a  b  c'  c1")
    >>> p2 = converter.parse("tinynotation: 4/4 C#4 D# E# F# G# A# B# c#  C#1")

    >>> p1.getElementsByClass(stream.Measure)[0].insert(0.0, instrument.Piccolo())
    >>> p1.getElementsByClass(stream.Measure)[0].insert(2.0, instrument.AltoSaxophone())
    >>> p1.getElementsByClass(stream.Measure)[1].insert(3.0, instrument.Piccolo())

    >>> p2.getElementsByClass(stream.Measure)[0].insert(0.0, instrument.Trombone())
    >>> p2.getElementsByClass(stream.Measure)[0].insert(3.0, instrument.Piccolo())  # not likely
    >>> p2.getElementsByClass(stream.Measure)[1].insert(1.0, instrument.Trombone())

    >>> s = stream.Score()
    >>> s.insert(0, p1)
    >>> s.insert(0, p2)
    >>> s.show('text')
    {0.0} <music21.stream.Part ...>
        {0.0} <music21.stream.Measure 1 offset=0.0>
            {0.0} <music21.instrument.Piccolo 'Piccolo'>
            {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.instrument.AltoSaxophone 'Alto Saxophone'>
            {2.0} <music21.note.Note E>
            {3.0} <music21.note.Note F>
        {4.0} <music21.stream.Measure 2 offset=4.0>
            {0.0} <music21.note.Note G>
            {1.0} <music21.note.Note A>
            {2.0} <music21.note.Note B>
            {3.0} <music21.instrument.Piccolo 'Piccolo'>
            {3.0} <music21.note.Note C>
        {8.0} <music21.stream.Measure 3 offset=8.0>
            {0.0} <music21.note.Note C>
            {4.0} <music21.bar.Barline type=final>
    {0.0} <music21.stream.Part ...>
        {0.0} <music21.stream.Measure 1 offset=0.0>
            {0.0} <music21.instrument.Trombone 'Trombone'>
            {0.0} <music21.clef.BassClef>
            {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.instrument.Piccolo 'Piccolo'>
            {3.0} <music21.note.Note F#>
        {4.0} <music21.stream.Measure 2 offset=4.0>
            {0.0} <music21.note.Note G#>
            {1.0} <music21.instrument.Trombone 'Trombone'>
            {1.0} <music21.note.Note A#>
            {2.0} <music21.note.Note B#>
            {3.0} <music21.note.Note C#>
        {8.0} <music21.stream.Measure 3 offset=8.0>
            {0.0} <music21.note.Note C#>
            {4.0} <music21.bar.Barline type=final>

    >>> s2 = instrument.partitionByInstrument(s)
    >>> len(s2.parts)
    3

    # TODO: this step might not be necessary:

    >>> for p in s2.parts:
    ...     p.makeRests(fillGaps=True, inPlace=True)

    # TODO: this step SHOULD not be necessary (.template()):

    >>> for p in s2.parts:
    ...     p.makeMeasures(inPlace=True)
    ...     p.makeTies(inPlace=True)

    >>> s2.show('text')
    {0.0} <music21.stream.Part Piccolo>
        {0.0} <music21.stream.Measure 1 offset=0.0>
            {0.0} <music21.instrument.Piccolo 'Piccolo'>
            {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.Rest quarter>
            {3.0} <music21.note.Note F#>
        {4.0} <music21.stream.Measure 2 offset=4.0>
            {0.0} <music21.note.Note G#>
            {1.0} <music21.note.Rest half>
            {3.0} <music21.note.Note C>
        {8.0} <music21.stream.Measure 3 offset=8.0>
            {0.0} <music21.note.Note C>
            {4.0} <music21.bar.Barline type=final>
    {0.0} <music21.stream.Part Alto Saxophone>
        {0.0} <music21.stream.Measure 1 offset=0.0>
            {0.0} <music21.instrument.AltoSaxophone 'Alto Saxophone'>
            {0.0} <music21.clef.TrebleClef>
            {0.0} <music21.meter.TimeSignature 4/4>
            {0.0} <music21.note.Rest half>
            {2.0} <music21.note.Note E>
            {3.0} <music21.note.Note F>
        {4.0} <music21.stream.Measure 2 offset=4.0>
            {0.0} <music21.note.Note G>
            {1.0} <music21.note.Note A>
            {2.0} <music21.note.Note B>
            {3.0} <music21.bar.Barline type=final>
    {0.0} <music21.stream.Part Trombone>
        {0.0} <music21.stream.Measure 1 offset=0.0>
            {0.0} <music21.instrument.Trombone 'Trombone'>
            {0.0} <music21.clef.BassClef>
            {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.Rest quarter>
        {4.0} <music21.stream.Measure 2 offset=4.0>
            {0.0} <music21.note.Rest quarter>
            {1.0} <music21.note.Note A#>
            {2.0} <music21.note.Note B#>
            {3.0} <music21.note.Note C#>
        {8.0} <music21.stream.Measure 3 offset=8.0>
            {0.0} <music21.note.Note C#>
            {4.0} <music21.bar.Barline type=final>

    * Changed in v8: returns the original stream if there are no instruments.

    TODO: parts should be in Score Order. Coincidence that this almost works.
    TODO: use proper recursion to make a copy of the stream.
    TODO: final barlines should be aligned.
    r   r   r$   Tr   rC   PartF)includeEndBoundarymustFinishInSpanmustBeginInSpan)rK  r   rL  Scorer   flattenrM  rN  extendDurationr$   r   r5   r  idisStreamr   durationquarterLengthgetElementsByOffsetgetElementsNotOfClasselementOffsetStreamExceptionrJ  )	streamObjr   r   rQ  instrumentIteratornamesinstrumentObjpostrW  pel	subStreamr   startendcollr  rX  s                     r    partitionByInstrumentr  1  sh   D '')FLLN	I%%'(FLLN//>CHHQ& ? ##FMM2<6 3 :0;E+''u49E}8UE-..4"5 , 6<<>DFKKM	E%L./ eVAq  {{KK		2&	--j9AHHE((QZZ555Ca&&,"-f5A00#(!& $ 1 D //
;HHY44Q7; <# : > 11*=&'# >K -- s   ,!JJ 	J 	c           
         | j                         }g }t        dt        |      dz         D ]G  }t        t        |      |z
  dz         D ](  }|j                  dj	                  ||||z                 * I |S )zM
    find all combinations of instrumentString.  Remove all punctuation.
    rb    )splitrf   re   rD   rE   )instrumentString
sampleListallCombsizer   s        r    _combinationsr    su     "'')JGaZ1,-s:-12ANN388JqT$:;< 3 . Nr!   c                  ,    e Zd ZdZdZdZdZdZdZdZ	dZ
y	)
SearchLanguageallenglishfrenchgermanitalianrussianspanishabbreviationN)rn   ro   rp   ALLENGLISHFRENCHGERMANITALIANRUSSIANSPANISHABBREVIATIONr*   r!   r    r  r  	  s*    
CGFFGGG!Lr!   r  c                   ddl m} |j                         }|t        vrt	        d| d      t        ||dz         }| }| j                  dd      } | j                         } t        j                  |       } t        |       }d}d	}t        j                  d
      }|D ]  }		 ||	   }
t        ||
      }t        j                  |j                  vrt         |       }|j!                         j                         }|?t#        |j%                               t#        |j%                               k\  rt'        ||      s|}||_        |} |t	        d|       ||j*                  vr|S |D ]N  }		 |j,                  |	j                            }|j*                  |   |   }t/        j0                  |      |_         |S  |S # t        $ r Y +w xY w# t        $ r Y nw xY w)a  
    Given a string with instrument content (from an orchestral score
    for example), attempts to return an appropriate
    :class:`~music21.instrument.Instrument`.

    >>> t1 = instrument.fromString('Clarinet 2 in A')
    >>> t1
    <music21.instrument.Clarinet 'Clarinet 2 in A'>
    >>> t1.transposition
    <music21.interval.Interval m-3>

    >>> t2 = instrument.fromString('Clarinetto 3')
    >>> t2
    <music21.instrument.Clarinet 'Clarinetto 3'>

    >>> t3 = instrument.fromString('flauto 2')
    >>> t3
    <music21.instrument.Flute 'flauto 2'>

    Excess information is ignored, and the useful information can be extracted
    correctly as long as it's sequential.

    >>> t4 = instrument.fromString('I <3 music saxofono tenore go beavers')
    >>> t4
    <music21.instrument.TenorSaxophone 'I <3 music saxofono tenore go beavers'>

    Some more demos:

    >>> t5 = instrument.fromString('Bb Clarinet')
    >>> t5
    <music21.instrument.Clarinet 'Bb Clarinet'>
    >>> t5.transposition
    <music21.interval.Interval M-2>

    >>> t6 = instrument.fromString('Clarinet in B-flat')
    >>> t5.__class__ == t6.__class__
    True

    >>> t5.transposition == t6.transposition
    True

    >>> t7 = instrument.fromString('B-flat Clarinet.')
    >>> t5.__class__ == t7.__class__ and t5.transposition == t7.transposition
    True

    >>> t8 = instrument.fromString('Eb Clarinet')
    >>> t5.__class__ == t8.__class__
    True
    >>> t8.transposition
    <music21.interval.Interval m3>

    Note that because of the ubiquity of B-flat clarinets and trumpets, and the
    rareness of B-natural forms of those instruments, this gives a B-flat, not
    B-natural clarinet, using the German form:

    >>> t9 = instrument.fromString('Klarinette in B.')
    >>> t9
    <music21.instrument.Clarinet 'Klarinette in B.'>
    >>> t9.transposition
    <music21.interval.Interval M-2>

    Use "H" or "b-natural" to get an instrument in B-major.  Or donate one to me,
    and I'll change this back!

    Standard abbreviations are acceptable:

    >>> t10 = instrument.fromString('Cl in B-flat')
    >>> t10
    <music21.instrument.Clarinet 'Cl in B-flat'>
    >>> t10.transposition
    <music21.interval.Interval M-2>

    This should work with or without a terminal period (for both 'Cl' and 'Cl.'):

    >>> t11 = instrument.fromString('Cl. in B-flat')
    >>> t11.__class__ == t10.__class__
    True

    Previously an exact instrument name was not always working:

    >>> instrument.fromString('Flute')
    <music21.instrument.Flute 'Flute'>

    This common MIDI instrument was not previously working:

    >>> instrument.fromString('Choir (Aahs)')
    <music21.instrument.Choir 'Choir (Aahs)'>

    By default, this function searches over all stored instrument names.
    This includes multiple languages as well as the abbreviations
    (an honorary 'language' for these purposes).

    Alternatively, you can specify the language to search using the `language`
    argument. (New in v7.3.)

    >>> t12 = instrument.fromString('Klarinette', language=instrument.SearchLanguage.GERMAN)
    >>> t12
    <music21.instrument.Clarinet 'Klarinette'>

    This case works because the name 'Klarinette' is a recognised instrument name in German
    and appears in the German language list.
    If you search for a German name like 'Klarinette' on the French list (language='french'),
    then it won't be found and an InstrumentException will be raised.
    An InstrumentException is also raised if the specified language is not
    one of those currently supported:
    'english', 'french', 'german', 'italian', 'russian', 'spanish', and 'abbreviation'.

    Note that the language string is not case-sensitive, so 'French' is also fine.
    r   instrumentLookupChosen language  not currently supported.ToClassName.r  NrC   zmusic21.instrumentz(Could not match string with instrument: )music21.languageExcerptsr  r  r  r	   getattrreplacer   removePunctuationr  	importlibimport_moduler   Music21Object__mro__r  rV   re   r  r   r5   r<   pitchFullNameToNamer
   r   )r  languager  
sourceDictinstrumentStringOrigallCombinationsbestInstrumentrV   this_module	substring	classNamethisInstClassthisInstrumentthisBestName	bestPitchbestIntervals                   r    
fromStringr  	  s	   ^ :~~H~%!$4XJ>W"XYY)8m+CDJ+'//S9'--///0@A#$45ONH))*>?K$		"9-I#K;M!!)>)>>*_N)224::<L&<--/0C8H4II&~}E "00D-'! %& !67K6LMO 	O'555 %		(<<Y__=NOI+99(CINL+3+<+<\+JN(  % %  		   		s&    B$F;,A	G;	GG	GGc                    ddl m} t        ||dz         }g }|j                         D ]  \  }}| |k(  s|j	                  |        |S )a  
    Retrieve the key or keys (variant instrument names)
    from an instrumentLookup dict, given
    the language (which instrumentLookup dict) and
    value (classNameString).

    Returns all relevant keys as a list of strings (empty if no matches).
    r   r  r  )r  r  r  itemsrD   )classNameStringr  r  r  returnskeyvalues          r    _getKeysr  	  sP     :)8m+CDJG &&(
Ue#NN3 ) Nr!   c                >   |j                         }i }| j                  xs d}|t        j                  k(  r8t        D ]-  }|t        j                  u rt	        ||      |t        |      <   / |S |t        vrt        d| d      t	        |t        |            ||<   |S )u  
    Retrieves all currently stored names for a given instrument.

    The instrumentClass should be a valid music21
    :class:`~music21.instrument.Instrument`.

    By default, this function searches over all supported languages
    including instrument name abbreviations (an honorary 'language' for these purposes),
    and returns a dict with keys for the language tested and values as a list of
    strings for any names in that language.

    >>> instrument.getAllNamesForInstrument(instrument.Flute())
    {'english': ['flute', 'flutes', 'transverse flute'],
    'french': ['flûte', 'flûte traversière', 'flûtes', 'grande flûte'],
    'german': ['flöte', 'flöten', 'querflöte'],
    'italian': ['flauti', 'flauto', 'flauto traverso'],
    'russian': ['fleita'],
    'spanish': ['flauta', 'flauta de boehm', 'flauta de concierto',
                'flauta traversa', 'flauta travesera', 'flautas'],
    'abbreviation': ['fl']}

    Alternatively, you can specify the language to search using the `language`
    argument.

    >>> instrument.getAllNamesForInstrument(instrument.Flute(), language='german')
    {'german': ['flöte', 'flöten', 'querflöte']}

    An InstrumentException is raised if the specified language is not
    one of those currently supported:
    'english', 'french', 'german', 'italian', 'russian', 'spanish', and 'abbreviation'.

    Note that the language string is not case-sensitive, so 'German' is also fine.

    rC   r  r  )r  r5   r  r  r  rK   r	   )instrumentClassr  instrumentNameDictinstrumentClassNamelangs        r    getAllNamesForInstrumentr  	  s    J ~~H)88>B>%%%"D~))),45H$,Os4y) #  
	'!$4XJ>W"XYY'/0C^T\E]'^8$r!   c                      e Zd Zy)TestExternalNr  r*   r!   r    r  r  	
  r  r!   r  c                  B    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zy
)Testc                2    ddl m}  || t                      y )Nr   )testCopyAll)music21.test.commonTestr  globals)r?   r  s     r    testCopyAndDeepcopyzTest.testCopyAndDeepcopy
  s    7D')$r!   c                   ddl m}  |j                         }t               }d|_        |j                  |       |j                  t        j                         d        |j                         }t               }d|_        |j                  |       |j                  t        j                  d      d        |j                         }|j                  d|       |j                  d|       y )Nr   r   testr^  test2g4)rK  r   rN  r   r/   rD   repeatAppendr   Noter~   r  r   )r?   r   s1i1s2i2s3s          r    testMusicXMLExportzTest.testMusicXMLExport
  s    "V]]_X
		"
		R( V]]_W
		"
		$,V\\^
		!R
		!Rr!   c                l   ddl m} ddl m}  |j                         } |j                         }|j                  |j                                 |j                         }|j                  |j                                |j                  d|       |j                  d|       |j                  |      }| j                  t        |      d       | j                  t        |j                         j                  |j                              d        |j                         }|j                  d|j!                                |j                  d|j#                                |j                  |      }| j                  t        |      d       | j                  t        ||j                           d       y )Nr   r   r   r   r   )rK  r   r   r  r  rD   r~   rR  r   r  assertEqualre   r  rM  r$   rN  r_  r   r?   r   r   r   p1p2r  s          r    testPartitionByInstrumentAzTest.testPartitionByInstrumentA)
  sG   &" FLLNV[[]
		*""$%V[[]
		*$$&'	B	B//2TA&T\\^>>z?T?TUVXYZ
 FMMO	J'')*	Z))+,//2TA&T*"7"7891=r!   c                F   ddl m} ddl m}  |j                         } |j                         }|j                  |j                                |j                  t        j                         d        |j                         }|j                  |j                                |j                  t        j                         d       |j                  d|       |j                  d|       |j                  |      }| j                  t        |      d       | j                  t        ||j                           d       | j                  t        |j                   d   j"                        d       | j                  t        |j                   d   j"                        d       y )Nr   r  r   r   r  r   rb   )rK  r   r   r  r  rD   r~   r  r   r  rR  r   r  r  re   r$   partsnotesr  s          r    testPartitionByInstrumentBzTest.testPartitionByInstrumentBG
  s'   &" FLLNV[[]
		*""$%
		Q'V[[]
		*$$&'
		R(	B	B//2TA&T*"7"7891=TZZ]00115TZZ]00126r!   c                   ddl m} ddl m}  |j                         } |j                         }|j                  |j                                |j                  t        j                  d      d       |j                  |j                                |j                  t        j                  d      d        |j                         }|j                  |j                                |j                  t        j                  d      d	       |j                  |j                                |j                  t        j                  d
      d       |j                  d|       |j                  d|       |j                  |      }| j                  t!        |      d       | j                  t!        ||j"                           d       | j                  |j$                  d   j'                         j(                  d       | j                  t!        |j$                  d   j*                        d       | j                  |j$                  d   j'                         j(                  d       | j                  t!        |j$                  d   j*                        d       | j                  |j$                  d	   j'                         j(                  d       | j                  t!        |j$                  d	   j*                        d	       | j                  |j$                  d   j'                         j(                  d       | j                  t!        |j$                  d   j*                        d       y )Nr   r  r   ar   br[  cr   dr\  r~   rb   r  rR  rK  )rK  r   r   r  r  rD   r~   r  r   r  r
  rR  rK  r   r  r  re   r$   r  getInstrumentr5   r  r  s          r    testPartitionByInstrumentCzTest.testPartitionByInstrumentC]
  sd   &" FLLNV[[]
		*""$%
		#*
		*++-.
		#*V[[]
		*$$&'
		#*
		*""$%
		#*	B	B//2TA&T*"7"7891=A446EEwOTZZ]00115A446EEGXYTZZ]00115A446EEyQTZZ]00115A446EEwOTZZ]00115r!   c                   ddl m} ddl m}  |j                         } |j                         }|j                  |j                                |j                  t        j                  d      d       |j                  |j                                |j                  t        j                  d      d       |j                  |j                                |j                  t        j                  d      d	        |j                         }|j                  |j                                |j                  t        j                  d
      d       |j                  |j                                |j                  t        j                  d      d       |j                  |j                                |j                  t        j                  d      d       |j                  d|       |j                  d|       |j                  |      }| j                  t!        |      d       | j                  t!        ||j"                           d       | j                  |j$                  d   j'                         j(                  d       | j                  t!        |j$                  d   j*                        d       | j                  |j$                  d   j*                  D cg c]  }|j,                   c}g d       y c c}w )Nr   r  r   r  r   r  r[  r  r]  r  r   r  r\  frb   r~   r  )              ?       @      @      @      @g      @      "@      $@      &@      (@      *@)rK  r   r   r  r  rD   r~   r  r   r  r
  rR  rK  r   r  r  re   r$   r  r  r5   r  r   )r?   r   r   r   r  r  r  ns           r    testPartitionByInstrumentDzTest.testPartitionByInstrumentD
  s   &" FLLNV[[]
		*""$%
		#*
		*++-.
		#*
		*""$%
		#*V[[]
		*$$&'
		#*
		*""$%
		#*
		*""$%
		#*	B	B//2TA&T*"7"7891=A446EEwOTZZ]00126DJJqM,?,?@,?q!((,?@Y	[@s   K=c                   ddl m} ddl m}  |j                         }|j	                  |j                                |j                  t        j                  d      d       |j	                  |j                                |j                  t        j                  d      d       |j	                  |j                                |j                  t        j                  d      d	       |j	                  |j                                |j                  t        j                  d
      d       |j	                  |j                                |j                  t        j                  d      d       |j	                  |j                                |j                  t        j                  d      d       |}|j                  |      }| j                  t        |      d       | j                  t        ||j                           d       | j                  |j                   d   j#                         j$                  d       | j                  t        |j                   d   j&                        d       g }|j                   d   j&                  }|D ]  }|j	                  |j(                          | j                  |g d       y )Nr   r  r   r  r   r  r[  r  r]  r  r   r  r\  r  rb   r~   r  )r   r!  r"  r#  r$  r%  r&  r'  r(  r)  r*  g      4@)rK  r   r   r  rD   r~   r  r   r  r
  rR  rK  r  r  re   r$   r  r  r5   r  r   )	r?   r   r   r  r   r  
offsetListppnr+  s	            r    testPartitionByInstrumentEzTest.testPartitionByInstrumentE
  s   &" V[[]
		*""$%
		#*
		*++-.
		#*
		*""$%
		#*
		*$$&'
		#*
		*""$%
		#*
		*""$%
		#*//2TA&T*"7"7891=A446EEwOTZZ]00126
jjm!!Aahh'  	Z	\r!   c                   ddl m} ddl m}  |j                         }|j	                  |j                                |j	                  t        j                                |j	                  |j                                |j	                  t        j                                |j                  |      }| j                  t        |      d       y )Nr   r  r   r   )rK  r   r   rN  rD   r
  r   r  r  r  r  re   )r?   r   r   r  r  s        r    testPartitionByInstrumentFzTest.testPartitionByInstrumentF
  s    &"V]]_
		*++-.
		$))+
		*//#$
		$))+//3TA&r!   c                   ddl m} d}| j                  |j                  |      j                  |       ddg}|D ]1  }|j                  ||      j                  }| j                  ||       3 ddg}|D ]%  }| j                  t        |j                  ||       ' |j                         }| j                  |j                  |t        j                        d	d
gi       | j                  t        |j                  |d       y )Nr   r  
Klarinetter  German)r  r  finnishr  fl)rK  r   r  r  r5   assertRaisesr	   rK  r  r  r  )r?   r   
testStringworkingExampleslangStr	instrNamefailingExamplesrX  s           r    testLanguageChoicezTest.testLanguageChoice
  s%   & "
 	..z:II#	% $# 'G"--j7-KZZIY
3 ' $$ 'G1(33('.  0 ' !<<TFTFaFa = c(4&1	3 	-$==#, 	 	.r!   N)rn   ro   rp   r  r  r  r  r  r,  r0  r2  r>  r*   r!   r    r  r  
  s5    %,><7, 6J"[N%\N'H(.r!   r  __main__)r   stream.Streamrm   zstream.Stream | None)F)r   r@  r   boolrm   r@  )rG  rF  rm   r$   )r  r@  rm   r@  )r  rK   r  r  )r  rK   r  r  )r  r$   r  r  )rq   
__future__r   collectionsr   collections.abcr   r  unittesttypingtrK  r   r   r   music21.exceptions21r	   r
   r   r   music21.tree.treesr   TYPE_CHECKINGr   EnvironmentenvironLocalr   r#   r  r$   rv   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  r%  r+  r0  r6  r<  rA  rE  rK  rR  rY  r_  rc  rg  ro  rt  rz  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  r   r  r	  r  r  r  r  r   r*  r.  r3  r7  r<  r@  rD  rL  rO  rR  rU  rX  r_  rf  rj  ro  rs  rv  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rE  rH  rZ  r  r  r  r  enumsStrEnumr  r  r  r  r  TestCaser  r  
_DOC_ORDERrn   mainTestr*   r!   r    <module>rR     s   # # $       4    )??&{&&|4
 !&$*<$R $'(:'T~## ~J0 0- -*
-$ 
-5# 52  2  E *0J 0	- 	-	-E 	-
- 
-
- 
-
-
 
-4z 4n
7 
7
7 
7
7" 
76! 6&
. 
.
C 
C7V 77V 7
76 
7
76 
7
76 
7	7 	7	7 	76 6    + +	, 	,
5e 
5	,u 	,u  
e 
e 	- 	-
6$ 
6
6! 
668 6,	-  	-	-G 	-	-" 	-	6y 	6	6I 	6	6Y 	6	7	 	7!   j 6? 6.
6o 
6	, 	,-8 -	,? 	,- -	
 	4	* 4	n"  ! $ # $ , ,>! >  !   I# I 3% 30# 0/! /# ,! ,5G 5I7 I&8g 857 55G 53' 3/' /.I" I&! 	 	.  .:% :I# I(1# 1I$ II  I I" II# II" I $ - -0! 0. .1) 1-% -
z 
/h /57 5,8 ,-H -0x 0,8 ,H A
 A3 @0&i^AuAuA }A u	A
 }A }A {A zA wA |A A 
A A 	A A  !A" #A$ %A& 'A( 	)A* 	+A, 	-A. 	/A0 	1A2 3A4 5A6 7A8 9A: ;A< =A> ?A@ AAB CAD EAF GAH IAJ KAL MAN OAP QAR SAT UAV WAX 
YAZ [A\ ]A^ _A` aAb cAd eAf gAh iAj kAl mAn oAp qAr sAt uAv wAx yAz {A| }A~ A@ AAB CAD EAF GAH IAJ KAL MAN OAP QAR SAT UAV WAX YAZ [A\ 
]A^ _A` aAb cAd eAf gAh iAj kAl mAn oAp qAr sAt uAv wAx yAz {A| }A~ A@ AAB CAD EAF GAH IAJ KAL MAN OAP QAR SAT UAV WAX YAZ [A\ ]A^ _A` aAb cAd eAf gAh iAj kAl mAn oAp 
								AA H@K\	"V\\)) " +9*<*<c'cN )7(:(:%, 9G8J8J4'54p	8$$ 	O.8 O.h \
zGT	 r!   