jdxi_editor.midi.file.trim ========================== .. py:module:: jdxi_editor.midi.file.trim .. autoapi-nested-parse:: 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 ---------- .. autoapisummary:: jdxi_editor.midi.file.trim.Event jdxi_editor.midi.file.trim._STATE_META jdxi_editor.midi.file.trim._END_OF_TRACK Functions --------- .. autoapisummary:: jdxi_editor.midi.file.trim._is_note_on jdxi_editor.midi.file.trim._is_note_off jdxi_editor.midi.file.trim._is_note jdxi_editor.midi.file.trim._absolute jdxi_editor.midi.file.trim._to_track jdxi_editor.midi.file.trim._notes_in_range jdxi_editor.midi.file.trim._state_key jdxi_editor.midi.file.trim._check_range jdxi_editor.midi.file.trim.trim_track jdxi_editor.midi.file.trim.trim_midi_file Module Contents --------------- .. py:data:: Event .. py:data:: _STATE_META .. py:data:: _END_OF_TRACK .. py:function:: _is_note_on(msg: mido.Message) -> bool .. py:function:: _is_note_off(msg: mido.Message) -> bool .. py:function:: _is_note(msg: mido.Message) -> bool .. py:function:: _absolute(track: mido.MidiTrack) -> list[Event] .. py:function:: _to_track(events: Iterable[Event], end_tick: int) -> mido.MidiTrack A track of *events* (stable-sorted by tick), ending at *end_tick*. .. py:function:: _notes_in_range(events: list[Event], start: int, end: int) -> list[Event] 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. .. py:function:: _state_key(index: int, msg: mido.Message) -> Optional[tuple] 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. .. py:function:: _check_range(start: int, end: int) -> None .. py:function:: trim_track(track: mido.MidiTrack, start: int, end: int) -> mido.MidiTrack *track* with only the notes that begin in [start, end) (ticks), at the same times; its other events and its length are unchanged. .. py:function:: trim_midi_file(midi_file: mido.MidiFile, start: int, end: int) -> mido.MidiFile A new file holding [start, end) (ticks) of *midi_file*, moved to tick 0.