Skip to content

The jam machine dreams up music compositions through deep neural hallucinations. Just import the raw inspiration into your favorite DAW using the generated MIDI file to finish producing your original tracks.

License

Notifications You must be signed in to change notification settings

misnaej/the-jam-machine

 
 

Repository files navigation

The Jam Machine

A Generative AI that composes MIDI music

Try it on HuggingFace Python 3.11+


What is The Jam Machine?

The Jam Machine is an AI music composition tool that generates harmonious MIDI sequences. It's designed for musicians (beginners and professionals) looking for inspiration or backing tracks.

Key Features:

  • Generate 8+ bars of multi-instrument MIDI music
  • Control instruments, note density, and creativity level
  • Download MIDI files to edit in your favorite DAW
  • Runs locally or via web interface

How It Works

┌─────────────────────────────────────────────────────────────────────────────┐
│                           THE JAM MACHINE                                   │
└─────────────────────────────────────────────────────────────────────────────┘

  ┌──────────────────────────────────────────────────────────────────────────┐
  │  TRAINING (one-time, already done)                                       │
  │                                                                          │
  │    5000 MIDI Songs ──► Encoder ──► Text Tokens ──► Train GPT-2 Model     │
  │                                                                          │
  │    Example text: "PIECE_START TRACK_START INST=DRUMS DENSITY=3           │
  │                   BAR_START NOTE_ON=36 TIME_DELTA=2 NOTE_OFF=36..."      │
  └──────────────────────────────────────────────────────────────────────────┘

                                     │
                                     ▼

  ┌──────────────────────────────────────────────────────────────────────────┐
  │  GENERATION (what happens when you use it)                               │
  │                                                                          │
  │                    ┌─────────────────┐                                   │
  │    Your Input ───► │   GPT-2 Model   │ ───► Generated Text               │
  │                    └─────────────────┘                                   │
  │                                                                          │
  │    • Instrument (Drums, Bass, Lead...)                                   │
  │    • Density (how many notes: 1-3)                                       │
  │    • Temperature (creativity: 0.1-1.0)                                   │
  └──────────────────────────────────────────────────────────────────────────┘

                                     │
                                     ▼

  ┌──────────────────────────────────────────────────────────────────────────┐
  │  OUTPUT                                                                  │
  │                                                                          │
  │    Generated Text ──► Decoder ──► MIDI File ──► Audio Preview            │
  │                                                                          │
  │    Download the MIDI and import into GarageBand, Ableton, FL Studio...   │
  └──────────────────────────────────────────────────────────────────────────┘

The Magic: Text-Based Music

The Jam Machine converts music into text, like a language:

Musical Concept Text Representation
Start of piece PIECE_START
New instrument track TRACK_START INST=DRUMS
Note density DENSITY=3
Play a note NOTE_ON=60 (middle C)
Wait 1 beat TIME_DELTA=4
Release note NOTE_OFF=60
End of bar BAR_END

The GPT-2 model learns patterns from 5000 songs and generates new, coherent sequences.


Quick Start

Option 1: Try Online (No Installation)

👉 Launch on HuggingFace

Option 2: Local Installation

Prerequisites

  • Python 3.11+
  • FluidSynth (audio synthesis):
    # macOS
    brew install fluidsynth
    
    # Ubuntu/Debian
    sudo apt install fluidsynth
    
    # Windows - see https://github.com/FluidSynth/fluidsynth/wiki/Download

Installation

# Clone the repository
git clone https://github.com/misnaej/the-jam-machine.git
cd the-jam-machine

# Option A: Use setup script (recommended)
./scripts/setup-env.sh

# Option B: Manual setup
pip install pipenv
pipenv install -e ".[ci]"
pipenv shell

Run the App

pipenv run python app/playground.py

Open the URL shown in your terminal (usually http://localhost:7860).


Usage Guide

Web Interface

  1. Choose an instrument for each track (Drums, Bass, Lead, etc.)
  2. Set creativity (temperature) - higher = more experimental
  3. Set density - how many notes per bar
  4. Click Generate - wait a few seconds
  5. Listen to the preview and view the piano roll
  6. Download the MIDI file

Python API

from the_jam_machine.preprocessing.load import LoadModel
from the_jam_machine.generating.generate import GenerateMidiText
from the_jam_machine.embedding.decoder import TextDecoder
from the_jam_machine.utils import get_miditok

# Load model
model, tokenizer = LoadModel(
    "JammyMachina/elec-gmusic-familized-model-13-12__17-35-53",
    from_huggingface=True
).load_model_and_tokenizer()

# Generate
generator = GenerateMidiText(model, tokenizer)
generator.generate_piece(
    instrument_list=["DRUMS", "4", "3"],  # Drums, Bass, Guitar
    density_list=[3, 2, 3],
    temperature_list=[0.7, 0.7, 0.7],
)

# Get the generated text
piece_text = generator.get_whole_piece_from_bar_dict()

# Convert to MIDI
decoder = TextDecoder(get_miditok())
decoder.get_midi(piece_text, filename="my_song.mid")

Example Script

For more experimental generation:

pipenv run python examples/generation_playground.py

Project Structure

the-jam-machine/
├── app/
│   └── playground.py          # Gradio web interface
├── src/the_jam_machine/
│   ├── embedding/             # MIDI ↔ text conversion
│   │   ├── encoder.py         # MIDI → text
│   │   └── decoder.py         # text → MIDI
│   ├── generating/            # Music generation
│   │   ├── generate.py        # Main orchestrator
│   │   ├── generation_engine.py  # GPT-2 interaction
│   │   ├── piece_builder.py   # Multi-track piece assembly
│   │   ├── track_builder.py   # Single track generation
│   │   └── prompt_handler.py  # Token prompt construction
│   ├── preprocessing/         # Model loading
│   └── training/              # Model training pipelines
├── examples/                  # Example scripts
├── .plans/                    # Refactoring plans and audits
└── test/                      # Test suite

Development

Running Tests

pipenv run pytest test/

Code Quality

# Lint
pipenv run ruff check src/ app/

# Format
pipenv run ruff format src/ app/

See CLAUDE.md for development guidelines.

Development of this repository is supported by Claude Code.


Contributors


Resources


Troubleshooting

FluidSynth Issues

If you encounter errors with audio playback:

  • Check this guide
  • Ensure FluidSynth is in your PATH
  • On macOS: brew reinstall fluidsynth

Model Download Issues

The model (~500MB) downloads automatically on first run. If it fails:

  • Check your internet connection
  • Try: huggingface-cli login if you have rate limits

License

MIT License - feel free to use, modify, and distribute.

Have Fun Making Music! 🎵

About

The jam machine dreams up music compositions through deep neural hallucinations. Just import the raw inspiration into your favorite DAW using the generated MIDI file to finish producing your original tracks.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 97.0%
  • Python 2.9%
  • Shell 0.1%