
    }Kg                     |   d 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mZmZmZmZ ddlmZ ddlmZmZmZmZ g dZ eg dg dg dg dg dg dg dg dg dg d
      Z eg dd      D  ci c]  \  } }|| 
 c}} Z ej@                  d      Z! ej@                  d      Z"ddddd d!d"d#d$ddd%dd d!d#d&d$dd'd%dd d#d d!d"dddd(d#dd d!d$dddd#d%dd d&d$ddd#d'd%dd)d&d$dd#d*Z#dddd+d,d-d.d*Z$ddddd/d/dd/dd0d1
Z%d2e&d3ejN                  fd4Z(d5ee&e)f   d3ejN                  fd6Z* ed78      d9d9d:d5ee&e)f   d;e+d<e+d3ee&   fd=       Z,d3ee&e)f   fd>Z-d3ee&   fd?Z.ed@e&d3e)fdA       Z/ed@ee&   d3ejN                  fdB       Z/ed@ee&ee&   ee&   f   d3ee)ejN                  f   fdC       Z/d@ee&ee&   ee&   f   d3ee)ejN                  f   fdDZ/edgd@e&dFe&d<e+d3e&fdG       Z0edgd@ee&   dFe&d<e+d3ejN                  fdH       Z0edgd@ee&ee&   ee&   f   dFe&d<e+d3ee&ejN                  f   fdI       Z0dhd@ee&ee&   ee&   f   dFe&d<e+d3ee&ejN                  f   fdJZ0didKe&d<e+d3e&fdLZ1 ed78      d9dMdNd@e&d<e+dOe+d3ee&   fdP       Z2d@e&d3ejN                  fdQZ3 ed78      d9dRdSe&dTe)d<e+d3e&fdU       Z4 ed9d9d9V      dW        Z5 ed9d9d9V      dX        Z6 ed9d9d9V      dY        Z7e&jq                  dZd[      Z9e&jq                  dZd\      Z:edEdEdEd]d^edSe&d_e;d<e+d3e&f
d`       Z<edEdEdEd]d^ee   dSe&d_e;d<e+d3ejN                  f
da       Z<edEdEdEd]d^ee   dSe&d_e;d<e+d3ee&ejN                  f   f
db       Z< edc e=g d]      d      dded9d]d^ee   dSe&d_e;d<e+d3ee&ejN                  f   f
df       Z<yc c}} w )jzMusic notation utilities    N)jit)Counter   )	INTERVALS   )cache)ParameterError)DictListIterableUnionoverload)	vectorize)_ScalarOrSequence_FloatLike_co_SequenceLike_IterableLike)	key_to_degreeskey_to_notesmela_to_degreesmela_to_svarathaat_to_degrees	list_mela
list_thaatfifths_to_noteinterval_to_fjsr   r            	      )r   r   r   r   r    r!   
   )r   r      r   r    r!   r#   r   r   r$   r   r       r#   )r   r   r$   r   r    r&   r#   )r   r   r      r    r!   r"   )r   r   r   r'   r    r!   r"   )r   r   r   r'   r    r&   r"   )r   r   r$   r'   r    r&   r"   )r   r   r   r   r    r&   r"   )
bilavalkhamajkafiasavaribhairavikalyanmarvapoorvitodibhairav)H	kanakangiratnangi
ganamurthi
vanaspathi	manavathitanarupi	senavathihanumathodidhenukanatakapriyakokilapriya	rupavathigayakapriyavakulabharanammayamalavagaulachakravakomsuryakanthamhatakambarijhankaradhwaninatabhairavi	keeravanikharaharapriyagaurimanoharivarunapriyamararanjini	charukesi	sarasangiharikambhojidheerasankarabharanamnaganandini	yagapriyaragavardhinigangeyabhushanivagadheeswarisulini
chalanattasalagam
jalarnavamjhalavaralinavaneethampavani
raghupriya
gavambodhi
bhavapriyasubhapanthuvaralishadvidhamargini
suvarnangi	divyamanidhavalambarinamanarayanikamavardhini	ramapriyagamanasramaviswambhari
syamalangishanmukhapriyasimhendramadhyamam	hemavathidharmavathineethimathi
kanthamanirishabhapriyalatangivachaspathimechakalyanichitrambari
sucharitrajyotisvarupinidhatuvardhininasikabhushanikosalamrasikapriyau   ^(?P<tonic>[A-Ga-g])(?P<accidental>[#♯𝄪b!♭𝄫♮n]*):((?P<scale>(maj|min)(or)?)|(?P<mode>(((ion|dor|phryg|lyd|mixolyd|aeol|locr)(ian)?)|phr|mix|aeo|loc)))$ud   ^(?P<note>[A-Ga-g])(?P<accidental>[#♯𝄪b!♭𝄫♮n]*)(?P<octave>[+-]?\d+)?(?P<cents>[+-]\d+)?$CDEFGABrz   r{   r|   r}   r~   r   r      B♭   E♭   A♭   D♭   F♯   G♭)iondorphrlydmixaeolocr$   r   r   r'   )
#   ♮ nb!   ♯   ♭   𝄪   𝄫thaatreturnc                 V    t        j                  t        | j                                  S )a5  Construct the svara indices (degrees) for a given thaat

    Parameters
    ----------
    thaat : str
        The name of the thaat

    Returns
    -------
    indices : np.ndarray
        A list of the seven svara indices (starting from 0=Sa)
        contained in the specified thaat

    See Also
    --------
    key_to_degrees
    mela_to_degrees
    list_thaat

    Examples
    --------
    >>> librosa.thaat_to_degrees('bilaval')
    array([ 0,  2,  4,  5,  7,  9, 11])

    >>> librosa.thaat_to_degrees('todi')
    array([ 0,  1,  3,  6,  7,  8, 11])
    )npasarray	THAAT_MAPlower)r   s    Y/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/librosa/core/notation.pyr   r      s    8 ::i.//    melac                    t        | t              rt        | j                            dz
  }n#d| cxk  rdk  r	n n| dz
  }nt	        d|  d      dg}|dz  }d|cxk  rdk  rn n|j                  ddg       nd|cxk  rd	k  rn n|j                  dd
g       nyd	|cxk  rdk  rn n|j                  ddg       nWd|cxk  rdk  rn n|j                  dd
g       n5d|cxk  rdk  rn n|j                  ddg       n|j                  d
dg       |dk  r|j                  d       n|j                  d       |j                  d       |dz  }|dk(  r|j                  ddg       nw|dk(  r|j                  ddg       n^|dk(  r|j                  ddg       nE|d
k(  r|j                  ddg       n,|dk(  r|j                  ddg       n|j                  ddg       t        j                  |      S )a  Construct the svara indices (degrees) for a given melakarta raga

    Parameters
    ----------
    mela : str or int
        Either the name or integer index ([1, 2, ..., 72]) of the melakarta raga

    Returns
    -------
    degrees : np.ndarray
        A list of the seven svara indices (starting from 0=Sa)
        contained in the specified raga

    See Also
    --------
    thaat_to_degrees
    key_to_degrees
    list_mela

    Examples
    --------
    Melakarta #1 (kanakangi):

    >>> librosa.mela_to_degrees(1)
    array([0, 1, 2, 5, 7, 8, 9])

    Or using a name directly:

    >>> librosa.mela_to_degrees('kanakangi')
    array([0, 1, 2, 5, 7, 8, 9])
    r   r   H   mela= must be in range [1, 72]$   r'   r      r$      r         r   r    r&   r!   r#   r"   )	
isinstancestrMELAKARTA_MAPr   r	   extendappendr   array)r   indexdegreesr   uppers        r   r   r      s   @ $djjl+a/	
TRquTF*CDEE cG BJEE~A~1v	
eb1v	u	r	1v	u	r	1v	u	r	1v 	1v rzq 	q NN1 AIEz1v	!2w	!2w	!2w	!2w 	Bx 88Gr   r#   )levelT)abbrunicoder   r   c                H   g d}t        | t              rt        | j                            dz
  }n#d| cxk  rdk  r	n n| dz
  }nt	        d|  d      |dz  }|dk  rd	|d
<   nd|d
<   |dk  rd|d<   nd|d<   |dz  }|dk(  rd|d<   nd|d<   |dk(  rd|d<   nd|d<   |r7t        j                  dddd      }|D cg c]  }|j                  |       }}|s7t        j                  dddd      }	|D cg c]  }|j                  |	       }}t        |      S c c}w c c}w )uL  Spell the Carnatic svara names for a given melakarta raga

    This function exists to resolve enharmonic equivalences between
    pitch classes:

        - Ri2 / Ga1
        - Ri3 / Ga2
        - Dha2 / Ni1
        - Dha3 / Ni2

    For svara outside the raga, names are chosen to preserve orderings
    so that all Ri precede all Ga, and all Dha precede all Ni.

    Parameters
    ----------
    mela : str or int
        the name or numerical index of the melakarta raga

    abbr : bool
        If `True`, use single-letter svara names: S, R, G, ...

        If `False`, use full names: Sa, Ri, Ga, ...

    unicode : bool
        If `True`, use unicode symbols for numberings, e.g., Ri₁

        If `False`, use low-order ASCII, e.g., Ri1.

    Returns
    -------
    svara : list of strings

        The svara names for each of the 12 pitch classes.

    See Also
    --------
    key_to_notes
    mela_to_degrees
    list_mela

    Examples
    --------
    Melakarta #1 (Kanakangi) uses R1, G1, D1, N1

    >>> librosa.mela_to_svara(1)
    ['S', 'R₁', 'G₁', 'G₂', 'G₃', 'M₁', 'M₂', 'P', 'D₁', 'N₁', 'N₂', 'N₃']

    #19 (Jhankaradhwani) uses R2 and G2 so the third svara are Ri:

    >>> librosa.mela_to_svara(19)
    ['S', 'R₁', 'R₂', 'G₂', 'G₃', 'M₁', 'M₂', 'P', 'D₁', 'N₁', 'N₂', 'N₃']

    #31 (Yagapriya) uses R3 and G3, so third and fourth svara are Ri:

    >>> librosa.mela_to_svara(31)
    ['S', 'R₁', 'R₂', 'R₃', 'G₃', 'M₁', 'M₂', 'P', 'D₁', 'N₁', 'N₂', 'N₃']

    #34 (Vagadheeswari) uses D2 and N2, so Ni1 becomes Dha2:

    >>> librosa.mela_to_svara(34)
    ['S', 'R₁', 'R₂', 'R₃', 'G₃', 'M₁', 'M₂', 'P', 'D₁', 'D₂', 'N₂', 'N₃']

    #36 (Chalanatta) uses D3 and N3, so Ni2 becomes Dha3:

    >>> librosa.mela_to_svara(36)
    ['S', 'R₁', 'R₂', 'R₃', 'G₃', 'M₁', 'M₂', 'P', 'D₁', 'D₂', 'D₃', 'N₃']

    # You can also query by raga name instead of index:

    >>> librosa.mela_to_svara('chalanatta')
    ['S', 'R₁', 'R₂', 'R₃', 'G₃', 'M₁', 'M₂', 'P', 'D₁', 'D₂', 'D₃', 'N₃']
    )Sau   Ri₁r   r   u   Ga₃u   Ma₁u   Ma₂Pau   Dha₁r   r   u   Ni₃r   r   r   r   r   r   r'   u   Ga₁r   u   Ri₂r   u   Ga₂r$   u   Ri₃u   Ni₁r!   u   Dha₂r   u   Dha₃r#   u   Ni₂r   )ahi123)u   ₁u   ₂u   ₃)r   r   r   r   r	   	maketrans	translatelist)
r   r   r   	svara_mapmela_idxr   r   t_abbrst_unis
             r   r   r     sX   ZI $ .2	
TR!8uTF*CDEE rMEqy!	! "	! rz!	! "	!qLE z!	! #	! z#	" #	"Rbr:;2;<)QQ[[()	<sKL1:;AQ[['	;	? = <s   <D5Dc                  *    t         j                         S )aU  List melakarta ragas by name and index.

    Melakarta raga names are transcribed from [#]_, with the exception of #45
    (subhapanthuvarali).

    .. [#] Bhagyalekshmy, S. (1990).
        Ragas in Carnatic music.
        South Asia Books.

    Returns
    -------
    mela_map : dict
        A dictionary mapping melakarta raga names to indices (1, 2, ..., 72)

    Examples
    --------
    >>> librosa.list_mela()
    {'kanakangi': 1,
     'ratnangi': 2,
     'ganamurthi': 3,
     'vanaspathi': 4,
     ...}

    See Also
    --------
    mela_to_degrees
    mela_to_svara
    list_thaat
    )r   copy r   r   r   r     s    < r   c                  <    t        t        j                               S )a}  List supported thaats by name.

    Returns
    -------
    thaats : list
        A list of supported thaats

    Examples
    --------
    >>> librosa.list_thaat()
    ['bilaval',
     'khamaj',
     'kafi',
     'asavari',
     'bhairavi',
     'kalyan',
     'marva',
     'poorvi',
     'todi',
     'bhairav']

    See Also
    --------
    list_mela
    thaat_to_degrees
    )r   r   keysr   r   r   r   r     s    6 	 !!r   keyc                      y Nr   r   s    r   __note_to_degreer         r   c                      y r   r   r   s    r   r   r     r   r   c                      y r   r   r   s    r   r   r     r   r   c           	         t        | t              s,t        j                  | D cg c]  }t	        |       c}      S t
        j                  |       }|st        d| d      |j                  d      j                         }|j                  d      }ddddd	d
dd}t        |      }||   t        t        D cg c]  }t        |   ||   z   c}      z   dz  S c c}w c c}w )u  Take a note name and return the degree of that note (e.g. 'C#' -> 1). We allow possibilities like "C#b".

    >>> librosa.__note_to_degree('B#')
    0

    >>> librosa.__note_to_degree('D♮##b')
    3

    >>> librosa.__note_to_degree(['B#','D♮##b'])
    array([0,3])

    Improper key format: r   note
accidentalr   r   r   r   r    r!   r"   r   r   )r   r   r   r   r   NOTE_REmatchr	   groupr   r   sumACC_MAP)r   r   r   letterr   	pitch_mapcounteraccs           r   r   r     s     c3xxc:c)!,c:;; MM#E4SG<==[[ &&(F\*JaaaaabIIj!Gfc'"R'373<'#,#>'"RSSUWWW ; #Ss   C9C 
.additional_accc                      y r   r   r   r   r   s      r   __simplify_noter     r   r   c                      y r   r   r   s      r   r   r     r   r   c                      y r   r   r   s      r   r   r     r   r   c           	         t        | t              s1t        j                  | D cg c]  }t	        ||z   |       c}      S t
        j                  | |z         }|st        d| d      |j                  d      j                         }|j                  d      }t        |      }t        t        D cg c]  }t        |   ||   z   c}      }	|}
|	dk\  r|
d|	dz  z  d	|	dz  z  z   z  }
n|
d
|	dz  z  dt        |	      dz  z  z   z  }
|s,t        j                  dddddd      }|
j                  |      }
|
S c c}w c c}w )uF  Take in a note name and simplify by canceling sharp-flat pairs, and doubling accidentals as appropriate.

    >>> librosa.__simplify_note('C♭♯')
    'C'

    >>> librosa.__simplify_note('C♭♭♭')
    'C♭𝄫'

    >>> librosa.__simplify_note(['C♭♯', 'C♭♭♭'])
    array(['C', 'C♭𝄫'], dtype='<U3')

    r   r   r   r   r   r   r   r   r   r   r   r   ##r   bbr   r   r   r   r   r   )r   r   r   r   r   r   r   r	   r   r   r   r   r   absr   r   )r   r   r   r   r   r   r   r   r   offsetsimplified_notetranslationss               r   r   r     sN    c#xxUXYUXPQ>)97KUXYZZMM#n,-E4SG<==[[ &&(F\*Jj!GA#'#,-ABFOqy5&(+VVQY-???5&(+VS[!^-DDD}}S$sTXad%ef)33LA- Z Bs   D93D>	signaturec                 V   t         j                  |       }|st        dj                  |             |j	                  d      s|j	                  d      sjt        |j	                  d      j                         |j	                  d      z   |      |j	                  d      rd|j	                  d      z   z   } | S dz   } | S |j	                  d      j                         d	d
 }t        |   |j	                  d      j                            }t        ||j	                  d      z   |      dz   S )ue  Translate a mode (eg D:dorian) into its equivalent major key. If unicode==True, return the accidentals as unicode symbols, regardless of nature of accidentals in signature. Otherwise, return accidentals as ASCII symbols.

    >>> librosa.__mode_to_key('Db:loc')
    'E𝄫:maj'

    >>> librosa.__mode_to_key('D♭:loc', unicode = False)
    'Ebb:maj'

    zImproper format: {:s}scalemodetonicr   r   :r   Nr$   z:maj)	KEY_REr   r	   formatr   r   r   r   
MAJOR_DICT)r   r   r   r   r   s        r   __mode_to_keyr   B  s8    LL#E4;;IFGG{{75;;v#6#EKK$8$>$>$@\AZ$Zdkl  KP  KV  KV  W^  K_nqrwr}r}  F  sG  oG  h	 eg  h	 ;;v$$&r*D tU[[1779:E5\!::gNvUUr   Fr   naturalr   c                &    t         j                  |       }|st        d| d      ddddddd	d
}|j                  d      j	                         }|j                  d      }t        |D cg c]  }t        |    c}      }|j                  d      s|j                  d      st        |       }	t        |	||      S |j                  d      dd j                         }
t        |      dk\  }|rddd}|t        j                  |         }t        ||t        |      dz
  z  z   dz   |
z   d      }|D cg c]  }t        ||       }}t        |      }t        j                  |t        j                   |dk(        d          }t#        |      }|s/t$        j'                  dddddd       t#         fd |D              }|S |
d!k(  }|r||   |z   dz  d"z  }n||   |z   dz  dz   d"z  }|dk  rd}n |dkD  rd#}nd|cxk  rd$k  rn nd#}n|d$kD  rd}g d%}g d&}g d'}g d(}|}|dk(  r|d)k(  rd"}r't)        d|d$z
  dz         D ]  }||   \  }}|||<    |}n.d"|z
  d"z  }t)        d|d$z
  dz         D ]  }||   \  }}|||<    |}|rLt+        t-        |             }t/        |      D ]*  \  }}t        |      |v rt1        |      dk(  s#|d*z   ||<   , |s/t$        j'                  dddddd       t#         fd+|D              }|S c c}w c c}w ),uN  List all 12 note names in the chromatic scale, as spelled according to
    a given key (major or minor) or mode (see below for details and accepted abbreviations).

    This function exists to resolve enharmonic equivalences between different
    spellings for the same pitch (e.g. C♯ vs D♭), and is primarily useful when producing
    human-readable outputs (e.g. plotting) for pitch content.

    Note names are decided by the following rules:

    1. If the tonic of the key has an accidental (sharp or flat), that accidental will be
       used consistently for all notes.

    2. If the tonic does not have an accidental, accidentals will be inferred to minimize
       the total number used for diatonic scale degrees.

    3. If there is a tie (e.g., in the case of C:maj vs A:min), sharps will be preferred.

    Parameters
    ----------
    key : string
        Must be in the form TONIC:key.  Tonic must be upper case (``CDEFGAB``),
        key must be lower-case
        (``major``, ``minor``, ``ionian``, ``dorian``, ``phrygian``, ``lydian``, ``mixolydian``, ``aeolian``, ``locrian``).

        The following abbreviations are supported for the modes: either the first three letters of the mode name
        (e.g. "mix") or the mode name without "ian" (e.g. "mixolyd").

        Both ``major`` and ``maj`` are supported as mode abbreviations.

        Single and multiple accidentals (``b!♭`` for flat, ``#♯`` for sharp, ``𝄪𝄫`` for double-accidentals, or any combination thereof) are supported.

        Examples: ``C:maj, C:major, Dbb:min, A♭:min, D:aeo, E𝄪:phryg``.

    unicode : bool
        If ``True`` (default), use Unicode symbols (♯𝄪♭𝄫)for accidentals.

        If ``False``, Unicode symbols will be mapped to low-order ASCII representations::

            ♯ -> #, 𝄪 -> ##, ♭ -> b, 𝄫 -> bb, ♮ -> n

    natural : bool
        If ``True'', mark natural accidentals with a natural symbol (♮).

        If ``False`` (default), do not print natural symbols.

        For example, `note_to_degrees('D:maj')[0]` is `C` if `natural=False` (default) and `C♮` if `natural=True`.

    Returns
    -------
    notes : list
        ``notes[k]`` is the name for semitone ``k`` (starting from C)
        under the given key.  All chromatic notes (0 through 11) are
        included.

    See Also
    --------
    midi_to_note

    Examples
    --------
    `C:maj` will use all sharps

    >>> librosa.key_to_notes('C:maj')
    ['C', 'C♯', 'D', 'D♯', 'E', 'F', 'F♯', 'G', 'G♯', 'A', 'A♯', 'B']

    `A:min` has the same notes

    >>> librosa.key_to_notes('A:min')
    ['C', 'C♯', 'D', 'D♯', 'E', 'F', 'F♯', 'G', 'G♯', 'A', 'A♯', 'B']

    `A♯:min` will use sharps, but spell note 0 (`C`) as `B♯`

    >>> librosa.key_to_notes('A#:min')
    ['B♯', 'C♯', 'D', 'D♯', 'E', 'E♯', 'F♯', 'G', 'G♯', 'A', 'A♯', 'B']

    `G♯:maj` will use a double-sharp to spell note 7 (`G`) as `F𝄪`:

    >>> librosa.key_to_notes('G#:maj')
    ['B♯', 'C♯', 'D', 'D♯', 'E', 'E♯', 'F♯', 'F𝄪', 'G♯', 'A', 'A♯', 'B']

    `F♭:min` will use double-flats

    >>> librosa.key_to_notes('Fb:min')
    ['D𝄫', 'D♭', 'E𝄫', 'E♭', 'F♭', 'F', 'G♭', 'A𝄫', 'A♭', 'B𝄫', 'B♭', 'C♭']

    `G:loc` uses flats

    >>> librosa.key_to_notes('G:loc')
    ['C', 'D♭', 'D', 'E♭', 'E', 'F', 'G♭', 'G', 'A♭', 'A', 'B♭', 'B']

    If `natural=True`, print natural accidentals.

    >>> librosa.key_to_notes('G:loc', natural=True)
    ['C', 'D♭', 'D♮', 'E♭', 'E♮', 'F', 'G♭', 'G', 'A♭', 'A♮', 'B♭', 'B♮']

    >>> librosa.key_to_notes('D:maj', natural=True)
    ['C♮', 'C♯', 'D', 'D♯', 'E', 'F♮', 'F♯', 'G', 'G♯', 'A', 'A♯', 'B']

    >>> librosa.key_to_notes('G#:maj', unicode = False, natural = True)
    ['B#', 'C#', 'Dn', 'D#', 'En', 'E#', 'F#', 'F##', 'G#', 'An', 'A#', 'B']

    r   r   r   r   r   r   r    r!   r"   r   r   r   r   r   r   Nr$   r   r   r   r   r   r   F)r   )shiftr   r   r   r   r   r   c              3   @   K   | ]  }|j                          y wr   r   .0r   r   s     r   	<genexpr>zkey_to_notes.<locals>.<genexpr>  s     BEq\2E   majr   Tr'   )rz   u   C♯r{   u   D♯r|   r}   r   r~   u   G♯r   u   A♯r   )rz   r   r{   r   r|   r}   r   r~   r   r   r   r   ))r   u   E♯)r   u   B♯)r    u   F𝄪)r   u   C𝄪)r!   u   G𝄪)r   u   D𝄪)r"   u   A𝄪))r"   u   C♭)r   u   F♭)r!   u   B𝄫)r   u   E𝄫)r    u   A𝄫)r   u   D𝄫r   r   c              3   @   K   | ]  }|j                          y wr   r  r  s     r   r  zkey_to_notes.<locals>.<genexpr>G  s     >1Q[[.r  )r   r   r	   r   r   r   r   r   r   r   r   r   signr   r   rollargwherer   r   r   rangesetr   	enumeratelen)!r   r   r   r   r   r   r   r   r   equivr   multiplesign_mapr   intermediate_notesr   notesr   majortonic_number
use_sharpsnotes_sharp
notes_flatsharp_correctionsflat_correctionsn_sharpsr   r   namen_flatsscale_notesplacer   s!                                   @r   r   r   ^  s}   R LLE4SG<==aaaaabIIKK &&(E\*J*5*3'#,*56F{{6%++g"6c"E7gFFKK !$**,E6{A~H 5)!"''&/2)%FA0N*Ns*RSX*XdijCUVCU4~6CUV"5)bkk'Q,&?&B%BCU==d3X\eh)ijLBEBBE UNE "5)F2a72="5)F2a7!;rA z
	!
	
l	Q	
		
 ^K\J HqUc\q(Q,*+A+A.KE4!%K , $* q'A+/*A*1-KE4 $Ju +  .-.$U+KE4%44y!|#Eze	 , }}S$sTXad%ef>>>Lq 6  Ws   +L	5Lc                    t        t        j                  g d      t        j                  g d            }t        j	                  |       }|st        d| d      |j                  d      s|j                  d      sFt        |       }t        |j                  d      dd	    }t        j                  t        |      |       S d
ddddddd}|j                  d      j                         }|j                  d      }t        |      }t        t        D 	cg c]  }	t        |	   ||	   z   c}	      }|j                  d      dd	 j                         }
||
   ||   z   |z   dz  S c c}	w )u`  Construct the diatonic scale degrees for a given key.

    Parameters
    ----------
    key : str
        Must be in the form TONIC:key.  Tonic must be upper case (``CDEFGAB``),
        key must be lower-case
        (``maj``, ``min``, ``ionian``, ``dorian``, ``phrygian``, ``lydian``, ``mixolydian``, ``aeolian``, ``locrian``).

        The following abbreviations are supported for the modes: either the first three letters of the mode name
        (e.g. "mix") or the mode name without "ian" (e.g. "mixolyd").

        Both ``major`` and ``maj`` are supported as abbreviations.

        Single and multiple accidentals (``b!♭`` for flat, or ``#♯`` for sharp) are supported.

        Examples: ``C:maj, C:major, Dbb:min, A♭:min, D:aeo, E𝄪:phryg``.

    Returns
    -------
    degrees : np.ndarray
        An array containing the semitone numbers (0=C, 1=C#, ... 11=B)
        for each of the seven scale degrees in the given key, starting
        from the tonic.

    See Also
    --------
    key_to_notes

    Examples
    --------
    >>> librosa.key_to_degrees('C:maj')
    array([ 0,  2,  4,  5,  7,  9, 11])

    >>> librosa.key_to_degrees('C#:maj')
    array([ 1,  3,  5,  6,  8, 10,  0])

    >>> librosa.key_to_degrees('A:min')
    array([ 9, 11,  0,  2,  4,  5,  7])

    >>> librosa.key_to_degrees('A:min')
    array([ 9, 11,  0,  2,  4,  5,  7])

    r   r%   )r	  minr   r   r   r   Nr$   r   r   r   r   r    r!   r"   r   r   r   r   )dictr   r   r   r   r	   r   r   OFFSET_DICTr  r   r   r   r   r   r   )r   r  r   r  r   r   r   r   countsr   r   s              r   r   r   M  sM   Z HH+,"((;Q2RE LLE4SG<=={{6%++g"6c"U[[0!45ww~e,fW55aaaaabIIKK &&(E\*JZ Fg>gs'#,vc{*g>?FKK !$**,E%L9U++f4::	 ?s   E(r   unisonfifthsc                 d   d}ddddddddddd
}|r	dd	d
ddd}ndddddd}t         j                  |       }|st        d| d      |j                  d      j	                         }t        j                  |j                  d      D cg c]  }||   	 c}      }	|j                  |      }
||
|z   dz     }|	|
|z   dz  z   }|t        j                  |      dz     t        t        |      dz        z  |t        j                  |         t        t        |      dz        z  z   }||z   S c c}w )u  Calculate the note name for a given number of perfect fifths
    from a specified unison.

    This function is primarily intended as a utility routine for
    Functional Just System (FJS) notation conversions.

    This function does not assume the "circle of fifths" or equal temperament,
    so 12 fifths will not generally produce a note of the same pitch class
    due to the accumulation of accidentals.

    Parameters
    ----------
    unison : str
        The name of the starting (unison) note, e.g., 'C' or 'Bb'.
        Unicode accidentals are supported.

    fifths : integer
        The number of perfect fifths to deviate from unison.

    unicode : bool
        If ``True`` (default), use Unicode symbols (♯𝄪♭𝄫)for accidentals.

        If ``False``, accidentals will be encoded as low-order ASCII representations::

            ♯ -> #, 𝄪 -> ##, ♭ -> b, 𝄫 -> bb

    Returns
    -------
    note : str
        The name of the requested note

    Examples
    --------
    >>> librosa.fifths_to_note(unison='C', fifths=6)
    'F♯'

    >>> librosa.fifths_to_note(unison='G', fifths=-3)
    'B♭'

    >>> librosa.fifths_to_note(unison='Eb', fifths=11, unicode=False)
    'G#'

    FCGDAEBr   r   r   r   r   )
