Melody and midi generation forked from random-midi by Jobsecond.
I use random-midi and lilypond (a program for typesetting sheet music in LaTeX) to generate short melodies and corresponding sheet music, intended for practising note reading for guitar.
This project is written in Python 3.6.
Install MIDIUtil with pip
:
pip install MIDIUtil
Install lilypond with apt:
sudo apt-get install lilypond
In order to play midi files you may want to install timidity:
sudo apt-get install timidity timidity-interfaces-extra
or VLC and the appropriate plugin:
sudo apt-get install vlc vlc-plugin-fluidsynth
Simply run main.py
. A standard MIDI file will be generated in output
folder. The filename is {timestamp}.mid
. You'll also find a PDF file of the corresponding sheet music in output/{timestamp}.pdf
, and the text file compiled by lilypond into this sheet music in output/{timestamp}.txt
.
The melodies produced are very short: by default, 10 melodies of 8 notes are produced.
There are four optional command-line arguments:
python main.py --tempo <tempo> --num-exercises <# exercises> --num-bars <# bars per exercise> --key <key>
The default tempo is slow (45). The default number of exercises (number of short melodies to be generated) is 10. The default number of bars is two, with four notes to a bar.
Keys are A through G. Sharp and flat keys are available by adding an is
or es
suffix respectively (taken from Lilypond's note naming convention), so, for example,
python main.py --key ges
will produce exercises using the G♯ major scale. In the produced sheet music, accidentals are used rather than indicating the key signature.
The following is sheet music generated for the sequence of melodies found in the example MIDI file here. The PDF can be found here.