Skip to main content

Process MIDI piano with (almost) no pain

Project description

Fortepyan :musical_keyboard:

GitHub CI Python 3.9 PyPI version PyPI download month

fortepyan is a glorified pandas wrapper for midi files with piano music.

The main class to operate with is MidiPiece, which gives you access to the notes dataframe, and some useful utilities:

from fortepyan import MidiPiece

piece = MidiPiece.from_file("foo.mid")

piece.df
#        pitch  velocity        start          end  duration
# 0         52        70     0.000000     0.538542  0.538542
# 1         52        62     0.660417     0.951562  0.291146
# 2         57        62    20.769792    21.207812  0.438021
# 3         67        65    62.172917    62.510937  0.338021
# 4         69        56    62.179167    62.232292  0.053125

Using with HuggingFace datasets:

from datasets import load_datasets

dataset = load_dataset("epr-labs/maestro-sustain-v2", split="train")
piece = MidiPiece.from_huggingface(dataset[312])
piece.source
# {
#     'composer': 'Franz Liszt',
#     'title': 'Dante Sonata',
#     'split': 'train',
#     'year': 2009,
#     'midi_filename': '2009/MIDI-Unprocessed_11_R1_2009_06-09_ORIG_MID--AUDIO_11_R1_2009_11_R1_2009_09_WAV.midi',
#     'dataset': 'maestro'
# }

Usage

import fortepyan as ff

piece = ff.MidiPiece.from_file("mymidi.mid")

ff.view.draw_pianoroll_with_velocities(piece)
ff.view.make_piano_roll_video(piece, "tmp.mp4")

Contributing

Development

Pre-commit hooks with forced python formatting (black, flake8, and isort):

pip install pre-commit
pre-commit install

Whenever you execute git commit the files altered / added within the commit will be checked and corrected. black and isort can modify files locally - if that happens you have to git add them again. You might also be prompted to introduce some fixes manually.

To run the hooks against all files without running git commit:

pre-commit run --all-files

Package release:

# from the root directory with clean working tree
# replace patch with one of: [major, minor, patch]
./scripts/release/start_release.sh patch

# Make any additional changes to the release commit
./scripts/release/finish_release.sh

Tests

Recommended way to run and monitor tests is using pytest-watch:

ptw

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

fortepyan-0.4.6.tar.gz (25.4 kB view details)

Uploaded Source

Built Distribution

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

fortepyan-0.4.6-py3-none-any.whl (31.7 kB view details)

Uploaded Python 3

File details

Details for the file fortepyan-0.4.6.tar.gz.

File metadata

  • Download URL: fortepyan-0.4.6.tar.gz
  • Upload date:
  • Size: 25.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for fortepyan-0.4.6.tar.gz
Algorithm Hash digest
SHA256 9fd1846099c036cc2f5ec2252d423693574c35dc28bb36047b7584a1b3b345f7
MD5 1feb9e4c5bf68d3e27931ea15d46772c
BLAKE2b-256 62d8a0c76dc959251c089eab7f9c130f37e9e7b4b75937280e0e35ebabff19be

See more details on using hashes here.

File details

Details for the file fortepyan-0.4.6-py3-none-any.whl.

File metadata

  • Download URL: fortepyan-0.4.6-py3-none-any.whl
  • Upload date:
  • Size: 31.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.18

File hashes

Hashes for fortepyan-0.4.6-py3-none-any.whl
Algorithm Hash digest
SHA256 4373223bd73b405a21caa55e4ecfce3e895bba8fc3cdde16f8b64dcd249daaa4
MD5 50caed6d9fe1c0f4ebd0ddadcd51c7b9
BLAKE2b-256 2002ed107a9054bfc32f0d3c9aad51abdcb3f9b44ef4f2727a224fedc8047272

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