Skip to main content

Python library for generating melodies using the concept of Eulerian paths

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

emg-0.1.8.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

emg-0.1.8-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file emg-0.1.8.tar.gz.

File metadata

  • Download URL: emg-0.1.8.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.11

File hashes

Hashes for emg-0.1.8.tar.gz
Algorithm Hash digest
SHA256 90725b99deddcfcdc7104472bdb5460f77de61529b756d280c3312486d9ccd84
MD5 4d4d7833feddde83e9c128a23519eace
BLAKE2b-256 ba1fe095a68510c7e0283f0764a04e185415f47e73f5b9bb0da4f975aa94661b

See more details on using hashes here.

File details

Details for the file emg-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: emg-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.11

File hashes

Hashes for emg-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 f561b31072d0c47547be3f4b08258ca044ba891abb0b75926089c4a376528970
MD5 fcf2abfdd0b3d858a3cb404e7b0b4126
BLAKE2b-256 e5fc3017160a4abd59249a7eb2568dbce188e9394dae9280e43e84010c274fdc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page