
    3j                   B   U d 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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 e
j*                  rddlmZ ddlmZ ddlmZ  ej2                  d      ZdZded<    G d dej:                        Zej>                  dej@                  dejB                  diZ"g dZ#dZ$dWdZ% G d dej:                        Z&e&jN                  e&jP                  e&jR                  e&jT                  e&jV                  e&jX                  e&jZ                  e&j\                  e&j^                  g	Z0dZ1e&jN                  e&jP                  e&jR                  e&jT                  e&jd                  e&jf                  e&jX                  e&jZ                  e&j\                  e&j^                  g
Z4dZ5ddddd d!d"d#Z6e&jV                  Z7e&jd                  Z8e&jf                  Z9e7d$fe8dfe9dfe8d%fe9d%fe7dfe&jT                  dfe7dfe8d&fe9d&fe8d fe9d fgZ:[7[8[9 G d' d(ejv                        Z<	 	 	 	 dXd)Z=d* Z>dYd+Z?dZd,Z@d[d-ZA	 	 	 	 d\d.ZBd]d/ZCi ZDd0ed1<   d^d3ZE G d4 d5ej                        ZG G d6 d7eG      ZH G d8 d9eG      ZI G d: d;eG      ZJ	 	 	 	 d_d<ZK	 	 	 	 	 	 d`d=ZL	 	 	 	 	 	 dad>ZM	 	 	 	 	 	 dbd?ZN	 	 	 	 	 	 dcd@ZO	 	 	 	 	 	 dddAZP G dB d2eG      ZQe	 	 	 	 dedC       ZRe	 	 	 	 dfdD       ZR	 	 	 	 dgdEZRe	 	 	 	 dedF       ZSe	 	 	 	 dfdG       ZS	 	 	 	 dgdHZSe	 	 	 	 dedI       ZTe	 	 	 	 dfdJ       ZT	 	 	 	 dgdKZTe	 	 	 	 dedL       ZUe	 	 	 	 dfdM       ZU	 	 	 	 dgdNZUdOdP	 	 	 	 	 dhdQZV	 	 	 	 	 	 didRZWdjdSZXdT ZYdU ZZeMeOePeQgZ[e\dVk(  rddlZ ej                          yy)kz
This module defines various types of interval objects.
Fundamental classes are :class:`~music21.interval.Interval`,
:class:`~music21.interval.GenericInterval`,
and :class:`~music21.interval.ChromaticInterval`.
    )annotations)FractionN)overload)base)common)cacheMethod)StepName)environment)exceptions21)keynotepitchinterval)CDEFGABztuple[StepName, ...]	STEPNAMESc                      e Zd ZdZdZdZy)	Directionr      N)__name__
__module____qualname__
DESCENDINGOBLIQUE	ASCENDING     =/DATA/.local/lib/python3.12/site-packages/music21/interval.pyr   r   3   s    JGIr%   r   
DescendingOblique	Ascending)ERRORPerfectMajorMinor	Augmented
DiminishedzDoubly-AugmentedzDoubly-DiminishedzTriply-AugmentedzTriply-DiminishedzQuadruply-AugmentedzQuadruply-Diminished)r*   PMmr   dAAddAAAdddAAAAddddc                    t        | d      rt        |d      rt        |d      rt        | d      st        d| d|d      yy)zR
    Raise a ValueError if note1 and note2 are not both Notes or both Pitches
    r   znote1 z and note2 z must both be notes or pitchesN)hasattr
ValueErrornote1note2s     r&   _same_classr@   K   sN     
	 )@w'w0G6%+eY>\]^^ 1H'r%   c                  l    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZddZd Zed        Zd Zd Zd Zy)	Specifiera0  
    An enumeration for "specifiers" such as Major, Minor, etc.
    that has some special properties.

    >>> from music21.interval import Specifier
    >>> Specifier.PERFECT
    <Specifier.PERFECT>

    Value numbers are arbitrary and just there for backwards compatibility
    with pre v6 work:

    >>> Specifier.PERFECT.value
    1
    >>> Specifier.PERFECT.name
    'PERFECT'

    >>> str(Specifier.PERFECT)
    'P'
    >>> str(Specifier.MINOR)
    'm'
    >>> str(Specifier.DBLDIM)
    'dd'
    >>> Specifier.DBLDIM.niceName
    'Doubly-Diminished'
    r                        	   
      c                L    t        t        t        | j                                 S N)strprefixSpecsintvalueselfs    r&   __str__zSpecifier.__str__z   s     ;s4::/00r%   c                "    d| j                    dS )Nz<Specifier.>namerS   s    r&   __repr__zSpecifier.__repr__   s    TYYKq))r%   c                :    t         t        | j                           S rN   )niceSpecNamesrQ   rR   rS   s    r&   niceNamezSpecifier.niceName   s     S_--r%   c                P    t        | j                        }g d}t        ||         S )a4  
        Return a new specifier that inverts this Specifier.

        >>> interval.Specifier.MAJOR.inversion()
        <Specifier.MINOR>
        >>> interval.Specifier.DIMINISHED.inversion()
        <Specifier.AUGMENTED>
        >>> interval.Specifier.PERFECT.inversion()
        <Specifier.PERFECT>
        )Nr   rD   rC   rF   rE   rH   rG   rJ   rI   rL   rK   )rQ   rR   rB   )rT   v
inversionss      r&   	inversionzSpecifier.inversion   s%     

O>
A''r%   c           
     x    ddddddddd	d
	}	 |t        |          S # t        $ r}t        | d      |d}~ww xY w)a  
        Returns the number of semitones this specifier is above PERFECT

        >>> Specifier = interval.Specifier

        Augmented and Doubly-Augmented intervals are one and two semitones above
        perfect, respectively:

        >>> Specifier.AUGMENTED.semitonesAbovePerfect()
        1
        >>> Specifier.DBLAUG.semitonesAbovePerfect()
        2

        Diminished intervals are negative numbers of semitones above perfect:

        >>> Specifier.DIMINISHED.semitonesAbovePerfect()
        -1
        >>> Specifier.TRPDIM.semitonesAbovePerfect()
        -3

        Perfect is 0:

        >>> Specifier.PERFECT.semitonesAbovePerfect()
        0

        Major and minor cannot be compared to Perfect, so they raise an
        IntervalException

        >>> Specifier.MINOR.semitonesAbovePerfect()
        Traceback (most recent call last):
        music21.interval.IntervalException: <Specifier.MINOR> cannot be compared to Perfect
        r   r   rC   rD   rE   r   )	r0   r   r4   r6   r8   r3   r5   r7   r9   z cannot be compared to PerfectNrO   KeyErrorIntervalException)rT   semitonesAdjustPerfectkes      r&   semitonesAbovePerfectzSpecifier.semitonesAbovePerfect   se    F 
"
	W)#d)44 	W#th.L$MNTVV	Ws    	949c                z    ddddddddd	d
d
}	 |t        |          S # t        $ r}t        | d      |d}~ww xY w)a  
        Returns the number of semitones this specifier is above Major

        >>> Specifier = interval.Specifier

        Augmented and Doubly-Augmented intervals are one and two semitones above
        major, respectively:

        >>> Specifier.AUGMENTED.semitonesAboveMajor()
        1
        >>> Specifier.DBLAUG.semitonesAboveMajor()
        2

        Minor is below major, so it returns -1.

        >>> Specifier.MINOR.semitonesAboveMajor()
        -1

        Diminished intervals are below minor:

        >>> Specifier.DIMINISHED.semitonesAboveMajor()
        -2
        >>> Specifier.DBLDIM.semitonesAboveMajor()
        -3

        Major is 0:

        >>> Specifier.MAJOR.semitonesAboveMajor()
        0

        Perfect cannot be compared to Major, so it raises an
        IntervalException

        >>> Specifier.PERFECT.semitonesAboveMajor()
        Traceback (most recent call last):
        music21.interval.IntervalException: <Specifier.PERFECT> cannot be compared to Major
        r   r   r   rC   rD   rE   rc   rd   re   )
r1   r2   r   r4   r6   r8   r3   r5   r7   r9   z cannot be compared to MajorNrf   )rT   semitonesAdjustImperfrj   s      r&   semitonesAboveMajorzSpecifier.semitonesAboveMajor   sh    P !
	U(T33 	U#th.J$KLRTT	Us    	:5:NreturnrO   )r   r   r    __doc__PERFECTMAJORMINOR	AUGMENTED
DIMINISHEDDBLAUGDBLDIMTRPAUGTRPDIMQUADAUGQUADDIMrU   rZ   propertyr]   ra   rk   ro   r$   r%   r&   rB   rB   T   sp    2 GEEIJFFFFGG1
* . .( 0Wd6Ur%   rB   rE   rF   rC   rH   rJ   rL   )r   rC   rD   rE   rF   rG   rH   r   rD   rG   c                      e Zd Zy)rh   N)r   r   r    r$   r%   r&   rh   rh   >  s    r%   rh   c                    t        | d      r$d| j                  v rt        j                  d|       S t        j                  d|       }|j                  j
                  |ur||j                  _        |j                  S )a  
    utility function to return either the object itself
    or the `.pitch` if it's a Note.

    >>> p = pitch.Pitch('D#4')
    >>> interval._extractPitch(p) is p
    True
    >>> nEflat = note.Note('E-4')
    >>> interval._extractPitch(nEflat) is nEflat.pitch
    True

    If given a Note, also sets the client of the Pitch to be the Note if not already done
    (for safety, since the Note will be discarded.)
    classesPitchzmusic21.pitch.Pitchzmusic21.note.Note)r;   r   tcastr   _client)nOrPns     r&   _extractPitchr   D  s`    " tYGt||$;vv+T22	"D)Awwa77Nr%   c                ,    | dk(  ry| dkD  r| dz   S | dz
  S )am  
    Returns an integer of the generic interval number
    (P5 = 5, M3 = 3, minor 3 = 3 also) etc. from the given staff distance.

    >>> interval.convertStaffDistanceToInterval(3)
    4
    >>> interval.convertStaffDistanceToInterval(7)
    8
    >>> interval.convertStaffDistanceToInterval(0)
    1
    >>> interval.convertStaffDistanceToInterval(-1)
    -2
    r   r   r$   )	staffDists    r&   convertStaffDistanceToIntervalr   ]  s)     A~	Q1}1}r%   c                    | dk(  ry| dkD  r't        | dz
  dz        }| dz
  |dz  z
  }t        |   |fS t        | dz        }| dz
  |dz  z
  }t        |   |dz
  fS )u  
    Convert a diatonic number to a step name (without accidental) and an octave integer.
    The lowest C on a Bösendorfer Imperial Grand is assigned 1 the D above it is 2,
    E is 3, etc.  See pitch.diatonicNoteNum for more details

    >>> interval.convertDiatonicNumberToStep(15)
    ('C', 2)
    >>> interval.convertDiatonicNumberToStep(23)
    ('D', 3)
    >>> interval.convertDiatonicNumberToStep(0)
    ('B', -1)
    >>> interval.convertDiatonicNumberToStep(1)
    ('C', 0)

    Extremely high and absurdly low numbers also produce "notes".

    >>> interval.convertDiatonicNumberToStep(2100)
    ('B', 299)
    >>> interval.convertDiatonicNumberToStep(-19)
    ('D', -3)

    OMIT_FROM_DOCS

    >>> interval.convertDiatonicNumberToStep(2)
    ('D', 0)
    >>> interval.convertDiatonicNumberToStep(3)
    ('E', 0)
    >>> interval.convertDiatonicNumberToStep(4)
    ('F', 0)
    >>> interval.convertDiatonicNumberToStep(5)
    ('G', 0)
    >>> interval.convertDiatonicNumberToStep(-1)
    ('A', -1)
    >>> interval.convertDiatonicNumberToStep(-2)
    ('G', -1)
    >>> interval.convertDiatonicNumberToStep(-6)
    ('C', -1)
    >>> interval.convertDiatonicNumberToStep(-7)
    ('B', -2)
    r   )r   r   r   g      @rH   )rQ   r   )dnoctave
stepNumbers      r&   convertDiatonicNumberToStepr   s  s}    T 
Qw	ab1f^$1f!,
$f,,R!V1f!,
$vz22r%   c                    t        | t              r| S t        | t              rt        |       S t        | t              st	        d| d      | t
        v rt        t
        j                  |             S | j                         t
        dd D cg c]  }|j                          c}v rHt        t
              D ]6  \  }}|	| j                         |j                         k(  s+t        |      c S  | j                         t        dd D cg c]  }|j                          c}v rSt        dt        t                    D ]7  }| j                         t        |   j                         k(  s,t        |      c S  t        d|       c c}w c c}w )a  
    Given an integer or a string representing a "specifier" (major, minor,
    perfect, diminished, etc.), return the Specifier.

    >>> interval.parseSpecifier('p')
    <Specifier.PERFECT>
    >>> interval.parseSpecifier('P')
    <Specifier.PERFECT>
    >>> interval.parseSpecifier('M')
    <Specifier.MAJOR>
    >>> interval.parseSpecifier('major')
    <Specifier.MAJOR>
    >>> interval.parseSpecifier('m')
    <Specifier.MINOR>
    >>> interval.parseSpecifier('Augmented')
    <Specifier.AUGMENTED>
    >>> interval.parseSpecifier('a')
    <Specifier.AUGMENTED>

    This is not very useful, but they are there for completeness:

    >>> interval.parseSpecifier(interval.Specifier.MAJOR)
    <Specifier.MAJOR>

    This is the same as calling a Specifier by value:

    >>> interval.parseSpecifier(3)
    <Specifier.MINOR>

    Why? Because of this:

    >>> interval.Specifier.MINOR.value
    3

    Unparsable strings raise an IntervalException:

    >>> interval.parseSpecifier('Zebra')
    Traceback (most recent call last):
    music21.interval.IntervalException: Cannot find a match for value: 'Zebra'

    Illegal intervals raise a ValueError:

    >>> interval.parseSpecifier(None)
    Traceback (most recent call last):
    ValueError: Value None must be int, str, or Specifier
    zValue z must be int, str, or Specifierr   NzCannot find a match for value: )
isinstancerB   rQ   rO   r<   rP   indexlower	enumerater\   rangelenrh   )rR   xiprefixs       r&   parseSpecifierr     sS   ^ %#%eS!6%*IJKK**5122 {{}KO<OqO<<";/IAv~{{}. |#	 0 {{}M!",=>,=q,=>>q#m,-A{{}a 0 6 6 88 |# . =eYG
HH = ?s   F
Fc                p   t        | t              r| }t        j                  }nt        | t              r| j                         j                         } t        j                  }t        j                  t        j                  fD ]S  }t        |   j                         | v s|}| j                  t        |   j                         d      j                         } U | t        j                  j                  v rt        j                  j                  |    }nt        d| d      t        d|  d      ||z  }|S )a  
    Convert an interval specified in terms of its name (second, third)
    into an integer. If integers are passed, assume they are correct.

    >>> interval.convertGeneric(3)
    3
    >>> interval.convertGeneric('third')
    3
    >>> interval.convertGeneric('3rd')
    3
    >>> interval.convertGeneric('octave')
    8
    >>> interval.convertGeneric('twelfth')
    12
    >>> interval.convertGeneric('descending twelfth')
    -12
    >>> interval.convertGeneric(12)
    12
    >>> interval.convertGeneric(-12)
    -12
    >>> interval.convertGeneric(1)
    1

    >>> interval.convertGeneric(None)
    Traceback (most recent call last):
    music21.interval.IntervalException: Cannot get a direction from None.

    Strings are not the same as numbers:

    >>> interval.convertGeneric('1')
    Traceback (most recent call last):
    music21.interval.IntervalException: Cannot convert '1' to an interval.

    But this works:

    >>> interval.convertGeneric('1st')
    1
     zCannot convert z to an interval.zCannot get a direction from .)r   rQ   r   r#   rO   stripr   r!   directionTermsreplacer   numberToolsordinalsToNumbersrh   )rR   postdirectionScalar	directions       r&   convertGenericr     s   P %#--	E3	##% $--#..	0C0CDIi(..0E9"+nY&?&E&E&GLRRT E
 F&&888%%77>D#oeY>N$OPP">ugQ GHH/!DKr%   c                    | dk  rd}nd}t        | d      \  } }|dz  }|dkD  r
|dz
  }| dz  } t        |       } t        |       dz  }t        |       dz  }t        |   \  }}|||dz  z   |z  |fS )	a.  
    Given a number of semitones (positive or negative),
    return a default diatonic specifier and cent offset.

    >>> interval.convertSemitoneToSpecifierGenericMicrotone(2.5)
    (<Specifier.MAJOR>, 2, 50.0)
    >>> interval.convertSemitoneToSpecifierGenericMicrotone(-2.5)
    (<Specifier.MINOR>, -3, 50.0)
    >>> interval.convertSemitoneToSpecifierGenericMicrotone(-2.25)
    (<Specifier.MAJOR>, -2, -25.0)
    >>> interval.convertSemitoneToSpecifierGenericMicrotone(-1.0)
    (<Specifier.MINOR>, -2, 0.0)
    >>> interval.convertSemitoneToSpecifierGenericMicrotone(2.25)
    (<Specifier.MAJOR>, 2, 25.0)
    >>> interval.convertSemitoneToSpecifierGenericMicrotone(1.0)
    (<Specifier.MINOR>, 2, 0.0)
    >>> interval.convertSemitoneToSpecifierGenericMicrotone(1.75)
    (<Specifier.MAJOR>, 2, -25.0)
    >>> interval.convertSemitoneToSpecifierGenericMicrotone(1.9)
    (<Specifier.MAJOR>, 2, -10.0...)
    >>> interval.convertSemitoneToSpecifierGenericMicrotone(0.25)
    (<Specifier.PERFECT>, 1, 25.0)
    >>> interval.convertSemitoneToSpecifierGenericMicrotone(12.25)
    (<Specifier.PERFECT>, 8, 25.0)
    >>> interval.convertSemitoneToSpecifierGenericMicrotone(24.25)
    (<Specifier.PERFECT>, 15, 25.0)
    >>> interval.convertSemitoneToSpecifierGenericMicrotone(23.75)
    (<Specifier.PERFECT>, 15, -25.0)
    r   r   r         Y@2   d      rH   )divmodrQ   absSEMITONES_TO_SPEC_GENERIC)countdirScalemicrocentssizer   specgenerics           r&   *convertSemitoneToSpecifierGenericMicrotoner   1  s    @ qy%#LE5EMErz
JEu:?DZ2F-d3MD'7fqj)X5u==r%   c                (    t        |       \  }}}||fS )a  
    Given a number of semitones, return a default diatonic specifier, and
    a number that can be used as a GenericInterval

    >>> interval.convertSemitoneToSpecifierGeneric(0)
    (<Specifier.PERFECT>, 1)
    >>> interval.convertSemitoneToSpecifierGeneric(-2)
    (<Specifier.MAJOR>, -2)
    >>> interval.convertSemitoneToSpecifierGeneric(1)
    (<Specifier.MINOR>, 2)
    >>> interval.convertSemitoneToSpecifierGeneric(7)
    (<Specifier.PERFECT>, 5)
    >>> interval.convertSemitoneToSpecifierGeneric(11)
    (<Specifier.MAJOR>, 7)
    >>> interval.convertSemitoneToSpecifierGeneric(12)
    (<Specifier.PERFECT>, 8)
    >>> interval.convertSemitoneToSpecifierGeneric(13)
    (<Specifier.MINOR>, 9)
    >>> interval.convertSemitoneToSpecifierGeneric(-15)
    (<Specifier.MINOR>, -10)
    >>> interval.convertSemitoneToSpecifierGeneric(24)
    (<Specifier.PERFECT>, 15)

    Note that the tritone is given as diminished fifth, not augmented fourth:

    >>> interval.convertSemitoneToSpecifierGeneric(6)
    (<Specifier.DIMINISHED>, 5)

    Microtones are rounded here:

    >>> interval.convertSemitoneToSpecifierGeneric(0.4)
    (<Specifier.PERFECT>, 1)
    >>> interval.convertSemitoneToSpecifierGeneric(0.6)
    (<Specifier.MINOR>, 2)
    )r   )r   	specifier	semitonesunused_cent_offsets       r&   !convertSemitoneToSpecifierGenericr   f  s$    J 0ZZ_/`,Iy,y!!r%   z'dict[str, tuple[pitch.Pitch, Fraction]]_pythagorean_cacheIntervalc                d   ddl m}  |d      }|j                  |       }|j                  t        v rt        |j                     \  }}n|}|}t        d      D ]|  }|j                  |j                  k(  rt        dd      |z  }|} n_|j                  |j                  k(  rt        dd      |z  }|} n3|j                  d      }|j                  d      }~ t        d	|  d
      ||ft        |j                  <   t        |j                  |j                  z
  dz        }	|t        dd      |	z  z  S )a  
    Returns the interval ratio in pythagorean tuning, always as a Fraction object.

    >>> iList = [interval.Interval(name) for name in ('P4', 'P5', 'M7', 'm23')]
    >>> iList
    [<music21.interval.Interval P4>,
     <music21.interval.Interval P5>,
     <music21.interval.Interval M7>,
     <music21.interval.Interval m23>]

    >>> [interval.intervalToPythagoreanRatio(i) for i in iList]
    [Fraction(4, 3), Fraction(3, 2), Fraction(243, 128), Fraction(2048, 243)]

    Throws an exception if no ratio can be found, such as for quarter tones.

    >>> p1, p2 = pitch.Pitch('C1'), pitch.Pitch('C1')
    >>> p2.accidental = 'half-sharp'

    >>> fiftyCent = interval.Interval(p1, p2)
    >>> fiftyCent
    <music21.interval.Interval A1 (-50c)>

    >>> interval.intervalToPythagoreanRatio(fiftyCent)
    Traceback (most recent call last):
    music21.interval.IntervalException: Could not find a pythagorean ratio for
        <music21.interval.Interval A1 (-50c)>.
    r   )r   C1%   rD   rC   P5z-P5z'Could not find a pythagorean ratio for r   r   r   )
