MIDI¶
MIDI mapping detection and compile-definition generation for note-to-parameter conversion.
midi ¶
MIDI-to-CV auto-detection and mapping for gen-dsp instruments.
Scans gen~ parameter names to detect MIDI-mappable parameters (gate, freq, vel) and produces compile-time constants for the platform wrappers.
Only activates for 0-input (generator) plugins. Effects are never MIDI-mapped.
MidiMapping
dataclass
¶
MidiMapping(
enabled: bool,
gate_idx: Optional[int] = None,
freq_idx: Optional[int] = None,
vel_idx: Optional[int] = None,
freq_unit: str = "hz",
num_voices: int = 1,
)
Compile-time MIDI-to-parameter mapping for instrument plugins.
Attributes:
| Name | Type | Description |
|---|---|---|
enabled |
bool
|
Whether MIDI note handling code should be generated. |
gate_idx |
Optional[int]
|
Parameter index for gate (None if not mapped). |
freq_idx |
Optional[int]
|
Parameter index for frequency (None if not mapped). |
vel_idx |
Optional[int]
|
Parameter index for velocity (None if not mapped). |
freq_unit |
str
|
"hz" for mtof conversion, "midi" for raw note number. |
detect_midi_mapping ¶
detect_midi_mapping(
manifest: Manifest,
no_midi: bool = False,
midi_gate: Optional[str] = None,
midi_freq: Optional[str] = None,
midi_vel: Optional[str] = None,
midi_freq_unit: str = "hz",
) -> MidiMapping
Detect MIDI parameter mapping from a manifest.
Detection rules: 1. Only for 0-input plugins (generators). Effects -> disabled. 2. If no_midi is True -> disabled. 3. If any explicit --midi-* name is provided, use those (implies enabled). 4. Otherwise auto-detect by scanning param names for known patterns. Gate is required for auto-detection to activate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
Manifest
|
The plugin manifest with param metadata. |
required |
no_midi
|
bool
|
Force MIDI off. |
False
|
midi_gate
|
Optional[str]
|
Explicit gate param name override. |
None
|
midi_freq
|
Optional[str]
|
Explicit freq param name override. |
None
|
midi_vel
|
Optional[str]
|
Explicit vel param name override. |
None
|
midi_freq_unit
|
str
|
"hz" (default, mtof conversion) or "midi" (raw note). |
'hz'
|
Returns:
| Type | Description |
|---|---|
MidiMapping
|
MidiMapping with detected/configured indices. |
build_midi_defines ¶
Build CMake compile definition lines for a MIDI mapping.
Returns an empty string if MIDI is disabled, or newline+indent-separated definition strings like "MIDI_ENABLED=1\n MIDI_GATE_IDX=5".
Shared by all CMake-based platforms (CLAP, VST3, etc.).