Control other musical elements
The MusicLang model is controlled by a set of tags that can be used to guide the generation of the music. The tags are used to control for example the density of notes, the number of voices playing at the same time, the pitch register, specific notes that should be used in the generated music.
You control the tags at the bar/track level. So you can have different tags (or not at all) for each bar and each track.
The tags are used to guide the model to generate music that is more likely to be similar to the tags.
You can tag a given score using this package and use the tags as a prompt for the model to generate music that looks alike the tagged score.
Example
In the following example, we constrain the model to generate a piano track with a dense monophonic melody and constrain the second bar of the bass track to use a quite high register:
>>> import os
>>> from maidi import MidiScore, instrument
>>> import maidi.chords_symbols as cs
>>> from maidi.integrations.api import MusicLangAPI
>>> MUSICLANG_API_KEY = os.getenv("MUSICLANG_API_KEY")
>>> score = MidiScore.from_empty(instruments=[instrument.PIANO, instrument.ACOUSTIC_BASS], nb_bars=5, ts=(4, 4), tempo=120)
>>> mask, tags, chords = score.get_empty_controls(prevent_silence=True)
>>> mask[:, :] = 1 # Regenerate everything in the score
>>> for i in range(mask.shape[1]):
... tags[0][i] = ['CONTROL_DENSITY__HIGH', 'CONTROL_MAX_POLYPHONY__1']
>>> tags[1][1] = ['CONTROL_MIN_REGISTER__alto', 'CONTROL_MAX_REGISTER__alto']
>>> api = MusicLangAPI(MUSICLANG_API_KEY, verbose=True)
>>> predicted_score = api.predict(score, mask=mask, tags=tags, chords=chords, async_mode=False, polling_interval=3)
>>> predicted_score.write("predicted_score.mid")
Automatically tag a score
M(AI)DI provides a feature to automatically extract the tags from a score. So you can do analysis of a given score or even use it as a prompt for the model to generate music that “looks alike” the analyzed one.
The following example shows how to extract the tags from a given score:
>>> from maidi.analysis import tags_providers
>>> from maidi import MidiScore, midi_library
>>> from maidi.analysis import ScoreTagger
>>> score = MidiScore.from_midi(midi_library.get_midi_file('drum_and_bass'))
>>> tagger = ScoreTagger([
... tags_providers.DensityTagsProvider(),
... tags_providers.MinMaxPolyphonyTagsProvider(),
... tags_providers.MinMaxRegisterTagsProvider(),
... tags_providers.SpecialNotesTagsProvider(),
... ])
>>> tags = tagger.tag_score(score)
>>> chords = score.get_chords()
>>> from maidi import MidiScore, midi_library
>>> from maidi.analysis import ScoreTagger
>>> score = MidiScore.from_midi(midi_library.get_midi_file('drum_and_bass'))
>>> tagger = ScoreTagger([
... tags_providers.DensityTagsProvider(),
... tags_providers.MinMaxPolyphonyTagsProvider(),
... tags_providers.MinMaxRegisterTagsProvider(),
... tags_providers.SpecialNotesTagsProvider(),
... ])
>>> tags = tagger.tag_score(score)
>>> chords = score.get_chords()