Eulerian Melody Generator
emg is a Python library for generating algorithmic melodies using Eulerian paths with de Bruijn graphs. It can compose a melody from stochastically generated musical motifs by building a Eulerian path, visualize the related de Bruijn graph, and export the melody as an MP3 using a SoundFont file. MuseScore has a number of SoundFont files (e.g., TimGM6mb.sf2) that can be downloaded here.
✨ Features
- Stochastically generate musical motifs (or k-mers) over a chosen musical scale
- Build and visualize a de Bruijn graph from the musical motifs
- Find Eulerian paths in the graph to create coherent melodic sequences
- Export melodies in MP3 format and de Bruijn graphs in PNG format
- Several configurable parameters: scale, tempo, k‑mer length, repeats, etc.
📦 Installation
pip install emg
Built for Python 3.12 or above.
System Prerequisites:
These tools can be installed using Homebrew on Mac OS:
brew install ffmpeg
brew install fluid-synth
🚀 Quick Start
from emg.generator import EulerianMelodyGenerator
# Path to your SoundFont file
sf2_path = "TimGM6mb.sf2"
# Create a generator instance
generator = EulerianMelodyGenerator(
soundfont_path=sf2_path,
scale="C-Major-Pentatonic",
bpm=200,
kmer_length=4,
num_kmers=8,
num_repeats=8,
random_seed=2
)
# Run the full pipeline
generator.run_generation_pipeline(
graph_png_path="graph.png",
mp3_output_path="melody.mp3"
)
Use FFmpeg to convert the MP3 file to an MP4 file (taking the PNG export of the de Bruijn graph - or some other image - as cover art), for uploading to platforms such as YouTube:
ffmpeg -loop 1 -i graph.png -i melody.mp3 \
-c:v libx264 -tune stillimage -c:a aac -b:a 192k \
-pix_fmt yuv420p -shortest melody.mp4
📚 API Reference
See here
Metadata
Release files for emg 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| emg-0.1.8.tar.gz | 6.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| emg-0.1.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.5 kB
Release files / emg-0.1.8.tar.gz
| Download URL | emg-0.1.8.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
90725b99deddcfcdc7104472bdb5460f77de61529b756d280c3312486d9ccd84
|
|
BLAKE2b-256 checksum How to use checksums |
ba1fe095a68510c7e0283f0764a04e185415f47e73f5b9bb0da4f975aa94661b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.11
|
Release files / emg-0.1.8-py3-none-any.whl
| Download URL | emg-0.1.8-py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f561b31072d0c47547be3f4b08258ca044ba891abb0b75926089c4a376528970
|
|
BLAKE2b-256 checksum How to use checksums |
e5fc3017160a4abd59249a7eb2568dbce188e9394dae9280e43e84010c274fdc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.11
|