Skip to main content

Procedural music generator

Project description

Pylint Unit tests License: AGPL v3

Music Generation

This tool procedurally generates music based on codified Western classical music principles.

Getting started

To run the music generator, install it using pip, then run the package from the project root folder:

python -m pip install continuo
python -m continuo

Example music

Example music can be found here.

⚠️ State of the repository ⚠️

This repository is unlikely to receive new features in the future, although maintenance and small fixes will still be done.

This means that some features that are missing now will stay missing (but feel free to submit a pull request to add them!), and non-optimal aspects of the codebase or the application are unlikely to get fixed.

Parameterization

Custom parameterization is possible over the command line interface or an external configuration file, but currently not consolidated into one config file.

Command line interface

The application supports configuration of almost every configurable setting directly over the command line interface.

A full list of the available arguments is listed below:

usage: __main__.py [-h] [--generate-config [CONFIG_FILEPATH]]
                   [--config-file CONFIG_FILE] [--playback {True,False}]
                   [--save [SAVE_FILEPATH]]
                   [--format [{wav,json} [{wav,json} ...]]]
                   [--load [LOAD_FILEPATH]] [--time-length TIME_LENGTH]
                   [--layers LAYERS] [--tempo TEMPO] [--mode {major,minor}]
                   [--base-note BASE_NOTE] [--motif-length MOTIF_LENGTH]
                   [--layer-offsets [LAYER_OFFSETS [LAYER_OFFSETS ...]]]
                   [--sophistication SOPHISTICATION] [--variations VARIATIONS]
                   [--motifs MOTIFS]

optional arguments:
  -h, --help            show this help message and exit
  --generate-config [CONFIG_FILEPATH], -g [CONFIG_FILEPATH]
                        Generates a template music configuration file under
                        the specified filepath
  --config-file CONFIG_FILE, -c CONFIG_FILE
                        The filepath of a music configuration file
  --playback {True,False}, -p {True,False}
                        Determines whether the generated music should be
                        played back
  --save [SAVE_FILEPATH], -s [SAVE_FILEPATH]
                        Saves the generated music to a wav-file under the
                        specified filepath
  --format [{wav,json} [{wav,json} ...]], -f [{wav,json} [{wav,json} ...]]
                        The formats which should be used when saving the
                        generated music to file
  --load [LOAD_FILEPATH], -lo [LOAD_FILEPATH]
                        The filepath of a saved music json file
  --time-length TIME_LENGTH, --time TIME_LENGTH, -ti TIME_LENGTH
                        The length of time the generated music should last
  --layers LAYERS, -l LAYERS
                        The amount of layers to be generated
  --tempo TEMPO, -t TEMPO
                        The tempo of the generated music
  --mode {major,minor}, -m {major,minor}
                        The mode of the generated music
  --base-note BASE_NOTE, -b BASE_NOTE
                        The lowest note used in the generated music (e.g. A3)
  --motif-length MOTIF_LENGTH, -ml MOTIF_LENGTH
                        The length of the generated motifs
  --layer-offsets [LAYER_OFFSETS [LAYER_OFFSETS ...]], -o [LAYER_OFFSETS [LAYER_OFFSETS ...]]
                        The amount of semitones layers should be offset from
                        base note
  --sophistication SOPHISTICATION, -so SOPHISTICATION
                        The amount of options that should be considered when
                        generating new notes
  --variations VARIATIONS, -v VARIATIONS
                        The amount of motif variations to be considered
  --motifs MOTIFS       The amount of motifs to be considered

The help message can be brought up by running:

python -m continuo -h

Configuration file

Advanced settings, such as intervals, harmonies and consonance mappings can not be directly provided over the command line interface, but may be provided in an external configuration file.

Generate a template configuration file by running:

python -m continuo --generate-config <filename>

To run the music generator with a configuration file, run:

python -m continuo --config-file <filename>

The configuration file currently supports 4 main advanced settings:

  • "momentums": a list of non-unique integers that are used to factorise note intervals to decide direction. This should only contain -1, 0 or 1, but may technically contain anything.
  • "intervals": a list of non-unique integers that will be chosen from by the music generator when generating motifs.
  • "consonance_dict": a mapping of integer intervals to the respective (float) consonance (the lower, the more dissonant the interval is treated as and will be avoided).
  • "harmony_dict": a mapping of integer intervals to a list of integer intervals, representing all possible continuations from one note to another.

An example configuration file could look like this:

{
    "momentums": [-1, 0, 1],
    "intervals": [0, 0, 1, 1, 2, 3],
    "consonance_dict": {
        "0": 0.25,
        "1": -0.25,
        "2": 1,
        "3": 0.5,
        "4": 0.5,
        "5": 0.5,
        "6": -0.25
    },
    "harmony_dict": {
        "0": [6, 1, 3],
        "1": [4],
        "2": [1, 3],
        "3": [4],
        "4": [0, 5],
        "5": [4, 1],
        "6": [0]
    }
}

Contributions

All contributions are welcome! Please read the contribution guidelines.

Python

Written in Python 3.8.3.

License

This repository is open-source software available under the AGPL-3.0 License.

Contact

Please raise an issue for code changes. To reach out, please send an email to richard@baltrusch.net.

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

continuo-0.3.0.tar.gz (25.8 kB view details)

Uploaded Source

Built Distribution

continuo-0.3.0-py3-none-any.whl (26.7 kB view details)

Uploaded Python 3

File details

Details for the file continuo-0.3.0.tar.gz.

File metadata

  • Download URL: continuo-0.3.0.tar.gz
  • Upload date:
  • Size: 25.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.9

File hashes

Hashes for continuo-0.3.0.tar.gz
Algorithm Hash digest
SHA256 2c56dd7bc66a390f6cbf685a4c9cac9a9604537f155667e2aa928b1cb3979554
MD5 c04d56e07a5a1eca46b38ac338f6b371
BLAKE2b-256 2efc51df6df2a31cb0a269ae14009e2a8c582467574f8a4676c72ff2822e2cc7

See more details on using hashes here.

File details

Details for the file continuo-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: continuo-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 26.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.9

File hashes

Hashes for continuo-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 31198b81ce8d134cdcffd9c71eb5087da94af7977e13cd2204c61d068fcec3c9
MD5 fdbdbfec861c335719c0c926efd13613
BLAKE2b-256 c3dd6da085670751f31d9ae701f36a39dcc430a73f3c96d04742407609e1f201

See more details on using hashes here.

Supported by

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