Skip to main content

Make piano-roll animations from midi files

Project description

Midani

Demo frame

Make piano-roll animations from midi files.

Another demo frame

Dependencies

Requires Python >= 3.8

  • Python libraries:
    • opencv-python
    • mido
  • Other:
    • R to plot frames
    • FFmpeg to add audio

Installation

To install R and FFmpeg on MacOS with Homebrew:

brew install r
brew install ffmpeg

To install Python dependencies, from script directory:

pip install -r requirements.txt

To install the script itself, from the script directory:

pip install .

Example Usage:

Create an animation with the default settings:

midani --midi [MIDIFILE]

The same, but add audio as well:

midani --midi [MIDIFILE] --audio [AUDIOFILE]

The same, but animate at 2fps rather than the default 30fps, so you can get a flavor of the results without waiting quite so long:

midani --midi [MIDIFILE] --audio [AUDIOFILE] --test

Create an animation using one of the sample settings and one of the sample midi/audio files:

midani --settings sample_settings/settings1.py

Usage

usage: midani [-h] [-m MIDI] [-a AUDIO] [-s [SETTINGS ...]] [-t] [-e]
              [-f FRAMES]

Animate a midi file. The path to a midi file must either be included as a
command line argument with -m/--midi, or it must be specified with the
"midi_fname" keyword argument in a settings file provided with -s/--settings.

optional arguments:
  -h, --help            show this help message and exit
  -m MIDI, --midi MIDI  path to midi file to animate
  -a AUDIO, --audio AUDIO
                        path to audio file to add to video
  -s [SETTINGS ...], --settings [SETTINGS ...]
                        path to settings files, each containing a Python
                        dictionary
  -t, --test            set frame rate to a maximum of 2 fps
  -e, --eval            use 'eval()' rather than 'ast.literal_eval()' to parse
                        settings.
  -f FRAMES, --frames FRAMES
                        a comma-separated list of numbers (with no spaces);
                        specifies a list of individual frames to be drawn

Configuration

For full documentation of the various settings available, and for how to set per-voice settings, see docs/settings.md.

To configure with custom settings, save one or more files, each containing only a python dictionary, and pass them as arguments with -s/--settings. (Usually, only one settings file is necessary, but you might want to use more than one if, for instance, you want to define a general style shared between several animations, but nevertheless tweak the settings for each individual midi file. When the same setting is found in multiple settings files, the setting in the last-listed file has precedence.)

For example, if you wanted a "primary color" note color palette, with white background color, you could save the following dictionary in a file called example.py and then invoke the script with --settings example.py:

{
    "color_palette": (
        (255, 0, 0),
        (0, 255, 0),
        (0, 0, 255),
    ),
    "bg_colors": (
        (255, 255, 255),
    ),
}

For more examples, see the files in sample_settings/.

The settings files are ordinarily parsed with ast.literal_eval(), thus (to quote the Python docs) they "may only consist of the following Python literal structures: strings, bytes, numbers, tuples, lists, dicts, sets, booleans, and None." (If you get an error like ValueError: malformed node or string, then you are probably using expressions that ast.literal_eval() cannot parse.) If you wish to use conveniences like arithmetic expressions or list comprehensions, you can pass the --eval flag, and the settings files will instead be parsed with eval(). Don't do anything reckless with this! (E.g., use --eval with settings from sources that you do not trust.)

Miscellany

Why, you might ask, is R used to plot frames, rather than a Python plotting library like Matplotlib? For no better reason than that at the time I started the script (in summer 2018), R was the only plotting software I was familiar with.

Sample files

The subdirectory sample_settings contains a few sample settings files to quickly demonstrate a few of the different options available.

The subdirectory sample_music contains a few midi files to play with for demo purposes. I created these algorithmically with another project of mine. I have provided mp3s generated therefrom with fluidsynth and a free General MIDI soundfont. The audio fidelity may leave something to be desired.

Known issues

VLC is recommended for playback of output video files. Videos also play back correctly on Youtube. But they don't always play back correctly with Quicktime:

  • if framerate is too slow (e.g., with --test flag), there is no video playback (only a static green screen)
  • audio playback doesn't seem to work.

Major TODOs

  • finish sample_settings

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

midani-0.0.1.tar.gz (39.5 kB view details)

Uploaded Source

Built Distribution

midani-0.0.1-py3-none-any.whl (41.1 kB view details)

Uploaded Python 3

File details

Details for the file midani-0.0.1.tar.gz.

File metadata

  • Download URL: midani-0.0.1.tar.gz
  • Upload date:
  • Size: 39.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.4

File hashes

Hashes for midani-0.0.1.tar.gz
Algorithm Hash digest
SHA256 b62c5ae5fddb86661bb4878d4d28bab407c56c74b09da6e5afeb6bac98f3833d
MD5 6b9f3c531f8b23f239051220ad19a395
BLAKE2b-256 a24d4238d99c8e9ca0c853a416777ac2a73b6432bbacb69423ebd04bc5b6fe6a

See more details on using hashes here.

File details

Details for the file midani-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: midani-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 41.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.4

File hashes

Hashes for midani-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 12874a8c62e589d4161fb388fa0bad9ac8441242781b952a0ca8a02ea2f6aa3c
MD5 67dd691b374972cb05d34f453bafb3a9
BLAKE2b-256 87df162410f78cc1413ba68fc03a02733d2417e5ae31c8fee4100fa58230b69d

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