132 lines
3.4 KiB
Markdown
132 lines
3.4 KiB
Markdown
# MusicGen
|
|
|
|
Generate electronic music without AI
|
|
|
|
## Requirements
|
|
|
|
- Rust 1.87.0+
|
|
|
|
## Build
|
|
|
|
```bash
|
|
git clone <repository-url>
|
|
cd music
|
|
cargo build --release
|
|
```
|
|
|
|
## JSON Configuration
|
|
|
|
Create declaritive songs with structured JSON:
|
|
|
|
```bash
|
|
cargo run --bin musicgen json examples/bliss.json
|
|
```
|
|
|
|
### From Binary
|
|
```bash
|
|
./target/release/musicgen json examples/bliss.json
|
|
```
|
|
|
|
### Basic JSON Structure
|
|
|
|
```json
|
|
{
|
|
"composition": {
|
|
"key": 60,
|
|
"scale": "minor",
|
|
"tempo": 85.0,
|
|
"measures": 16
|
|
},
|
|
"tracks": [
|
|
{
|
|
"name": "bass",
|
|
"instrument": "sine",
|
|
"volume": 0.8,
|
|
"pattern": {
|
|
"type": "custom",
|
|
"steps": [
|
|
{ "time": 0.0, "note": "C2", "duration": 0.75, "velocity": 0.9 }
|
|
]
|
|
}
|
|
}
|
|
],
|
|
"export": {
|
|
"filename": "my_song",
|
|
"format": "wav"
|
|
}
|
|
}
|
|
```
|
|
|
|
### Definitions
|
|
|
|
- **Track** - Each track like a single instrument in a band (like the bass or drums)
|
|
- **Pattern** - The sequence of notes that a track plays.
|
|
- **Steps** - Individual notes in your pattern.
|
|
- **Velocity** - How loud to play the note (0.0 = whisper quiet, 1.0 = full volume)
|
|
- **Loop Length** - How long your pattern is before it repeats (in beats)
|
|
- **Measures** - Groups of beats (usually 4 beats = 1 measure). Like counting "1-2-3-4, 1-2-3-4"
|
|
- **Tempo/BPM** - How fast the song goes. 120 BPM = 120 beats per minute
|
|
- **Key** - What note the song is "centered" around (like C major or A minor)
|
|
- **MIDI Notes** - Just numbers for musical notes. 60 = middle C, 69 = A above middle C. Or use note names like "C4" or "A4"
|
|
- **Duration** - How long a note plays for (in beats). 1.0 = one full beat, 0.5 = half a beat
|
|
- **Waveforms** - The "shape" of the sound. Sine = smooth/warm, Square = retro video game, Sawtooth = buzzy/bright
|
|
- **Effects** - Things that change how your track sounds. Lowpass = makes it muffled, Delay = adds echo
|
|
- **Time Signature** - How many beats per measure. 4/4 means 4 beats per measure (most common)
|
|
- **Chord** - Multiple notes played together. Like C major = C + E + G played at the same time
|
|
- **Arpeggio** - Playing chord notes one after another instead of all together
|
|
|
|
### Available Options
|
|
|
|
- **Instruments**: `sine`, `square`, `sawtooth`, `triangle`, `noise`
|
|
- **Scales**: `major`, `minor`, `dorian`, `pentatonic`, `blues`, `chromatic`
|
|
- **Keys**: MIDI numbers (60 = C4) or note names (`"C4"`, `"F#3"`)
|
|
- **Pattern Types**: `custom`, `chord`, `arpeggio`, `sequence`
|
|
- **Effects**: `lowpass`, `highpass`, `delay`, `reverb`, `chorus`, `distortion`
|
|
|
|
### Track Configuration
|
|
|
|
```json
|
|
{
|
|
"tracks": [
|
|
{
|
|
"name": "bass",
|
|
"instrument": "sine",
|
|
"volume": 0.8,
|
|
"pattern": {
|
|
"type": "custom",
|
|
"steps": [
|
|
{ "time": 0.0, "note": "C2", "duration": 0.75, "velocity": 0.9 },
|
|
{ "time": 2.0, "note": "G2", "duration": 0.75, "velocity": 0.8 }
|
|
],
|
|
"loop_length": 4.0
|
|
},
|
|
"effects": [
|
|
{
|
|
"type": "lowpass",
|
|
"cutoff": 400.0,
|
|
"resonance": 1.8
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"name": "drums",
|
|
"instrument": "noise",
|
|
"volume": 0.6,
|
|
"pattern": {
|
|
"type": "custom",
|
|
"steps": [
|
|
{ "time": 0.0, "note": "C1", "duration": 0.1, "velocity": 1.0 },
|
|
{ "time": 1.0, "note": "E3", "duration": 0.05, "velocity": 0.7 }
|
|
]
|
|
}
|
|
}
|
|
]
|
|
}
|
|
```
|
|
|
|
See `examples` for complete examples and the full schema.
|
|
|
|
## Output
|
|
|
|
All audio files are saved to the `output/` directory.
|