jdxi_editor.midi.pattern.compiler

Pattern compiler

Turns a step pattern into a mido.MidiFile. The same file is played by the shared TransportController and written by Save, so what you hear is what is saved, and a saved pattern sounds the same in the MIDI File Player.

The file is Type 1: - track 0: tempo, time signature - one track per pattern row (named, notes on the row’s channel) Every track ends exactly at the end of the last bar, so looping the file repeats whole bars with no gap.

Example

>>> spec = PatternSpec(bars=1, steps_per_bar=16, bpm=120,
...                    rows=[PatternRow("Digital Synth 1", channel=0)],
...                    notes=[PatternNote(bar=0, step=0, row=0, note=60,
...                                       velocity=100, duration_ticks=120)])
>>> compile_pattern(spec).length
2.0

Attributes

DEFAULT_TICKS_PER_BEAT

STEPS_PER_BEAT

TIME_SIGNATURE_DENOMINATOR

MIN_VELOCITY

MAX_VELOCITY

Classes

PatternRow

A sequencer row: its track name and MIDI channel (0-15).

PatternNote

One active step.

PatternSpec

Everything needed to compile a pattern.

Functions

compile_pattern(spec) → mido.MidiFile

Compile spec to a Type 1 MIDI file.

_conductor_track(spec) → mido.MidiTrack

_row_track(spec, row, notes) → mido.MidiTrack

Module Contents

jdxi_editor.midi.pattern.compiler.DEFAULT_TICKS_PER_BEAT = 480[source]
jdxi_editor.midi.pattern.compiler.STEPS_PER_BEAT = 4[source]
jdxi_editor.midi.pattern.compiler.TIME_SIGNATURE_DENOMINATOR = 4[source]
jdxi_editor.midi.pattern.compiler.MIN_VELOCITY = 1[source]
jdxi_editor.midi.pattern.compiler.MAX_VELOCITY = 127[source]
class jdxi_editor.midi.pattern.compiler.PatternRow[source]

A sequencer row: its track name and MIDI channel (0-15).

name: str[source]
channel: int[source]
class jdxi_editor.midi.pattern.compiler.PatternNote[source]

One active step.

bar: int[source]
step: int[source]
row: int[source]
note: int[source]
velocity: int[source]
duration_ticks: int[source]
class jdxi_editor.midi.pattern.compiler.PatternSpec[source]

Everything needed to compile a pattern.

bars: int[source]
steps_per_bar: int[source]
bpm: float[source]
rows: list[PatternRow][source]
notes: list[PatternNote] = [][source]
ticks_per_beat: int = 480[source]
property ticks_per_step: int[source]
property ticks_per_bar: int[source]
property length_ticks: int[source]
step_tick(bar: int, step: int) → int[source]

Absolute tick of step in bar.

jdxi_editor.midi.pattern.compiler.compile_pattern(spec: PatternSpec) → mido.MidiFile[source]

Compile spec to a Type 1 MIDI file.

  • Velocities are clamped to 1–127.

  • Notes are clipped at the pattern end, and where the same note on the same row starts again, so a long note never cuts off its successor.

  • A note-off sorts before a note-on at the same tick.

jdxi_editor.midi.pattern.compiler._conductor_track(spec: PatternSpec) → mido.MidiTrack[source]
jdxi_editor.midi.pattern.compiler._row_track(spec: PatternSpec, row: PatternRow, notes: list[PatternNote]) → mido.MidiTrack[source]