jdxi_editor.ui.editors.pattern.learner

Pattern Learner Module

Handles MIDI input learning for the Pattern Sequencer. Captures incoming MIDI notes and records them into the pattern grid in real-time, supporting both note-on and note-off events with automatic step advancement.

Attributes

converter

Classes

PatternLearnerState

Enumeration of learning states.

PatternLearnerConfig

Configuration for the pattern learner.

PatternLearnerEvent

Represents a learned pattern event.

PatternLearner

Learns pattern from incoming MIDI messages.

Module Contents

class jdxi_editor.ui.editors.pattern.learner.PatternLearnerState[source]

Enumeration of learning states.

IDLE = 'idle'[source]
LEARNING = 'learning'[source]
STOPPED = 'stopped'[source]
class jdxi_editor.ui.editors.pattern.learner.PatternLearnerConfig(total_steps: int = 16, total_rows: int = 4, default_velocity: int = 100, default_duration_ms: float = 120.0)[source]

Configuration for the pattern learner.

total_steps = 16[source]
total_rows = 4[source]
default_velocity = 100[source]
default_duration_ms = 120.0[source]
class jdxi_editor.ui.editors.pattern.learner.PatternLearnerEvent(step: int, row: int, note: int, velocity: int, duration_ms: float, midi_note: picomidi.messages.note.MidiNote | None = None)[source]

Represents a learned pattern event.

step[source]
row[source]
note[source]
velocity[source]
duration_ms[source]
midi_note[source]
class jdxi_editor.ui.editors.pattern.learner.PatternLearner(config: PatternLearnerConfig | None = None, midi_converter: jdxi_editor.midi.conversion.note.MidiNoteConverter | None = None, scope: str = 'PatternLearner')[source]

Learns pattern from incoming MIDI messages.

Captures MIDI note-on and note-off events and records them into a pattern grid. Automatically advances through steps as notes are released.

config[source]
midi_converter = None[source]
scope = 'PatternLearner'[source]
state = 'idle'[source]
current_step = 0[source]
current_measure_index = 0[source]
learned_pattern: List[List[int | None]][source]
active_notes: Dict[int, int][source]
midi_track[source]
on_step_advance: Callable[[int], None] | None = None[source]
on_note_learned: Callable[[PatternLearnerEvent], None] | None = None[source]
on_learning_stopped: Callable[[], None] | None = None[source]
on_learning_started: Callable[[], None] | None = None[source]
learned_events: List[PatternLearnerEvent] = [][source]
start_learning() None[source]

Start the pattern learning process.

stop_learning() None[source]

Stop the pattern learning process.

process_midi_message(message: mido.Message) None[source]

Process an incoming MIDI message during learning.

Handles NOTE_ON (velocity > 0) and NOTE_OFF messages. Automatically advances the step when a note-off is received.

Parameters:

message – Mido Message object

_handle_note_on(message: mido.Message) None[source]

Handle a NOTE_ON message.

Records the note in the learned pattern and marks it as active.

Parameters:

message – Mido NOTE_ON message with velocity > 0

_handle_note_off(message: mido.Message) None[source]

Handle a NOTE_OFF message or NOTE_ON with velocity 0.

Marks the note as inactive and advances to the next step.

Parameters:

message – Mido NOTE_OFF message or NOTE_ON with velocity 0

_advance_step() None[source]

Advance to the next step in the pattern.

_find_row_for_note(midi_note: int) int | None[source]

Find the row that corresponds to a MIDI note.

Uses the MIDI converter if available, otherwise falls back to hardcoded ranges.

Parameters:

midi_note – MIDI note number

Returns:

Row index (0-3) or None if note doesn’t match any row

clear_learned_pattern() None[source]

Clear the learned pattern and reset state.

get_learned_pattern() List[List[int | None]][source]

Get the learned pattern.

Returns:

2D list where pattern[row][step] = MIDI note number or None

get_learned_events() List[PatternLearnerEvent][source]

Get all events that occurred during learning.

Returns:

List of PatternLearnerEvent objects

get_pattern_for_row(row: int) List[int | None][source]

Get the learned pattern for a specific row.

Parameters:

row – Row index (0-3)

Returns:

List of MIDI notes for the row (or None for empty steps)

get_midi_track()[source]

Get the recorded MIDI track.

Returns:

MidiTrack object with NOTE_ON and NOTE_OFF messages

is_learning() bool[source]

Check if currently learning.

set_config(config: PatternLearnerConfig) None[source]

Update the learner configuration.

Parameters:

config – New configuration

set_midi_converter(converter: jdxi_editor.midi.conversion.note.MidiNoteConverter) None[source]

Set or update the MIDI converter.

Parameters:

converter – MidiNoteConverter instance

jdxi_editor.ui.editors.pattern.learner.converter[source]