music21.pitchr   	transposerY   r   r   r   rh   rQ   ps)
intervalObjr   start_pitchend_pitch_wanted	end_pitchratioend_pitch_upend_pitch_downcounteroctavess
             r&   intervalToPythagoreanRatior     sK   8 $+K",,[9
  22-.>.C.CD	5 #$ RyG  $4$9$99 A'1(	$$(8(=(== A'1*	  ,55d;!/!9!9%!@ ! $9+aHJ J 5>u4D+001#&&5;<G8Aq>W,,,r%   c                  n    e Zd ZdZddZej                  dd	 	 	 d	d       Zej                  d        Zy)
IntervalBasez-
    General base class for inheritance.
    c                t    | j                  |j                        }t        j                  |      }||_        |S )aV  
        Uses self.transposePitch to do the same to a note.

        >>> n1 = note.Note('C#4', quarterLength=2.0)
        >>> i = interval.Interval('d5')
        >>> n2 = i.transposeNote(n1)
        >>> n2
        <music21.note.Note G>
        >>> n2.pitch
        <music21.pitch.Pitch G4>
        >>> n2.duration.type
        'half'
        )transposePitchr   copydeepcopy)rT   r>   newPitchnewNotes       r&   transposeNotezIntervalBase.transposeNote  s2     &&u{{3--& r%   FinPlacec                   t         zq
        IntervalBase does not know how to do this, so it must be overridden in
        derived classes.
        NotImplementedError)rT   pitch1r   s      r&   r   zIntervalBase.transposePitch  s
     "!r%   c                    t         r   r   rS   s    r&   reversezIntervalBase.reverse  s
     "!r%   N)r>   	note.Noterq   r   )r   pitch.Pitchr   bool)	r   r   r    rr   r   abcabstractmethodr   r   r$   r%   r&   r   r     sW    & 	 (-"*" !%" " 	" "r%   r   c                  h    e Zd ZdZ	 d&	 d' fdZd Zd Zd Zed(d       Z	e	j                  d)d       Z	ed(d       Zej                  d)d	       Zed(d
       Zed*d       Zed+d       Zed+d       Zed+d       Zed+d       Zed,d       Zed(d       Zed(d       Zed(d       Zed(d       Zed(d       Zed(d       Zed+d       Zd-dZed.d       Zed.d       Zed.d       Zed(d       Zed(d       Zed(d       Z e!d/d       Z"d/d Z#d!d"d0d#Z$	 d1d!d"	 	 	 	 	 d2d$Z%d3d%Z& xZ'S )4GenericIntervalav  
    A GenericInterval is an interval such as Third, Seventh, Octave, or Tenth.
    Constructor takes an integer or string specifying the interval and direction.

    The interval is not specified in half-steps, but in numeric values
    derived from interval names:
    a Third is 3; a Seventh is 7, etc. String values for interval names ('3rd' or 'third')
    are generally accepted, but discouraged since not every one will work.

    staffDistance: the number of lines or spaces apart, eg:

        E.g. C4 to C4 = 0;  C4 to D4 = 1;  C4 to B3 = -1

    Two generic intervals are the equal if their size and direction are the same.

    >>> gi = interval.GenericInterval(8)
    >>> gi
    <music21.interval.GenericInterval 8>

    >>> third = interval.GenericInterval(3)
    >>> third.directed
    3
    >>> third.direction
    <Direction.ASCENDING: 1>
    >>> third.perfectable
    False
    >>> third.staffDistance
    2

    We can also specify intervals from strings:

    >>> third = interval.GenericInterval('Third')
    >>> third
    <music21.interval.GenericInterval 3>
    >>> third.directed
    3

    or like this:

    >>> thirdDown = interval.GenericInterval('Descending Third')
    >>> thirdDown
    <music21.interval.GenericInterval -3>
    >>> thirdDown.directed
    -3

    A lot of tools for working with large intervals

    >>> twelfthDown = interval.GenericInterval(-12)
    >>> twelfthDown.niceName
    'Twelfth'
    >>> twelfthDown.perfectable
    True
    >>> twelfthDown.staffDistance
    -11
    >>> twelfthDown.mod7
    4
    >>> twelfthDown.directed
    -12
    >>> twelfthDown.undirected
    12

    >>> complement12 = twelfthDown.complement()
    >>> complement12.niceName
    'Fourth'
    >>> complement12.staffDistance
    3

    Note this illegal interval:

    >>> zeroth = interval.GenericInterval(0)
    Traceback (most recent call last):
    music21.interval.IntervalException: The Zeroth is not an interval

    However, this is okay:

    >>> descendingUnison = interval.GenericInterval(-1)
    >>> descendingUnison.direction
    <Direction.DESCENDING: -1>
    >>> descendingUnison.directed
    -1
    >>> descendingUnison.undirected
    1

    This is because we don't yet know what type of unison this is: is it
    a Perfect Unison or an Augmented Unison (or Augmented Prime as some prefer)?
    Thus, the illegal check will be moved to a higher level Interval object.

    A second is a step:

    >>> second = interval.GenericInterval(2)
    >>> second.isDiatonicStep
    True
    >>> second.isStep
    True

    A third is not:

    >>> third = interval.GenericInterval(-3)
    >>> third.isDiatonicStep
    False
    >>> third.isStep
    False

    Intervals more than three octaves use numbers with abbreviations instead of names

    >>> threeOctaveSecond = interval.GenericInterval(23)
    >>> threeOctaveSecond.niceName
    '23rd'

    >>> threeOctaveThird = interval.GenericInterval(24)
    >>> threeOctaveThird.niceName
    '24th'
    >>> threeOctaveThird.isDiatonicStep
    False
    >>> threeOctaveThird.isStep
    False
    >>> threeOctaveThird.simpleNiceName
    'Third'

    * Changed in v6: large intervals get abbreviations.
    c                R    t        |   di | d| _        t        |      | _        y )Nr   r$   )super__init___valuer   rR   )rT   rR   keywords	__class__s      r&   r   zGenericInterval.__init__~  s(     	$8$#E*
r%   c                ,    t        | j                        S rN   rO   directedrS   s    r&   _reprInternalzGenericInterval._reprInternal      4==!!r%   c                d    t        |t        |             sy| j                  |j                  k(  ryy)a  
        True if value and direction are the same.

        >>> a = interval.GenericInterval('Third')
        >>> b = interval.GenericInterval(-3)
        >>> c = interval.GenericInterval(3)
        >>> d = interval.GenericInterval(6)
        >>> a == b
        False
        >>> a == a == c
        True
        >>> b == c
        False
        >>> a != d
        True
        >>> a in [b, c, d]
        True

        >>> a == ''
        False
        >>> a is None
        False
        FT)r   typerR   rT   others     r&   __eq__zGenericInterval.__eq__  s+    0 %d,ZZ5;;&r%   c                    t        |       dz	  S NrE   idrS   s    r&   __hash__zGenericInterval.__hash__      $x1}r%   c                    | j                   S )z
        The size of this interval as an integer.  Synonym for `self.directed`

        >>> interval.GenericInterval('Descending Sixth').value
        -6
        )r   rS   s    r&   rR   zGenericInterval.value  s     {{r%   c                R    | j                          |dk(  rt        d      || _        y )Nr   zThe Zeroth is not an interval)
clearCacherh   r   rT   newValues     r&   rR   zGenericInterval.value  s&    q=#$CDDr%   c                    | j                   S )z
        Synonym for `self.value`

        >>> sixthDown = interval.GenericInterval(-6)
        >>> sixthDown.directed
        -6
        >>> sixthDown.directed = 2
        >>> sixthDown.value
        2
        rR   rS   s    r&   r   zGenericInterval.directed  s     zzr%   c                    || _         y rN   r  r  s     r&   r   zGenericInterval.directed  s	    
r%   c                ,    t        | j                        S )z
        Returns the absolute value of `self.directed`.  Read-only

        >>> sixthDown = interval.GenericInterval(-6)
        >>> sixthDown.undirected
        6
        )r   rR   rS   s    r&   
undirectedzGenericInterval.undirected  s     4::r%   c                    | j                   }|dk(  rt        j                  S |dk  rt        j                  S t        j                  S )ah  
        Returns a Direction Enum value for the direction of this interval:

        >>> interval.GenericInterval('Descending Fifth').direction
        <Direction.DESCENDING: -1>

        >>> interval.GenericInterval('Unison').direction
        <Direction.OBLIQUE: 0>

        >>> interval.GenericInterval(4).direction
        <Direction.ASCENDING: 1>
        r   r   )r   r   r"   r!   r#   )rT   r3   s     r&   r   zGenericInterval.direction  s?     MM6$$$U'''&&&r%   c                     | j                   dkD  S )aW  
        Returns True if the undirected interval is bigger than a second.

        >>> interval.GenericInterval('Octave').isSkip
        True
        >>> interval.GenericInterval('Descending 2nd').isSkip
        False
        >>> interval.GenericInterval(1).isSkip
        False

        Note that Unisons are neither steps nor skips.
        rC   r  rS   s    r&   isSkipzGenericInterval.isSkip  s     ""r%   c                     | j                   dk(  S )a  
        Return True if this interval is a step (a second).
        A synonym for `isStep` for generic intervals.

        >>> interval.GenericInterval(-2).isDiatonicStep
        True
        >>> interval.GenericInterval(1).isDiatonicStep
        False
        >>> interval.GenericInterval(9).isDiatonicStep
        False

        Note that Unisons are neither steps nor skips.
        rC   r  rS   s    r&   isDiatonicStepzGenericInterval.isDiatonicStep  s     !##r%   c                    | j                   S )a:  
        Return True if this interval is a step (a second).
        A synonym for `isDiatonicStep` for generic intervals.

        >>> interval.GenericInterval(2).isStep
        True
        >>> interval.GenericInterval(1).isStep
        False
        >>> interval.GenericInterval(-9).isStep
        False
        )r  rS   s    r&   isStepzGenericInterval.isStep  s     """r%   c                     | j                   dk(  S )zt
        Returns True if this interval is a Unison.

        Note that Unisons are neither steps nor skips.
        r   r  rS   s    r&   isUnisonzGenericInterval.isUnison  s     !##r%   c                T    t        | j                  d      \  }}|dk(  r|dz  }d}||fS )zF
        Returns simpleUndirectedSteps and undirectedOctaves.
        rH   r   r   )r   r  )rT   r   stepss      r&   _simpleStepsAndOctavesz&GenericInterval._simpleStepsAndOctaves'  s7      3A:qLGEg~r%   c                     | j                   d   S )z
        Return the undirected distance within an octave

        >>> interval.GenericInterval('Descending Ninth').simpleUndirected
        2
        >>> interval.GenericInterval(8).simpleUndirected
        1
        r   r  rS   s    r&   simpleUndirectedz GenericInterval.simpleUndirected3  s     **1--r%   c                H    | j                   }| j                  dk\  r|dk(  ry|S )a  
        Same as simpleUndirected, but allows octaves and double octaves, etc.
        to remain 8, which is useful for a
        number of parallel octave vs. unison routines.

        >>> interval.GenericInterval('Descending Ninth').semiSimpleUndirected
        2
        >>> interval.GenericInterval(8).semiSimpleUndirected
        8
        >>> interval.GenericInterval(-15).semiSimpleUndirected
        8
        r   rI   )r  undirectedOctavesrT   r  s     r&   semiSimpleUndirectedz$GenericInterval.semiSimpleUndirected?  s/      00!!Q&+;q+@##r%   c                     | j                   d   S )aw  
        Returns the number of octaves (without direction) for an interval

        >>> interval.GenericInterval(5).undirectedOctaves
        0
        >>> interval.GenericInterval('Descending Ninth').undirectedOctaves
        1
        >>> interval.GenericInterval(8).undirectedOctaves
        1
        >>> interval.GenericInterval(-15).undirectedOctaves
        2
        r   r  rS   s    r&   r  z!GenericInterval.undirectedOctavesS  s     **1--r%   c                b    | j                   }| j                  t        j                  k(  rd|z  S |S )a<  
        Return the number of octaves with direction.

        >>> interval.GenericInterval(5).octaves
        0
        >>> interval.GenericInterval('Descending Ninth').octaves
        -1
        >>> interval.GenericInterval(8).octaves
        1
        >>> interval.GenericInterval(-15).octaves
        -2
        r   )r  r   r   r!   )rT   r  s     r&   r   zGenericInterval.octavesc  s4     !22>>Y111)))$$r%   c                l    | j                   }| j                  t        j                  k(  r
|dkD  rd|z  S |S )a  
        Return the directed distance within an octave

        >>> interval.GenericInterval('Descending Ninth').simpleDirected
        -2
        >>> interval.GenericInterval(8).simpleDirected
        1
        >>> interval.GenericInterval(-8).simpleDirected
        1
        r   r   )r  r   r   r!   r  s     r&   simpleDirectedzGenericInterval.simpleDirectedw  s<      00>>Y1116F6J(((##r%   c                l    | j                   }| j                  t        j                  k(  r
|dkD  rd|z  S |S )a  
        Return the same as semiSimpleUndirected but with descending intervals
        as a negative number

        >>> interval.GenericInterval('Descending Ninth').semiSimpleDirected
        -2
        >>> interval.GenericInterval(8).semiSimpleDirected
        8
        >>> interval.GenericInterval(-15).semiSimpleDirected
        -8
        >>> interval.GenericInterval(-8).semiSimpleDirected
        -8
        r   r   )r  r   r   r!   )rT   r  s     r&   semiSimpleDirectedz"GenericInterval.semiSimpleDirected  s<      $88>>Y1116JQ6N,,,''r%   c                    | j                   dv S )aU  
        Returns True if the interval might represent a perfect interval,
        that is, it is a Generic 4th, 5th, or unison/octave

        >>> interval.GenericInterval(4).perfectable
        True
        >>> interval.GenericInterval(-12).perfectable
        True
        >>> interval.GenericInterval(3).perfectable
        False
        )r   rE   rF   )r  rS   s    r&   perfectablezGenericInterval.perfectable  s     $$	11r%   c                    	 t         j                  j                  |   S # t        $ r. t	        |      t         j                  j                  |      z   cY S w xY wrN   )r   r   musicOrdinals
IndexErrorrO   ordinalAbbreviation)rT   keyVals     r&   _nameFromIntzGenericInterval._nameFromInt  sP    	P%%33F;; 	Pv;!3!3!G!G!OOO	Ps    4AAc                8    | j                  | j                        S )a  
        Return the niceName as a string for this Interval

        >>> interval.GenericInterval(4).niceName
        'Fourth'
        >>> interval.GenericInterval(-12).niceName
        'Twelfth'
        >>> interval.GenericInterval(3).niceName
        'Third'

        Extremely large intervals get displayed as abbreviations

        >>> interval.GenericInterval(44).niceName
        '44th'

        * Changed in v6: large numbers get the 'th' or 'rd' etc. suffix.
        )r*  r  rS   s    r&   r]   zGenericInterval.niceName  s    &   11r%   c                8    | j                  | j                        S )a+  
        Return the niceName as a string for this Interval's simple form

        >>> interval.GenericInterval(4).simpleNiceName
        'Fourth'
        >>> interval.GenericInterval(-12).simpleNiceName
        'Fifth'
        >>> interval.GenericInterval(8).simpleNiceName
        'Unison'
        )r*  r  rS   s    r&   simpleNiceNamezGenericInterval.simpleNiceName  s       !6!677r%   c                8    | j                  | j                        S )a;  
        Return the niceName as a string for this Interval's semiSimple form

        >>> interval.GenericInterval(4).semiSimpleNiceName
        'Fourth'
        >>> interval.GenericInterval(-12).semiSimpleNiceName
        'Fifth'
        >>> interval.GenericInterval(8).semiSimpleNiceName
        'Octave'
        )r*  r  rS   s    r&   semiSimpleNiceNamez"GenericInterval.semiSimpleNiceName  s       !:!:;;r%   c                8    | j                   }|dkD  r|dz
  S |dz   S )a  
        Return the number of spaces/stafflines that this
        interval represents.  A unison is 0, an ascending second is 1,
        a descending third is -2, etc.

        Useful for interval arithmetic

        >>> interval.GenericInterval('Ascending Third').staffDistance
        2
        >>> interval.GenericInterval(-8).staffDistance
        -7
        >>> interval.GenericInterval(1).staffDistance
        0
        r   r   )r   )rT   r   s     r&   staffDistancezGenericInterval.staffDistance  s(      ==a<a<a<r%   c                     d| j                   z
  S )a  
        Return the inversion of this interval within an octave.
        For instance, seconds become sevenths, octaves become unisons,
        and vice versa.

        All are undirected intervals.

        >>> interval.GenericInterval(4).mod7inversion
        5
        >>> interval.GenericInterval('Descending Octave').mod7inversion
        1
        >>> interval.GenericInterval(9).mod7inversion
        7
        rJ   )r  rS   s    r&   mod7inversionzGenericInterval.mod7inversion  s      4,,,,r%   c                l    | j                   t        j                  k(  r| j                  S | j                  S )a  
        Return this interval as a number 1-7, that is, within an octave,
        but unlike simpleDirected or simpleUndirected, turn descending
        seconds into sevenths, etc.  Used for calculating step names.

        For instance, going down a step from C, or GenericInterval(-2),
        would give a B, which is the same as GenericInterval(7) (not counting
        octaves), but going up a step from C, or GenericInterval(2) is D, which
        is the same as going up a 9th.

        >>> interval.GenericInterval(-2).mod7
        7
        >>> interval.GenericInterval(2).mod7
        2
        >>> interval.GenericInterval(9).mod7
        2
        >>> interval.GenericInterval('Unison').mod7
        1
        >>> interval.GenericInterval('Descending Octave').mod7
        1
        >>> interval.GenericInterval(15).mod7
        1

        See :meth:`music21.chord.Chord.semitonesFromChordStep` for a place
        this is used.
        )r   r   r!   r3  r   rS   s    r&   mod7zGenericInterval.mod7  s.    8 >>Y111%%%&&&r%   c                ,    t        | j                        S )a  
        Returns a new GenericInterval object where 3rds are 6ths, etc.

        >>> third = interval.GenericInterval('Third')
        >>> third.complement()
        <music21.interval.GenericInterval 6>

        Note that currently direction is lost after a complement relationship:

        >>> fourth = interval.GenericInterval(-4)
        >>> fourthComp = fourth.complement()
        >>> fourthComp
        <music21.interval.GenericInterval 5>
        >>> fourthComp.directed
        5

        Called more than once, this may return the exact identical object:

        >>> fourthComp.complement() is fourthComp.complement()
        True
        )r   r3  rS   s    r&   
complementzGenericInterval.complement/  s    . t1122r%   c                    | j                   dk(  rt        d      S t        | j                   d| j                  z  z        S )a>  
        Returns a new GenericInterval object that is inverted.

        >>> aInterval = interval.GenericInterval('Third')
        >>> aInterval.reverse()
        <music21.interval.GenericInterval -3>

        >>> aInterval = interval.GenericInterval(-13)
        >>> aInterval.direction
        <Direction.DESCENDING: -1>
        >>> aInterval.reverse()
        <music21.interval.GenericInterval 13>

        Unisons invert to unisons

        >>> aInterval = interval.GenericInterval(1)
        >>> aInterval.reverse()
        <music21.interval.GenericInterval 1>
        r   r   )r  r   r   rS   s    r&   r   zGenericInterval.reverseH  s8    ( ??a"1%%"4??b4>>6I#JKKr%   Fr   c                   |j                   d}nd}|j                  }|r|}nt        j                  |      }|| j                  z   |_        |rd|_         |s|S y)a?  
        transpose a pitch, retaining the accidental if any.

        >>> aPitch = pitch.Pitch('g4')
        >>> genericFifth = interval.GenericInterval(5)
        >>> bPitch = genericFifth.transposePitch(aPitch)
        >>> bPitch
        <music21.pitch.Pitch D5>

        If inPlace is True then applied to the current pitch:

        >>> gPitch = pitch.Pitch('g4')
        >>> genericFifth = interval.GenericInterval(5)
        >>> genericFifth.transposePitch(gPitch, inPlace=True)
        >>> gPitch
        <music21.pitch.Pitch D5>

        A generic interval transformation retains accidentals:

        >>> a2 = pitch.Pitch('B-')
        >>> cPitch = genericFifth.transposePitch(a2)
        >>> cPitch
        <music21.pitch.Pitch F->
        >>> a2.octave == cPitch.octave
        True

        Can be done inPlace as well, in which case, nothing is returned:

        >>> gSharp = pitch.Pitch('g#4')
        >>> genericFifth = interval.GenericInterval(5)
        >>> genericFifth.transposePitch(gSharp, inPlace=True)
        >>> gSharp
        <music21.pitch.Pitch D#5>
        NTF)r   diatonicNoteNumr   r   r1  )rT   pr   useImplicitOctavepitchDNNr   s         r&   r   zGenericInterval.transposePitcha  sf    F 88 $ %$$H}}Q'H#+d.@.@#@ "HOO r%   c                  ddl m} || j                  ||      S |j                  |j                        }||j
                  nd}|j                  |j                  j
                  nd}||z
  }| j                  ||      }	|r|}	|j                  |	j                        }
|
|
j
                  nd}||z   }|dk7  r |j                  |      |	_        n|	j                  d|	_        |s|	S y)a
  
        Transposes a pitch while remaining aware of its key context,
        for modal transposition:

        If k is None, works the same as `.transposePitch`:

        >>> aPitch = pitch.Pitch('g4')
        >>> genericFifth = interval.GenericInterval(5)
        >>> bPitch = genericFifth.transposePitchKeyAware(aPitch, None)
        >>> bPitch
        <music21.pitch.Pitch D5>

        But if a key or keySignature (such as one from `.getContextByClass(key.KeySignature)`)
        is given, then the fun begins:

        >>> fis = pitch.Pitch('F#4')
        >>> e = pitch.Pitch('E')
        >>> gMaj = key.Key('G')
        >>> genericStep = interval.GenericInterval('second')
        >>> genericStep.transposePitchKeyAware(fis, gMaj)
        <music21.pitch.Pitch G4>
        >>> genericStep.transposePitchKeyAware(e, gMaj)
        <music21.pitch.Pitch F#>

        If a pitch already has an accidental that contradicts the current
        key, the difference between that pitch and the new key is applied
        to the new pitch:

        >>> fNat = pitch.Pitch('F4')
        >>> genericStep.transposePitchKeyAware(fNat, gMaj)
        <music21.pitch.Pitch G-4>

        inPlace should work:

        >>> genericStep.transposePitchKeyAware(fis, gMaj, inPlace=True)
        >>> fis
        <music21.pitch.Pitch G4>

        This is used for Stream.transpose when a GenericInterval is given:

        >>> s = converter.parse('tinyNotation: 4/4 d4 e f f# g1 a-4 g b- a c1')
        >>> s.measure(1).insert(0, key.Key('G'))
        >>> s.measure(3).insert(0, key.Key('c'))
        >>> s2 = s.transpose(interval.GenericInterval(2))
        >>> s2.show('text')
        {0.0} <music21.stream.Measure 1 offset=0.0>
            {0.0} <music21.clef.TrebleClef>
            {0.0} <music21.key.Key of G major>
            {0.0} <music21.meter.TimeSignature 4/4>
            {0.0} <music21.note.Note E>
            {1.0} <music21.note.Note F#>
            {2.0} <music21.note.Note G->
            {3.0} <music21.note.Note G>
        {4.0} <music21.stream.Measure 2 offset=4.0>
            {0.0} <music21.note.Note A>
        {8.0} <music21.stream.Measure 3 offset=8.0>
            {0.0} <music21.key.Key of c minor>
            {0.0} <music21.note.Note B->
            {1.0} <music21.note.Note A->
            {2.0} <music21.note.Note C>
            {3.0} <music21.note.Note B>
        {12.0} <music21.stream.Measure 4 offset=12.0>
            {0.0} <music21.note.Note D>
            {4.0} <music21.bar.Barline type=final>

        Does not take into account harmonic or melodic minor.
        r   r   Nr   )music21r   r   accidentalByStepstepalter
accidental
Accidental)rT   r;  kr   r   r@  	stepAlterpAlteroffsetFromKeyr   newAccidentalByStepnewStepAlternewPitchAlters                r&   transposePitchKeyAwarez&GenericInterval.transposePitchKeyAware  s    T 	"9&&q'&::--aff5.>.J$**PQ	'(||'?##Q*&&q'&:H00?4G4S*00YZ$}4A"2%"2"2="AH  ,"&HO r%   c                    t        ||       S )aI  
        Given a specifier, return a :class:`~music21.interval.DiatonicInterval` object.

        Specifier should be provided as an `interval.Specifier` enumeration or
        a string name, such as 'dd', 'M', or 'perfect'.

        >>> third = interval.GenericInterval('Third')
        >>> third.getDiatonic(interval.Specifier.MAJOR)
        <music21.interval.DiatonicInterval M3>
        >>> third.getDiatonic('minor')
        <music21.interval.DiatonicInterval m3>
        >>> third.getDiatonic('d')
        <music21.interval.DiatonicInterval d3>
        >>> third.getDiatonic(interval.Specifier.TRPAUG)
        <music21.interval.DiatonicInterval AAA3>

        Old in, specifier values are also allowed

        >>> third.getDiatonic(2)
        <music21.interval.DiatonicInterval M3>

        >>> fifth = interval.GenericInterval('fifth')
        >>> fifth.getDiatonic('perfect')
        <music21.interval.DiatonicInterval P5>

        >>> fifth.getDiatonic('major')
        Traceback (most recent call last):
        music21.interval.IntervalException: Cannot create a 'Major Fifth'
        )DiatonicInterval)rT   r   s     r&   getDiatoniczGenericInterval.getDiatonic  s    <  	400r%   )Unison)rR   	int | strrq   rQ   )r  rQ   rq   r   rq   r   )rq   ztuple[int, int])r)  rQ   rq   rO   rp   rq   r   r;  r   rN   )r;  r   rE  zkey.KeySignature | Noner   r   )r   zSpecifier | strrq   rN  )(r   r   r    rr   r   r   r   r   r~   rR   setterr   r  r   r  r  r  r  r  r  r  r  r   r   r"  r$  r*  r]   r-  r/  r1  r3  r5  r   r7  r   r   rL  rO  __classcell__r   s   @r&   r   r     sz   xt #+++">   \\    __    ' '* # # $ $  # # $ $ 	 	 	. 	. $ $& . . % %& $ $" ( (( 2 2P 2 2( 8 8 < <    * - -" ' 'B 3 30L2 9> 3p $(b
 bb !b
 bH1r%   r   c                      e Zd ZU dZdddZded<   	 	 d&	 	 	 d' fdZd(dZd	 Zd
 Z	e
d(d       Ze
d(d       Ze
d(d       Ze
d(d       Ze
d(d       Ze
d(d       Ze
d(d       Ze
d)d       Ze
d(d       Ze
d(d       Ze
d(d       Ze
d(d       Ze
d(d       Ze
d(d       Ze
d*d       Ze
d*d       Ze
d*d       Ze
d*d       Ze
d(d       Ze
d(d       Zd+dZd,d Z d!d"d-d#Z!e
d(d$       Z"e
d.d%       Z# xZ$S )/rN  a  
    A class representing a diatonic interval. Two required arguments are a string `specifier`
    (such as perfect, major, or minor) and `generic`, either an int
    of an interval size (such as 2, 2nd, or second) or a
    :class:`~music21.interval.GenericInterval` object.

    Two DiatonicIntervals are the same if their GenericIntervals
    are the same and their specifiers are the same and they should be
    if their directions are the same, but this is not checked yet.

    The `specifier` is an enumeration/Specifier object.

    The `generic` is an integer or GenericInterval instance.

    >>> unison = interval.DiatonicInterval(interval.Specifier.PERFECT, 1)
    >>> unison
    <music21.interval.DiatonicInterval P1>
    >>> unison.simpleName
    'P1'
    >>> unison.specifier
    <Specifier.PERFECT>
    >>> unison.generic
    <music21.interval.GenericInterval 1>
    >>> unison.direction
    <Direction.OBLIQUE: 0>

    The first value can be a string:

    >>> major3a = interval.DiatonicInterval('major', 3)
    >>> major3a.simpleName
    'M3'
    >>> major3a.niceName
    'Major Third'
    >>> major3a.semiSimpleName
    'M3'
    >>> major3a.directedSimpleName
    'M3'
    >>> major3a.mod7inversion
    'm6'

    Or the first attribute can be a string abbreviation
    (not case sensitive, except Major vs. minor):

    >>> major3b = interval.DiatonicInterval('M', 3)
    >>> major3b.niceName
    'Major Third'

    A string can be given for the second argument (generic interval):

    >>> major3c = interval.DiatonicInterval('major', 'third')
    >>> major3c.niceName
    'Major Third'

    >>> p8 = interval.DiatonicInterval('perfect', 'octave')
    >>> p8.niceName
    'Perfect Octave'

    >>> genericTenth = interval.GenericInterval(10)
    >>> minor10 = interval.DiatonicInterval('m', genericTenth)
    >>> minor10.mod7
    'm3'
    >>> minor10.isDiatonicStep
    False
    >>> minor10.isStep
    False

    >>> aInterval = interval.DiatonicInterval('major', 2)
    >>> aInterval.isDiatonicStep
    True
    >>> aInterval.isStep
    True

    >>> augAscending = interval.DiatonicInterval('augmented', 1)
    >>> augAscending
    <music21.interval.DiatonicInterval A1>
    >>> augAscending.isDiatonicStep
    False
    >>> augAscending.isStep  # TODO: should this be True???
    False
    >>> augAscending.directedNiceName
    'Ascending Augmented Unison'

    For Augmented Unisons, the diatonic interval is ascending while the `.generic` is oblique:

    >>> augAscending.direction
    <Direction.ASCENDING: 1>
    >>> augAscending.generic.direction
    <Direction.OBLIQUE: 0>

    >>> dimDescending = augAscending.reverse()
    >>> dimDescending
    <music21.interval.DiatonicInterval d1>
    >>> dimDescending.directedNiceName
    'Descending Diminished Unison'
    >>> dimDescending.direction
    <Direction.DESCENDING: -1>

    This raises an error:

    >>> interval.DiatonicInterval('Perfect', -1)
    Traceback (most recent call last):
    music21.interval.IntervalException: There is no such thing as a descending Perfect Unison
    zUA :class:`~music21.interval.Specifier` enum representing the Quality of the interval.zTA :class:`~music21.interval.GenericInterval` enum representing the general interval.)r   r   zdict[str, str]	_DOC_ATTRc                   t        |   di | |  |  t        |t              r|| _        nDt        j                  |      st        |t              rt        |      | _        nt        d|      t        |      | _
        | j                  t        j                  t        j                  fv r| j                  j                  s3| j                  t        j                  k(  rP| j                  j                  s:t        d| j                  j                    d| j                  j                    d      | j                  t        j                  k(  r%| j                  j"                  dk(  rt        d      y y )Nzincorrect generic argument: zCannot create a ' 'r   z5There is no such thing as a descending Perfect Unisonr$   )r   r   r   r   r   r   isIntrO   rh   r   r   rB   rt   ru   r$  rs   r]   rR   )rT   r   r   r   r   s       r&   r   zDiatonicInterval.__init__  s#    	$8$g/"DL\\'"j#&>*73DL $&B7+$NOO (	2^^	AAdllF^F^NNi&7&77@X@X##DNN$;$;#<Adll>S>S=TTUV  >>Y...4<<3E3E3K#$[\\ 4L.r%   c                    | j                   S rN   rX   rS   s    r&   r   zDiatonicInterval._reprInternal  s    yyr%   c                    t        |d      syt        |d      sy| j                  |j                  k(  r3| j                  |j                  k(  r| j                  |j                  k(  ryy)a.  
        True if generic, specifier, and direction are the same.

        >>> a = interval.DiatonicInterval('major', 3)
        >>> b = interval.DiatonicInterval('minor', 3)
        >>> c = interval.DiatonicInterval('major', 3)
        >>> d = interval.DiatonicInterval('diminished', 4)
        >>> a == b
        False
        >>> a == c
        True
        >>> a == d
        False
        >>> e = interval.DiatonicInterval('d', 4)
        >>> d == e
        True

        Intervals do not compare to strings:

        >>> e == 'd4'
        False
        r   Fr   T)r;   r   r   r   r   s     r&   r   zDiatonicInterval.__eq__  sV    . ui(,
 LLEMM)%//1NNeoo5r%   c                    t        |       dz	  S r   r   rS   s    r&   r   zDiatonicInterval.__hash__  r   r%   c                l    t        | j                        t        | j                  j                        z   S )z
        The name of the interval in abbreviated form without direction.

        >>> interval.DiatonicInterval('Perfect', 'Fourth').name
        'P4'
        >>> interval.DiatonicInterval(interval.Specifier.MAJOR, -6).name
        'M6'
        )rO   r   r   r  rS   s    r&   rY   zDiatonicInterval.name  s'     4>>"S)@)@%AAAr%   c                b    | j                   j                  dz   | j                  j                  z   S )z
        Return the full form of the name of a Diatonic interval

        >>> interval.DiatonicInterval('P', 4).niceName
        'Perfect Fourth'
        r]  )r   r]   r   rS   s    r&   r]   zDiatonicInterval.niceName  s(     ~~&&,t||/D/DDDr%   c                .    | j                   j                  S )z
        Same as `.specifier.niceName` -- the nice name of the specifier alone

        >>> p12 = interval.DiatonicInterval('P', -12)
        >>> p12.specificName
        'Perfect'
        )r   r]   rS   s    r&   specificNamezDiatonicInterval.specificName  s     ~~&&&r%   c                l    t        | j                        t        | j                  j                        z   S )z
        Return the name of a Diatonic interval removing octaves

        >>> interval.DiatonicInterval('Augmented', 'Twelfth').simpleName
        'A5'
        )rO   r   r   r  rS   s    r&   
simpleNamezDiatonicInterval.simpleName  s'     4>>"S)F)F%GGGr%   c                b    | j                   j                  dz   | j                  j                  z   S )z
        Return the full name of a Diatonic interval, simplifying octaves

        >>> interval.DiatonicInterval('d', 14).simpleNiceName
        'Diminished Seventh'
        r]  )r   r]   r   r-  rS   s    r&   r-  zDiatonicInterval.simpleNiceName  s(     ~~&&,t||/J/JJJr%   c                l    t        | j                        t        | j                  j                        z   S )aX  
        Return the name of a Diatonic interval removing octaves except that
        octaves (and double octaves) themselves are 8 instead of 1

        >>> interval.DiatonicInterval('Augmented', 'Twelfth').semiSimpleName
        'A5'
        >>> interval.DiatonicInterval('Diminished', 'Descending Octave').semiSimpleName
        'd8'
        )rO   r   r   r  rS   s    r&   semiSimpleNamezDiatonicInterval.semiSimpleName	  s'     4>>"S)J)J%KKKr%   c                b    | j                   j                  dz   | j                  j                  z   S )a  
        Return the full name of a Diatonic interval removing octaves except that
        octaves (and double octaves) themselves are 8 instead of 1

        >>> interval.DiatonicInterval('Augmented', 'Twelfth').semiSimpleNiceName
        'Augmented Fifth'
        >>> interval.DiatonicInterval('Diminished', 'Descending Octave').semiSimpleNiceName
        'Diminished Octave'
        r]  )r   r]   r   r/  rS   s    r&   r/  z#DiatonicInterval.semiSimpleNiceName  s(     ~~&&,t||/N/NNNr%   c                   | j                   j                  dk7  r| j                   j                  S | j                  t        j
                  k(  r| j                   j                  S t        j                  | j                        t        j                  t        j                        k  rt        j                  S t        j                  S )a  
        The direction of the DiatonicInterval:

        >>> interval.DiatonicInterval('Augmented', 'Twelfth').direction
        <Direction.ASCENDING: 1>

        >>> interval.DiatonicInterval('M', -2).direction
        <Direction.DESCENDING: -1>

        >>> interval.DiatonicInterval('P', 1).direction
        <Direction.OBLIQUE: 0>

        In the absence of other evidence, assumes that augmented unisons are
        ascending and diminished unisons are descending:

        >>> interval.DiatonicInterval('d', 1).direction
        <Direction.DESCENDING: -1>

        >>> interval.DiatonicInterval('A', 1).direction
        <Direction.ASCENDING: 1>

        Note that in the case of non-perfect unisons/primes, the `.generic.direction`
        will be `OBLIQUE` while the diatonic direction may be ASCENDING, DESCENDING,
        or OBLIQUE.

        >>> interval.DiatonicInterval('A', 1).generic.direction
        <Direction.OBLIQUE: 0>

        r   )r   r  r   r   rB   rs   perfSpecifiersr   rw   r   r!   r#   rS   s    r&   r   zDiatonicInterval.direction#  s    > <<""a'<<)))>>Y...<<))) />3G3G	H\H\3]]'''&&&r%   c                l    t        | j                        t        | j                  j                        z   S )z
        The name of the interval in abbreviated form with direction.

        >>> interval.DiatonicInterval('Minor', -6).directedName
        'm-6'
        )rO   r   r   r   rS   s    r&   directedNamezDiatonicInterval.directedNameP  s'     4>>"S)>)>%???r%   c                H    t         | j                     dz   | j                  z   S )a.  
        The name of the interval in full form with direction.

        >>> interval.DiatonicInterval('P', 11).directedNiceName
        'Ascending Perfect Eleventh'
        >>> interval.DiatonicInterval('Diminished', 'Descending Octave').directedNiceName
        'Descending Diminished Octave'
        r]  )r   r   r]   rS   s    r&   directedNiceNamez!DiatonicInterval.directedNiceNameZ  s!     dnn-3dmmCCr%   c                l    t        | j                        t        | j                  j                        z   S )z
        The name of the interval in abbreviated form with direction, reduced to one octave

        >>> interval.DiatonicInterval('Minor', -14).directedSimpleName
        'm-7'
        )rO   r   r   r   rS   s    r&   directedSimpleNamez#DiatonicInterval.directedSimpleNamef  s'     4>>"S)D)D%EEEr%   c                H    t         | j                     dz   | j                  z   S )aL  
        The name of the interval, reduced to within an octave, in full form with direction.

        >>> interval.DiatonicInterval('P', 11).directedNiceName
        'Ascending Perfect Eleventh'
        >>> interval.DiatonicInterval('Diminished', 'Descending Octave').directedNiceName
        'Descending Diminished Octave'
        r]  )r   r   r-  rS   s    r&   directedSimpleNiceNamez'DiatonicInterval.directedSimpleNiceNamep  s#     dnn-3d6I6IIIr%   c                l    t        | j                        t        | j                  j                        z   S )a>  
        The name of the interval in abbreviated form with direction, reduced to one octave,
        except for octaves themselves

        >>> interval.DiatonicInterval('Minor', -14).directedSemiSimpleName
        'm-7'
        >>> interval.DiatonicInterval('P', 'Octave').directedSemiSimpleName
        'P8'
        )rO   r   r   r"  rS   s    r&   directedSemiSimpleNamez'DiatonicInterval.directedSemiSimpleName|  s'     4>>"S)H)H%IIIr%   c                H    t         | j                     dz   | j                  z   S )a@  
        The name of the interval in full form with direction.

        >>> interval.DiatonicInterval('P', 11).directedSemiSimpleNiceName
        'Ascending Perfect Fourth'
        >>> interval.DiatonicInterval('Diminished', 'Descending Octave').directedSemiSimpleNiceName
        'Descending Diminished Octave'
        r]  )r   r   r/  rS   s    r&   directedSemiSimpleNiceNamez+DiatonicInterval.directedSemiSimpleNiceName  s#     dnn-3d6M6MMMr%   c                .    | j                   j                  S )z
        Same as GenericInterval.isStep and .isDiatonicStep

        >>> interval.DiatonicInterval('M', 2).isStep
        True
        >>> interval.DiatonicInterval('P', 5).isStep
        False
        )r   r  rS   s    r&   r  zDiatonicInterval.isStep       ||"""r%   c                .    | j                   j                  S )z
        Same as GenericInterval.isDiatonicStep and .isStep

        >>> interval.DiatonicInterval('M', 2).isDiatonicStep
        True
        >>> interval.DiatonicInterval('P', 5).isDiatonicStep
        False
        )r   r  rS   s    r&   r  zDiatonicInterval.isDiatonicStep  s     ||***r%   c                .    | j                   j                  S )z
        Same as GenericInterval.isSkip

        >>> interval.DiatonicInterval('M', 2).isSkip
        False
        >>> interval.DiatonicInterval('P', 5).isSkip
        True
        )r   r  rS   s    r&   r  zDiatonicInterval.isSkip  r|  r%   c                .    | j                   j                  S )a  
        Is the generic component of this interval able to be made perfect?
        That is, is this a type of unison, fourth, fifth, or octave (or larger
        component).

        Note that this does not ask if THIS interval is perfect.  A diminished
        fifth is not perfect, but as a fifth it is perfectable.

        An augmented seventh sounds like a perfect octave but no seventh can
        ever be perfect.

        >>> interval.DiatonicInterval('M', 2).perfectable
        False
        >>> interval.DiatonicInterval('P', 12).perfectable
        True
        >>> interval.DiatonicInterval('A', 12).perfectable
        True
        )r   r$  rS   s    r&   r$  zDiatonicInterval.perfectable  s    ( ||'''r%   c                    t        | j                  j                               t        | j                  j                        z   S )a-  
        Return an inversion of the interval within an octave, losing
        direction.  Returns as a string.

        >>> interval.DiatonicInterval('M', 2).mod7inversion
        'm7'
        >>> interval.DiatonicInterval('A', 4).mod7inversion
        'd5'
        >>> interval.DiatonicInterval('P', 1).mod7inversion
        'P8'

        Everything is within an octave:

        >>> interval.DiatonicInterval('M', 9).mod7inversion
        'm7'

        Direction is lost:

        >>> interval.DiatonicInterval('d', -3).mod7inversion
        'A6'
        )rO   r   ra   r   r3  rS   s    r&   r3  zDiatonicInterval.mod7inversion  s0    . 4>>++-.T\\5O5O1PPPr%   c                l    | j                   t        j                  k(  r| j                  S | j                  S )a`  
        Return this interval as string of a specifier followed by a number 1-7,
        representing a diatonic interval within an octave,
        but unlike simpleDirected or simpleUndirected, turns descending
        seconds into sevenths, etc.

        For instance, going down a minor second from C
        would give a B, which is the same as going up a major seventh to B.

        This method gives a string representing a diatonic interval that
        will reach the same note as this DiatonicInterval but within an octave
        up from the basic note.

        >>> interval.DiatonicInterval('m', -2).mod7
        'M7'
        >>> interval.DiatonicInterval('m', 2).mod7
        'm2'
        >>> interval.DiatonicInterval('M', 9).mod7
        'M2'
        >>> interval.DiatonicInterval('Perfect', 'Unison').mod7
        'P1'
        >>> interval.DiatonicInterval('Perfect', 'Descending Octave').mod7
        'P1'
        >>> interval.DiatonicInterval(interval.Specifier.AUGMENTED, -4).mod7
        'd5'

        See :meth:`music21.chord.Chord.semitonesFromChordStep` for a place
        this is used.
        )r   r   r!   r3  rh  rS   s    r&   r5  zDiatonicInterval.mod7  s,    > >>Y111%%%??"r%   c                    | j                   j                  dk(  r$t        | j                  j	                         d      S t        | j                  | j                   j                               S )a   
        Return a :class:`~music21.interval.DiatonicInterval` that is
        an inversion of this Interval.

        >>> aInterval = interval.DiatonicInterval('major', 3)
        >>> aInterval.reverse().directedName
        'M-3'

        >>> aInterval = interval.DiatonicInterval('augmented', 5)
        >>> aInterval.reverse().directedName
        'A-5'

        (Ascending) Augmented Unisons reverse to (Descending)
        Diminished Unisons and vice versa

        >>> aug1 = interval.DiatonicInterval('augmented', 1)
        >>> aug1.direction
        <Direction.ASCENDING: 1>
        >>> aug1.directedName
        'A1'
        >>> dimUnison = aug1.reverse()
        >>> dimUnison.directedName
        'd1'
        >>> dimUnison.directedNiceName
        'Descending Diminished Unison'
        r   )r   r   rN  r   ra   r   rS   s    r&   r   zDiatonicInterval.reverse  sS    6 <<  A%#DNN$<$<$>BB#DNN$(LL$8$8$:< <r%   c                   t        t        | j                  j                        dz        }t        | j                  j
                     }| j                  j                  r| j                  j                         }n| j                  j                         }|dz  |z   |z   }| j                  j                  t        j                  k(  r|dz  }t        |      S )a  
        Return a :class:`music21.interval.ChromaticInterval`
        based on the size of this Interval.

        >>> aInterval = interval.DiatonicInterval('major', 'third')
        >>> aInterval.niceName
        'Major Third'
        >>> aInterval.getChromatic()
        <music21.interval.ChromaticInterval 4>

        >>> aInterval = interval.DiatonicInterval('augmented', -5)
        >>> aInterval.niceName
        'Augmented Fifth'
        >>> aInterval.getChromatic()
        <music21.interval.ChromaticInterval -8>

        >>> aInterval = interval.DiatonicInterval('minor', 'second')
        >>> aInterval.niceName
        'Minor Second'
        >>> aInterval.getChromatic()
        <music21.interval.ChromaticInterval 1>
        rH   r   r   )rQ   r   r   r1  semitonesGenericr  r$  r   rk   ro   r   r   r!   ChromaticInterval)rT   octaveOffsetsemitonesStartsemitonesAdjustr   s        r&   getChromaticzDiatonicInterval.getChromatic4  s    4 3t||99:Q>?)$,,*G*GH<<##"nnBBDO #nn@@BO!B&.8?J	<<!!Y%9%99OI ++r%   Fr   c               ^    t        | | j                               }|j                  ||      S )a  
        Calls transposePitch from a full interval object.

        This is not particularly optimized since it
        requires creating both a ChromaticInterval
        object and a full Interval object. But it's here for completeness.

        >>> di = interval.DiatonicInterval('P', 11)
        >>> p = pitch.Pitch('C#4')
        >>> di.transposePitch(p)
        <music21.pitch.Pitch F#5>

        Previous pitch was unchanged.  inPlace=True changes that.

        >>> p
        <music21.pitch.Pitch C#4>
        >>> di.transposePitch(p, inPlace=True)
        >>> p
        <music21.pitch.Pitch F#5>

        * Changed in v6: added inPlace.
        diatonic	chromaticr   )r   r  r   )rT   r;  r   fullIntervalObjects       r&   r   zDiatonicInterval.transposePitch_  s0    0 &tt?P?P?RS!00G0DDr%   c                (    t         | j                     S )z
        Returns the abbreviation for the specifier.

        >>> i = interval.Interval('M-10')
        >>> d = i.diatonic
        >>> d.specifierAbbreviation
        'M'
        )rP   r   rS   s    r&   specifierAbbreviationz&DiatonicInterval.specifierAbbreviationz  s     4>>**r%   c                @    | j                         }|r|j                  S y)a  
        Return the number of cents in this interval.  Returns a float,
        always assuming an equal-tempered presentation.

        >>> i = interval.DiatonicInterval('minor', 'second')
        >>> i.niceName
        'Minor Second'
        >>> i.cents
        100.0
        g        )r  r   )rT   cs     r&   r   zDiatonicInterval.cents  s!     77Nr%   )r0   r   )r   z	str | intr   zint | GenericInterval | strrp   rS  rT  rq   rN  rq   r  rV  rq   float)%r   r   r    rr   r[  __annotations__r   r   r   r   r~   rY   r]   rf  rh  r-  rk  r/  r   rp  rr  rt  rv  rx  rz  r  r  r  r$  r3  r5  r   r  r   r  r   rX  rY  s   @r&   rN  rN    s=   fP6-!I~  '*45]#]1]<$L 	B 	B E E ' ' H H K K 
L 
L 
O 
O *' *'X @ @ 	D 	D F F 	J 	J 
J 
J 	N 	N 	# 	# 	+ 	+ 	# 	# ( (* Q Q2 !# !#P<B),V 9> E6 	+ 	+  r%   rN  c                      e Zd ZdZdd fdZddZd Zd Zedd       Z	edd       Z
edd       Zedd	       Zedd
       Zedd       Zedd       Zedd       Zedd       Zedd       ZddZddZddddZ xZS ) r  a  
    Chromatic interval class. Unlike a :class:`~music21.interval.DiatonicInterval`,
    this IntervalBase subclass treats interval spaces in half-steps.
    So Major 3rd and Diminished 4th are the same.

    Two ChromaticIntervals are equal if their size and direction are equal.

    >>> aInterval = interval.ChromaticInterval(-14)
    >>> aInterval.semitones
    -14
    >>> aInterval.undirected
    14
    >>> aInterval.mod12
    10
    >>> aInterval.intervalClass
    2
    >>> aInterval.isChromaticStep
    False
    >>> aInterval.isStep
    False

    >>> aInterval = interval.ChromaticInterval(1)
    >>> aInterval.isChromaticStep
    True
    >>> aInterval.isStep
    True
    c                d    t        |   di | |t        |      k(  rt        |      }|| _        y )Nr$   )r   r   rQ   r   )rT   r   r   r   s      r&   r   zChromaticInterval.__init__  s/    $8$I&II$-r%   c                ,    t        | j                        S rN   r   rS   s    r&   r   zChromaticInterval._reprInternal  r   r%   c                R    t        |d      sy| j                  |j                  k(  ryy)a  
        True if number of semitones is the same.

        >>> a = interval.ChromaticInterval(-14)
        >>> b = interval.ChromaticInterval(14)
        >>> c = interval.ChromaticInterval(-14)
        >>> d = interval.ChromaticInterval(7)
        >>> e = interval.ChromaticInterval(2)

        >>> a == b
        False
        >>> a == c
        True
        >>> a == d
        False
        >>> b == e
        False

        Intervals do not equal numbers:

        >>> interval.ChromaticInterval(7) == 7
        False
        r   FT)r;   r   r   s     r&   r   zChromaticInterval.__eq__  s'    0 uk*>>U__,r%   c                    t        |       dz	  S r   r   rS   s    r&   r   zChromaticInterval.__hash__  r   r%   c                4    t        | j                  dz  d      S )z
        Return the number of cents in a ChromaticInterval:

        >>> dime = interval.ChromaticInterval(0.1)
        >>> dime.cents
        10.0
        r   rF   )roundr   rS   s    r&   r   zChromaticInterval.cents  s     T^^e+Q//r%   c                    | j                   S )z
        A synonym for `.semitones`

        >>> tritoneDown = interval.ChromaticInterval(-6)
        >>> tritoneDown.directed
        -6
        r   rS   s    r&   r   zChromaticInterval.directed  s     ~~r%   c                ,    t        | j                        S )z
        The absolute value of the number of semitones:

        >>> tritoneDown = interval.ChromaticInterval(-6)
        >>> tritoneDown.undirected
        6
        )r   r   rS   s    r&   r  zChromaticInterval.undirected  s     4>>""r%   c                    | j                   dkD  rt        j                  S | j                   dk  rt        j                  S t        j                  S )a  
        Returns an enum of the direction:

        >>> interval.ChromaticInterval(-3).direction
        <Direction.DESCENDING: -1>

        note that the number can be helpful for multiplication:

        >>> interval.ChromaticInterval(-3).direction * 9
        -9
        r   )r   r   r#   r!   r"   rS   s    r&   r   zChromaticInterval.direction	  s@     ==1&&&==1'''   r%   c                     | j                   dz  S )a  
        The number of semitones within an octave using modulo arithmatic.

        (see :meth:`~music21.interval.ChromaticInterval.simpleUndirected`
        for a similar method that puts musical
        intuition above mathematical intuition)

        >>> interval.ChromaticInterval(15).mod12
        3
        >>> interval.ChromaticInterval(-4).mod12
        8
        >>> interval.ChromaticInterval(-16).mod12
        8
        r   r  rS   s    r&   mod12zChromaticInterval.mod12	  s      ~~""r%   c                     | j                   dz  S )a  
        The number of semitones within an octave while ignoring direction.

        (see :meth:`~music21.interval.ChromaticInterval.mod12`
        for a similar method that puts mathematical
        intuition above musical intuition)

        >>> interval.ChromaticInterval(15).simpleUndirected
        3
        >>> interval.ChromaticInterval(-4).simpleUndirected
        4
        >>> interval.ChromaticInterval(-16).simpleUndirected
        4
        r   r  rS   s    r&   r  z"ChromaticInterval.simpleUndirected-	  s      ##r%   c                r    | j                   t        j                  k(  rd| j                  z  S | j                  S )a&  
        The number of semitones within an octave while preserving direction.

        >>> interval.ChromaticInterval(15).simpleDirected
        3
        >>> interval.ChromaticInterval(-4).simpleDirected
        -4
        >>> interval.ChromaticInterval(-16).simpleDirected
        -4
        r   )r   r   r!   r  rS   s    r&   r   z ChromaticInterval.simpleDirected?	  s3     >>Y111----(((r%   c                D    t        | j                        }|dkD  rd|z
  S |S )NrG   r   )rQ   r  )rT   r  s     r&   intervalClasszChromaticInterval.intervalClassP	  s%    DJJ19:Lr%   c                     | j                   dk(  S )Nr   r  rS   s    r&   isChromaticStepz!ChromaticInterval.isChromaticStepX	  s    !##r%   c                    | j                   S rN   )r  rS   s    r&   r  zChromaticInterval.isStep\	  s    ###r%   c                L    t        | j                  d| j                  z  z        S )a  
        Return an inverted :class:`~music21.interval.ChromaticInterval`,
        that is, reversing the direction.

        >>> aInterval = interval.ChromaticInterval(-14)
        >>> aInterval.reverse()
        <music21.interval.ChromaticInterval 14>

        >>> aInterval = interval.ChromaticInterval(3)
        >>> aInterval.reverse()
        <music21.interval.ChromaticInterval -3>
        r   )r  r  r   rS   s    r&   r   zChromaticInterval.reversed	  s!     !B4G!HIIr%   c                J    t        | j                        \  }}t        ||      S )a  
        Given a ChromaticInterval, return a :class:`~music21.interval.DiatonicInterval`
        object of the same size.

        While there is more than one Generic Interval for any given chromatic
        interval, this is needed to permit easy chromatic specification of
        Interval objects.  Augmented or diminished intervals are never returned
        except for the interval of 6 which returns a diminished fifth, not
        augmented fourth.

        >>> aInterval = interval.ChromaticInterval(5)
        >>> aInterval.getDiatonic()
        <music21.interval.DiatonicInterval P4>

        >>> aInterval = interval.ChromaticInterval(6)
        >>> aInterval.getDiatonic()
        <music21.interval.DiatonicInterval d5>

        >>> aInterval = interval.ChromaticInterval(7)
        >>> aInterval.getDiatonic()
        <music21.interval.DiatonicInterval P5>

        >>> aInterval = interval.ChromaticInterval(11)
        >>> aInterval.getDiatonic()
        <music21.interval.DiatonicInterval M7>
        )r   r   rN  )rT   r   r   s      r&   rO  zChromaticInterval.getDiatonics	  s$    8 ?t~~N	7	733r%   Fr   c                   |j                   d}nd}|j                  }|st        j                  |      }n|}|| j                  z   |_        |du rd|_         |s|S y)a/  
        Given a :class:`~music21.pitch.Pitch` object, return a new,
        transposed Pitch, that is transformed
        according to this ChromaticInterval.

        Because :class:`~music21.interval.ChromaticInterval` object
        do not take into account diatonic spelling,
        the new Pitch is simplified to the most common intervals.  See
        :meth:`~music21.pitch.Pitch.simplifyEnharmonic` with ``mostCommon = True``
        to see the results.

        >>> tritone = interval.ChromaticInterval(6)
        >>> p = pitch.Pitch('E#4')
        >>> p2 = tritone.transposePitch(p)
        >>> p2
        <music21.pitch.Pitch B4>
        >>> p3 = tritone.transposePitch(p2)
        >>> p3
        <music21.pitch.Pitch F5>

        If no octave number is given then octaves "wrap around" and thus even
        after transposing upward, you could end up with a pitch that is
        displayed as lower than the original:

        >>> p4 = pitch.Pitch('B')
        >>> p4.ps
        71.0
        >>> p5 = tritone.transposePitch(p4)

        Since the octave on p4 was implicit, the ps here wraps around

        >>> p5.ps
        65.0

        Afterward, the spelling of the new pitch will always be inferred.

        >>> p4.spellingIsInferred
        False
        >>> p5.spellingIsInferred
        True

        Can be done inPlace as well:

        >>> p = pitch.Pitch('E#4')
        >>> tritone.transposePitch(p, inPlace=True)
        >>> p
        <music21.pitch.Pitch B4>
        >>> p.spellingIsInferred
        True

        * Changed in v6: added inPlace.
        NTF)r   r   r   r   r   )rT   r;  r   r<  ppsr   s         r&   r   z ChromaticInterval.transposePitch	  sf    l 88 $ %dd}}Q'HHDNN*$"HOO r%   )r   )r   int | floatrp   r  rq   r  rS  rR  rT  r  r  rV  )r   r   r    rr   r   r   r   r   r~   r   r   r  r   r  r  r   r  r  r  r   rO  r   rX  rY  s   @r&   r  r    s   8."@
 0 0   # # ! !& # #" $ $" ) )    $ $ $ $J4> 9> F Fr%   r  c                4   d}d| v r| j                  dd      } d}nd}| j                         }d|v r4t        j                  dd| t        j                  j
                        } d}n5d	|v r1t        j                  d
