
    }Kg                       d Z ddlmZ ddlm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mZ dd
lmZ ddlmZmZmZm Z m!Z!m"Z"m#Z# ddl$m%Z% er$ddlZddl&m'Z'm(Z( ddl)m*Z* ddl+m,Z- ddl.m/Z/ ddl0m1Z1 g dZ2 G d dejf                        Z4 G d dejf                        Z5 G d dejf                        Z6 G d dejf                        Z7 G d dejf                        Z8 G d dejf                        Z9 G d d ejf                        Z: G d! d"ejf                        Z; G d# d$ejf                        Z< G d% d&      Z=d'd(d)d*d+	 	 	 	 	 	 	 	 	 	 	 dSd,Z>d- Z?d.Z@d/ZAd0ZBd1ZCd2ZDd3ZE eFeED  cg c]  } | | f c}  ee@e@      D  cg c]  } |  c} z    eeAeA      D  cg c]  } |  c} z    eeBeB      D  cg c]  } |  c} z    eeCeC      D  cg c]  } |  c} z    eeDeD      D  cg c]  } |  c} z         ZGddddd4d5ddddd6d7d8d9d:dddd'd;d'dddd<	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dTd=ZHd> ZId? ZJdUd@ZKdA ZL	 	 	 	 	 	 	 	 	 	 dVdBZM	 dW	 	 	 	 	 	 	 	 	 dXdCZN	 	 	 	 dY	 	 	 	 	 	 	 	 	 	 	 	 	 dZdDZO	 	 	 d[	 	 	 	 	 	 	 	 	 	 	 d\dEZP	 	 	 	 	 d]	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d^dFZQd_d`dGZR	 da	 	 	 	 	 	 	 	 	 dbdHZS	 	 	 dc	 	 	 	 	 	 	 	 	 	 	 dddIZTdedJZU	 da	 	 	 	 	 	 	 	 	 dbdKZVdL ZWd4dMdNd8dOdPdd;d e       dQ
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dfdRZXyc c} w c c} w c c} w c c} w c c} w c c} w )ga  
Display
=======

Data visualization
------------------
.. autosummary::
    :toctree: generated/

    specshow
    waveshow

Axis formatting
---------------
.. autosummary::
    :toctree: generated/

    TimeFormatter
    NoteFormatter
    SvaraFormatter
    FJSFormatter
    LogHzFormatter
    ChromaFormatter
    ChromaSvaraFormatter
    ChromaFJSFormatter
    TonnetzFormatter

Miscellaneous
-------------
.. autosummary::
    :toctree: generated/

    cmap
    AdaptiveWaveplot

    )annotations)productN)	colormaps   )core)util)	rename_kw
Deprecated)ParameterError)TYPE_CHECKINGAny
CollectionOptionalUnionCallableDict)_FloatLike_co)QuadMeshPolyCollection)Line2D)Path)MarkerStyle)Colormap)specshowwaveshowcmapTimeFormatterNoteFormatterFJSFormatterLogHzFormatterChromaFormatterChromaSvaraFormatterChromaFJSFormatterTonnetzFormatterAdaptiveWaveplotc                  $    e Zd ZdZdddZdddZy)	r   uq  A tick formatter for time axes.

    Automatically switches between seconds, minutes:seconds,
    or hours:minutes:seconds.

    Parameters
    ----------
    lag : bool
        If ``True``, then the time axis is interpreted in lag coordinates.
        Anything past the midpoint will be converted to negative time.

    unit : str or None
        Abbreviation of the string representation for axis labels and ticks.
        List of supported units:
        * `"h"`: hour-based format (`H:MM:SS`)
        * `"m"`: minute-based format (`M:SS`)
        * `"s"`: second-based format (`S.sss` in scientific notation)
        * `"ms"`: millisecond-based format (`s.µµµ` in scientific notation)
        * `None`: adaptive to the duration of the underlying time range: similar
        to `"h"` above 3600 seconds; to `"m"` between 60 and 3600 seconds; to
        `"s"` between 1 and 60 seconds; and to `"ms"` below 1 second.


    See Also
    --------
    matplotlib.ticker.Formatter


    Examples
    --------
    For normal time

    >>> import matplotlib.pyplot as plt
    >>> times = np.arange(30)
    >>> values = np.random.randn(len(times))
    >>> fig, ax = plt.subplots()
    >>> ax.plot(times, values)
    >>> ax.xaxis.set_major_formatter(librosa.display.TimeFormatter())
    >>> ax.set(xlabel='Time')

    Manually set the physical time unit of the x-axis to milliseconds

    >>> times = np.arange(100)
    >>> values = np.random.randn(len(times))
    >>> fig, ax = plt.subplots()
    >>> ax.plot(times, values)
    >>> ax.xaxis.set_major_formatter(librosa.display.TimeFormatter(unit='ms'))
    >>> ax.set(xlabel='Time (ms)')

    For lag plots

    >>> times = np.arange(60)
    >>> values = np.random.randn(len(times))
    >>> fig, ax = plt.subplots()
    >>> ax.plot(times, values)
    >>> ax.xaxis.set_major_formatter(librosa.display.TimeFormatter(lag=True))
    >>> ax.set(xlabel='Lag')
    Nc                D    |dvrt        d|       || _        || _        y )N)hmsmsNzUnknown time unit: )r   unitlag)selfr-   r,   s      S/home/alanp/www/video.onchill/myenv/lib/python3.12/site-packages/librosa/display.py__init__zTimeFormatter.__init__   s,    22 #6tf!=>>	    c           
        | j                   j                         \  }}| j                   j                         \  }}| j                  r)||dz  k\  r!||kD  ryt	        j
                  ||z
        }d}n|}d}| j                  dk(  s| j                  e||z
  dkD  r]dj                  t        |dz        t        t	        j                  |d	z  d
            t        t	        j                  |d
                  }	n| j                  dk(  s| j                  D||z
  d
kD  r<dj                  t        |d	z        t        t	        j                  |d
                  }	no| j                  dk(  r|d}	n[| j                  dk(  r||z
  dk\  r|d}	n?| j                  dk(  rdj                  |dz        }	n| j                  dk(  r||z
  dk  r|d}	|d	dS )zReturn the time format as pos      ? -r(   Ni  z{:d}:{:02d}:{:02d}g      @g      N@<   r)   z{:d}:{:02d}r*   z.3gr   z.2gr+   z{:.3g}i  z.3f)
axisget_data_intervalget_view_intervalr-   npabsr,   formatintmod)
r.   xpos_dmaxvminvmaxvaluesignr*   s
             r/   __call__zTimeFormatter.__call__   s   ))--/4YY002
d 88TCZ4xFF1t8$EDED99!2t9K$++EFN#BFF54<,-BFF5"%&A
 YY#499#44$;;K$$S%6BFF5"<M8NOAYY#+AYY$D4K1$4+AYY$-AYY$D4K!O+Aq!Ar1   )FN)r-   boolr,   Optional[str]Nr?   floatr@   Optional[int]returnstr__name__
__module____qualname____doc__r0   rG    r1   r/   r   r   S   s    9v" r1   r   c                  :    e Zd ZdZ	 	 	 	 d	 	 	 	 	 	 	 ddZdddZy)	r   a  Ticker formatter for Notes

    Parameters
    ----------
    octave : bool
        If ``True``, display the octave number along with the note name.

        Otherwise, only show the note name (and cent deviation)

    major : bool
        If ``True``, ticks are always labeled.

        If ``False``, ticks are only labeled if the span is less than 2 octaves

    key : str
        Key for determining pitch spelling.

    unicode : bool
        If ``True``, use unicode symbols for accidentals.

        If ``False``, use ASCII symbols for accidentals.

    See Also
    --------
    LogHzFormatter
    matplotlib.ticker.Formatter

    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> values = librosa.midi_to_hz(np.arange(48, 72))
    >>> fig, ax = plt.subplots(nrows=2)
    >>> ax[0].bar(np.arange(len(values)), values)
    >>> ax[0].set(ylabel='Hz')
    >>> ax[1].bar(np.arange(len(values)), values)
    >>> ax[1].yaxis.set_major_formatter(librosa.display.NoteFormatter())
    >>> ax[1].set(ylabel='Note')
    c                <    || _         || _        || _        || _        y rJ   )octavemajorkeyunicode)r.   rX   rY   rZ   r[   s        r/   r0   zNoteFormatter.__init__   s      
r1   Nc                   |dk  ry| j                   j                         \  }}| j                  s|dt        d|      z  kD  ry|dt        d|      z  k  }t	        j
                  || j                  || j                  | j                        S )Apply the formatter to positionr   r4      r      rX   centsrZ   r[   )	r7   r9   rY   maxr   