r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   zImproper note format: r   r   r   r    )r   r   r	   r   r   r   r   r   r  intr   )r(  r)  r   COFMAPacc_mapacc_map_invr   pitchor   
circle_idx
raw_output	acc_indexacc_strs                 r   r   r     sl   \ F G F6bI$CTbAMM&!E5fQZ@AA KK%%'E VV\)BC)BAWQZ)BCDF e$Jf,12J *v-!33I "''),q01CI!5 BGGI&'#c)nq.@*AABG  Ds   
D-)nopythonnogilr   c                 `    | dt        j                  t        j                  |              z  z  S )zCompute the octave-folded interval.

    This maps intervals to the range [1, 2).

    This is part of the FJS notation converter.
    It is equivalent to the `red` function described in the FJS
    documentation.
           @)r   floorlog2ds    r   __o_foldr>    (     ,,,--r   c                 `    | dt        j                  t        j                  |              z  z  S )a  Compute the balanced, octave-folded interval.

    This maps intervals to the range [sqrt(2)/2, sqrt(2)).

    This is part of the FJS notation converter.
    It is equivalent to the `reb` function described in the FJS
    documentation, but with a simpler implementation.
    r9  )r   roundr;  r<  s    r   	__bo_foldrB    r?  r   c                    t        j                  t        j                  |            }t        d      D ]T  }dD ]H  }t        j                  t        j                  t	        | d||z  z  z                    |k  sA||z  c c S  |dz  }V S )zAccelerated helper function for finding the number of fifths
    to get within tolerance of a given interval.

    This implementation will give up after 32 fifths
        r  g      @r   )r   r   r;  r  rB  )interval	tolerancelog_tolerancepowerr  s        r   __fifth_searchrI  
  s     FF2779-.MrDrwwyCEDL4I)IJKL ! t|#  	
  Lr   