d| t        j                  j
                        } |dv rd} d}n|dv rd} d}t        t        j                        D ]V  \  }}|j                         |v st        j                  d| dt        |      | t        j                  j
                        } X t        j                  |       \  }}	 t        |      |z  }|}
t        |      }|j                  |
      }||j!                         |fS # t        $ r}	t        d|d| d      |	d}	~	ww xY w)a=  
    A function for processing interval strings and returning
    diatonic and chromatic interval objects. Used by the Interval class, below.
    The last entry is a boolean indicating whether the diatonic interval is
    inferred (see 'half' and 'whole')

    >>> interval._stringToDiatonicChromatic('P5')
    (<music21.interval.DiatonicInterval P5>, <music21.interval.ChromaticInterval 7>, False)
    >>> interval._stringToDiatonicChromatic('p5')
    (<music21.interval.DiatonicInterval P5>, <music21.interval.ChromaticInterval 7>, False)
    >>> interval._stringToDiatonicChromatic('perfect5')
    (<music21.interval.DiatonicInterval P5>, <music21.interval.ChromaticInterval 7>, False)
    >>> interval._stringToDiatonicChromatic('perfect fifth')
    (<music21.interval.DiatonicInterval P5>, <music21.interval.ChromaticInterval 7>, False)

    >>> interval._stringToDiatonicChromatic('P-5')
    (<music21.interval.DiatonicInterval P5>, <music21.interval.ChromaticInterval -7>, False)
    >>> interval._stringToDiatonicChromatic('M3')
    (<music21.interval.DiatonicInterval M3>, <music21.interval.ChromaticInterval 4>, False)
    >>> interval._stringToDiatonicChromatic('m3')
    (<music21.interval.DiatonicInterval m3>, <music21.interval.ChromaticInterval 3>, False)

    >>> interval._stringToDiatonicChromatic('whole')
    (<music21.interval.DiatonicInterval M2>, <music21.interval.ChromaticInterval 2>, True)
    >>> interval._stringToDiatonicChromatic('half')
    (<music21.interval.DiatonicInterval m2>, <music21.interval.ChromaticInterval 1>, True)
    >>> interval._stringToDiatonicChromatic('-h')
    (<music21.interval.DiatonicInterval m2>, <music21.interval.ChromaticInterval -1>, True)

    >>> interval._stringToDiatonicChromatic('semitone')
    (<music21.interval.DiatonicInterval m2>, <music21.interval.ChromaticInterval 1>, True)
    F-r   r   r   