hz_to_noterX   rZ   r[   )r.   r?   r@   rC   rD   ra   s         r/   rG   zNoteFormatter.__call__   s}    6 YY002
dzzdQQ%55C4L((dkkDHHdll
 	
r1   )TTC:majT)rX   rH   rY   rH   rZ   rO   r[   rH   rJ   rK   rP   rU   r1   r/   r   r      sF    %R 

 
 	

 

r1   r   c                  D    e Zd ZdZ	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZdddZy)	SvaraFormattera  Ticker formatter for Svara

    Parameters
    ----------
    octave : bool
        If ``True``, display the octave number along with the note name.

        Otherwise, only show the note name (and cent deviation)

    major : bool
        If ``True``, ticks are always labeled.

        If ``False``, ticks are only labeled if the span is less than 2 octaves

    Sa : number > 0
        Frequency (in Hz) of Sa

    mela : str or int
        For Carnatic svara, the index or name of the melakarta raga in question

        To use Hindustani svara, set ``mela=None``

    unicode : bool
        If ``True``, use unicode symbols for accidentals.

        If ``False``, use ASCII symbols for accidentals.

    See Also
    --------
    NoteFormatter
    matplotlib.ticker.Formatter
    librosa.hz_to_svara_c
    librosa.hz_to_svara_h


    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> values = librosa.midi_to_hz(np.arange(48, 72))
    >>> fig, ax = plt.subplots(nrows=2)
    >>> ax[0].bar(np.arange(len(values)), values)
    >>> ax[0].set(ylabel='Hz')
    >>> ax[1].bar(np.arange(len(values)), values)
    >>> ax[1].yaxis.set_major_formatter(librosa.display.SvaraFormatter(261))
    >>> ax[1].set(ylabel='Note')
    Nc                r    |t        d      || _        || _        || _        || _        || _        || _        y )Nz5Sa frequency is required for svara display formatting)r   SarX   rY   abbrmelar[   )r.   rh   rX   rY   ri   rj   r[   s          r/   r0   zSvaraFormatter.__init__1  sE     : G  
		r1   c                   |dk  ry| j                   j                         \  }}| j                  s|dt        d|      z  kD  ry| j                  Bt        j                  || j                  | j                  | j                  | j                        S t        j                  || j                  | j                  | j                  | j                  | j                        S )Nr   r4   r^   r   rh   rX   ri   r[   rh   rj   rX   ri   r[   )r7   r9   rY   rb   rj   r   hz_to_svara_hrh   rX   ri   r[   hz_to_svara_cr.   r?   r@   rC   rD   s        r/   rG   zSvaraFormatter.__call__F  s    6 YY002
dzzdQQ%5599%%dggdkk		4<<  %%77YY{{YY r1   )TTFNT)rh   rL   rX   rH   rY   rH   ri   rH   rj   Optional[Union[str, int]]r[   rH   rJ   rK   rP   rU   r1   r/   rf   rf     s]    -d *.  	
  ( *r1   rf   c                  F    e Zd ZdZdddd	 	 	 	 	 	 	 	 	 	 	 	 	 ddZdd	dZy)
r   a  Ticker formatter for Functional Just System (FJS) notation

    Parameters
    ----------
    fmin : float
        The unison frequency for this axis

    intervals : str or array of float in [1, 2)
        The interval specification for the frequency axis.

        See `core.interval_frequencies` for supported values.

    major : bool
        If ``True``, ticks are always labeled.

        If ``False``, ticks are only labeled if the span is less than 2 octaves

    unison : str
        The unison note name.  If not provided, it will be inferred from fmin.

    unicode : bool
        If ``True``, use unicode symbols for accidentals.

        If ``False``, use ASCII symbols for accidentals.

    See Also
    --------
    NoteFormatter
    hz_to_fjs
    matplotlib.ticker.Formatter

    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> values = librosa.midi_to_hz(np.arange(48, 72))
    >>> fig, ax = plt.subplots(nrows=2)
    >>> ax[0].bar(np.arange(len(values)), values)
    >>> ax[0].set(ylabel='Hz')
    >>> ax[1].bar(np.arange(len(values)), values)
    >>> ax[1].yaxis.set_major_formatter(librosa.display.NoteFormatter())
    >>> ax[1].set(ylabel='Note')
    TN)rY   unisonr[   c                   || _         || _        || _        || _        || _        || _        || _        t        j                  ||||      | _	        y )Nfmin	intervalsbins_per_octave)
rv   rY   rs   r[   rw   n_binsrx   r   interval_frequenciesfrequencies_)r.   rv   ry   rx   rw   rY   rs   r[   s           r/   r0   zFJSFormatter.__init__  sR     	
". 55O
r1   c                ~   |dk  ry| j                   j                         \  }}| j                  s|dt        d|      z  kD  ryt	        j
                  t        j                  |      | j                        d   }t        j                  | j                  |   | j                  | j                  | j                        }|S )r]   r   r4   r^   r   )rv   rs   r[   )r7   r9   rY   rb   r   match_eventsr:   
atleast_1dr{   r   	hz_to_fjsrv   rs   r[   )r.   r?   r@   rC   rD   idxlabels          r/   rG   zFJSFormatter.__call__  s    6 YY002
dzzdQQ%55 a 0$2C2CDQG^^c";;LL	
 r1   )rv   r=   ry   r=   rx   r=   rw   Union[str, Collection[float]]rY   rH   rs   rI   r[   rH   rJ   rK   rP   rU   r1   r/   r   r   _  sc    )d  $
 
 	

 
 1
 
 
 
,r1   r   c                  $    e Zd ZdZdddZdddZy)	r    a  Ticker formatter for logarithmic frequency

    Parameters
    ----------
    major : bool
        If ``True``, ticks are always labeled.

        If ``False``, ticks are only labeled if the span is less than 2 octaves

    See Also
    --------
    NoteFormatter
    matplotlib.ticker.Formatter

    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> values = librosa.midi_to_hz(np.arange(48, 72))
    >>> fig, ax = plt.subplots(nrows=2)
    >>> ax[0].bar(np.arange(len(values)), values)
    >>> ax[0].yaxis.set_major_formatter(librosa.display.LogHzFormatter())
    >>> ax[0].set(ylabel='Hz')
    >>> ax[1].bar(np.arange(len(values)), values)
    >>> ax[1].yaxis.set_major_formatter(librosa.display.NoteFormatter())
    >>> ax[1].set(ylabel='Note')
    c                    || _         y rJ   rY   )r.   rY   s     r/   r0   zLogHzFormatter.__init__  s	    
