.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/musiclang_api/01_add_guitar_track.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_01_add_guitar_track.py: Generate a new track on a midi file ====================================================== In this example : - We load a 4 bar template from a midi file - We add a clean guitar track - We call the musiclang API to predict the score - We save the predicted score to a midi file .. GENERATED FROM PYTHON SOURCE LINES 12-33 .. 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')) # Add a clean guitar track and set the mask score = score.add_instrument(instrument.CLEAN_GUITAR) mask, _, _ = score.get_empty_controls(prevent_silence=True) mask[-1, :] = 1 # Generate the last track # Call the musiclang API to predict the score api = MusicLangAPI(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_01_add_guitar_track.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01_add_guitar_track.ipynb <01_add_guitar_track.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01_add_guitar_track.py <01_add_guitar_track.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 01_add_guitar_track.zip <01_add_guitar_track.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_