{"id":21711,"library":"pretty-midi","title":"pretty_midi","description":"Python library for handling MIDI data conveniently. Provides classes for MIDI files, instruments, notes, and pitch bends. Works with time signatures, key signatures, and tempo changes. Current version 0.2.11, with irregular releases (last release 2021).","status":"maintenance","version":"0.2.11","language":"python","source_language":"en","source_url":"https://github.com/craffel/pretty-midi","tags":["midi","audio","music","note"],"install":[{"cmd":"pip install pretty-midi","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for internal arrays and operations.","package":"numpy","optional":false},{"reason":"Required for MIDI file I/O (default backend).","package":"mido","optional":false},{"reason":"Required for signal processing functions (e.g., piano roll).","package":"scipy","optional":true}],"imports":[{"note":"","wrong":"","symbol":"PrettyMIDI","correct":"from pretty_midi import PrettyMIDI"},{"note":"","wrong":"","symbol":"Instrument","correct":"from pretty_midi import Instrument"},{"note":"","wrong":"","symbol":"Note","correct":"from pretty_midi import Note"}],"quickstart":{"code":"import pretty_midi\n# Create a MIDI file\nmidi = pretty_midi.PrettyMIDI()\npiano = pretty_midi.Instrument(program=0)  # Acoustic Grand Piano\n# Add a note (C4, start=0, end=1, velocity=100)\nnote = pretty_midi.Note(velocity=100, pitch=60, start=0, end=1)\npiano.notes.append(note)\nmidi.instruments.append(piano)\nmidi.write('example.mid')\nprint('MIDI file created.')","lang":"python","description":"Create a simple MIDI file with a piano note (C4)."},"warnings":[{"fix":"Update to pretty-midi >=0.2.10.","message":"numpy integer aliases removed in numpy 1.24+; use np.int32 directly.","severity":"breaking","affected_versions":"pretty-midi <=0.2.9 with numpy >=1.20"},{"fix":"Use Instrument(program=0, is_drum=True) for drum tracks.","message":"Instrument(...) with default program (0) creates an acoustic grand piano; for drums, set program=0 and is_drum=True.","severity":"gotcha","affected_versions":"all"},{"fix":"Always use seconds for note times; for beat-based timing, convert using tempo.","message":"Note start and end times are in seconds, not beats. Use MIDI tick conversion manually.","severity":"gotcha","affected_versions":"all"},{"fix":"Install mido and let pretty_midi use it as backend automatically.","message":"Backend 'pretty_midi.midi_processor' was deprecated and replaced by 'mido'. Old code using 'from pretty_midi.midi_processor import ...' will fail.","severity":"deprecated","affected_versions":">=0.2.6"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Install mido: pip install mido","cause":"The old midi_processor module was removed; mido is now required.","error":"AttributeError: module 'pretty_midi' has no attribute 'midi_processor'"},{"fix":"Update pretty-midi to 0.2.10 or later, or downgrade numpy.","cause":"numpy 1.24+ removed np.int; use np.int32.","error":"AttributeError: module 'numpy' has no attribute 'int'"},{"fix":"Use instrument.notes[index] to access notes, e.g., instrument.notes[0].","cause":"Trying to access notes like a list or dict instead of using the 'notes' attribute.","error":"TypeError: 'Note' object does not support item assignment"},{"fix":"Ensure key signature numbers are between -7 (7 flats) and 7 (7 sharps).","cause":"Key signature numbers must be in range -7 to 7. Check key signatures.","error":"ValueError: Unknown key signature number -1"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}