r1   Nc                    |dk  ry| j                   j                         \  }}| j                  s|dt        d|      z  kD  ry|dS )r]   r   r4   r^   r   g)r7   r9   rY   rb   rp   s        r/   rG   zLogHzFormatter.__call__  sG    6YY002
dzzdQQ%55Ar1   )T)rY   rH   rJ   rK   rP   rU   r1   r/   r    r      s    6
r1   r    c                  $    e Zd ZdZdddZdddZy)	r!   ac  A formatter for chroma axes

    See Also
    --------
    matplotlib.ticker.Formatter

    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> values = np.arange(12)
    >>> fig, ax = plt.subplots()
    >>> ax.plot(values)
    >>> ax.yaxis.set_major_formatter(librosa.display.ChromaFormatter())
    >>> ax.set(ylabel='Pitch class')
    c                     || _         || _        y rJ   rZ   r[   )r.   rZ   r[   s      r/   r0   zChromaFormatter.__init__  s    r1   Nc                p    t        j                  t        |      dd| j                  | j                        S )Format for chroma positionsFr`   )r   midi_to_noter=   rZ   r[   r.   r?   r@   s      r/   rG   zChromaFormatter.__call__  s,      F5488T\\
 	
r1   )rd   T)rZ   rO   r[   rH   rJ   rK   rP   rU   r1   r/   r!   r!     s     
r1   r!   c                  :    e Zd ZdZ	 	 	 	 d	 	 	 	 	 	 	 ddZdddZy)	r"   a!  A formatter for chroma axes with svara instead of notes.

    If mela is given, Carnatic svara names will be used.

    Otherwise, Hindustani svara names will be used.

    If `Sa` is not given, it will default to 0 (equivalent to `C`).

    See Also
    --------
    ChromaFormatter

    Nc                D    |d}|| _         || _        || _        || _        y )Nr   )rh   rj   ri   r[   )r.   rh   rj   ri   r[   s        r/   r0   zChromaSvaraFormatter.__init__  s*     :B		r1   c                4   | j                   Lt        j                  t        |      | j                  | j                   d| j
                  | j                        S t        j                  t        |      | j                  d| j
                  | j                        S )r   Frm   rl   )rj   r   midi_to_svara_cr=   rh   ri   r[   midi_to_svara_hr   s      r/   rG   zChromaSvaraFormatter.__call__  su    99 ''A77YYYY  ''A4775tyy$,, r1   )NNTT)rh   Optional[float]rj   zOptional[Union[int, str]]ri   rH   r[   rH   rJ   rK   rP   rU   r1   r/   r"   r"      sE      #*. ( 	
 r1   r"   c                  :    e Zd ZdZdddd	 	 	 	 	 	 	 ddZd	d
dZy)r#   a  A formatter for chroma axes with functional just notation

    See Also
    --------
    matplotlib.ticker.Formatter

    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> values = np.arange(12)
    >>> fig, ax = plt.subplots()
    >>> ax.plot(values)
    >>> ax.yaxis.set_major_formatter(librosa.display.ChromaFJSFormatter(intervals="ji5", bins_per_octave=12))
    >>> ax.set(ylabel='Pitch class')
    CTN)rs   r[   rx   c               X   || _         || _        || _        	 t        |t              st        |      }t        |t              st        d| d      || _        t        j                  | j                  d|| j                        | _        y # t        $ r}t        d| d      |d }~ww xY w)Nzbins_per_octave=z must be integer-valuedr   ru   z
intervals=z? must be of type str or a collection of numbers between 1 and 2)rs   r[   rw   
isinstancerO   lenr=   r   rx   r   rz   
intervals_	TypeError)r.   rw   rs   r[   rx   excs         r/   r0   zChromaFJSFormatter.__init__?  s     "	i-"%i.os3$&&77NO  )8D "77$$# $ 4 4	DO  	 YK'fg	s   A3B 	B)B$$B)c                    t        j                  | j                  t        |      | j                  z     | j
                  | j                        }|S )r   )rs   r[   )r   interval_to_fjsr   r=   rx   rs   r[   )r.   r?   r@   labs       r/   rG   zChromaFJSFormatter.__call__^  sB    ''OOCFT%9%99:;;LL

 
r1   )rw   r   rs   rO   r[   rH   rx   rM   rJ   rK   rP   rU   r1   r/   r#   r#   .  sD    ( )- 1 	
  '>r1   r#   c                      e Zd ZdZdddZy)r$   a`  A formatter for tonnetz axes

    See Also
    --------
    matplotlib.ticker.Formatter

    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> values = np.arange(6)
    >>> fig, ax = plt.subplots()
    >>> ax.plot(values)
    >>> ax.yaxis.set_major_formatter(librosa.display.TonnetzFormatter())
    >>> ax.set(ylabel='Tonnetz')
    Nc                "    g dt        |         S )zFormat for tonnetz positions)z5$_x$z5$_y$zm3$_x$zm3$_y$zM3$_x$zM3$_y$)r=   r   s      r/   rG   zTonnetzFormatter.__call__y  s    OPSTUPVWWr1   rJ   rK   )rQ   rR   rS   rT   rG   rU   r1   r/   r$   r$   h  s     Xr1   r$   c                  p    e Zd ZdZ	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZdd	 	 	 	 	 ddZdddd	Zdd
Zy)r%   ay  A helper class for managing adaptive wave visualizations.

    This object is used to dynamically switch between sample-based and envelope-based
    visualizations of waveforms.
    When the display is zoomed in such that no more than `max_samples` would be
    visible, the sample-based display is used.
    When displaying the raw samples would require more than `max_samples`, an
    envelope-based plot is used instead.

    You should never need to instantiate this object directly, as it is constructed
    automatically by `waveshow`.

    Parameters
    ----------
    times : np.ndarray
        An array containing the time index (in seconds) for each sample.

    y : np.ndarray
        An array containing the (monophonic) wave samples.

    steps : matplotlib.lines.Line2D
        The matplotlib artist used for the sample-based visualization.
        This is constructed by `matplotlib.pyplot.step`.

    envelope : matplotlib.collections.PolyCollection
        The matplotlib artist used for the envelope-based visualization.
        This is constructed by `matplotlib.pyplot.fill_between`.

    sr : number > 0
        The sampling rate of the audio

    max_samples : int > 0
        The maximum number of samples to use for sample-based display.

    transpose : bool
        If `True`, display the wave vertically instead of horizontally.

    See Also
    --------
    waveshow
    Fc                    || _         || _        || _        || _        || _        || _        || _        d | _        d | _        y rJ   )	timessamplesstepsenvelopesrmax_samples	transposecidax)r.   r   yr   r   r   r   r   s           r/   r0   zAdaptiveWaveplot.__init__  sD     

 &""&*.r1   c                (    | j                  d       y)z%Disconnect callback methods on deleteTstrictN)
disconnect)r.   s    r/   __del__zAdaptiveWaveplot.__del__  s    t$r1   xlim_changedsignalc                   | j                          || _        |j                  j                  || j                        | _        y)a  Connect the adaptor to a signal on an axes object.

        Note that if the adaptor has already been connected to an axes object,
        that connect is first broken and then replaced by a new callback.

        Parameters
        ----------
        ax : matplotlib.axes.Axes
            The axes to connect with this adaptor's `update`
        signal : string, {"xlim_changed", "ylim_changed"}
            The signal to connect

        See Also
        --------
        disconnect
        N)r   r   	callbacksconnectupdater   )r.   r   r   s      r/   r   zAdaptiveWaveplot.connect  s3    . 	 <<''<r1   r   c                   | j                   rA| j                   j                  j                  | j                         d| _        |rd| _         yyy)a  Disconnect the adaptor's update callback.

        Parameters
        ----------
        strict : bool
            If `True`, remove references to the connected axes.
            If `False` (default), only disconnect the callback.

            This functionality is intended primarily for internal use,
            and should have no observable effects for users.

        See Also
        --------
        connect
        N)r   r   r   r   )r.   r   s     r/   r   zAdaptiveWaveplot.disconnect  sB      77GG((2DH  r1   c                $   |j                   }| j                  rd|j                  | j                  z  }|j                  |j
                  }}| j                  | j                  }}| j                  j                         }nc|j                  | j                  z  }|j                  |j                  }}| j                  | j                  }}| j                  j                         }|| j                  k  r| j                  j!                  d       | j                  j!                  d       ||d   k  s||d   k\  r||z   dz  }	t#        j$                  | j                  |	d| j                  z  | j                  z  z
        }
