> For the complete documentation index, see [llms.txt](https://jjazzlab.gitbook.io/developer-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jjazzlab.gitbook.io/developer-guide/music-generation.md).

# Music generation

## Overview

JJazzLab framework → RhythmProvider → Rhythm → **MusicGenerator** → phrases → post-process

{% hint style="success" %}
The engine doesn’t have to care about real-time deadlines: JJazzLab handles scheduling and synchronization.
{% endhint %}

## RhythmProvider

Your engine must implement the [`RhythmProvider`](https://github.com/jjazzboss/JJazzLab/blob/master/core/Rhythm/src/main/java/org/jjazz/rhythm/spi/RhythmProvider.java) interface with the `@ServiceProvider` annotation, so that the [`RhythmDatabase`](https://github.com/jjazzboss/JJazzLab/blob/master/core/RhythmDatabase/src/main/java/org/jjazz/rhythmdatabase/api/RhythmDatabase.java) implementation can automatically find it upon startup. The used Netbeans mechanism is described [here](https://netbeans.apache.org/wiki/main/netbeansdevelopperfaq/DevFaqLookupDefault/) (lookup).&#x20;

**Example**: See [RhythmStubProviderImpl.java](https://github.com/jjazzboss/JJazzLab/blob/master/core/RhythmStubs/src/main/java/org/jjazz/rhythmstubs/RhythmStubProviderImpl.java) for a simple `RhythmProvider` implementation example.

## Rhythm, RhythmVoices and RhythmParameters&#x20;

The engine provides  [`Rhythm`](https://github.com/jjazzboss/JJazzLab/blob/master/core/Rhythm/src/main/java/org/jjazz/rhythm/api/Rhythm.java)  instances to the framework.&#x20;

The `Rhythm` interface notably defines :&#x20;

* name, time signature, preferred tempo, feel, etc.
* [`RhythmVoices`](https://github.com/jjazzboss/JJazzLab/blob/master/core/Rhythm/src/main/java/org/jjazz/rhythm/api/RhythmVoice.java) : the supported tracks (**Drums**, **Bass**, **Piano**, etc.). Each `RhythmVoice` defines the recommended Midi instrument and settings for the track.
* [`RhythmParameters`](https://github.com/jjazzboss/JJazzLab/blob/master/core/Rhythm/src/main/java/org/jjazz/rhythm/api/RhythmParameter.java) : the "control knobs" given to the user to modulate music generation. Common rhythm parameters are **Variation**, **Intensity**, **Mute**, etc. You see them in the Song Structure Editor, their value can be set for each Song Part. The framework provides default UI widget for each rhythm parameter type, but you can define your own UI widget if required.

{% hint style="info" %}
`Rhythm` instances are actually provided via `RhythmInfo` instances, which are used by the [`RhythmDatabase`](https://github.com/jjazzboss/JJazzLab/blob/master/core/RhythmDatabase/src/main/java/org/jjazz/rhythmdatabase/api/RhythmDatabase.java) for its cache file. They represent what the user sees in the rhythm selection dialog.
{% endhint %}

## MusicGenerator

A `Rhythm` instance should implement the [`MusicGeneratorProvider`](https://github.com/jjazzboss/JJazzLab/blob/master/core/RhythmMusicGeneration/src/main/java/org/jjazz/rhythmmusicgeneration/spi/MusicGeneratorProvider.java) interface.&#x20;

Actual music generation is performed by the provided [`MusicGenerator`](https://github.com/jjazzboss/JJazzLab/blob/master/core/RhythmMusicGeneration/src/main/java/org/jjazz/rhythmmusicgeneration/spi/MusicGenerator.java) instance. It receives a song context (chord leadsheet, song structure, tempo, etc.) and returns musical phrases (one per instrument) that form the backing track.

**Example**: See [RhythmStub.java](https://github.com/jjazzboss/JJazzLab/blob/master/core/RhythmStubs/src/main/java/org/jjazz/rhythmstubs/api/RhythmStub.java) for a simple `Rhythm` implementation example.

**Example**: See [DummyGenerator.java](https://github.com/jjazzboss/JJazzLab/blob/master/core/RhythmMusicGeneration/src/main/java/org/jjazz/rhythmmusicgeneration/api/DummyGenerator.java) for a simple `MusicGenerator` implementation example.

## Post-processing

After generation, the framework applies engine-independent post-processing to the returned phrases :&#x20;

* muting instruments in a song part
* per-channel velocity shift
* volume fade-out
* tempo factor changes
* etc.

The details of post-processing tasks performed by the framework are provided in the `MusicGenerator` interface comments.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://jjazzlab.gitbook.io/developer-guide/music-generation.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