0123456789u   ⁰¹²³⁴⁵⁶⁷⁸⁹u   ₀₁₂₃₄₅₆₇₈₉)r(  rF  r   rE  rF  c                     y r   r   rE  r(  rF  r   s       r   r   r   "       r   c                     y r   r   rL  s       r   r   r   -  rM  r   c                     y r   r   rL  s       r   r   r   8  rM  r   U)otypesexcludedg! ?c                   | dk  rt        d|  d      t        | |      }t        |||      }	 t        |       }t        t        j                  |d         }|D 	ci c]  }	|	d	kD  s	|	||	    }}	t        j                  |D 	cg c]  }	||	   dkD  s|	||	   z   c}	      }
t        j                  |D 	cg c]  }	||	   dk  s|	||	    z   c}	      }d
}|
dkD  r%|r||
dj                  t              z  }n|d|
 z  }|dkD  r)|r||dj                  t              z  }||z   S |d| z  }||z   S # t        $ r}t        d|        |d}~ww xY wc c}	w c c}	w c c}	w )u	  Convert an interval to Functional Just System (FJS) notation.

    See https://misotanni.github.io/fjs/en/index.html for a thorough overview
    of the FJS notation system, and the examples below.

    FJS conversion works by identifying a Pythagorean interval which is within
    a specified tolerance of the target interval, which provides the core note
    name.  If the interval is derived from ratios other than perfect fifths,
    then the remaining factors are encoded as superscripts for otonal
    (increasing) intervals and subscripts for utonal (decreasing) intervals.

    Parameters
    ----------
    interval : float > 0 or iterable of floats
        A (just) interval to notate in FJS.

    unison : str
        The name of the unison note (corresponding to `interval=1`).

    tolerance : float
        The tolerance threshold for identifying the core note name.

    unicode : bool
        If ``True`` (default), use Unicode symbols (♯𝄪♭𝄫)for accidentals,
        and superscripts/subscripts for otonal and utonal accidentals.

        If ``False``, accidentals will be encoded as low-order ASCII representations::

            ♯ -> #, 𝄪 -> ##, ♭ -> b, 𝄫 -> bb

        Otonal and utonal accidentals will be denoted by `^##` and `_##`
        respectively (see examples below).

    Raises
    ------
    ParameterError
        If the provided interval is not positive

        If the provided interval cannot be identified with a
        just intonation prime factorization.

    Returns
    -------
    note_fjs : str or np.ndarray(dtype=str)
        The interval(s) relative to the given unison in FJS notation.

    Examples
    --------
    Pythagorean intervals appear as expected, with no otonal
    or utonal extensions:

    >>> librosa.interval_to_fjs(3/2, unison='C')
    'G'
    >>> librosa.interval_to_fjs(4/3, unison='F')
    'B♭'

    A ptolemaic major third will appear with an otonal '5':

    >>> librosa.interval_to_fjs(5/4, unison='A')
    'C♯⁵'

    And a ptolemaic minor third will appear with utonal '5':

    >>> librosa.interval_to_fjs(6/5, unison='A')
    'C₅'

    More complex intervals will have compound accidentals.
    For example:

    >>> librosa.interval_to_fjs(25/14, unison='F#')
    'E²⁵₇'
    >>> librosa.interval_to_fjs(25/14, unison='F#', unicode=False)
    'E^25_7'

    Array inputs are also supported:

    >>> librosa.interval_to_fjs([3/2, 4/3, 5/3])
    array(['G', 'F', 'A⁵'], dtype='<U2')

    r   z	Interval=z must be strictly positive)r(  r)  r   r'   )decimalszUnknown interval=Nr$   r   r   r=  ^_)r	   rI  r   r>  r   r   aroundKeyErrorprodr   SUPER_TRANS	SUB_TRANS)rE  r(  rF  r   r)  	note_name