| j                  j'                  ||
|
| j                  z    ||
|
| j                  z           n6| j                  j!                  d       | j                  j!                  d       |j(                  j*                  j-                          y)a  Update the matplotlib display according to the current viewport limits.

        This is a callback function, and should not be used directly.

        Parameters
        ----------
        ax : matplotlib.axes.Axes
            The axes object to update
        FTr   r_   r3   N)viewLimr   heightr   y0y1r   r   r   	get_ydatawidthx0x1	get_xdatar   r   set_visibler:   searchsortedset_datafigurecanvas	draw_idle)r.   r   limsdimstartendxdataydatadatamidpoint_time	idx_starts              r/   r   zAdaptiveWaveplot.update  s    zz>>++'C$''3E<<5E::'')D**tww&C$''3E::t||5E::'')D $"""MM%%e,JJ""4( Q3$r(? "' 1OOJJd6F6F0F0P P	 

##)i$2B2B&BC)i$2B2B&BC MM%%d+JJ""5)
		""$r1   N)"V  +  F)r   
np.ndarrayr   r   r   r   r   r   r   rL   r   r=   r   rH   )rN   None)r   mplaxes.Axesr   rO   rN   r   )r   rH   rN   r   )r   r   rN   r   )	rQ   rR   rS   rT   r0   r   r   r   r   rU   r1   r/   r%   r%   ~  s    (`  // / 	/
 !/ / / /(% %	== 	=
 
=: ,1 ,-%r1   r%   Tmagmagray_rcoolwarm)robustcmap_seq	cmap_boolcmap_divc                  t        j                  |       } | j                  dk(  r	t        |   S | t        j                  |          } |rd\  }}nd\  }}t        j
                  | ||g      \  }}|dk\  s|dk  r	t        |   S t        |   S )a  Get a default colormap from the given data.

    If the data is boolean, use a black and white colormap.

    If the data has both positive and negative values,
    use a diverging colormap.

    Otherwise, use a sequential colormap.

    Parameters
    ----------
    data : np.ndarray
        Input data
    robust : bool
        If True, discard the top and bottom 2% of data when calculating
        range.
    cmap_seq : str
        The sequential colormap name
    cmap_bool : str
        The boolean colormap name
    cmap_div : str
        The diverging colormap name

    Returns
    -------
    cmap : matplotlib.colors.Colormap
        The colormap to use for ``data``

    See Also
    --------
    matplotlib.pyplot.colormaps
    rH   )r_   b   )r   d   r   )r:   r~   dtypemcmisfinite
percentile)	r   r   r   r   r   min_pmax_pmin_valmax_vals	            r/   r   r   $  s    P ==DzzV9~D!"Duu}}TE5>:GW!|w!|8}x=r1   c                |    t        j                  t        j                  | ||            }|j	                  d      S )zCompute the max-envelope of non-overlapping frames of x at length hop

    x is assumed to be multi-channel, of shape (n_channels, n_samples).
    )frame_length
hop_lengthr   )r7   )r:   r;   r   framerb   )r?   hopx_frames      r/   
__enveloper   `  s0    
 ffTZZDEG;;A;r1   )chromachroma_hchroma_c
chroma_fjs)cqt_hzcqt_note	cqt_svara)linearffthzfft_note	fft_svara)timer(   r)   r*   r+   )r-   lag_hlag_mlag_slag_ms)tempofourier_tempomellogtonnetzframesr         i             rd   F)x_coordsy_coordsx_axisy_axisr   r   n_fft
win_lengthrv   fmax	tempo_min	tempo_maxtuningrx   rZ   rh   rj   thaatauto_aspecthtkr[   rw   rs   r   c                  t        j                  | j                  t         j                        r,t	        j
                  dd       t        j                  |       } |j                  dt        |              |j                  dd       |j                  dd       |j                  d	d
       t        |||	|
