Skip to content

misnaej/the-jam-machine

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

519 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

The Jam Machine

A Generative AI that composes MIDI music

CI Try it on HuggingFace Python 3.11+ Ruff License: MIT Tests Coverage Docstring Coverage Security Claude Code


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.


Documentation

Full documentation on GitHub Pages

Page Description
Encoding & Decoding Guide Step-by-step walkthrough of the MIDI-to-text pipeline, token vocabulary, quantization, and a worked example using The Strokes' Reptilia
Embedding Explorer Interactive visualizations of how the GPT-2 model represents MIDI tokens β€” embedding space, attention patterns, and head specialization

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 -m jammy.app.playground

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

Run with Docker (CPU only)

# Set up your HuggingFace token (optional, for faster downloads)
cp .env.example .env
# Edit .env with your token from https://huggingface.co/settings/tokens

docker compose up

Open http://localhost:7860. Generated output is available in ./output/ on the host. The image uses CPU-only PyTorch (~2.5GB) and works on both amd64 and arm64.


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 jammy.load import load_model_and_tokenizer
from jammy.generating.config import GenerationConfig, TrackConfig
from jammy.generating.generate import GenerateMidiText
from jammy.embedding.decoder import TextDecoder
from jammy.utils import get_miditok

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

# Generate
tracks = [
    TrackConfig(instrument="DRUMS", density=3, temperature=0.7),
    TrackConfig(instrument="4", density=2, temperature=0.7),   # Bass
    TrackConfig(instrument="3", density=2, temperature=0.7),   # Guitar
]
generator = GenerateMidiText(model, tokenizer, config=GenerationConfig(n_bars=8))
generator.generate_piece(tracks)

# Get the generated text and convert to MIDI
piece_text = generator.get_piece_text()
decoder = TextDecoder(get_miditok())
decoder.get_midi(piece_text, filename="my_song.mid")

Examples

# Generate new music
pipenv run python examples/generate.py

# Encode/decode a MIDI file (roundtrip demo)
pipenv run python examples/encode_decode.py

Output goes to output/examples/. See examples/README.md for details.


Project Structure

the-jam-machine/
β”œβ”€β”€ src/jammy/                 # Main package
β”‚   β”œβ”€β”€ app/                   # Gradio web interface
β”‚   β”œβ”€β”€ analysis/              # Model visualization tools
β”‚   β”œβ”€β”€ embedding/             # MIDI ↔ text conversion
β”‚   β”œβ”€β”€ generating/            # Music generation (GPT-2)
β”‚   β”œβ”€β”€ preprocessing/         # Data preprocessing
β”‚   └── training/              # Model training
β”œβ”€β”€ hf_space/                  # HuggingFace Space deployment
β”œβ”€β”€ examples/                  # Runnable example scripts
β”œβ”€β”€ test/                      # Test suite (149 tests)
β”œβ”€β”€ docs/                      # GitHub Pages site
└── scripts/                   # Build, test, deploy scripts

Development

Running Tests

pipenv run pytest test/ -v

Code Quality

# Lint
pipenv run ruff check src/ test/ app/ examples/

# Format
pipenv run ruff format src/ test/ app/ examples/

# Security audit
pipenv run pip-audit

Contributing with Claude Code

Development of this repository is supported by Claude Code. The project includes custom skills and agents for a structured workflow:

Skill What it does
/check Run tests + lint + format
/lint Run ruff check + format
/commit Lint, commit, and push to current branch
/review Run design + docs review agents
/pr Generate squash merge message

Workflow:

  1. Create a feature branch from main
  2. Make changes, run /check to verify
  3. Run /commit to lint, commit, and push
  4. Create a PR, run /pr for review and merge message
  5. Squash and merge into main

See CLAUDE.md for full development guidelines.


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.

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

 
 
 

Contributors

Languages

  • Python 95.7%
  • Shell 4.0%
  • Dockerfile 0.3%