descendingzdescending\s*)flags	ascendingzascending\\s*)wwholetoneM2T)hhalfsemitonem2z\s*zCould not find an int in z, from r   N)r   r   resub	RegexFlag
IGNORECASEr   r   r&  rO   getNumFromStrrQ   r<   rh   r   rO  r  )rR   inferredr   value_lowerr   ordinalfoundremaingenericNumbervespecName	gInterval	dIntervals                r&   _stringToDiatonicChromaticr  	  s   H H
e|c2&++-K{"'U",,:Q:QR		#'U",,:Q:QR ,,	1	1 4 45
7==?k)FFc'#.q6 !#!8!8E 6 ((/ME6E
X- H.I%%h/Ii,,.88  'yyB
	s   7E6 6	F?FFc                    t        |       t        |      }}|j                  |j                  z
  }t        |      }t        |      S )a4  
    Given two :class:`~music21.note.Note` objects,
    returns a :class:`~music21.interval.GenericInterval` object.

    Works equally well with :class:`~music21.pitch.Pitch` objects

    >>> aNote = note.Note('c4')
    >>> bNote = note.Note('g5')
    >>> aInterval = interval.notesToGeneric(aNote, bNote)
    >>> aInterval
    <music21.interval.GenericInterval 12>

    >>> aPitch = pitch.Pitch('c#4')
    >>> bPitch = pitch.Pitch('f-5')
    >>> bInterval = interval.notesToGeneric(aPitch, bPitch)
    >>> bInterval
    <music21.interval.GenericInterval 11>
    )r   r:  r   r   )n1n2p1p2r   genDists         r&   notesToGenericr  .
  sB    , b!=#4R""R%7%77I,Y7G7##r%   c                r    t        |       t        |      }}t        |j                  |j                  z
        S )a"  
    Given two :class:`~music21.note.Note` objects,
    returns a :class:`~music21.interval.ChromaticInterval` object.

    Works equally well with :class:`~music21.pitch.Pitch` objects.

    >>> aNote = note.Note('c4')
    >>> bNote = note.Note('g#5')
    >>> interval.notesToChromatic(aNote, bNote)
    <music21.interval.ChromaticInterval 20>

    >>> aPitch = pitch.Pitch('c#4')
    >>> bPitch = pitch.Pitch('f-5')
    >>> bInterval = interval.notesToChromatic(aPitch, bPitch)
    >>> bInterval
    <music21.interval.ChromaticInterval 15>
    )r   r  r   )r  r  r  r  s       r&   notesToChromaticr  J
  s.    * b!=#4RRUURUU]++r%   c                   d}|| j                   dz
     d| j                  z  z   }| j                  |j                  k7  rJ| j                  t        j                  k7  r-|j                  t        j                  k7  rd|j
                  z  }n(| j
                  dk(  r|j                  }n|j
                  }|j
                  dkD  rd}nd}t        t        ||z               }| j                  r	 t        t        |z   |z
     }|S 	 t        t         |z   |z
     }|S # t        $ r }t        dt        ||z
        z         |d	}~ww xY w# t        $ r }t        d
