o
    o’×i}F  ã                   @   s  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	 g d¢Z
eg d¢g d	¢g d
¢g d¢g d¢g d¢g d¢g d¢g d¢g d¢d
Zdd„ eg d¢dƒD ƒZdd„ Zdd„ Ze	edddddœdd „ƒƒZd!d"„ Zd#d$„ Ze	edddd%œd&d'„ƒƒZd(d)„ ZdS )*zMusic notation utilitiesé    Né   )Úcache)ÚParameterError)Údeprecate_positional_args)Úkey_to_degreesÚkey_to_notesÚmela_to_degreesÚmela_to_svaraÚthaat_to_degreesÚ	list_melaÚ
list_thaat©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Úbhairavc                 C   s   i | ]\}}||“qS © r#   )Ú.0ÚiÚkr#   r#   úS/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/librosa/core/notation.pyÚ
<dictcomp>#   s    ÿÿr(   )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Úrasikapriyar   c                 C   s   t  t|  ¡  ¡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)Úthaatr#   r#   r'   r
   u   s   r
   c                 C   sð  t | tƒrt|  ¡  d }nd|   k rdkrn n| d }ntd | ¡ƒ‚dg}|d }d|  kr7dk rAn n| ddg¡ nWd|  krKdk rUn n| dd	g¡ nCd|  kr_d
k rin n| ddg¡ n/d
|  krsdk r}n n| dd	g¡ nd|  kr‡dk r‘n n| ddg¡ n| d	dg¡ |dk r¢| d¡ n| d¡ | d¡ |d }|dkr¼| ddg¡ n7|dkrÈ| ddg¡ n+|dkrÔ| ddg¡ n|d	krà| ddg¡ n|dkrì| ddg¡ n| ddg¡ t 	|¡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_MAPrt   r   ÚformatÚextendÚappendrq   Úarray)ÚmelaÚindexÚdegreesrt   Úupperr#   r#   r'   r   ”   sF   
!



r   r   )ÚlevelT)ÚabbrÚunicodec                C   sø   g d¢}t | tƒrt|  ¡  d }nd|   k rdkr#n n| d }ntd | ¡ƒ‚|d }|dk r7d|d	< nd
|d	< |dk rDd|d< nd|d< |d }|dkrUd|d< nd|d< |dkrbd|d< nd|d< |rodd„ |D ƒ}|sxdd„ |D ƒ}t|ƒS )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â‚NNu   Gaâ‚ƒu   Maâ‚u   Maâ‚‚ÚPau   Dhaâ‚NNu   Niâ‚ƒr   r   rv   rw   rx   r   u   Gaâ‚r   u   Riâ‚‚r|   u   Gaâ‚‚r   u   Riâ‚ƒu   Niâ‚r   u   Dhaâ‚‚r   u   Dhaâ‚ƒr   u   Niâ‚‚c              
   S   s$   g | ]}|  t d d d dœ¡¡‘qS )Ú )ÚaÚhr%   ©Ú	translater~   Ú	maketrans©r$   Úsr#   r#   r'   Ú
<listcomp>  s    ÿz!mela_to_svara.<locals>.<listcomp>c              
   S   s$   g | ]}|  t d dddœ¡¡‘qS )Ú1Ú2Ú3)u   â‚u   â‚‚u   â‚ƒr   r“   r#   r#   r'   r•   „  s    ÿÿ)r}   r~   r   rt   r   r€   Úlist)r„   r‰   rŠ   Ú	svara_mapÚmela_idxrt   r‡   r#   r#   r'   r	   ÷   s:   M





ÿþr	   c                   C   s   t  ¡ 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   Úcopyr#   r#   r#   r'   r   Œ  s   r   c                   C   s   t t ¡ ƒ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™   rs   Úkeysr#   r#   r#   r'   r   ­  s   r   )rŠ   c                   sÖ  t  d| ¡}|std | ¡ƒ‚ddddddd	d
œ}dddddddœ}| d¡ ¡ }| d¡}|| }| d¡dd…  ¡ }|dk}	|	rN|| | d d }
n|| | d d d }
|dk rad}n|dkrhd}nd|
  krrdk rwn nd}n|
