MIDITool is an AI-powered music generation pipeline that creates MIDI files using LLMs. It provides a hierarchical context model (projects, groups, tracks, clips) and a multi-stage pipeline for generating musical ideas and converting them to MIDI.
- Multi-level context hierarchy (Project > Group > Track > Clip)
- AI-driven music generation using various LLM providers
- MIDI file generation and processing with automatic playback
- Command-line interface for easy interaction
- Support for multiple LLM providers (Mistral, Anthropic, OpenAI, etc.)
- Advanced LLM-based MIDI validation and analysis
- Automatic MIDI repair tools for track lengths and end-of-track markers
- Two-phase generation with validation feedback and retries
- Simple single-track MIDI generation for improved reliability
- Mandatory MIDI validation with automatic retry
- Debug logging for LLM inputs and outputs
- Configurable for different musical styles and contexts
# Clone the repository
git clone https://github.com/Foundation42/miditool.git
cd miditool
# Install dependencies
bun install
# Copy environment template and fill in your API keys
cp .env.example .env
# Edit .env with your API keys
# Set up MIDI playback (on Linux)
bun run setup-timidity# Show help
bun start help
# Test LLM connection
bun run test-llm
# Test with specific LLM provider
bun run test-mistral-cli # Test Mistral
bun run test-openai # Test OpenAI
# Generate known-good MIDI files
bun run generate-good-midi # Create a standards-compliant MIDI file
bun run generate-test-melody # Create a test melody with clear notes
# Create and generate projects
bun run create-example # Create an example project structure
bun run generate example-project # Generate MIDI for a project
bun run simple-test # Run a simple single-clip generation test
bun run two-phase-test # Test two-phase generation with validation
# MIDI tools
bun run play <path-to-midi-file> # Play a MIDI file
bun run analyze-midi <midi-file> # Analyze a MIDI file
bun run fix-midi <midi-file> # Repair a problematic MIDI fileimport { MusicGenerationPipeline } from "miditool";
// Create a pipeline
const pipeline = new MusicGenerationPipeline({
outputDir: "./my-output-dir",
maxConcurrentRequests: 2
});
// Create a project
const project = pipeline.createProject("My Project", {
description: "A cool music project",
style: "Electronic",
tempo: 128,
key: "F minor",
timeSignature: "4/4"
});
// Add a group
const group = pipeline.createGroup(project, "Synths", {
role: "melody"
});
// Add a track
const track = pipeline.createTrack(group, "Lead Synth", "Analog Synth");
// Add a clip
const clip = pipeline.createClip(track, "Main Melody", 0, 8, {
description: "The main melody hook for the song"
});
// Generate the clip
await pipeline.generateClip(project, group, track, clip);ANTHROPIC_API_KEY: API key for Anthropic (Claude)OPENAI_API_KEY: API key for OpenAIMISTRAL_API_KEY: API key for MistralGOOGLE_API_KEY: API key for Gemini/Vertex AIDEEPSEEK_API_KEY: API key for DeepSeekOLLAMA_ENDPOINT: Endpoint for Ollama (local LLMs)
LLM_PROVIDER: Default LLM provider (anthropic, openai, mistral, etc.)LLM_MODEL: Specific model to use with the provider
OUTPUT_DIR: Directory for output files (default: ./output)MAX_CONCURRENT_REQUESTS: Maximum number of concurrent LLM requests (default: 2)
# Run type checking
bun run typecheck
# Format code
bun run format
# Build for production
bun run build
# List all supported LLM providers
bun run list-providersFor MIDI playback, the tool requires one of the following players:
- FluidSynth (recommended):
sudo pacman -S fluidsynth soundfont-fluid(Arch) orsudo apt install fluidsynth fluid-soundfont-gm(Ubuntu) - TiMidity++:
sudo pacman -S timidity++(Arch) orsudo apt install timidity(Ubuntu)
Run bun run setup-timidity to configure TiMidity with the correct soundfonts.
src/: Source codetypes.ts: Core type definitionsllm.ts: LLM interface wrappersmidi.ts: MIDI utilitiespipeline.ts: Core pipeline implementationcli.ts: Command-line interface
tests/: Test scriptstools/: Utility toolsmidi-analyzer.ts: Tool to validate MIDI filesmidi-fixer.ts: Tool to repair MIDI filessetup-timidity.sh: Script to configure TiMidity
output/: Generated MIDI files
MIT
This project was created using Bun, a fast all-in-one JavaScript runtime.