t        ||z
        z         |d	}~ww xY w)aX  
    Given a :class:`~music21.interval.GenericInterval` and
    a :class:`~music21.interval.ChromaticInterval` object, return a specifier
    (i.e. Specifier.MAJOR, Specifier.MINOR, etc.).

    >>> aInterval = interval.GenericInterval('seventh')
    >>> bInterval = interval.ChromaticInterval(11)
    >>> interval._getSpecifierFromGenericChromatic(aInterval, bInterval)
    <Specifier.MAJOR>
    >>> interval.parseSpecifier('major')
    <Specifier.MAJOR>

    Absurdly altered interval:

    >>> cInterval = interval.GenericInterval('second')
    >>> dInterval = interval.ChromaticInterval(10)  # 8x augmented second
    >>> interval._getSpecifierFromGenericChromatic(cInterval, dInterval)
    Traceback (most recent call last):
    music21.interval.IntervalException: cannot get a specifier for a note with
        this many semitones off of Major: 8
    )r   rC   rE   rF   rH   rJ   rL   r   r   r   r   g-C6?g-C6zKcannot get a specifier for a note with this many semitones off of Perfect: NzIcannot get a specifier for a note with this many semitones off of Major: )r  r  r   r   r"   r  r   rQ   r  r$  rn  
