.. _midi:

.. WARNING: DO NOT EDIT THIS FILE:
   AUTOMATICALLY GENERATED.
   PLEASE EDIT THE .py FILE DIRECTLY.

MIDI Test Project
=================

MIDI will only play from **Trusted** notebooks.

.. code:: ipython3

    from music21 import *

.. code:: ipython3

    m = converter.parse('tinynotation: 4/4 c4 d e f')

.. code:: ipython3

    m.show('midi')



.. raw:: html

    
    <div id="midiPlayerDiv98">
        <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 = "midiPlayerDiv98";
        const b64 = "TVRoZAAAAAYAAQACJ2BNVHJrAAAAFAD/UQMHoSAA/1gEBAIYCM5g/y8ATVRyawAAADIA/wMAAOAAQM5gkDxazmCAPAAAkD5azmCAPgAAkEBazmCAQAAAkEFazmCAQQDOYP8vAA==";
        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>

