jdxi_editor.midi.file.trim

Trim a MIDI file, or one of its tracks, to a range of ticks.

  • trim_midi_file: keep [start, end) of every track and move it to the start of the file. The tempo, time signature, programs, controllers and SysEx in force at start are kept at tick 0, so the excerpt sounds as it did in place.

  • trim_track: remove a track’s notes outside [start, end) and leave its timing and other events as they were, so it stays in step with the other tracks.

Notes that begin before start are dropped; notes still sounding at end are released there.

Attributes

Event

_STATE_META

_END_OF_TRACK

Functions

_is_note_on(msg) → bool

_is_note_off(msg) → bool

_is_note(msg) → bool

_absolute(track) → list[Event]

_to_track(events, end_tick) → mido.MidiTrack

A track of events (stable-sorted by tick), ending at end_tick.

_notes_in_range(events, start, end) → list[Event]

The note-ons of events in [start, end) with their note-offs, a note-off

_state_key(index, msg) → Optional[tuple]

What msg sets, if it is state to carry over a cut: a later message with

_check_range(start, end) → None

trim_track(track, start, end) → mido.MidiTrack

track with only the notes that begin in [start, end) (ticks), at the

trim_midi_file(midi_file, start, end) → mido.MidiFile

A new file holding [start, end) (ticks) of midi_file, moved to tick 0.

Module Contents

jdxi_editor.midi.file.trim.Event[source]
jdxi_editor.midi.file.trim._STATE_META[source]
jdxi_editor.midi.file.trim._END_OF_TRACK[source]
jdxi_editor.midi.file.trim._is_note_on(msg: mido.Message) → bool[source]
jdxi_editor.midi.file.trim._is_note_off(msg: mido.Message) → bool[source]
jdxi_editor.midi.file.trim._is_note(msg: mido.Message) → bool[source]
jdxi_editor.midi.file.trim._absolute(track: mido.MidiTrack) → list[Event][source]
jdxi_editor.midi.file.trim._to_track(events: Iterable[Event], end_tick: int) → mido.MidiTrack[source]

A track of events (stable-sorted by tick), ending at end_tick.

jdxi_editor.midi.file.trim._notes_in_range(events: list[Event], start: int, end: int) → list[Event][source]

The note-ons of events in [start, end) with their note-offs, a note-off after end moved to end. Other events are left out.

jdxi_editor.midi.file.trim._state_key(index: int, msg: mido.Message) → tuple | None[source]

What msg sets, if it is state to carry over a cut: a later message with the same key replaces it. None for events that only matter where they are.

jdxi_editor.midi.file.trim._check_range(start: int, end: int) → None[source]
jdxi_editor.midi.file.trim.trim_track(track: mido.MidiTrack, start: int, end: int) → mido.MidiTrack[source]

track with only the notes that begin in [start, end) (ticks), at the same times; its other events and its length are unchanged.

jdxi_editor.midi.file.trim.trim_midi_file(midi_file: mido.MidiFile, start: int, end: int) → mido.MidiFile[source]

A new file holding [start, end) (ticks) of midi_file, moved to tick 0.