
    qis                         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	m
Z
mZ ddlmZmZ ddlmZ  ed	
      e G d de                    ZdgZy)zProcessor class for Pop2Piano.    N   )BatchFeature)ProcessorMixin)BatchEncodingPaddingStrategyTruncationStrategy)
TensorTypeauto_docstring)requires)essentialibrosapretty_midiscipytorch)backendsc                   ,    e Zd Z fdZe	 	 	 	 	 	 	 	 	 	 ddej                  ee   z  eej                     z  de	ee	   z  dz  de	de
dz  deez  de
ez  ez  d	e
ez  ez  d
e	dz  de	dz  de
deez  fd       Z	 ddede
defdZ fdZed        Z xZS )Pop2PianoProcessorc                 &    t         |   ||       y N)super__init__)selffeature_extractor	tokenizer	__class__s      d/opt/pipecat/venv/lib/python3.12/site-packages/transformers/models/pop2piano/processing_pop2piano.pyr   zPop2PianoProcessor.__init__   s    *I6    Naudiosampling_ratesteps_per_beatresamplenotespadding
truncation
max_lengthpad_to_multiple_ofverbosereturnc           
          |||t        d      || | j                  d||||d|}| | j                  d|||||	|
d|}|S ||S d   d<   |S )a  
        sampling_rate (`int` or `list[int]`, *optional*):
            The sampling rate of the input audio in Hz. This should match the sampling rate used by the feature
            extractor. If not provided, the default sampling rate from the processor configuration will be used.
        steps_per_beat (`int`, *optional*, defaults to `2`):
            The number of time steps per musical beat. This parameter controls the temporal resolution of the
            musical representation. A higher value provides finer temporal granularity but increases the sequence
            length. Used when processing audio to extract musical features.
        notes (`list` or `TensorType`, *optional*):
            Pre-extracted musical notes in MIDI format. When provided, the processor skips audio feature extraction
            and directly processes the notes through the tokenizer. Each note should be represented as a list or
            tensor containing pitch, velocity, and timing information.
        z{You have to specify at least audios and sampling_rate in order to use feature extractor or notes to use the tokenizer part.)r   r   r    r!   )r"   r#   r$   r%   r&   r'   	token_ids )
ValueErrorr   r   )r   r   r   r    r!   r"   r#   r$   r%   r&   r'   kwargsinputsencoded_token_idss                 r   __call__zPop2PianoProcessor.__call__!   s    < Mm3%-3 
 !:+T++ +-!	
 F  . !%%#5! ! =M]m3$$ #4K"@F;Mr   feature_extractor_outputreturn_midic                 >    | j                   j                  |||      S )z
        This method uses [`Pop2PianoTokenizer.batch_decode`] method to convert model generated token_ids to midi_notes.

        Please refer to the docstring of the above two methods for more information.
        )r*   r1   r2   )r   batch_decode)r   r*   r1   r2   s       r   r4   zPop2PianoProcessor.batch_decodeb   s)     ~~**:R`k + 
 	
r   c                     t         j                  j                  |      rt        d| d      t        j                  |d       t        |   |fi |S )NzProvided path (z#) should be a directory, not a fileT)exist_ok)ospathisfiler,   makedirsr   save_pretrained)r   save_directoryr-   r   s      r   r;   z"Pop2PianoProcessor.save_pretrainedr   sL    77>>.)~.>>abcc
NT2w&~@@@r   c                 2     | j                   |fi |} | | S r   )_get_arguments_from_pretrained)clspretrained_model_name_or_pathr-   argss       r   from_pretrainedz"Pop2PianoProcessor.from_pretrainedx   s%    1s112OZSYZDzr   )
NN   TNFNNNT)T)__name__
__module____qualname__r   r
   npndarraylistfloatintboolr	   strr   r   r   r   r0   r4   r;   classmethodrB   __classcell__)r   s   @r   r   r      s=   7  >B04 $#'056:!%)->zzDK'$rzz*::> T#Y-> 	>
 +> j > o-> 3J!33> $J>  $J> > 
	%> >H !	
 #/
 	

 

 A  r   r   )__doc__r7   numpyrG   feature_extraction_utilsr   processing_utilsr   tokenization_pythonr   r   r   utilsr	   r
   utils.import_utilsr   r   __all__r+   r   r   <module>rX      sZ    % 	  4 . U U / * 
KL^ ^  M^B  
 r   