.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/musiclang_api/06_control_the_tracks.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_06_control_the_tracks.py: Deep musical control over the generation =================================================== MusicLang allows you to control the chord progression of your song. In this example : - We constrain the model to generate a piano track with a dense monophonic melody - We constrain the second bar of the bass track to use a quite high register By using and modifying this example you will be able to add deep control over the music generated with musiclang Check :ref:`tags` to get the full list of available tags .. GENERATED FROM PYTHON SOURCE LINES 15-44 .. code-block:: Python import os from maidi import MidiScore, instrument import maidi.chords_symbols as cs from maidi.integrations.api import MusicLangAPI # Assuming MUSICLANG_API_KEY is set in the environment MUSICLANG_API_KEY = os.getenv("MUSICLANG_API_KEY") # Create a 4 bar template with the given instruments score = MidiScore.from_empty( instruments=[instrument.PIANO, instrument.ACOUSTIC_BASS], nb_bars=5, ts=(4, 4), tempo=120 ) # Get the controls (the prompt) for this score mask, tags, chords = score.get_empty_controls(prevent_silence=True) mask[:, :] = 1 # Regenerate everything in the score # Let control the tags for i in range(mask.shape[1]): tags[0][i] = ['CONTROL_DENSITY__HIGH', 'CONTROL_MAX_POLYPHONY__1'] # Second bar of the bass track use a quite high register (like alto) tags[1][1] = ['CONTROL_MIN_REGISTER__alto', 'CONTROL_MAX_REGISTER__alto'] # Call the musiclang API to predict the score api = MusicLangAPI(api_key=MUSICLANG_API_KEY, verbose=True) predicted_score = api.predict(score, mask, tags=tags, chords=chords, async_mode=False, polling_interval=3 ) predicted_score.write("predicted_score.mid") .. _sphx_glr_download_auto_examples_musiclang_api_06_control_the_tracks.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 06_control_the_tracks.ipynb <06_control_the_tracks.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 06_control_the_tracks.py <06_control_the_tracks.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 06_control_the_tracks.zip <06_control_the_tracks.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_