||||||||||      }t        ||| j                  d   fi |}t        ||| j                  d   fi |}t        |      } |j                  ||| fi |}t        ||       t        ||d||       t        ||d||       t!        |j"                  |||||||	|||t%        |             t!        |j&                  |||||||	|||t%        |             t)        |||j+                         |j-                               r|r|j/                  d       |S )a"  Display a spectrogram/chromagram/cqt/etc.

    For a detailed overview of this function, see :ref:`sphx_glr_auto_examples_plot_display.py`

    Parameters
    ----------
    data : np.ndarray [shape=(d, n)]
        Matrix to display (e.g., spectrogram)

    sr : number > 0 [scalar]
        Sample rate used to determine time scale in x-axis.

    hop_length : int > 0 [scalar]
        Hop length, also used to determine time scale in x-axis

    n_fft : int > 0 or None
        Number of samples per frame in STFT/spectrogram displays.
        By default, this will be inferred from the shape of ``data``
        as ``2 * (d - 1)``.
        If ``data`` was generated using an odd frame length, the correct
        value can be specified here.

    win_length : int > 0 or None
        The number of samples per window.
        By default, this will be inferred to match ``n_fft``.
        This is primarily useful for specifying odd window lengths in
        Fourier tempogram displays.

    x_axis, y_axis : None or str
        Range for the x- and y-axes.

        Valid types are:

        - None, 'none', or 'off' : no axis decoration is displayed.

        Frequency types:

        - 'linear', 'fft', 'hz' : frequency range is determined by
          the FFT window and sampling rate.
        - 'log' : the spectrum is displayed on a log scale.
        - 'fft_note': the spectrum is displayed on a log scale with pitches marked.
        - 'fft_svara': the spectrum is displayed on a log scale with svara marked.
        - 'mel' : frequencies are determined by the mel scale.
        - 'cqt_hz' : frequencies are determined by the CQT scale.
        - 'cqt_note' : pitches are determined by the CQT scale.
        - 'cqt_svara' : like `cqt_note` but using Hindustani or Carnatic svara
        - 'vqt_fjs' : like `cqt_note` but using Functional Just System (FJS)
          notation.  This requires a just intonation-based variable-Q
          transform representation.

        All frequency types are plotted in units of Hz.

        Any spectrogram parameters (hop_length, sr, bins_per_octave, etc.)
        used to generate the input data should also be provided when
        calling `specshow`.

        Categorical types:

        - 'chroma' : pitches are determined by the chroma filters.
          Pitch classes are arranged at integer locations (0-11) according to
          a given key.

        - `chroma_h`, `chroma_c`: pitches are determined by chroma filters,
          and labeled as svara in the Hindustani (`chroma_h`) or Carnatic (`chroma_c`)
          according to a given thaat (Hindustani) or melakarta raga (Carnatic).

        - 'chroma_fjs': pitches are determined by chroma filters using just
          intonation.  All pitch classes are annotated.

        - 'tonnetz' : axes are labeled by Tonnetz dimensions (0-5)
        - 'frames' : markers are shown as frame counts.

        Time types:

        - 'time' : markers are shown as milliseconds, seconds, minutes, or hours.
                Values are plotted in units of seconds.
        - 'h' : markers are shown as hours, minutes, and seconds.
        - 'm' : markers are shown as minutes and seconds.
        - 's' : markers are shown as seconds.
        - 'ms' : markers are shown as milliseconds.
        - 'lag' : like time, but past the halfway point counts as negative values.
        - 'lag_h' : same as lag, but in hours, minutes and seconds.
        - 'lag_m' : same as lag, but in minutes and seconds.
        - 'lag_s' : same as lag, but in seconds.
        - 'lag_ms' : same as lag, but in milliseconds.

        Rhythm:

        - 'tempo' : markers are shown as beats-per-minute (BPM)
            using a logarithmic scale.  This is useful for
            visualizing the outputs of `feature.tempogram`.

        - 'fourier_tempo' : same as `'tempo'`, but used when
            tempograms are calculated in the Frequency domain
            using `feature.fourier_tempogram`.

    x_coords, y_coords : np.ndarray [shape=data.shape[0 or 1]]
        Optional positioning coordinates of the input data.
        These can be use to explicitly set the location of each
        element ``data[i, j]``, e.g., for displaying beat-synchronous
        features in natural time coordinates.

        If not provided, they are inferred from ``x_axis`` and ``y_axis``.

    fmin : float > 0 [scalar] or None
        Frequency of the lowest spectrogram bin.  Used for Mel, CQT, and VQT
        scales.

        If ``y_axis`` is `cqt_hz` or `cqt_note` and ``fmin`` is not given,
        it is set by default to ``note_to_hz('C1')``.

    fmax : float > 0 [scalar] or None
        Used for setting the Mel frequency scales

    tempo_min : float > 0 [scalar]
        Lowest tempo (in beats per minute) for tempogram display.

    tempo_max : float > 0 [scalar]
        Highest tempo (in beats per minute) for tempogram display.

    tuning : float
        Tuning deviation from A440, in fractions of a bin.

        This is used for CQT frequency scales, so that ``fmin`` is adjusted
        to ``fmin * 2**(tuning / bins_per_octave)``.

    bins_per_octave : int > 0 [scalar]
        Number of bins per octave.  Used for CQT frequency scale.

    key : str
        The reference key to use when using note axes (`cqt_note`, `chroma`).

    Sa : float or int
        If using Hindustani or Carnatic svara axis decorations, specify Sa.

        For `cqt_svara`, ``Sa`` should be specified as a frequency in Hz.

        For `chroma_c` or `chroma_h`, ``Sa`` should correspond to the position
        of Sa within the chromagram.
        If not provided, Sa will default to 0 (equivalent to `C`)

    mela : str or int, optional
        If using `chroma_c` or `cqt_svara` display mode, specify the melakarta raga.

    thaat : str, optional
        If using `chroma_h` display mode, specify the parent thaat.

    intervals : str or array of floats in [1, 2), optional
        If using an FJS notation (`chroma_fjs`, `vqt_fjs`), the interval specification.

        See `core.interval_frequencies` for a description of supported values.

    unison : str, optional
        If using an FJS notation (`chroma_fjs`, `vqt_fjs`), the pitch name of the unison
        interval.  If not provided, it will be inferred from `fmin` (for VQT display) or
        assumed as `'C'` (for chroma display).

    auto_aspect : bool
        Axes will have 'equal' aspect if the horizontal and vertical dimensions
        cover the same extent and their types match.

        To override, set to `False`.

    htk : bool
        If plotting on a mel frequency axis, specify which version of the mel
        scale to use.

            - `False`: use Slaney formula (default)
            - `True`: use HTK formula

        See `core.mel_frequencies` for more information.

    unicode : bool
        If using note or svara decorations, setting `unicode=True`
        will use unicode glyphs for accidentals and octave encoding.

        Setting `unicode=False` will use ASCII glyphs.  This can be helpful
        if your font does not support musical notation symbols.

    ax : matplotlib.axes.Axes or None
        Axes to plot on instead of the default `plt.gca()`.

    **kwargs : additional keyword arguments
        Arguments passed through to `matplotlib.pyplot.pcolormesh`.

        By default, the following options are set:

            - ``rasterized=True``
            - ``shading='auto'``
            - ``edgecolors='None'``

        The ``cmap`` option if not provided, is inferred from data automatically.
        Set ``cmap=None`` to use matplotlib's default colormap.

    Returns
    -------
    colormesh : `matplotlib.collections.QuadMesh`
        The color mesh object produced by `matplotlib.pyplot.pcolormesh`

    See Also
    --------
    cmap : Automatic colormap detection
    matplotlib.pyplot.pcolormesh

    Examples
    --------
    Visualize an STFT power spectrum using default parameters

    >>> import matplotlib.pyplot as plt
    >>> y, sr = librosa.load(librosa.ex('choice'), duration=15)
    >>> fig, ax = plt.subplots(nrows=2, ncols=1, sharex=True)
    >>> D = librosa.amplitude_to_db(np.abs(librosa.stft(y)), ref=np.max)
    >>> img = librosa.display.specshow(D, y_axis='linear', x_axis='time',
    ...                                sr=sr, ax=ax[0])
    >>> ax[0].set(title='Linear-frequency power spectrogram')
    >>> ax[0].label_outer()

    Or on a logarithmic scale, and using a larger hop

    >>> hop_length = 1024
    >>> D = librosa.amplitude_to_db(np.abs(librosa.stft(y, hop_length=hop_length)),
    ...                             ref=np.max)
    >>> librosa.display.specshow(D, y_axis='log', sr=sr, hop_length=hop_length,
    ...                          x_axis='time', ax=ax[1])
    >>> ax[1].set(title='Log-frequency power spectrogram')
    >>> ax[1].label_outer()
    >>> fig.colorbar(img, ax=ax, format="%+2.f dB")
    zBTrying to display complex-valued input. Showing magnitude instead.r_   
stacklevelr   
rasterizedT
edgecolorsr   shadingauto)kwargsr   rv   r  r  rx   r   r  r  rZ   r  r[   rw   rs   r   r   r?   )r  r  r   )
rZ   rh   rj   r  r[   rv   rs   rw   rx   ry   equal)r:   
issubdtyper   complexfloatingwarningswarnr;   
setdefaultr   dict__mesh_coordsshape__check_axes
pcolormesh__set_current_image__scale_axes__decorate_axisxaxisr   yaxis__same_axesget_xlimget_ylim
set_aspect)r   r  r  r  r  r   r   r  r  rv   r  r  r  r  rx   rZ   rh   rj   r  r  r  r[   rw   rs   r   r"  
all_paramsaxesouts                                r/   r   r     s   B 
}}TZZ!3!34S	
 vvd|
fd4j)
lD)
lF+
i('J$ VXtzz!}K
KHVXtzz!}K
KHD
$//(Hd
=f
=CC  vsi9Mvsi9M 

'8} 

'8}  664==?DMMOD Jr1   c                4    | t        j                  |       yy)z
    Set the current image when working in pyplot mode.

    If the provided ``ax`` is not `None`, then we assume that the user is using the object API.
    In this case, the pyplot current image is not set.
    N)pltsci)r   imgs     r/   r.  r.    s     
z r1   c           	        |2t        |      ||dz   fvrt        dt        |       d| d| d      |S i dt        dt        d	t        d
t        dt        dt        dt        dt        dt        dt        dt        dt
        dt
        dt
        dt        dt        dt        i dt        dt        dt        dt        dt        dt        dt        dt        d t        d!t        d"t        d#t        d$t        d%t        d&t        d't        dt        }| |vrt        d(|         ||    |fi |S ))zCompute axis coordinatesNr   zCoordinate shape mismatch: z!=z or z+1r   r   r   r   r   r  r  cqtr   r   r   vqt_fjsvqt_hzvqt_noter   r   r   r   r   r(   r)   r*   r+   r-   r   r  r  r  r  offr  r  r	  zUnknown axis type: )r   r   __coord_fft_hz__coord_mel_hz__coord_cqt_hz__coord_vqt_hz__coord_chroma	__coord_n__coord_time__coord_tempo__coord_fourier_tempo)ax_typecoordsnr"  	coord_maps        r/   r*  r*    sF   v;q!a%j( -c&k]"QCtA3bI  #A.#A~#A 	N#A 	^	#A
 	n#A 	~#A 	~#A 	~#A 	.#A 	N#A 	^#A 	>#A 	.#A 	N#A 	.#A  	N!#A" 	N##A$ 	i%#A& 	'#A( 	\)#A* 	\+#A, 	\-#A. 	l/#A0 	|1#A2 	3#A4 	5#A6 	7#A8 	,9#A: 	9;#A< 	y=#A> 	?#A@ 	.A#AB 	)C#AD 	iE#AIJ i27)<==9Wa*6**r1   c                    | t        j                         } | S t        | t        j                        s#t        dj                  t        |                   | S )zDCheck if "axes" is an instance of an axis object. If not, use `gca`.zG`axes` must be an instance of matplotlib.axes.Axes. Found type(axes)={})r;  gcar   mplaxesAxesr   r<   type)r8  s    r/   r,  r,  +  sP    |wwy K gll+""(&d"4
 	
 Kr1   c                n   t               }d}d}d}|dk(  r| j                  }	| j                  }
