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
Classes
Enumeration of learning states. |
|
Configuration for the pattern learner. |
|
Represents a learned pattern event. |
|
Learns pattern from incoming MIDI messages. |
Module Contents
- class jdxi_editor.ui.editors.pattern.learner.PatternLearnerState[source]
Enumeration of learning states.
- 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.
- 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.
- 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.
- on_note_learned: Callable[[PatternLearnerEvent], None] | None = None[source]
- learned_events: List[PatternLearnerEvent] = [][source]
- 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
- _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
- 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
- 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