perfOffsetr'  rh   rO   
specifiers	majOffset)	gIntcIntnoteValsnormalSemis
theseSemisroundingErrorsemisRoundedr   ies	            r&   !_getSpecifierFromGenericChromaticr  c
  s   2 &H400145T=S=S8SSK$..()"3"33)J[J[8[ $//)
	A	]]
 __
 uZ-789L	&zL'@;'NOI 	"9|#;k#IJI   	#%'*:+C'DE 	  	##%(k)A%BC 	s0   (D >D? 	D<D77D<?	E(E##E(c                2    t        | |      }t        ||       S )a  
    Given a :class:`~music21.interval.GenericInterval` and
    a :class:`~music21.interval.ChromaticInterval` object,
    return a :class:`~music21.interval.DiatonicInterval`.

    >>> aInterval = interval.GenericInterval('descending fifth')
    >>> bInterval = interval.ChromaticInterval(-7)
    >>> cInterval = interval.intervalsToDiatonic(aInterval, bInterval)
    >>> cInterval
    <music21.interval.DiatonicInterval P5>
    )r  rN  )r  r  r   s      r&   intervalsToDiatonicr  
  s     2$=IIt,,r%   c                    t        | t              st        |       }n| }t        |t              st        |      }n|}t        ||      }t	        ||      }t        ||      S )ak  
    Given a :class:`~music21.interval.GenericInterval` and a
    :class:`~music21.interval.ChromaticInterval` object, return
    a full :class:`~music21.interval.Interval`.

    >>> aInterval = interval.GenericInterval('descending fifth')
    >>> bInterval = interval.ChromaticInterval(-8)
    >>> cInterval = interval.intervalFromGenericAndChromatic(aInterval, bInterval)
    >>> cInterval
    <music21.interval.Interval A-5>

    >>> cInterval.name
    'A5'
    >>> cInterval.directedName
    'A-5'
    >>> cInterval.directedNiceName
    'Descending Augmented Fifth'

    >>> interval.intervalFromGenericAndChromatic(3, 4)
    <music21.interval.Interval M3>
    >>> interval.intervalFromGenericAndChromatic(3, 3)
    <music21.interval.Interval m3>

    >>> interval.intervalFromGenericAndChromatic(5, 6)
    <music21.interval.Interval d5>
    >>> interval.intervalFromGenericAndChromatic(5, 5)
    <music21.interval.Interval dd5>
    >>> interval.intervalFromGenericAndChromatic(-2, -2)
    <music21.interval.Interval M-2>

    >>> interval.intervalFromGenericAndChromatic(1, 0.5)
    <music21.interval.Interval A1 (-50c)>

    r  )r   r   r  r  rN  r   )r  r  gIntVcIntVr   dInts         r&   intervalFromGenericAndChromaticr  
  s]    N dO,%d-.!$'1%?IIu-DTU33r%   c            	      &    e Zd ZdZ	 	 d/dddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d0 fdZd Z fdZd Zed1d       Z	ed2d	       Z
ed2d
       Zed2d       Zed2d       Zed2d       Zed2d       Zed2d       Zed2d       Zed2d       Zed2d       Zed3d       Zed4d       Zed5d       Zed2d       Zed6d       Zed6d       Zed6d       Zed6d       Zd6dZed7d       Zed8d       Zed9d       Zd9dZ d d!d d"	 	 	 d:d#Z!d d$	 	 	 	 	 d;d%Z"d& Z#ed<d'       Z$e$jJ                  d=d(       Z$ed<d)       Z&e&jJ                  d>d*       Z&ed?d+       Z'e'jJ                  d@d,       Z'ed?d-       Z(e(jJ                  d@d.       Z( xZ)S )Ar   a9  
    An Interval class that encapsulates both
    :class:`~music21.interval.ChromaticInterval` and
    :class:`~music21.interval.DiatonicInterval` objects all in one model.

    The interval is specified either as named arguments, a
    :class:`~music21.interval.DiatonicInterval` and
    a :class:`~music21.interval.ChromaticInterval`,
    or two :class:`~music21.note.Note` objects
    (or :class:`~music21.interval.Pitch` objects),
    from which both a ChromaticInterval and DiatonicInterval are derived.

    >>> p1 = pitch.Pitch('c3')
    >>> p2 = pitch.Pitch('c5')
    >>> aInterval = interval.Interval(pitchStart=p1, pitchEnd=p2)
    >>> aInterval
    <music21.interval.Interval P15>
    >>> aInterval.name
    'P15'
    >>> aInterval.pitchStart is p1
    True
    >>> aInterval.pitchEnd is p2
    True

    Reduce to less than an octave:

    >>> aInterval.simpleName
    'P1'

    Reduce to no more than an octave:

    >>> aInterval.semiSimpleName
    'P8'

    An interval can also be specified directly:

    >>> aInterval = interval.Interval('m3')
    >>> aInterval
    <music21.interval.Interval m3>
    >>> aInterval = interval.Interval('M3')
    >>> aInterval
    <music21.interval.Interval M3>

    >>> aInterval = interval.Interval('p5')
    >>> aInterval
    <music21.interval.Interval P5>
    >>> aInterval.isChromaticStep
    False
    >>> aInterval.isDiatonicStep
    False
    >>> aInterval.isStep
    False

    Some ways of creating half-steps.

    >>> aInterval = interval.Interval('half')
    >>> aInterval
    <music21.interval.Interval m2>
    >>> aInterval.isChromaticStep
    True
    >>> aInterval.isDiatonicStep
    True
    >>> aInterval.isStep
    True

    >>> aInterval = interval.Interval('-h')
    >>> aInterval
    <music21.interval.Interval m-2>
    >>> aInterval.directedName
    'm-2'
    >>> aInterval.name
    'm2'

    A single int is treated as a number of half-steps:

    >>> aInterval = interval.Interval(4)
    >>> aInterval
    <music21.interval.Interval M3>

    >>> aInterval = interval.Interval(7)
    >>> aInterval
    <music21.interval.Interval P5>

    If giving a starting pitch, an ending pitch has to be specified.

    >>> aInterval = interval.Interval(pitchStart=p1)
    Traceback (most recent call last):
    ValueError: either both the starting and the ending pitch (or note) must be given
        or neither can be given. You cannot have one without the other.

    An Interval can be constructed from a DiatonicInterval and ChromaticInterval
    object (or just one):

    >>> diaInterval = interval.DiatonicInterval('major', 'third')
    >>> chrInterval = interval.ChromaticInterval(4)
    >>> fullInterval = interval.Interval(diatonic=diaInterval, chromatic=chrInterval)
    >>> fullInterval
    <music21.interval.Interval M3>

    >>> fullInterval = interval.Interval(diatonic=diaInterval)
    >>> fullInterval.semitones
    4
    >>> fullInterval = interval.Interval(chromatic=chrInterval)
    >>> fullInterval.diatonic.name
    'M3'
    >>> fullInterval.implicitDiatonic
    True

    Two Intervals are the same if their Chromatic and Diatonic intervals
    are the same.

    >>> aInt = interval.Interval('P4')
    >>> bInt = interval.Interval(
    ...        diatonic=interval.DiatonicInterval('P', 4),
    ...        chromatic=interval.ChromaticInterval(5),
    ...        )
    >>> aInt == bInt
    True

    N.B. that interval.Interval('A4') != 'A4'

    >>> interval.Interval('A4') == 'A4'
    False

    More demonstrations using pitches:

    >>> aPitch = pitch.Pitch('c4')
    >>> bPitch = pitch.Pitch('g5')
    >>> aInterval = interval.Interval(aPitch, bPitch)
    >>> aInterval
    <music21.interval.Interval P12>
    >>> bInterval = interval.Interval(pitchStart=aPitch, pitchEnd=bPitch)
    >>> aInterval.niceName == bInterval.niceName
    True

    >>> aPitch = pitch.Pitch('c#4')
    >>> bPitch = pitch.Pitch('f-5')
    >>> cInterval = interval.Interval(aPitch, bPitch)
    >>> cInterval
    <music21.interval.Interval dd11>

    >>> cPitch = pitch.Pitch('e#4')
    >>> dPitch = pitch.Pitch('f-4')
    >>> dInterval = interval.Interval(cPitch, dPitch)
    >>> dInterval
    <music21.interval.Interval dd2>

    >>> ePitch = pitch.Pitch('e##4')
    >>> fPitch = pitch.Pitch('f--4')
    >>> dInterval = interval.Interval(ePitch, fPitch)
    >>> dInterval
    <music21.interval.Interval dddd2>

    >>> gPitch = pitch.Pitch('c--4')
    >>> hPitch = pitch.Pitch('c##4')
    >>> iInterval = interval.Interval(gPitch, hPitch)
    >>> iInterval
    <music21.interval.Interval AAAA1>

    >>> interval.Interval(pitch.Pitch('e##4'), pitch.Pitch('f--5'))
    <music21.interval.Interval dddd9>

    * Changed in v8:
      - Pitches are emphasized over notes.
      - It is not possible to create an interval with a name and a pitchStart/noteStart
      and automatically get a pitchEnd/noteEnd in the process.  Set them later.
      - Incompatible keywords raise ValueError not IntervalException.
      - An empty instantiation gives a P1 interval.

    OMIT_FROM_DOCS

    >>> aInterval = interval.Interval('M2')
    >>> aInterval.isChromaticStep
    False
    >>> aInterval.isDiatonicStep
    True
    >>> aInterval.isStep
    True

    >>> aInterval = interval.Interval('dd3')
    >>> aInterval.isChromaticStep
    True
    >>> aInterval.isDiatonicStep
    False
    >>> aInterval.isStep
    True

    This is in OMIT_FROM_etc. put changelog above.
    N)r  r  