n| j                  }	| j                  }
|dk(  rd}d||<   d||<   nT|d	v rd
}d||<   nH|dv r.d}d||<   t        t        j                  d            ||<   d||<   n|dv rd
}d||<    |
||       ny |	|fi | y)zSet the axis scaling	linthreshbaselinscaler?   r  symlogg     @@r_   )r?  r   r   r   rA  rB  r@  r  )r  r   r   C2r3   r  r  N)r)  
set_xscaleset_xlim
set_yscaleset_ylimrL   r   
note_to_hz)r8  rM  whichr  r  r"  threshrX  scalescalerlimitmodes               r/   r/  r/  7  s    VFFDE| %vt	  
 t	4	4ttt45vu	.	.ti#
46r1   c                   ddddd}|dk(  rb| j                  t                      | j                  t        j                  t        j                  d                   | j                  d       y|d	k(  r| j                  t        ||
             t        j                  |      }| j                  t        j                  t
        j                  j                  dt        j                  d      z  |      j                                      | j                  d       y|dk(  r|d}| j                  t        ||             |t        j                  d      }nt        j                  |      }t        j                   ||z   d      }| j                  t        j                  t
        j                  j                  dt        j                  d      z  |      j                                      | j                  d       y|dk(  r|d}| j                  t        |||             t        j"                  |      }t        j                   ||z   d      }| j                  t        j                  t
        j                  j                  dt        j                  d      z  |      j                                      | j                  d       y|dk(  r|t        j$                  d      }|t        j&                  |dd      }| j                  t)        |	|||
             t+        |	t,              rP|
dkD  rKt        j.                  dd|	|
d      }t        j.                  |
d|	|
d      }t1        j2                  ||      }nt        j                  |
      }| j                  t        j                  |             | j                  d       y|dv rZ| j                  t        j4                                | j                  t        j6                  d              | j                  d!       y|d"k(  rV| j                  t9        dd#             | j                  t        j:                  dg d$%             | j                  d&       y||v rh| j                  t9        |d#             | j                  t        j:                  dg d$%             | j                  d'j=                  ||                y|d(k(  rV| j                  t9        dd#             | j                  t        j:                  dg d$%             | j                  d)       yt+        |t,              r~|j?                  d*      rm|d+d }| j                  t9        |d#             | j                  t        j:                  dg d$%             | j                  d,j=                  ||                y|d-k(  r| j                  tA        ||
             t        jB                  t        j$                  d            }d|t        jD                  |      z
  z  }| j                  t        j6                  d|f.             | jG                  tA        |d|/             | jI                  t        j6                  d|dt        j                  dd      d0z  z  z  .             | j                  d1       y|d2k(  r| j                  tK        |||             dt        jB                  |      t        jD                  t        jB                  |            z
  z  }| j                  t        j6                  d|f.             | jG                  tK        ||d|3             | jI                  t        j6                  d|dt        j                  dd      d0z  z  z  .             | j                  d       y|d4k(  r|t        j$                  d      }| j                  tM        |	||||
|5             t        jB                  |      }d|t        jD                  |      z
  z  }| j                  t        j6                  d|f.             | jG                  tM        |	||||
|d6             | jI                  t        j                  t        j.                  |dz  |
z  ||	d7                   | j                  d1       y|d8k(  r|t        j$                  d      }| j                  tO                      t        jB                  |      }d|t        jD                  |      z
  z  }| j                  t        j6                  d|f.             | jG                  tO        d9             | jI                  t        j6                  dt        j.                  d||	d7      .             | j                  d:       y|d;k(  r|t        j$                  d      }| j                  tA        ||
             t        jB                  |      }d|t        jD                  |      z
  z  }| j                  t        j6                  d|f.             | jG                  tA        ||d<             | jI                  t        j6                  dt        j.                  d||	d7      .             | j                  d1       y|d=v r| j                  tO                      t        jB                  t        j$                  d            }d|t        jD                  |      z
  z  }| j                  t        j6                  d|f.             | j                  t        j6                  d              | jG                  tO        d9             | jI                  t        j6                  d|dt        j                  dd      d0z  z  z  .             | j                  d:       y|d>k(  r | j                  tA        ||
             t        jB                  t        j$                  d            }d|t        jD                  |      z
  z  }| j                  t        jP                  | jS                                      | jG                  tA        |d|/             | jI                  t        j6                  ddt        j                  dd      d0z  z  .             | j                  d1       y|d?k(  r| j                  tK        |||             t        jB                  |      }d|t        jD                  |      z
  z  }| j                  t        jP                  | jS                         d|g.             | jG                  tK        ||d|3             | jI                  t        j6                  d|dt        j                  dd      d0z  z  z  .             | j                  d       y|d@v rg| j                  t        j4                                | j                  t        jP                  | jS                                      | j                  d:       y|dAv r5| j                  t        j4                                | j                  d:       y|dBv r| j                  dC       y|dDv r#| j                  dE       | jU                  g        ytW        dF|       )Gz,Configure axis tickers, locators, and labelshoursminutessecondsmilliseconds)r(   r)   r*   r+   r     Tonnetzr   r   r  
   zPitch classr   Nr   )rh   r[   Svarar   )rh   rj   r[   r   C1F)rX   ra   )rw   rs   r[   rx      r   )rv   rw   rx   sortTr\         @)rX  BPMr   )r,   r-   )r   g      ?   rm  ro  )pruner   TimezTime ({:s})r-   Laglag_r^   z
Lag ({:s})r   )rX  subs)rZ   rY   r[         (@Noter   )rh   rj   rY   r[   r@  )rw   rv   rs   r[   rx   ry   )rw   rv   rs   r[   rx   ry   rY   ru   rA  r   HzrB  )rZ   r[   rY   )r   r   r   )r  r  )r   r   r   )r	  Frames)rC  noneNr4   zUnsupported axis type: ),set_major_formatterr$   set_major_locator	mpltickerFixedLocatorr:   arangeset_label_textr!   r   key_to_degreesaddouterravelr"   thaat_to_degreesr>   mela_to_degreesra  rc   r#   r   rO   rz   r   r}   ScalarFormatter
LogLocatorr   MaxNLocatorr<   
startswithr   log2floorset_minor_formatterset_minor_locatorrf   r   r    SymmetricalLogLocatorget_transform	set_ticksr   )r7   rM  rZ   rh   rj   r  r[   rv   rs   rw   rx   ry   
time_unitsdegreestick_intervalsall_intervalsr,   log_C1C_offset	sa_offsetlog_fminfmin_offsetlog_Sas                          r/   r0  r0  g  sM    YYnUJ)  !1!34y55biilCDI&	H	  S'!JK%%c*""266<<RYYr]0BG#L#R#R#TU	
 	M*	J	:B  !5W!MN=iimG++E2G&&2r*""266<<RYYr]0BG#L#R#R#TU	
 	G$	J	:B   BT7C	
 &&t,&&2r*""266<<RYYr]0BG#L#R#R#TU	
 	G$	L	 <??4(D>__T%uEF  # /		
 i%/A*= "66# /N !55# /M ''FG ii0Gy55g>?M*	.	.  !:!:!<=y33=>E"	F	  De!DE!!4FG	
 	F#	J	  G!GH!!4FG	
 	M00G1DEF	E	  Dd!CD!!4FG	
 	E"	GS	!g&8&8&@qr{  Dd!CD!!4FG	
 	L//
40@AB	J	  3!HI./6BHHV$445y33H;OP  3eW!UV  x#"))Ar2BT2I*JJ	

 	F#	K	  2D'!RSBGGBK"((2772;*??@	y33I<PQ  bt5'J	
 	  y3299Q3Cd3J+KK	

 	G$	I	<??4(D  # /		
 774=h();;<y33K>RS  # /
	
 	""))RK?2'$&			
 	F#	H	<??4(D  !12774=h();;<y33K>RS  e!<=  ..[Ir	
 	D!	J	<??4(D  3!HI774=h();;<y33K>RS  3u!UV  ..[Ir	
 	F#	J	  !12./6BHHV$445y33H;OPy33=>  e!<=  x#"))Ar2BT2I*JJ	

 	D!	J	  3!HI./6BHHV$445y>>t?Q?Q?STU  3eW!UV  c		!R8H48O0PQ	
 	F#	K	  2D'!RSFRXXf%556	++""$3i[	

 	  bt5'J	
 	  y3299Q3Cd3J+KK	

 	G$	N	"  !:!:!<=y>>t?Q?Q?STUD!	+	+  !:!:!<=D!	J	H%	)	)Br 6wi@AAr1   c                H    |d| dz
  z  }t        j                  ||      }|S )z Get the frequencies for FFT binsr_   r   )r   r  )r   fft_frequencies)rO  r   r  _kwargsbasiss        r/   rD  rD    s/     }QU   Be4ELr1   c                N    |d}|d|z  }t        j                  | |||      }|S )z Get the frequencies for Mel binsr  r3   )rv   r  r  )r   mel_frequencies)rO  rv   r  r   r  r  r  s          r/   rE  rE    s7     ||Rx  DcBELr1   c                    |t        j                  d      }|d|j                  dd      |z  z  z  }t        j                  | ||      }t	        j
                  |d|z  kD        rt        j                  dd	       |S )