interval_bpowersexcpotonalutonalsuffixs                r   r   r   C  s   t 1}y
2LMNN Hi0F fVWMIFh'
299Z!<=
 %+4Fqa!ealFF4 WWfFfq	Aa6!9nfFGFWWvGv!QaF1I:ovGHFFz
--k::F&l"Fz
--i88F v &l"Fv/  F0
;<#EF 5 GGs;   )D6 
E(EE
E7E E 6	E?EE)..)r   T)T)>__doc__renumpyr   numbar   collectionsr   	intervalsr   _cacher   util.exceptionsr	   typingr
   r   r   r   r   util.decoratorsr   _typingr   r   r   r   __all__r%  r   r  r   compiler   r   r   r&  r   r   ndarrayr   r,  r   boolr   r   r   r   r   r   r   r   r   r>  rB  rI  r   rZ  r[  floatr   r  )r   ks   00r   <module>ru     s    	       , 8 8 ' T T
 "!	"#!
 !	"	  I	
T 	
WLOL1 qDLOf 
s
 "** 3Ss3SQc&sSVWf3V&sY\]3Ss3VT3SvCcPSTc&vCVYZf3V&v\_`
 1QqSTV!"2aPR\]gi
j0C 0BJJ 0>_%S/ _bjj _D R+/N
S/N$(N:>N	#YN Nb 4S>  B"DI ": 
# #  
	-,   
	%]3%7# FG ERUWYWaWaRaLb  
X%]3%7# FG XERUVXV`V`R`La X8 
 c  s  
 
s+ S t _a_i_i  
 
sM#$6EF X[ ko z  AD  FH  FP  FP  AP  {Q  
$sM#$6EF $X[ $im $y~  @C  EG  EO  EO  @O  zP $LVS V4 V3 V8 R.25 jc jt jT jTRUY j j\C; C;

 C;L R@D Y c Y 3 Y  Y  Y  Y x d$d+	. ,	. d$d+	. ,	. d$d+ ,& mmL*GHMM,(HI	 
   	
  	 
 
 M*  	
  ZZ 
 
 .  	
  3

? 
 #$F GH  .  	
  3

? Is Os   N8