dkr}d}g d¢}g d¢}g d¢}g d¢}|
}|
dkr™|dkr™d}|r´td|d d ƒD ]}|| \}}|||< q¤|}nd|
 d }td|d d ƒD ]}|| \}}|||< qÃ|}|sét 	dddd d!œ¡‰ t
‡ fd"d#„|D ƒƒ}|S )$u±	  Lists all 12 note names in the chromatic scale, as spelled according to
    a given key (major or minor).

    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 (``maj`` or ``min``).

        Single accidentals (``b!â™­`` for flat, or ``#â™¯`` for sharp) are supported.

        Examples: ``C:maj, Db:min, Aâ™­:min``.

    unicode : bool
        If ``True`` (default), use Unicode symbols (â™¯ð„ªâ™­ð„«)for accidentals.

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

            â™¯ -> #, ð„ª -> ##, â™­ -> b, ð„« -> bb

    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â™­']
    õK   ^(?P<tonic>[A-Ga-g])(?P<accidental>[#â™¯b!â™­]?):(?P<scale>(maj|min)(or)?)$úImproper key format: {:s}r   r   r   r   r   r   r   ©ÚCÚDÚEÚFÚGÚAÚBr   éÿÿÿÿ©ú#r   Úbú!õ   â™¯õ   â™­ÚtonicÚ
accidentalÚscaleNr   Úmajry   FTr   )r¡   u   Câ™¯r¢   u   Dâ™¯r£   r¤   u   Fâ™¯r¥   u   Gâ™¯r¦   u   Aâ™¯r§   )r¡   u   Dâ™­r¢   u   Eâ™­r£   r¤   u   Gâ™­r¥   u   Aâ™­r¦   u   Bâ™­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ª   z##r«   Úbb)r­   u   ð„ªr®   u   ð„«c                 3   s    | ]}|  ˆ ¡V  qd S )N)r‘   )r$   Ún©Útranslationsr#   r'   Ú	<genexpr>z  s   € zkey_to_notes.<locals>.<genexpr>)ÚreÚmatchr   r€   Úgroupr‡   rt   Úranger~   r’   r™   )ÚkeyrŠ   r¹   Ú	pitch_mapÚacc_mapr¯   r°   Úoffsetr±   ÚmajorÚtonic_numberÚ
use_sharpsÚnotes_sharpÚ
notes_flatÚsharp_correctionsÚflat_correctionsÚn_sharpsr´   r…   ÚnameÚnotesÚn_flatsr#   rµ   r'   r   Ë  sZ   Mü
	


r   c           	      C   s²   t t g d¢¡t g d¢¡d}t d| ¡}|std | ¡ƒ‚dddd	d
dddœ}dddddddœ}| d¡ ¡ }| d¡}|| }| d¡dd…  	¡ }|| ||  | d S )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`` or ``min``).

        Single accidentals (``b!â™­`` for flat, or ``#â™¯`` for sharp) are supported.

        Examples: ``C:maj, Db:min, Aâ™­:min``.

    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])

    r   r   )r²   Úminrž   rŸ   r   r   r   r   r   r   r   r    r   r¨   r©   r¯   r°   r±   Nr   ry   )
Údictrq   rƒ   r¸   r¹   r   r€   rº   r‡   rt   )	r¼   rÉ   r¹   r½   r¾   r¯   r°   r¿   r±   r#   r#   r'   r     s    $ÿü
r   )Ú__doc__r¸   Únumpyrq   Ú_cacher   Úutil.exceptionsr   Úutil.decoratorsr   Ú__all__rÌ   rs   Ú	enumerater   r
   r   r	   r   r   r   r   r#   r#   r#   r'   Ú<module>   sL   
öJµþRc ! 3