zGet CQT bin frequenciesrq  rt  r  r  )rv   rx   r3   _Frequency axis exceeds Nyquist. Did you remember to set all spectrogram parameters in specshow?r^   r  )r   ra  getcqt_frequenciesr:   anyr&  r'  )rO  rv   rx   r   r  freqss         r/   rF  rF    s     |t$ #'++h4FGGD   	'E 
vvecBhN	
 Lr1   c                    |t        j                  d      }|t        d      t        j                  | |||      }t	        j
                  |d|z  kD        rt        j                  dd       |S )Nrq  z8VQT axis coordinates cannot be defined without intervalsru   r3   r  r^   r  )r   ra  r   rz   r:   r  r&  r'  )rO  rv   rx   r   rw   rs   r  r  s           r/   rG  rG    su     |t$WXX%%		?E 
vvecBhN	
 Lr1   c                @    t        j                  dd| z  |z  | d      S )zGet chroma bin numbersr   r|  F)numendpoint)r:   linspace)rO  rx   r  s      r/   rH  rH    s     ;;q4!86ANNr1   c                B    t        j                  | dz   ||      dd }|S )zTempo coordinatesr   r   r   N)r   tempo_frequencies)rO  r   r   r  r  s        r/   rK  rK    s(     ""1q5RJGKELr1   c                J    |d| dz
  z  }t        j                  |||      }|S )zFourier tempogram coordinatesr_   r   )r   r   r  )r   fourier_tempo_frequencies)rO  r   r   r  r  r  s         r/   rL  rL    s7     !a%[
 ***E Lr1   c                ,    t        j                  |       S )zGet bare positions)r:   r  )rO  r  s     r/   rI  rI    s    99Q<r1   c                \    t        j                  t        j                  |       ||      }|S )z Get time coordinates from framesr  )r   frames_to_timer:   r  )rO  r   r   r  r   s        r/   rJ  rJ    s%     ++BIIaLRJWELr1   c                ,    | |ft         v }||k(  }|xr |S )z>Check if two axes are similar, used to determine squared plots)_AXIS_COMPAT)r  r  xlimylimaxes_compatible_and_not_noneaxes_same_lims         r/   r3  r3  #  s&    $*F#3|#C DLM'9M9r1   r   r   r4   post)
r   
max_pointsr7   offsetmarkerwherer   r   r   r  c       
   	     P   t        j                  | d       | j                  dk(  r| t        j                  ddf   } |dk  rt        d| d      t        |	      }t        d|
d	|d
d      }t        d| j                  d   |z        }t        | |      }|d    |d   }}|t        j                  | |d      z   }|d| | dd|f   }}|j                  }d}|j                  }|r||}}|j                  }d}|j                   } |j"                  ||f||d|\  }d|vr |j%                  d|j'                                 ||dt)        |      |z  |   ||f||d|}t+        || d   |||||      }|j-                  ||       |j/                  |       t1        ||       |S )a  Visualize a waveform in the time domain.

    This function constructs a plot which adaptively switches between a raw
    samples-based view of the signal (`matplotlib.pyplot.step`) and an
    amplitude-envelope view of the signal (`matplotlib.pyplot.fill_between`)
    depending on the time extent of the plot's viewport.

    More specifically, when the plot spans a time interval of less than ``max_points /
    sr`` (by default, 1/2 second), the samples-based view is used, and otherwise a
    downsampled amplitude envelope is used.
    This is done to limit the complexity of the visual elements to guarantee an
    efficient, visually interpretable plot.

    When using interactive rendering (e.g., in a Jupyter notebook or IPython
    console), the plot will automatically update as the view-port is changed, either
    through widget controls or programmatic updates.

    .. note:: When visualizing stereo waveforms, the amplitude envelope will be generated
        so that the upper limits derive from the left channel, and the lower limits derive
        from the right channel, which can produce a vertically asymmetric plot.

        When zoomed in to the sample view, only the first channel will be shown.
        If you want to visualize both channels at the sample level, it is recommended to
        plot each signal independently.

    Parameters
    ----------
    y : np.ndarray [shape=(n,) or (2,n)]
        audio time series (mono or stereo)

    sr : number > 0 [scalar]
        sampling rate of ``y`` (samples per second)

    max_points : positive integer
        Maximum number of samples to draw.  When the plot covers a time extent
        smaller than ``max_points / sr`` (default: 1/2 second), samples are drawn.

        If drawing raw samples would exceed `max_points`, then a downsampled
        amplitude envelope extracted from non-overlapping windows of `y` is
        visualized instead.  The parameters of the amplitude envelope are defined so
        that the resulting plot cannot produce more than `max_points` frames.

    axis : str or None
        Display style of the axis ticks and tick markers. Accepted values are:

        - 'time' : markers are shown as milliseconds, seconds, minutes, or hours.
                    Values are plotted in units of seconds.

        - 'h' : markers are shown as hours, minutes, and seconds.

        - 'm' : markers are shown as minutes and seconds.

        - 's' : markers are shown as seconds.

        - 'ms' : markers are shown as milliseconds.

        - 'lag' : like time, but past the halfway point counts as negative values.

        - 'lag_h' : same as lag, but in hours.

        - 'lag_m' : same as lag, but in minutes.

        - 'lag_s' : same as lag, but in seconds.

        - 'lag_ms' : same as lag, but in milliseconds.

        - `None`, 'none', or 'off': ticks and tick markers are hidden.

    x_axis : Deprecated
        Equivalent to `axis` parameter, included for backward compatibility.

        .. warning:: This parameter is deprecated as of 0.10.0 and
            will be removed in 1.0.  Use `axis=` instead going forward.

    ax : matplotlib.axes.Axes or None
        Axes to plot on instead of the default `plt.gca()`.

    offset : float
        Horizontal offset (in seconds) to start the waveform plot

    marker : string
        Marker symbol to use for sample values. (default: no markers)

        See Also: `matplotlib.markers`.

    where : string, {'pre', 'mid', 'post'}
        This setting determines how both waveform and envelope plots interpolate
        between observations.

        See `matplotlib.pyplot.step` for details.

        Default: 'post'

    label : string [optional]
        The label string applied to this plot.
        Note that the label

    transpose : bool
        If `True`, display the wave vertically instead of horizontally.

    **kwargs
        Additional keyword arguments to `matplotlib.pyplot.fill_between` and
        `matplotlib.pyplot.step`.

        Note that only those arguments which are common to both functions will be
        supported.

    Returns
    -------
    librosa.display.AdaptiveWaveplot
        An object of type `librosa.display.AdaptiveWaveplot`

    See Also
    --------
    AdaptiveWaveplot
    matplotlib.pyplot.step
    matplotlib.pyplot.fill_between
    matplotlib.pyplot.fill_betweenx
    matplotlib.markers

    Examples
    --------
    Plot a monophonic waveform with an envelope view

    >>> import matplotlib.pyplot as plt
    >>> y, sr = librosa.load(librosa.ex('choice'), duration=10)
    >>> fig, ax = plt.subplots(nrows=3, sharex=True)
    >>> librosa.display.waveshow(y, sr=sr, ax=ax[0])
    >>> ax[0].set(title='Envelope view, mono')
    >>> ax[0].label_outer()

    Or a stereo waveform

    >>> y, sr = librosa.load(librosa.ex('choice', hq=True), mono=False, duration=10)
    >>> librosa.display.waveshow(y, sr=sr, ax=ax[1])
    >>> ax[1].set(title='Envelope view, stereo')
    >>> ax[1].label_outer()

    Or harmonic and percussive components with transparency

    >>> y, sr = librosa.load(librosa.ex('choice'), duration=10)
    >>> y_harm, y_perc = librosa.effects.hpss(y)
    >>> librosa.display.waveshow(y_harm, sr=sr, alpha=0.5, ax=ax[2], label='Harmonic')
    >>> librosa.display.waveshow(y_perc, sr=sr, color='r', alpha=0.5, ax=ax[2], label='Percussive')
    >>> ax[2].set(title='Multiple waveforms')
    >>> ax[2].legend()

    Zooming in on a plot to show raw sample values

    >>> fig, (ax, ax2) = plt.subplots(nrows=2, sharex=True)
    >>> ax.set(xlim=[6.0, 6.01], title='Sample view', ylim=[-0.2, 0.2])
    >>> librosa.display.waveshow(y, sr=sr, ax=ax, marker='.', label='Full signal')
    >>> librosa.display.waveshow(y_harm, sr=sr, alpha=0.5, ax=ax2, label='Harmonic')
    >>> librosa.display.waveshow(y_perc, sr=sr, color='r', alpha=0.5, ax=ax2, label='Percussive')
    >>> ax.label_outer()
    >>> ax.legend()
    >>> ax2.legend()

    Plotting a transposed wave along with a self-similarity matrix

    >>> fig, ax = plt.subplot_mosaic("hSSS;hSSS;hSSS;.vvv")
    >>> y, sr = librosa.load(librosa.ex('trumpet'))
    >>> chroma = librosa.feature.chroma_cqt(y=y, sr=sr)
    >>> sim = librosa.segment.recurrence_matrix(chroma, mode='affinity')
    >>> librosa.display.specshow(sim, ax=ax['S'], sr=sr,
    ...                          x_axis='time', y_axis='time',
    ...                          auto_aspect=False)
    >>> ax['S'].label_outer()
    >>> ax['S'].sharex(ax['v'])
    >>> ax['S'].sharey(ax['h'])
    >>> ax['S'].set(title='Self-similarity')
    >>> librosa.display.waveshow(y, ax=ax['v'])
    >>> ax['v'].label_outer()
    >>> ax['v'].set(title='transpose=False')
    >>> librosa.display.waveshow(y, ax=ax['h'], transpose=True)
    >>> ax['h'].label_outer()
    >>> ax['h'].set(title='transpose=True')
    F)monor   Nr   zmax_points=z must be strictly positiver  r7   z0.10.0z1.0)old_name	old_valuenew_name	new_valueversion_deprecatedversion_removedr   r  r   ylim_changed)r  r  color)stepr   )r   r   r   r   )r   valid_audiondimr:   newaxisr   r,  r	   rb   r+  r   r   
