Music Generator
Generate music from MIDI files with Markov Chains
Upload MIDI files to begin
How does it work?
Picture from StackExchange
Markov Chains!
  • Way to model the probability of a sequence of events.
  • Many paths can be generated from a single starting point.
  • Used as a basic/rudimentary model of "AI" for language processing (n-Grams)
AI, Blockchain, Cloud!
Picture by Daniel Mietchen
N-Gram models
  • Connecting multiple objects together to establish relationship.
  • Famous for it's use in statistical language processing.
  • Simple to use, easily scalable.
  • Used in many areas, not just AI.
How We Made It
MIDI Files!
What is a MIDI File?
Picture from John Li
Musical Instrument Digital Interface
  • Carries Event Messages (NoteOn, NoteOff, etc.)
  • Records notes including notation, pitch, velocity, etc.
  • Standardized, though somewhat a pain to parse.
Example of 3 MIDI Events
NoteOnNote: C6Velocity: 127Delta Time: 208
NoteOnNote: E6Velocity: 127Delta Time: 203
NoteOffC6Velocity: 127Delta Time: 8000
Now, Why not just contruct Bi-Grams out of these events?
Well...
Notes are assumed continuously pressed down until told otherwise. By merely feeding our model with all events, Its up to essentially the model to randomly generate the corresponding NoteOff event for the NoteOn event
Modified Approach
Picture drawn by John Li
Parsing Notes
  1. Find all NoteOn events in the MIDI file.
  2. Find the nearest NoteOff event for each NoteOn event.
  3. Find the duration of each NoteOn event by summing all Deltas between the NoteOn and NoteOff events.
  4. Find the minimum time before the next note is played.
  5. Generate Bi-Grams for the note
Remember these events?
NoteOnNote: C6Velocity: 127Delta Time: 203
NoteOnNote: E6Velocity: 127Delta Time: 203
NoteOffC6Velocity: 127Delta Time: 8000
Example of Parsed MIDI Events
Play NoteNote: C6Velocity: 127Duration: 8203Delay: 203
Play NoteNote: E6Velocity: 127Duration: 8450Delay: 210
Generating Music from the Markov Chain
Picture drawn by John Li
  1. Start with a random note.
  2. Find all notes that have followed the current note.
  3. Using the precomputed probabilities, pick a weighted random note.
  4. Repeat until the song has been generated.
  5. Reparse current note format into events
  6. Generate a MIDI file from the events