containers

These classes simply hold MIDI data in a convenient form.

class pretty_midi.containers.Note(velocity, pitch, start, end)[source]

A note event.

Parameters:
velocityint

Note velocity.

pitchint

Note pitch, as a MIDI note number.

startfloat

Note on time, absolute, in seconds.

endfloat

Note off time, absolute, in seconds.

__init__(velocity, pitch, start, end)[source]
get_duration()[source]

Get the duration of the note in seconds.

class pretty_midi.containers.PitchBend(pitch, time)[source]

A pitch bend event.

Parameters:
pitchint

MIDI pitch bend amount, in the range [-8192, 8191].

timefloat

Time where the pitch bend occurs.

__init__(pitch, time)[source]
class pretty_midi.containers.ControlChange(number, value, time)[source]

A control change event.

Parameters:
numberint

The control change number, in [0, 127].

valueint

The value of the control change, in [0, 127].

timefloat

Time where the control change occurs.

__init__(number, value, time)[source]
class pretty_midi.containers.TimeSignature(numerator, denominator, time)[source]

Container for a Time Signature event, which contains the time signature numerator, denominator and the event time in seconds.

Examples

Instantiate a TimeSignature object with 6/8 time signature at 3.14 seconds:

>>> ts = TimeSignature(6, 8, 3.14)
>>> print(ts)
6/8 at 3.14 seconds
Attributes:
numeratorint

Numerator of time signature.

denominatorint

Denominator of time signature.

timefloat

Time of event in seconds.

__init__(numerator, denominator, time)[source]
class pretty_midi.containers.KeySignature(key_number, time)[source]

Contains the key signature and the event time in seconds. Only supports major and minor keys.

Examples

Instantiate a C# minor KeySignature object at 3.14 seconds:

>>> ks = KeySignature(13, 3.14)
>>> print(ks)
C# minor at 3.14 seconds
Attributes:
key_numberint

Key number according to [0, 11] Major, [12, 23] minor. For example, 0 is C Major, 12 is C minor.

timefloat

Time of event in seconds.

__init__(key_number, time)[source]
class pretty_midi.containers.Lyric(text, time)[source]

Timestamped lyric text.

Attributes:
textstr

The text of the lyric.

timefloat

The time in seconds of the lyric.

__init__(text, time)[source]
class pretty_midi.containers.Text(text, time)[source]

Timestamped text event.

Attributes:
textstr

The text.

timefloat

The time it occurs in seconds.

__init__(text, time)[source]