pitchStartpitchEnd	noteStartnoteEndrY   c              d   t        |   di |
 d| _        ||t        d      t	        |      }|@t        |t              r|}	n-t        |t        t        f      rt        |      }nt	        |      }|r|s|r|rt        d      |rt	        |      }|rt	        |      }|r|r|r|st        d      |r>|r<t        ||      }t        ||      }t        ||      }|s|r||k7  rt        d      |}|}|	r4t        |	      \  }}}|s|r||k7  s||k7  rt        d      |}|}|| _        nL|r|s|j                         }d| _        n0|r|s|j                         }n|s|st!        dd	      }t        d
      }t"        j$                  r|J |J || _        || _        || _        || _        d| _        y )NFz-Cannot supply a second value without a first.z;Cannot instantiate an interval with both notes and pitches.zeither both the starting and the ending pitch (or note) must be given or neither can be given.  You cannot have one without the other.znDo not pass in pitches/notes and diatonic/chromatic interval objects, unless they represent the same interval.zxDo not pass in a name and pitches/notes or diatonic/chromatic interval objects, unless they represent the same interval.Tr0   r   r   r   r$   )r   r   implicitDiatonicr<   r   r   rO   rQ   r  r  r  r  r  r  rO  r  rN  r   TYPE_CHECKINGr  r  _pitchStart	_pitchEndintervalType)rT   arg0arg1r  r  r  r  r  r  rY   r   genericIntervalchromaticNewdiatonicNewr  r   s                  r&   r   zInterval.__init__  s   $ 	$8$ ',| !PQQ$T*H$$D3,/-d3	*40
:Z[[&y1J$W-HxXj[  (,ZBO+JAL-o|LKX9+D S  %I"H2LT2R/KxXI,EU`I` S  %I"H$,D!x ,,.H$(D!i --/I)'Q/H)!,I ??'''(((*2,5 .8+3BDr%   c                    ddl m} 	 | j                         }|dk7  r- |j                  |      }| j
                  dz   t        |      z   S | j
                  S # t        $ r Y yw xY w)Nr   r   r   r]  )r?  r   _diatonicIntervalCentShiftAttributeError	Microtonerp  rO   )rT   r   shiftr   s       r&   r   zInterval._reprInternal  sk    !	335E A:#EOOE*E$$s*SZ77$$$  		s   A 	A"!A"c                    t         |   |      sy| j                  |j                  k(  r| j                  |j                  k(  ryy)a  
        True if .diatonic and .chromatic are equal.

        >>> a = interval.Interval('a4')
        >>> b = interval.Interval('d5')
        >>> c = interval.Interval('m3')
        >>> d = interval.Interval('d5')
        >>> a == b
        False
        >>> b == d
        True
        >>> a == c
        False
        >>> b in [a, c, d]
        True

        Now, of course, this makes sense:

        >>> a == 'hello'
        False

        But note well that this is also a False expression:

        >>> a == 'a4'
        False
        FT)r   r   r  r  )rT   r   r   s     r&   r   zInterval.__eq__"  s:    6 w~e$MMU^^+NNeoo5r%   c                    t        |       dz	  S r   r   rS   s    r&   r   zInterval.__hash__E  r   r%   c                .    | j                   j                  S )z
        Returns the :class:`~music21.interval.GenericInterval` object
        associated with this Interval

        >>> interval.Interval('P5').generic
        <music21.interval.GenericInterval 5>
        )r  r   rS   s    r&   r   zInterval.genericJ  s     }}$$$r%   c                .    | j                   j                  S )z
        Return the simple name of the interval, ignoring direction:

        >>> interval.Interval('Descending Perfect Fourth').name
        'P4'
        )r  rY   rS   s    r&   rY   zInterval.nameU  s     }}!!!r%   c                .    | j                   j                  S )zL
        >>> interval.Interval('m3').niceName
        'Minor Third'
        )r  r]   rS   s    r&   r]   zInterval.niceName_  s     }}%%%r%   c                .    | j                   j                  S rN   )r  rh  rS   s    r&   rh  zInterval.simpleNameg  s    }}'''r%   c                .    | j                   j                  S rN   )r  r-  rS   s    r&   r-  zInterval.simpleNiceNamek      }}+++r%   c                .    | j                   j                  S rN   )r  rk  rS   s    r&   rk  zInterval.semiSimpleNameo  r  r%   c                .    | j                   j                  S rN   )r  r/  rS   s    r&   r/  zInterval.semiSimpleNiceNames      }}///r%   c                .    | j                   j                  S rN   )r  rp  rS   s    r&   rp  zInterval.directedNamew      }})))r%   c                .    | j                   j                  S rN   )r  rr  rS   s    r&   rr  zInterval.directedNiceName{  s    }}---r%   c                .    | j                   j                  S rN   )r  rt  rS   s    r&   rt  zInterval.directedSimpleName  r  r%   c                .    | j                   j                  S rN   )r  rv  rS   s    r&   rv  zInterval.directedSimpleNiceName  s    }}333r%   c                .    | j                   j                  S rN   )r  r   rS   s    r&   r   zInterval.semitones      ~~'''r%   c                .    | j                   j                  S rN   )r  r   rS   s    r&   r   zInterval.direction  r  r%   c                .    | j                   j                  S rN   )r  r   rS   s    r&   r   zInterval.specifier  s    }}&&&r%   c                .    | j                   j                  S rN   )r  rf  rS   s    r&   rf  zInterval.specificName  r  r%   c                .    | j                   j                  S rN   )r  r  rS   s    r&   r  zInterval.isDiatonicStep  r  r%   c                .    | j                   j                  S rN   )r  r  rS   s    r&   r  zInterval.isChromaticStep  s    ~~---r%   c                6    | j                   xs | j                  S rN   )r  r  rS   s    r&   r  zInterval.isStep  s    ##:t':'::r%   c                .    | j                   j                  S rN   )r  r  rS   s    r&   r  zInterval.isSkip  s    }}###r%   c                "    | j                   dv ryy)a  
        returns True if the pitches are a major or
        minor third or sixth or perfect fifth or unison.

        These rules define all common-practice consonances
        (and earlier back to about 1300 all imperfect consonances)

        >>> i1 = interval.Interval(note.Note('C'), note.Note('E'))
        >>> i1.isConsonant()
        True
        >>> i1 = interval.Interval(note.Note('B-'), note.Note('C'))
        >>> i1.isConsonant()
        False
        )r   m3M3m6M6P1TF)rh  rS   s    r&   isConsonantzInterval.isConsonant  s     ??BBr%   c                @    t        | j                  j                        S )a  
        Return a new :class:`~music21.interval.Interval` object that is the
        complement of this Interval.

        >>> aInterval = interval.Interval('M3')
        >>> bInterval = aInterval.complement
        >>> bInterval
        <music21.interval.Interval m6>

        >>> cInterval = interval.Interval('A2')
        >>> dInterval = cInterval.complement
        >>> dInterval
        <music21.interval.Interval d7>
        )r   r  r3  rS   s    r&   r7  zInterval.complement  s      3344r%   c                .    | j                   j                  S )a  
        Return the interval class from the chromatic interval,
        that is, the lesser of the number of half-steps in the
        simpleInterval or its complement.

        >>> aInterval = interval.Interval('M3')
        >>> aInterval.intervalClass
        4

        >>> bInterval = interval.Interval('m6')
        >>> bInterval.intervalClass
        4

        Empty intervals return 0:

        >>> interval.Interval().intervalClass
        0

        * Changed in v6.5: empty intervals return 0.
        )r  r  rS   s    r&   r  zInterval.intervalClass  s    , ~~+++r%   c                .    | j                   j                  S )a  
        Return the cents from the chromatic interval, where 100 cents = a half-step

        >>> aInterval = interval.Interval('M3')
        >>> aInterval.cents
        400.0

        >>> p1 = pitch.Pitch('C4')
        >>> p2 = pitch.Pitch('D4')
        >>> p2.microtone = 30
        >>> microtoneInterval = interval.Interval(pitchStart=p1, pitchEnd=p2)
        >>> microtoneInterval.cents
        230.0

        OMIT_FROM_DOCS

        >>> interval.Interval().cents
        0.0
        )r  r   rS   s    r&   r   zInterval.cents  s    * ~~###r%   c                d    | j                   j                  }| j                  j                  }||z
  S )z
        Return the number of cents the diatonic
        interval needs to be shifted to
        correspond to microtonal value specified
        in the chromatic interval.
        )r  r   r  )rT   dCentscCentss      r&   r  z#Interval._diatonicIntervalCentShift  s,     $$%%r%   FrE   )r   maxAccidentalr   c                  |r"| j                         j                  |||      S |d}| j                  r| j                  j                  ||      }n| j	                  |||      }|j
                  I| j                  |j
                  |      |_        |j
                  j                  d|j
                  _        |s|S y)a  
        Given a :class:`~music21.pitch.Pitch` object, return a new,
        transposed Pitch, that is transformed
        according to this Interval. This is the main public interface to all
        transposition routines found on higher-level objects.

        The `maxAccidental` parameter sets an integer number of half step
        alterations that will be accepted in the transposed pitch before it
        is simplified. For example,
        a value of 2 will permit double sharps but not triple sharps.  The
        maxAccidental default is 4, because music21 does not support quintuple
        sharps/flats.  Set to None to try anyhow.

        >>> p1 = pitch.Pitch('A#4')
        >>> i = interval.Interval('m3')
        >>> p2 = i.transposePitch(p1)
        >>> p2
        <music21.pitch.Pitch C#5>
        >>> p2 = i.transposePitch(p1, reverse=True)
        >>> p2
        <music21.pitch.Pitch F##4>
        >>> i.transposePitch(p1, reverse=True, maxAccidental=1)
        <music21.pitch.Pitch G4>

        `Pitch` objects without octaves are transposed also into
        objects without octaves.  This might make them appear to be
        lower than the original even if transposed up:

        >>> anyA = pitch.Pitch('A')
        >>> anyC = i.transposePitch(anyA)
        >>> anyC
        <music21.pitch.Pitch C>
        >>> anyC.ps < anyA.ps  # !!
        True

        If inPlace is True then function is done in place and no pitch is returned.

        >>> p1 = pitch.Pitch('A4')
        >>> i = interval.Interval('m3')
        >>> i.transposePitch(p1, inPlace=True)
        >>> p1
        <music21.pitch.Pitch C5>

        Note that reverse=True is only there for historical reasons;
        it is the same as `i.reverse().transposePitch(x)` and that format
        will be much faster when calling many times.

        * Changed in v6: inPlace parameter added. Reverse and maxAccidental changed to keyword only.

        OMIT_FROM_DOCS

        TODO: More tests here, esp. on fundamental.

        >>> p1 = pitch.Pitch('C4')
        >>> i = interval.Interval(1)  # half-step, regardless of diatonic
        >>> p2 = i.transposePitch(p1)
        >>> p2
        <music21.pitch.Pitch C#4>
        >>> p3 = i.transposePitch(p2)
        >>> p3
        <music21.pitch.Pitch D4>
        )r'  r   Ni r   )r'  )r   r   r  r  _diatonicTransposePitchfundamentalr   )rT   r;  r   r'  r   pOuts         r&   r   zInterval.transposePitch	  s    H <<>00-Y`0aa !M  >>00 1 D
 //+ 0 D ==$#22+  3  D
 }}##+*.  'K r%   r   c               P   d}| j                   dk(  r6t        | j                        t        t        | j                              k(  rd}|j                  d}nd}|}t        j                  |      }|j                  }| j                  j                  j                  }	||	z   }
t        |
      \  }}||_        ||_        |j                  }d|_        d|_        t        ||      }| j                   j                  |j                   j                  z
  }|dk7  rG|dk\  r|dz
  }|j                  dz
  |_        |dk\  rt#        |      |kD  r|j$                  |z   |_        n||_        |sP|j                  |j                  |j                  j'                  |j                         d|j                  _        n|j                  W|j                  d|_        t*        j,                  r|j                  J |j                  j'                  |j                         n^|j                  &|j                  j'                  |j                         n,d|j                  _        n|r||j.                  dk(  r||_        |rd|_        |s|S |j.                  |_        |j                  |_        |S )	z
        abstracts out the diatonic aspects of transposing, so that implicitDiatonic and
        regular diatonic can use some of the same code.

        PRIVATE METHOD: Return p even if inPlace is True
        Fr  TNr   r   r   natural)rh  r  r   rQ   r   r   r   r:  r  r   r1  r   rA  rC  	microtoner   r  r   r   inheritDisplaydisplayStatusr   r  rY   )rT   r;  r'  r   inheritAccidentalDisplayStatusr<  r   pitch2oldDiatonicNumdistanceToMovenewDiatonicNumbernewStep	newOctaveoldPitch2Accidental	interval2halfStepsToFixs                   r&   r)  z Interval._diatonicTransposePitchm  sp    05&??d"uT^^'<c$..FY@Z'Z-1*88 $ %v&//..<<*^;89JK!$//  VV,	11I4G4G4Q4QQ
 Q B&!/"!4 & 1 !B&
 >"]2 #II6	$2!1$$0V5F5F5R%%44V5F5FG6:F%%3 $$,((4,-)??#)#4#4#@@#@))889J9JK((4))889J9JK:?))7 . (3/44	A(;F% FMM ++FK"MMFMMr%   c                    | j                   -| j                  !t        | j                  | j                         S t        | j                  j	                         | j
                  j	                               S )a  
        Return a reversed version of this interval.
        If :class:`~music21.pitch.Pitch` objects are stored as
        `pitchStart` and `pitchEnd`, these pitches are reversed.

        >>> p1 = pitch.Pitch('c3')
        >>> p2 = pitch.Pitch('g3')
        >>> intvP5 = interval.Interval(pitchStart=p1, pitchEnd=p2)
        >>> intvP5
        <music21.interval.Interval P5>
        >>> revInterval = intvP5.reverse()
        >>> revInterval
        <music21.interval.Interval P-5>
        >>> revInterval.pitchStart is intvP5.pitchEnd
        True

        >>> m3 = interval.Interval('m3')
        >>> m3.reverse()
        <music21.interval.Interval m-3>
        r  r  r  )r  r  r   r  r   r  rS   s    r&   r   zInterval.reverse  s^    * 'DNN,Fdnnd>N>NOOT]]%:%:%<&*nn&<&<&>@ @r%   c                    | j                   S )a  
        Get the start pitch or set it a new value.
        Setting this will adjust the value of the end pitch (`pitchEnd`).

        >>> maj3 = interval.Interval('M3')
        >>> maj3.pitchStart = pitch.Pitch('c4')
        >>> maj3.pitchEnd.nameWithOctave
        'E4'

        >>> p1 = pitch.Pitch('c3')
        >>> p2 = pitch.Pitch('g#3')
        >>> a5 = interval.Interval(p1, p2)
        >>> a5.name
        'A5'

        >>> a5.pitchStart = pitch.Pitch('g4')
        >>> a5.pitchEnd.nameWithOctave
        'D#5'

        >>> descM3 = interval.Interval('-M3')
        >>> descM3.pitchStart = pitch.Pitch('c4')
        >>> descM3.pitchEnd.nameWithOctave
        'A-3'

        >>> descM2 = interval.Interval('M-2')
        >>> descM2.pitchStart = pitch.Pitch('A#3')
        >>> descM2.pitchEnd.nameWithOctave
        'G#3'

        Implicit diatonic intervals do not need to
        follow the diatonic directed name:

        >>> halfStep = interval.Interval('h')
        >>> halfStep.directedName
        'm2'
        >>> halfStep.implicitDiatonic
        True
        >>> halfStep.pitchStart = pitch.Pitch('F-3')
        >>> halfStep.pitchEnd.nameWithOctave
        'F3'
        )r  rS   s    r&   r  zInterval.pitchStart  s    V r%   c                d    |d| _         d| _        y| j                  |      }|| _         || _        y)z
        Assuming that this interval is defined,
        we can set a new start Pitch (_pitchStart) and
        automatically set the end Pitch (_pitchEnd).
        Nr  r  r   )rT   r;  r2  s      r&   r  zInterval.pitchStart  s<     9#D!DN $$Q'r%   c                    | j                   S )a  
        Set the
        end pitch to a new value; this will adjust
        the value of the start pitch (`pitchStart`).

        >>> aInterval = interval.Interval('M3')
        >>> aInterval.pitchEnd = pitch.Pitch('E4')
        >>> aInterval.pitchStart.nameWithOctave
        'C4'

        >>> aInterval = interval.Interval('m2')
        >>> aInterval.pitchEnd = pitch.Pitch('A#3')
        >>> aInterval.pitchStart.nameWithOctave
        'G##3'

        >>> p1 = pitch.Pitch('G#3')
        >>> p2 = pitch.Pitch('C3')
        >>> aInterval = interval.Interval(p1, p2)
        >>> aInterval.directedName  # downward augmented fifth
        'A-5'
        >>> aInterval.pitchEnd = pitch.Pitch('C4')
        >>> aInterval.pitchStart.nameWithOctave
        'G#4'

        >>> aInterval = interval.Interval('M3')
        >>> aInterval.pitchEnd = pitch.Pitch('A-3')
        >>> aInterval.pitchStart.nameWithOctave
        'F-3'
        )r  rS   s    r&   r  zInterval.pitchEnd/  s    > ~~r%   c                h    |d| _         d| _        y| j                  |d      }|| _        || _         y)z
        Assuming that this interval is defined, we can
        set a new end note (_pitchEnd) and automatically have the start pitch (_pitchStart).
        NT)r   r?  )rT   r;  r   s      r&   r  zInterval.pitchEndP  sA     9#D!DN $$Q$5!r%   c                    | j                   }|r|j                  r|j                  S |rddlm}  |j                  |      S y)zm
        Return or set the Note that pitchStart is attached to.  For
        backwards compatibility
        r   r   r   N)r  r   r?  r   NoterT   r;  r   s      r&   r  zInterval.noteStartb  s:     OO99$4991%%r%   c                :    |r|j                   | _        y d | _        y rN   )r   r  rT   r   s     r&   r  zInterval.noteStartq  s    ggDO"DOr%   c                    | j                   }|r|j                  r|j                  S |rddlm}  |j                  |      S y)zk
        Return or set the Note that pitchEnd is attached to.  For
        backwards compatibility
        r   r   r   N)r  r   r?  r   rC  rD  s      r&   r  zInterval.noteEndx  s:     MM99$4991%%r%   c                :    |r|j                   | _        y d | _        y rN   )r   r  rF  s     r&   r  zInterval.noteEnd  s    GGDM DMr%   )NN)r  z6t.Union[str, int, float, pitch.Pitch, note.Note, None]r  zpitch.Pitch | note.Note | Noner  zDiatonicInterval | Noner  zChromaticInterval | Noner  pitch.Pitch | Noner  rI  r  note.Note | pitch.Pitch | Noner  rJ  rY   z
