• Stars
    star
    849
  • Rank 53,688 (Top 2 %)
  • Language
    Jupyter Notebook
  • License
    MIT License
  • Created over 11 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Utility functions for handling MIDI data in a nice/intuitive way.

pretty_midi contains utility function/classes for handling MIDI data, so that it's in a format which is easy to modify and extract information from.

Documentation is available here. You can also find a Jupyter notebook tutorial here.

pretty_midi is available via pip or via the setup.py script. In order to synthesize MIDI data using fluidsynth, you need the fluidsynth program and pyfluidsynth.

If you end up using pretty_midi in a published research project, please cite the following report:

Colin Raffel and Daniel P. W. Ellis. Intuitive Analysis, Creation and Manipulation of MIDI Data with pretty_midi. In Proceedings of the 15th International Conference on Music Information Retrieval Late Breaking and Demo Papers, 2014.

Example usage for analyzing, manipulating and synthesizing a MIDI file:

import pretty_midi
# Load MIDI file into PrettyMIDI object
midi_data = pretty_midi.PrettyMIDI('example.mid')
# Print an empirical estimate of its global tempo
print(midi_data.estimate_tempo())
# Compute the relative amount of each semitone across the entire song, a proxy for key
total_velocity = sum(sum(midi_data.get_chroma()))
print([sum(semitone)/total_velocity for semitone in midi_data.get_chroma()])
# Shift all notes up by 5 semitones
for instrument in midi_data.instruments:
    # Don't want to shift drum notes
    if not instrument.is_drum:
        for note in instrument.notes:
            note.pitch += 5
# Synthesize the resulting MIDI data using sine waves
audio_data = midi_data.synthesize()

Example usage for creating a simple MIDI file:

import pretty_midi
# Create a PrettyMIDI object
cello_c_chord = pretty_midi.PrettyMIDI()
# Create an Instrument instance for a cello instrument
cello_program = pretty_midi.instrument_name_to_program('Cello')
cello = pretty_midi.Instrument(program=cello_program)
# Iterate over note names, which will be converted to note number later
for note_name in ['C5', 'E5', 'G5']:
    # Retrieve the MIDI note number for this note name
    note_number = pretty_midi.note_name_to_number(note_name)
    # Create a Note instance for this note, starting at 0s and ending at .5s
    note = pretty_midi.Note(velocity=100, pitch=note_number, start=0, end=.5)
    # Add it to our cello instrument
    cello.notes.append(note)
# Add the cello instrument to the PrettyMIDI object
cello_c_chord.instruments.append(cello)
# Write out the MIDI data
cello_c_chord.write('cello-C-chord.mid')

More Repositories

1

mir_eval

Evaluation functions for music/audio information retrieval/signal processing algorithms.
Python
596
star
2

llm-seminar

Seminar on Large Language Models (COMP790-101 at UNC Chapel Hill, Fall 2022)
307
star
3

theano-tutorial

A collection of tutorials on neural networks, using Theano
Jupyter Notebook
222
star
4

midi-dataset

Code for creating a dataset of MIDI ground truth
Jupyter Notebook
160
star
5

mad

Code for "Online and Linear Time Attention by Enforcing Monotonic Alignments"
Jupyter Notebook
91
star
6

Lasagne-tutorial

Adding an ipynb tutorial to Lasagne
Python
53
star
7

mocha

Example implementation of Monotonic Chunkwise Attention.
Jupyter Notebook
49
star
8

ff-attention

Experiments using feedforward networks with attention
Python
47
star
9

jax-tutorial

A tutorial on JAX (https://github.com/google/jax/)
Jupyter Notebook
45
star
10

simple_spearmint

Spearmint, without the gum
Python
42
star
11

lstm_benchmarks

Benchmarking different LSTM libraries
Python
24
star
12

comp790-deep-learning-spring-2021

Course repository for the Spring COMP790 course "Deep Learning" at UNC
23
star
13

remixavier

Given a mixed song, remove components that you have
MATLAB
19
star
14

comp790-deep-learning-spring-2022

Course repository for the Spring 2022 COMP790 course "Deep Learning" at UNC
18
star
15

midi-ground-truth

Code for "Extracting Ground Truth Information from MIDI Files: A MIDIfesto"
Jupyter Notebook
18
star
16

craffel.github.io

Code for generating colinraffel.com and my CV
HTML
16
star
17

alignment-search

Parameter search for MIDI alignment
Python
15
star
18

csc2516-deep-learning-fall-2023

Course repository for the fall 2023 session of CSC2516 "Neural Networks and Deep Learning" at U of T
15
star
19

comp664-deep-learning-spring-2023

Course repository for the Spring 2023 COMP664 course "Deep Learning" at UNC
14
star
20

median-filter

A fast 1d median filter, for filtering the rows and columns of a matrix.
C
11
star
21

comp790-information-theory-fall-2021

Course repository for the Fall 2021 COMP790 course "Information Theory" at UNC
10
star
22

crucialpython

Code from the weekly Crucial Python jaminars. http://labrosa.ee.columbia.edu/crucialpython/
Python
10
star
23

align_midi

Code for MIDI-audio alignment
Python
9
star
24

djitw

Python just-in-time compiled DTW library
Python
8
star
25

thesis

My PhD thesis
TeX
8
star
26

pse

Code for embedding pairs of sequences in a fixed-dimensional space
Python
7
star
27

mir_evaluators

Evaluator scripts for mir_eval.
Python
7
star
28

lstm_problems

Suite of toy problems which can test whether a model can learn long-term dependencies.
Python
7
star
29

spikegram-coding

Code for computing a spikegram of an audio signal using matching pursuit
Python
6
star
30

dhs

Learning to convert sequences of feature vectors to downsampled sequences of hashes
Python
4
star
31

midi-dataset-ismir

Source for the ISMIR 2015 paper "Large-scale content-based matching of MIDI and audio files"
TeX
4
star
32

music-evolution

Code for reproducing the results in "Measuring the Evolution of Contemporary Western Popular Music", Serrร  et al.
Python
3
star
33

subsampling_in_expectation

Example code for "Training a Subsampling Mechanism in Expectation"
Jupyter Notebook
3
star
34

alignment-search-icassp2016

ICASSP 2016 paper, "Optimizing DTW-Based Audio-to-MIDI Alignment and Matching"
TeX
2
star
35

performerSynchronization

Code for measuring the synchronization of musicians, with many onset detection methods implemented.
Python
2
star
36

pruning_icassp2016

LaTeX source for ICASSP 2016 paper, "Pruning Subsequence Search with Attention-Based Embedding"
TeX
2
star
37

ismir2016extracting

LaTeX source for ISMIR 2016 paper "Extracting Ground-Truth Information from MIDI Files: A MIDIfesto"
TeX
1
star
38

dotfiles

cd && git clone --bare https://github.com/craffel/dotfiles.git .dotfiles && git --git-dir=.dotfiles --work-tree=. checkout
Shell
1
star
39

live-sets

Ableton Live set backup
1
star
40

rnntools

RNN layers for use with nntools
1
star
41

feature-inversion

Python
1
star
42

Snowball

"Download for a favor" content distribution web app
1
star
43

lattice-harp

Code for the Lattice Harp hybrid instrument/controller
Pure Data
1
star