Skip to main content

The Beat Machine is a library for playing with beats of songs.

Project description

beat-machine

Build Status Maintainability PyPI

The Beat Machine is a library for playing with beats of songs, inspired by the creations over on /r/BeatEdits. It works both as a library and as a command-line utility that reads effects from a JSON array.

Installation

One of the Beat Machine's dependencies, madmom, requires Cython to be present before installation. If you encounter an error along the lines of:

Command "python setup.py egg_info" failed with error code 1 in /tmp/tmp1d2dis8pbuild/madmom/

Try installing Cython (pip install Cython) beforehand as a separate build step.

Examples

A few examples of common edits are available below. In all cases, multiple effects can be supplied. When more than one effect is present, effects are applied in order of appearance.

Using the CLI

The CLI has the following usage (produced by python -m beatmachine --help):

Usage: __main__.py [OPTIONS]

Options:
  --input TEXT    File to process.  [required]
  --effects TEXT  JSON representation of effects to apply.  [required]
  --output TEXT   Output mp3 file path.  [required]
  --help          Show this message and exit.

Note that the program may appear to hang due to the time taken to locate beats.

Removing every other beat

The remove effect can't have a period of 1, because that would be silly (and result in nothing to work with).

$ python -m beatmachine \
    --input "in.mp3" \
    --output "out.mp3" \
    --effects '[{"type": "remove", "period": 2}]'

Cutting every beat in half

$ python -m beatmachine \
    --input "in.mp3" \
    --output "out.mp3" \
    --effects '[{"type": "cut", "period": 1}]'

Swapping beats 2 and 4

In the swap effect, the x_period and y_period fields are interchangeable, however they can't be equal.

$ python -m beatmachine \
    --input "in.mp3" \
    --output "out.mp3" \
    --effects '[{"type": "swap", "x_period": 2, "y_period": 4}]'

Halving every beat then duplicating every other beat

$ python -m beatmachine \
    --input "in.mp3" \
    --output "out.mp3" \
    --effects '[{"type": "cut", "period": 1},
                {"type": "repeat", "period": 2, "times": 2}]'

Using the Python module

Note that load_beats_by_signal is a rather long, blocking operation (~50 seconds for a 2 minute song on a Ryzen 5 2600 w/ 16GB of RAM). Your mileage may vary.

If slightly inaccurate results are acceptable, load_beats_by_bpm is also available, which is much less CPU- and memory-intensive. This method of loading beats is not capable of handling any kind of tempo change.

Removing every other beat

import beatmachine as bm

beats = bm.loader.load_beats_by_signal('in.mp3')  # A file-like object is also acceptable
effects = [bm.effects.periodic.RemoveEveryNth(period=2)]
result = sum(bm.editor.apply_effects(beats, effects))
result.export('out.mp3')

Other results come from modifying the effects list. See the effects module and its submodules for more possibilities.

Implementing a custom effect

There are two ways to create a basic effect class:

  • Create a class with the metaclass beatmachine.effects.base.EffectRegistry
  • Inherit from beatmachine.effects.base.BaseEffect with metaclass beatmachine.effects.base.EffectABCMeta
    • This is recommended since it provides all the necessary attributes as an abstract base class

The resulting effect class will automatically be loadable through beatmachine.effects.load_from_dict. Make sure that any configurable parameters are specified as keyword arguments, since load_from_dict passes fields directly to __init__.

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

beatmachine-2.1.0.tar.gz (21.3 kB view details)

Uploaded Source

Built Distribution

beatmachine-2.1.0-py2.py3-none-any.whl (20.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file beatmachine-2.1.0.tar.gz.

File metadata

  • Download URL: beatmachine-2.1.0.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.22.0

File hashes

Hashes for beatmachine-2.1.0.tar.gz
Algorithm Hash digest
SHA256 83e03a4e95b0270428f4fab6d04816e38ecf9c9d570112cf881c631043bf5cca
MD5 1c9c9eb012d31635c40cedd53bb4436c
BLAKE2b-256 f6b6a8b5db53a5b779a659274401deffa98f71918eaff53a9b1d5cd8fe2db5af

See more details on using hashes here.

File details

Details for the file beatmachine-2.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: beatmachine-2.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.22.0

File hashes

Hashes for beatmachine-2.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 93cbc00673bbe2b60ace3ad4034ba667a75be91cd79e7fcb0562cfd82a10b63e
MD5 90686b89dbd6ae613723489b92ade5b1
BLAKE2b-256 d0ed29b35c792b8fe39225d2d0dd1f25b63fa52662c34f585d3d5fdebc73eb08

See more details on using hashes here.

Supported by

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