times_likefill_betweenr1  fill_betweenxr2  r  r(  	get_colorr   r%   r   r   r0  )r   r   r  r7   r  r  r  r   r   r   r  r"  r8  r   y_envy_bottomy_topr   r   r   fillerr   dec_axisr   r   adaptors                             r/   r   r   *  s   B 	QU# 	vv{bjj!mQ{:,6PQRR D #D Qz12Jq*%E Ryj%(eHT__Q2!<<E *%qKZK'85EFFzzHeu##::tyyLfELVLHU f'5??#454E
Z'*45  H qtUHyG OODO( NN4 Hd#Nr1   )r   r   r   rH   r   rO   r   rO   r   rO   rN   r   )6r   r   r  Optional[np.ndarray]r  r  r  rI   r  rI   r   rL   r   r=   r  rM   r  rM   rv   r   r  r   r  r   r  r   r  rL   rx   r=   rZ   rO   rh   zOptional[Union[float, int]]rj   rq   r  rI   r  rH   r  rH   r[   rH   rw   z Optional[Union[str, np.ndarray]]rs   rI   r   Optional[mplaxes.Axes]r"  r   rN   r   )r8  r  rN   r   )
rd   NNNTNNNNN)r   N)
rO  r=   r   rL   r  rM   r  r   rN   r   )r  Nr   F)rO  r=   rv   r   r  r   r   rL   r  rH   r  r   rN   r   )Nr  r   )rO  r=   rv   Optional[_FloatLike_co]rx   r=   r   rL   r  r   rN   r   )Nr  r   NN)rO  r=   rv   r  rx   r=   r   rL   rw   z'Optional[Union[str, Collection[float]]]rs   rI   r  r   rN   r   )r  )rO  r=   rx   r=   r  r   rN   r   )r   r
  )
rO  r=   r   rL   r   r=   r  r   rN   r   )r   r
  N)rO  r=   r   rL   r   r=   r  rM   r  r   rN   r   )rO  r=   r  r   rN   r   )r   r   r   rL   r  r=   r7   rI   r  rL   r  z Union[str, MplPath, MarkerStyle]r  rO   r   rI   r   rH   r   r  r  z Optional[Union[str, Deprecated]]r"  r   rN   r%   )YrT   
__future__r   	itertoolsr   r&  numpyr:   
matplotlibr   r   matplotlib.axesr8  rS  matplotlib.tickertickerr  matplotlib.pyplotpyplotr;  r4   r   r   util.deprecationr	   r
   util.exceptionsr   typingr   r   r   r   r   r   r   _typingr   matplotlib.collectionsr   r   matplotlib.linesr   matplotlib.pathr   MplPathmatplotlib.markersr   matplotlib.colorsr   __all__	Formatterr   r   rf   r   r    r!   r"   r#   r$   r%   r   r   _chroma_ax_types_cqt_ax_types_freq_ax_types_time_ax_types_lag_ax_types_misc_ax_typessetr  r   r.  r*  r,  r/  r0  rD  rE  rF  rG  rH  rK  rL  rI  rJ  r3  r   )ts   0r/   <module>r     s  #H #    ' ! %    3 + R R R "?'/.*$e I'' e PC
I'' C
L[Y(( [|V9&& Vr)Y(( )X
i)) 
8+9.. +\7,, 7tXy** X,c% c%R 9
9 9 	9
 9 9 9x 
 #$^aV^$*,<=>=Qq=>?-787Qq789 ..9:9Qq9:; ..9:9Qq9:	;
 -787Qq789 &*%)   $  !#!$&*&*26 !%5N
N #N #	N
 N N 	N N N N N N N N N  !N" 
#N$ 	$%N& $'N( )N* +N, 
-N. /N0 01N2 3N4 	5N6 7N8 9Nb
0+f	-f 		
	sBn	 7;	
		&3	GJ		   

  		
 
  ( %)	

!  		
  B %)9= 

!  		
 7   :O 25
+.AD  $	
  	
  $ 25
+.AD:  /1!%/9|FF 	F 	F
 F F -F F F F 	F -F F Fo %>8::8s$   <L1	L6
,	L;
	M 
	M
4	M

