
    3jW$                    :   d Z ddlmZ ddlmZ ddlZddlZddlZddl	m
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
l	mZ ej&                  rddl	mZ ddlmZmZ  ej0                  d      Z	 	 ddd	 	 	 	 	 	 	 	 	 ddZ	 	 d	 	 	 	 	 	 	 	 	 ddZddZddZddZy)z
This module contains music21 Jupyter Notebook external converters, which
used to be in the main music21.converter.subConverters module.
    )annotations)SequenceN)common)runningInJupyterOrColabrunningInMarimo)	museScore)defaults)environment)stream)base)SubConverterConverterMidizipython21.convertersF)multipageWidgetc          	        ddl mmm} t	        t
        d         j                  d      r(d}t        j                  |      }  |d             y t        j                  }	t        j                  }
dt        _
        dt        _        t        | t        j                        r#| j                  D ]  }t!        |f||||d	|  y  |j"                  | |f|| d
|}|d   dk7  ry t%        j&                  |      }t%        j(                  ||      \  }}i t	        |      d t	        |      j+                  d       }t-        d|dz         D ]?  }|dz   t	        |      j/                  |      z   dz   }t1        j2                  |      }||<   A |dk(  r  |j5                         d             n~|s^t-        d|dz         D ]K  }|   j7                         s  |   j5                         d             ||k  s>  |d             M nddlm}  |d|f      dfd	       }|S |	t        _
        |
t        _        y )Nr   )ImagedisplayHTMLmusescoreDirectPNGPathz/skips\   iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAAAAAA6fptVAAAACklEQVQYV2P4DwABAQEAWk1v8QAAAABJRU5ErkJggg==Tdataretina )subConverterfmt
subformatsr   )r   	trimEdgespng-   z.pngz'<p style="padding-top: 20px">&nbsp;</p>)interact)pagec                    |    }|j                         r  |j                         d             y t        d|  d       y )NTr   zNo file for page .)exists
read_bytesprint)r!   inner_page_fpr   r   pagess     I/DATA/.local/lib/python3.12/site-packages/music21/ipython21/converters.pypage_displayz/showImageThroughMuseScore.<locals>.page_displayp   sB    !$KM##%=#;#;#=dKL)$q12    )r   )IPython.displayr   r   r   strenvironLocal
startswithbase64	b64decoder	   titleauthor
isinstancer   OpusscoresshowImageThroughMuseScorewriter   findLastPNGPathfindPNGRangerfindrangezfillpathlibPathr%   r$   
ipywidgetsr    )objr   r   r   r   keywordsr   	pngData64pngDatasavedDefaultTitlesavedDefaultAuthorsfplast_pnglast_number
num_digitsstempgpage_strpage_fpr    r*   r   r   r(   s                         @@@r)   r7   r7   "   sE    54
<012==gFP	""9-7401 !!HNHO#v{{#A%)% /   			
 %%	

 
B !}((,H'44RBKEr7&CGMM#&'DA{Q'#:Bj 99FB,,x(b	 (
 a2==?489;?+BRy!59#7#7#9$GH#D!JKL	 , 	(	;'	(	3 
)	3 &HN(HOr+   c                    |j                   | |f|dd|}t        |d      5 }|j                         }d d d        t              }t	               rt        |       y t               rt        |      S t        d      # 1 sw Y   JxY w)NT)r   addStartDelayrbzECannot run displayMusic21jMIDI if not running in a supported Notebook)	r8   openreadhtmlOutputForMidir   displayMusic21jMIDIJupyterr   displayMusic21jMIDIMarimo
ValueError)	rA   r   r   r   rB   rH   fbinaryMidiData
htmlOutputs	            r)   displayMusic21jMIDIr\   ~   s     
		
 	

 
B 
b$1 ! 
 #>2J ":.		(44`aa 
s   A>>Bc                0    ddl m}m}  | ||              y )Nr   )r   r   )r,   r   r   )r[   r   r   s      r)   rV   rV      s    -Dr+   c                $    ddl m}  || dd      S )Nr   )iframez100%80px)widthheight)marimor_   )r[   r_   s     r)   rW   rW      s    *F6::r+   c                    t        j                  |       }t        j                         }dt	         |             z   }|j                  d      }d|z   dz   |z   dz   |z   dz   S )NmidiPlayerDivzutf-8z
        <div id="a.  ">
            <p class="m21-trust-warning">
                This MIDI player only runs in <em>trusted</em> notebooks.
                In JupyterLab: File &rarr; Trust Notebook, then re-run this cell.
            </p>
        </div>
        <script>
        (function() {
            const outputId = "z";
            const b64 = "a	  ";
            const jsUrl = "https://cdn.jsdelivr.net/npm/music21j@0.23.1/releases/music21.debug.min.js";
            const cssUrl = "https://cdn.jsdelivr.net/npm/music21j@0.23.1/releases/music21j.min.css";

            const root = document.getElementById(outputId);
            const warning = root && root.querySelector(".m21-trust-warning");
            if (warning) warning.remove();

            function play(music21) {
                music21.common.urls.soundfontUrl = "https://cdn.jsdelivr.net/gh/cuthbertLab/midi-js-soundfonts@2026.05.15/FluidR3_GM/";
                music21.common.urls.midiPlayer = "https://cdn.jsdelivr.net/gh/cuthbertLab/music21j@v0.23.1/webResources/midiPlayer";
                const mp = new music21.miditools.MidiPlayer();
                mp.addPlayer("#" + outputId);
                mp.base64Load("data:audio/midi;base64," + b64);
            }

            window.m21conf = window.m21conf || { loadSoundfont: false };
            if (!document.querySelector("link[data-music21j]")) {
                const link = document.createElement("link");
                link.rel = "stylesheet";
                link.href = cssUrl;
                link.dataset.music21j = "1";
                document.head.appendChild(link);
            }

            // RequireJS / AMD route (Sphinx/nbsphinx HTML, classic Jupyter):
            // the music21j UMD bundle registers as an AMD module when define.amd
            // is present and never sets window.music21, so the script-tag/global
            // path below would fire play() with music21 undefined.
            if (typeof window.require === "function"
                    && typeof window.require.config === "function") {
                window.require.config({
                    paths: { music21: jsUrl.replace(/\.js$/, "") }
                });
                window.require(["music21"], play);
                return;
            }

            if (window.music21) {
                play(window.music21);
                return;
            }
            let script = document.querySelector("script[data-music21j]");
            if (!script) {
                script = document.createElement("script");
                script.src = jsUrl;
                script.dataset.music21j = "1";
                document.head.appendChild(script);
            }
            script.addEventListener("load", function() { play(window.music21); });
        })();
        </script>)r0   	b64encoder   SingletonCounterr-   decode)rZ   binaryBase64rG   outputId
utf_binarys        r)   rU   rU      s    ##N3L!AQS)H"))'2J #"	" %-	-0
  *
*3-= =r+   )musicxml)r   )
rA   base.Music21Objectr   r   r   r-   r   Sequence[str]r   bool)midi )
rA   rm   r   r   r   r-   r   rn   returnt.Any)r[   r-   rr   None)r[   r-   rr   rs   )rZ   bytesrr   r-   )__doc__
__future__r   collections.abcr   r0   r>   typingtmusic21r   music21.common.miscr   r   music21.converterr   r	   r
   r   TYPE_CHECKINGr   music21.converter.subConvertersr   r   Environmentr.   r7   r\   rV   rW   rU   rq   r+   r)   <module>r      s    # $     H '   ??K&{&&'=>  (	Z "Z	ZZ 
Z 	Z Z~  "	b	bb 
b 	b b6;
Cr+   