Forum Archive

MIDI in Python 3.

laszlo.j.hermann

Hallo, is there any posibily to reand and write MIDI files in Pythonista 3.
In Pythonista 2 there was the midiutil.MIDIFILE to crate MIDI Files. In 3 is no midiutil module.

JonB

class sound.MIDIPlayer(file_path[, sound_bank_path])
A MIDIPlayer provides simple playback functions for MIDI (.mid) files, using either the built-in “Merlin Silver” sound bank or one that you provide. If you provide a custom sound bank, it must be in sf2 format.

Also, midiutil is included with the python 2 interpreter in Pythonista3. I am guessing @omz either forgot to include it in the 3 site packages, or else it is not py3 compatible.

You could either use #!python2, or try copying the file from the python2 pylib site-packages to your own site-packages, and see if it works in py3.

#!python2
import os, midiutil,shutil
shutil.copytree(os.path.split(midiutil.__file__)[0],os.path.expanduser('~/Documents/site-packages-3/midiutil'))
omz

The midiutil module isn't compatible with Python 3, but as @JonB pointed out, you can still use Python 2 in Pythonista 3 (which is what the included "Random MIDI Melody" example does).

dgelessus

@omz Are you sure about that? In the Python 2 site-packages midiutil folder there is a MidiFile3.py that looks like it's meant to be compatible with Python 3...

laszlo.j.hermann

Many thanks for the answers. I would need a module to Read and Write/ Manipulate. Midiutil is only for writing/creating MIDI files.
https://github.com/vishnubob/python-midi/ has the necessary functionality but it has a hardware binding and I'm not so deep in Python to easily port it to Pythonista.
Any suggestion?

ccc

The current midiutil supports both Python 2 and Python 3.

omz

@ccc Good to know, thanks!

laszlo.j.hermann

OK mido helps.