str | NonerU  rp   r  )rq   zDirection | None)rq   zSpecifier | NonerT  rq   r   rR  r  )r;  r   r'  z
int | None)r;  r   r'  rQ   r   r   )rq   rI  )r;  rI  rq   None)r;  zmusic21.pitch.Pitch | Nonerq   rL  )rq   music21.note.Note | None)r   rM  rq   rL  )*r   r   r    rr   r   r   r   r   r~   r   rY   r]   rh  r-  rk  r/  rp  rr  rt  rv  r   r   r   rf  r  r  r  r  r   r7  r  r   r  r   r)  r   r  rW  r  r  r  rX  rY  s   @r&   r   r   
  s   |F (,48_E 485904.29=7;"&!_E%_E 2_E 1_E 3_E ._E ,_E 7_E 5_E   !_EB%!F
 % % " " & & ( ( , , , , 0 0 * * . . 0 0 4 4 ( ( ( ( ' ' * * , , . . ; ; $ $
( 5 5" , ,. $ $,	  %12$b%b '/	bP 16	e#.e 03e *.	eN@6 *  * X    $  @ __" ""   # #   ^^! !r%   c                     y rN   r$   r=   s     r&   getWrittenHigherNoterO         r%   c                     y rN   r$   r=   s     r&   rO  rO    rP  r%   c                    t        | |       t        |       t        |      }}|j                  }|j                  }||kD  r| S ||k  r|S t        | |      S )a  
    Given two :class:`~music21.pitch.Pitch` or :class:`~music21.note.Note` objects,
    this function returns the higher element based on diatonic note
    numbers. If the diatonic numbers are
    the same, returns the sounding higher element,
    or the first element if that is also the same.

    >>> cis = pitch.Pitch('C#')
    >>> deses = pitch.Pitch('D--')
    >>> higher = interval.getWrittenHigherNote(cis, deses)
    >>> higher is deses
    True

    >>> aPitch = pitch.Pitch('c#3')
    >>> bPitch = pitch.Pitch('d-3')
    >>> interval.getWrittenHigherNote(aPitch, bPitch)
    <music21.pitch.Pitch D-3>

    >>> aNote = note.Note('c#3')
    >>> bNote = note.Note('c3')
    >>> interval.getWrittenHigherNote(aNote, bNote) is aNote
    True
    )r@   r   r:  getAbsoluteHigherNoter>   r?   r  r  num1num2s         r&   rO  rO    s\    4 ue$mE&:RDDd{	$UE22r%   c                     y rN   r$   r=   s     r&   rS  rS    rP  r%   c                     y rN   r$   r=   s     r&   rS  rS    rP  r%   c                j    t        | |       t        | |      }|j                  }|dkD  r|S |dk  r| S | S )aq  
    Given two :class:`~music21.pitch.Pitch` or :class:`~music21.note.Note` objects,
    returns the higher element based on sounding pitch.
    If both sounding pitches are the same, returns the first element given.

    >>> aNote = note.Note('c#3')
    >>> bNote = note.Note('d--3')
    >>> interval.getAbsoluteHigherNote(aNote, bNote)
    <music21.note.Note C#>
    r   r@   r  r   r>   r?   r  r   s       r&   rS  rS    B     u .I##I1}	Qr%   c                     y rN   r$   r=   s     r&   getWrittenLowerNoter^    rP  r%   c                     y rN   r$   r=   s     r&   r^  r^    rP  r%   c                    t        | |       t        |       t        |      }}|j                  }|j                  }||k  r| S ||kD  r|S t        | |      S )a  
    Given two :class:`~music21.pitch.Pitch` or :class:`~music21.note.Note` objects,
    returns the lower element based on diatonic note
    number. If the diatonic number is
    the same returns the sounding lower element,
    or the first element if sounding pitch is also the same.

    >>> aNote = pitch.Pitch('C#3')
    >>> bNote = pitch.Pitch('D--3')
    >>> interval.getWrittenLowerNote(aNote, bNote)
    <music21.pitch.Pitch C#3>

    >>> aNote = pitch.Pitch('C#3')
    >>> bNote = pitch.Pitch('D-3')
    >>> interval.getWrittenLowerNote(aNote, bNote)
    <music21.pitch.Pitch C#3>

    Both elements should be pitches or notes -- if note2 is lower and not the same class
    as note1 raises a ValueError:

    >>> aNote = pitch.Pitch('C#4')
    >>> bNote = note.Note('C#3')
    >>> interval.getWrittenLowerNote(aNote, bNote)
    Traceback (most recent call last):
    ValueError: note1 <music21.pitch.Pitch C#4>
        and note2 <music21.note.Note C#> must both be notes or pitches
    )r@   r   r:  getAbsoluteLowerNoterT  s         r&   r^  r^    s\    < ue$mE&:RDDd{	#E511r%   c                     y rN   r$   r=   s     r&   ra  ra  !  rP  r%   c                     y rN   r$   r=   s     r&   ra  ra  '  rP  r%   c                j    t        | |       t        | |      }|j                  }|dkD  r| S |dk  r|S | S )al  
    Given two :class:`~music21.note.Note` or :class:`~music21.pitch.Pitch` objects, returns
    the lower element based on actual pitch.
    If both pitches are the same, returns the first element given.

    >>> aNote = pitch.Pitch('c#3')
    >>> bNote = pitch.Pitch('d--3')
    >>> interval.getAbsoluteLowerNote(aNote, bNote)
    <music21.pitch.Pitch D--3>
    r   rZ  r[  s       r&   ra  ra  .  r\  r%   Fr   c                   t        |t        t        f      rt        |      }n.t	        |d      s"t        d|j                  j                  z         |j                  | |      S )a  
    DEPRECATED: call `p.transpose(interval1)` directly

    Given a :class:`~music21.pitch.Pitch`
    and a :class:`~music21.interval.Interval` object (Not another class such
    as ChromaticInterval) or a string such as 'P5' or a number such as 6 (=tritone),
    return a new Pitch object at the appropriate pitch level.

    >>> aPitch = pitch.Pitch('C4')
    >>> P5 = interval.Interval('P5')
    >>> bPitch = interval.transposePitch(aPitch, P5)
    >>> bPitch
    <music21.pitch.Pitch G4>
    >>> bInterval = interval.Interval('P-5')
    >>> cPitch = interval.transposePitch(aPitch, bInterval)
    >>> cPitch
    <music21.pitch.Pitch F3>

    Pitches with implicit octaves should work,

    >>> dPitch = pitch.Pitch('G')
    >>> ePitch = interval.transposePitch(dPitch, P5)
    >>> ePitch
    <music21.pitch.Pitch D>

    Can be done inPlace as well

    >>> C4 = pitch.Pitch('C4')
    >>> interval.transposePitch(C4, P5, inPlace=True)
    >>> C4
    <music21.pitch.Pitch G4>

    * Changed in v6: added inPlace parameter.
    r   z8interval must be a music21.interval.Interval object not r   )	r   rO   rQ   r   r;   rh   r   r   r   )r   	interval1r   s      r&   r   r   F  sd    V )c3Z(Y'	y"23#J%%../  ##FG#<<r%   c                    t        |t              st        |      }n|}|j                  | j                        }t	        j
                  |       }||_        |S )a  
    To be deprecated: call `n.transpose(intervalString)` directly.

    Given a :class:`~music21.note.Note` and
    an interval string (such as 'P5') or an Interval object,
    return a new Note object at the appropriate pitch level.

    >>> aNote = note.Note('c4')
    >>> bNote = interval.transposeNote(aNote, 'p5')
    >>> bNote
    <music21.note.Note G>
    >>> bNote.pitch
    <music21.pitch.Pitch G4>

    >>> aNote = note.Note('f#4')
    >>> bNote = interval.transposeNote(aNote, 'm2')
    >>> bNote
    <music21.note.Note G>
    )r   r   r   r   r   r   )r>   intervalStringintvr   r   s        r&   r   r   |  sK    , nh/'""5;;/HmmE"GGMNr%   c                    t        | |      S )a  
    Soon to be DEPRECATED: Call Interval Directly

    Given two :class:`~music21.note.Note` objects, returns an
    :class:`~music21.interval.Interval` object. The same
    functionality is available by calling the Interval class
    with two Notes as arguments.

    >>> aNote = note.Note('c4')
    >>> bNote = note.Note('g5')
    >>> aInterval = interval.notesToInterval(aNote, bNote)
    >>> aInterval
    <music21.interval.Interval P12>
    r<  )r   )r  r  s     r&   notesToIntervalrk    s     b"--r%   c                    ddl m} | st        d       |j                  d      } |j                  d      }| D ]  }t	        ||      } t        ||      S )aG  
    Add a list of intervals and return the composite interval
    Intervals can be Interval objects or just strings.

    (Currently not particularly efficient for large lists)

    >>> A2 = interval.Interval('A2')
    >>> P5 = interval.Interval('P5')

    >>> interval.add([A2, P5])
    <music21.interval.Interval A6>
    >>> interval.add([P5, 'm2'])
    <music21.interval.Interval m6>
    >>> interval.add(['W', 'W', 'H', 'W', 'W', 'W', 'H'])
    <music21.interval.Interval P8>

    Direction does matter:

    >>> interval.add([P5, 'P-4'])
    <music21.interval.Interval M2>
    r   r   $Cannot add an empty set of intervalsC4r<  )r?  r   rh   r   r   r   )intervalListr   r  r  r   s        r&   addrp    sY    ,  FGG	T	B	T	BB" b"--r%   c                <   ddl m} | st        d       |j                  d      } |j                  d      }t	        |       D ]K  \  }}|dk(  rt        ||      }t        |d      st        |      }n|}t        ||j                               }M t        ||      S )a  
    Starts with the first interval and subtracts the
    following intervals from it:

    >>> interval.subtract(['P5', 'M3'])
    <music21.interval.Interval m3>
    >>> interval.subtract(['P4', 'd3'])
    <music21.interval.Interval A2>

    >>> m2Object = interval.Interval('m2')
    >>> interval.subtract(['M6', 'm2', m2Object])
    <music21.interval.Interval AA4>
    >>> interval.subtract(['P4', 'M-2'])
    <music21.interval.Interval P5>
    >>> interval.subtract(['A2', 'A2'])
    <music21.interval.Interval P1>
    >>> interval.subtract(['A1', 'P1'])
    <music21.interval.Interval A1>

    >>> interval.subtract(['P8', 'P1'])
    <music21.interval.Interval P8>
    >>> interval.subtract(['P8', 'd2'])
    <music21.interval.Interval A7>
    >>> interval.subtract(['P8', 'A1'])
    <music21.interval.Interval d8>

    >>> a = interval.subtract(['P5', 'A5'])
    >>> a.niceName
    'Diminished Unison'
    >>> a.directedNiceName
    'Descending Diminished Unison'
    >>> a.chromatic.semitones
    -1

    r   r   rm  rn  r  r<  )	r?  r   rh   r   r   r   r;   r   r   )ro  r   r  r  r   intIr   s          r&   subtractrs    s    H  FGG	T	B	T	B\*46D)B4-&tn"K$7$7$9:B + b"--r%   __main__)r>   note.Note | pitch.Pitchr?   ru  rq   rL  )r   ru  rq   r   )r   rQ   rq   ztuple[StepName, int])rR   zstr | int | Specifierrq   rB   )rR   rQ  rq   rQ   )r   r  rq   ztuple[Specifier, int, float])r   r  rq   ztuple[Specifier, int])r   r   rq   r   )rR   rO   rq   z0tuple[DiatonicInterval, ChromaticInterval, bool])r  pitch.Pitch | note.Noter  rv  rq   r   )r  rv  r  rv  rq   r  )r  r   r  r  rq   rB   )r  r   r  r  rq   rN  )r  zGenericInterval | intr  zChromaticInterval | int | floatrq   r   )r>   r   r?   ru  rq   r   )r>   r   r?   ru  rq   r   )r>   ru  r?   ru  rq   ru  )r   r   rf  str | Intervalrq   r   )r>   r   rh  rw  rq   r   rK  )^rr   
__future__r   	fractionsr   r   r   enumr  typingr   r   r?  r   r   music21.common.decoratorsr   music21.common.typesr	   r
   r   r  r   r   r   EnvironmentenvironLocalr   r  IntEnumr   r!   r"   r#   r   r\   rP   r@   rB   r}   r{   ry   rw   rs   rv   rx   rz   r|   rn  r  ru   rt   r  r  r  _P_m_Mr   Music21Exceptionrh   r   r   r   r   r   r   r   r   r   Music21Objectr   r   rN  r  r  r  r  r  r  r  r   rO  rS  r^  ra  r   r   rk  rp  rs  
_DOC_ORDERr   mainTestr$   r%   r&   <module>r     s   #  
   	     1 )    ?? '{&&z2
 #F	 E  &&##Y%%{4U [_kU kU` 
 
 OOOO
 	 		  ____ Gb!Wr1gAwQ"a9;O;OQR:SGb!Wr1gAwQ 
 	55 	
2,33jGIR=@2>2>!2>j&"R ?A ; @B-N("4%% ("VT1l T1n{	| {	| F
O9O95O9d$$$ $8,,, ,2?
?
? ?D-
-
- -&34
34
%34 34xX!| X!x 
 5' 

 
 5) 
$3 5$33$3P 
!6( 

 
!6* 

!640 
4& 

 
4( 
(24(22(2V 
 5' 

 
 5) 
 538 	3=3=3=
 3=l$)2B.$.B4.x  3-

 zG r%   