Generate random melody under specific rules.
This project is written in Python 3.6. I haven't tested in other versions.
MIDIUtil library is used in my project. You can install it simply by using pip
:
pip install MIDIUtil
Simply run main.py
. A standard MIDI file will be generated in output
folder. The filename is midi_{timestamp}.mid
.
You can play it using a media player (e.g. Windows Media Player) or import it into a Digital Audio Workstation (DAW).
By default, the melody is in major pentatonic scale, chord progression is C-Am-F-G (1-6-4-5), and percussion pattern is fixed. Also, the interval of notes within a phrase is constrained.
The rules can be modified in rules.json
.
You can also adjust the length of song and tempo in song_settings.json
.
Parameter | Description |
---|---|
notes |
Defines the notes used for composition. |
interval_upper |
Defines the upper bound of interval of notes. The values in this list will be randomly chosen. |
interval_lower |
Defines the lower bound of interval of notes. The values in this list will be randomly chosen. |
rhythm |
Defines rhythm pattern for melody. The numbers are in beats (quarter notes). |
seq_chord |
Defines the chord sequence. Notes in each sub-array will be played simultaneously to form a chord. |
seq_perc |
Defines the percussion sequence. The first element in the sub-array denotes the drum sound, and the second element denotes time value in beats. |
velocity |
Defines the velocity of strong, intermediate and weak beats. |
Parameter | Description |
---|---|
length |
Defines the length of song. |
tempo |
Defines the tempo of song, measured in Beats per Minute (BPM). |
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。