HipHop Midi Generator

First effort to use Claude AI to generate working software. So, so simple. All those years I spent laboriously coding things…

Should note that I’m just using the free tier of Claude.

Started with a very simple prompt: make a python program that generates random hiphop rhythms

Claude produced a fully functioning Python script and the following explanation:


I’ve created a comprehensive hip-hop rhythm generator that creates realistic drum patterns! Here’s what it does:

Key Features:

  • Multiple drum elements: Kicks, snares, hi-hats, and percussion
  • Authentic patterns: Based on real hip-hop rhythm templates (boom-bap, trap, etc.)
  • Complexity levels: Simple, medium, or complex variations
  • Interactive playback: Plays rhythms in real-time in the terminal
  • Pattern visualization: Shows rhythms in an easy-to-read grid format
  • Export functionality: Save patterns to text files for use in DAWs

How it works:

  1. Uses predefined templates for each drum element based on common hip-hop patterns
  2. Adds random variations to create unique combinations
  3. Supports 1-4 bar generations with customizable BPM
  4. Can play back rhythms with proper timing

Usage:

  • Run the program and choose from the menu options
  • Generate rhythms with different complexity levels
  • Play them back to hear how they sound
  • Export patterns for use in music production software

The generator includes classic patterns like the boom-bap kick (kick on 1 and the “and” of 2), standard backbeat snares (2 and 4), and various hi-hat patterns from simple 8th notes to complex trap-style patterns. The randomization ensures you get fresh variations while maintaining the essential groove characteristics of hip-hop.


All I needed to do was the copy the script into a text editor and save it as a .py file, then navigate to the relevant directory in Terminal and run the file (python3 HipHopGenerator.py).

The program launched, running directly in Terminal. It worked fine and even saved out a text file of the generated pattern. I realised, however, that it was currently lacking MIDI output, which would enable me to copy the file directly into my DAW to run via a drum plugin, so I requested this addition: can you revise the program to include midi export?

Claude dutifully did this, generating a new version of the software with MIDI export. It made a mistake this time around, placing the relevant function outside the main object definition. But this was quickly fixed when I asked it to address the Terminal error message (I just copied the error into the Claude prompt). Another version was produced, all working this time. The only issue was that I needed to install the Python MIDO library, which went into the Python3.11 directory. So now I needed to run the script via Python3.11 (python3.11 HipHopGenerator.py).

Here is how the program runs. You can see that I make a series of numerical choices and then the program exports a MIDI file, which works fine in any DAW.

Unbelievable!

Final observation – guess it would be easy to generate a GUI and make this a fully fledged desktop app, but I’ll leave that for another day.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *