.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/musiclang_api/04_regenerate_some_bars.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_musiclang_api_04_regenerate_some_bars.py: Regenerate only some bars of a specific tracks ====================================================== In this example : - We load a 4 bar template from a midi file (drum and bass - We regenerate only the first and last bar of the bass (second track) .. GENERATED FROM PYTHON SOURCE LINES 10-32 .. code-block:: Python import os from maidi import MidiScore, instrument, midi_library from maidi.integrations.api import MusicLangAPI # Assuming API_URL and MUSICLANG_API_KEY are set in the environment MUSICLANG_API_KEY = os.getenv("MUSICLANG_API_KEY") # Create a 4 bar template with the given instruments score = MidiScore.from_midi(midi_library.get_midi_file('drum_and_bass')) mask, _, _ = score.get_empty_controls(prevent_silence=True) # Let's set the mask to regenerate the bar we want mask[1, 0] = 1 # Second track, first bar mask[1, -1] = 1 # Second track last bar # Call the musiclang API to predict the score api = MusicLangAPI(api_key=MUSICLANG_API_KEY, verbose=True) predicted_score = api.predict(score, mask, async_mode=False, polling_interval=3 ) predicted_score.write("predicted_score.mid") .. _sphx_glr_download_auto_examples_musiclang_api_04_regenerate_some_bars.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 04_regenerate_some_bars.ipynb <04_regenerate_some_bars.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 04_regenerate_some_bars.py <04_regenerate_some_bars.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 04_regenerate_some_bars.zip <04_regenerate_some_bars.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_