I trained Markov Chain models on melodies and rhythms, and using them to augment existing MIDI files, adding new notes to the files to produce slightly more advanced arrangements.
You can find a working version here. I'm still learning all sorts of things about hosting things on AWS so do please let me know if this link is broken at any point.
###Diary of my work so far:
- Explaining the formats of the resulting files
- Extracting time series information in the rhythmic and melodic domains (first pass)
- Extracting time series information in the rhythmic and melodic domains (final pass)
- Getting Markov Chains up and running
- Recentered Markov Chains
- Quantizing Rhythm Sequences
- Making Markov Chains from Rhythmic Sequences
You may want to use a virtual environment to install the following Python packages:
Additionally, for the webapp to work, you'll want the following:
- Tendo
- Flask
- pyFluidSynth
- This can be tricky -- you'll need FluidSynth before this package will work, which has its own platform-dependent requirements. Check the installation page for details on this.
- The FluidR3_GM.sf2 soundfont file.
From the (Mac or Linux) terminal, run the following commands.
# move to the source directory of the repo
$ cd path/to/midi_levelUp/src
# run midi_funcs for a short demo of
# sequence extraction
$ python midi_funcs.py
# run markov_funcs for a short demo of
# creating markov chains and producing
# pickled models
$ python markov_funcs.py
# in d3_model folder:
$ python play_notes.py
###Note on storage space for webapp:
In order to clean up the wav files that get generated by play_notes.py
, you can set up a cron
job by opening the terminal and typing the following command:
# Edit the existing crontab file
$ sudo crontab -e
Once inside the editor, append the line
*/5 * * * * python /path/to/repo/d3_model/clear_static.py
and be sure to add a new line before EOF. The */5
will clear the files every five minutes, and you can change this at your own discretion (read more about cron files here).
###Note on persistence for webapp:
Type python play_notes.py &
to run the app in the background (i.e. you can still use your shell while the program runs). The program should persist, but in case something goes wrong, you can add a line like this to your crontab:
0 * * * * cd path/to/repo/ && . ./env/bin/activate && python d3_model/play_notes.py
The first two commands tell cron to change its default working directory from home to the right folder, and to activate the virtualenv (you can skip this middle command if you are running directly off your core machine).
The last command restarts the play_notes.py
script. This script includes a line at the beginning to make sure it's the only instance of itself running, and exits if the app is already up. The line above will attempt this restart process once an hour at the top of the hour, and you can change it at your discretion.