Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manipulating MIDI Files in Python

I'm looking for a way to change individual notes in a pre-existing MIDI file in Python. I've found a lot of packages that allow for the writing of MIDI files, but not altering existing ones. Is there a package that could help with this or a a way of parsing the hex of the MIDI file to accomplish this?

like image 534
Arger Avatar asked Jun 03 '13 23:06

Arger


2 Answers

The open-source program MIDICSV converts MIDI to text CSV and vice versa. You can open a CSV file as text and edit it easily using Python, without having to rely on any special modules.

For information on the MIDI protocol, please see:

  • MIDI file-format specification
  • MIDI messages

In a recent project I found this work very easy to do.

like image 107
brannerchinese Avatar answered Sep 19 '22 11:09

brannerchinese


You probably can't "alter existing files" if you mean modifying them in-place.

But you can just parse the MIDI file, change it (in-memory, or iteratively), and write a new one.

You didn't mention which packages you looked at to write MIDI files, but every one I've ever dealt with can also read MIDI files, so you probably already have everything you need.

And there's nothing requiring you to use the same package for both reading and writing. For example, you can use midiparser for reading and python-midi for writing; the code to map MIDI messages from one package's format to the other is trivial.

like image 21
abarnert Avatar answered Sep 22 '22 11:09

abarnert