Python Project MIDI API
The members of Project that read, write and build MIDI, and name General MIDI programs, drums and controllers. The track and clip members are on Python Project Edit API, and the lifecycle of Project on Python Projects API. Project MIDI walks through the workflow.
MIDI members
python
# Replace a MIDI clip's entire event list.
def set_midi_events(
self,
clip_id: int,
events: Sequence[ProjectMidiEvent] | np.ndarray,
) -> None: ...
# Transcribe mono audio straight into a MIDI clip's event list.
def transcribe_to_clip(
self,
clip_id: int,
samples: Sequence[float] | np.ndarray,
sample_rate: int,
*,
polyphonic: bool = False,
reference_hz: float | str | None = None,
f0_min_hz: float | None = None,
f0_max_hz: float | None = None,
min_note_ms: float | None = None,
segmentation_threshold_cents: float | None = None,
velocity_floor_db: float | None = None,
fixed_velocity: int | None = None,
group: int = 0,
channel: int = 0,
max_polyphony: int | None = None,
min_frame_peak_ratio: float | None = None,
min_ridge_peak_ratio: float | None = None,
reattack_ratio: float | None = None,
min_note_division: int | None = None,
monophonic_model: Literal['segments', 'singing'] | None = None,
) -> int: ...
# Import an in-memory SMF buffer; return the first added clip id.
def import_smf(self, data: bytes) -> int: ...
# Export the project's tempo map + MIDI clips to an SMF byte buffer.
def export_smf(self) -> bytes: ...
# Import an in-memory MIDI 2.0 Clip File (``SMF2CLIP``); return the first added clip id.
def import_clip_file(self, data: bytes) -> int: ...
# Export the project's tempo map + MIDI clips to a MIDI 2.0 Clip File (``SMF2CLIP``) byte buffer.
def export_clip_file(self) -> bytes: ...
# Set a MIDI clip's program / bank for one UMP group and channel at source PPQ 0.
def set_program(
self,
clip_id: int,
program: int,
*,
bank_msb: int | None = None,
bank_lsb: int | None = None,
group: int = 0,
channel: int = 0,
) -> None: ...
# Destructively bake a clip's MIDI-FX chain from a :data:`MidiFxConfig`.
def bake_midi_fx(
self,
clip_id: int,
config: MidiFxConfig,
*,
with_source_index: bool = False,
) -> np.ndarray | None: ...
# Count the events :meth:`bake_midi_fx` would produce, without baking.
def preview_midi_fx_count(self, clip_id: int, config: MidiFxConfig) -> int: ...
# Check the clip's exported playback window for unmatched notes.
def validate_midi_notes(self, clip_id: int) -> NotePairValidation: ...
# Pack a MIDI 1.0 note-on event accepted by :meth:`Project.set_midi_events`.
def midi_note_on(
ppq: float,
group: int,
channel: int,
note: int,
velocity: int,
) -> ProjectMidiEvent: ...
# Pack a MIDI 1.0 note-off event accepted by :meth:`Project.set_midi_events`.
def midi_note_off(
ppq: float,
group: int,
channel: int,
note: int,
velocity: int = 0,
) -> ProjectMidiEvent: ...
# Pack a MIDI 1.0 control-change event.
def midi_cc(
ppq: float,
group: int,
channel: int,
controller: int,
value: int,
) -> ProjectMidiEvent: ...
# Pack a MIDI 1.0 poly-pressure event.
def midi_poly_pressure(
ppq: float,
group: int,
channel: int,
note: int,
pressure: int,
) -> ProjectMidiEvent: ...
# Pack a MIDI 1.0 program-change event.
def midi_program(ppq: float, group: int, channel: int, program: int) -> ProjectMidiEvent: ...
# Pack a MIDI 1.0 channel-pressure event.
def midi_channel_pressure(
ppq: float,
group: int,
channel: int,
pressure: int,
) -> ProjectMidiEvent: ...
# Pack a MIDI 1.0 pitch-bend event (`bend` is unsigned 14-bit).
def midi_pitch_bend(ppq: float, group: int, channel: int, bend: int) -> ProjectMidiEvent: ...
# Pack a MIDI 2.0 note-on event (16-bit velocity; 0 still sounds).
def midi2_note_on(
ppq: float,
group: int,
channel: int,
note: int,
velocity16: int,
attribute_type: int = 0,
attribute_data: int = 0,
) -> ProjectMidiEvent: ...
# Pack a MIDI 2.0 note-off event (16-bit release velocity).
def midi2_note_off(
ppq: float,
group: int,
channel: int,
note: int,
velocity16: int = 0,
) -> ProjectMidiEvent: ...
# Pack a MIDI 2.0 control-change event (32-bit value).
def midi2_cc(
ppq: float,
group: int,
channel: int,
controller: int,
value32: int,
) -> ProjectMidiEvent: ...
# Pack a MIDI 2.0 poly-pressure event (32-bit pressure).
def midi2_poly_pressure(
ppq: float,
group: int,
channel: int,
note: int,
pressure32: int,
) -> ProjectMidiEvent: ...
# Pack a MIDI 2.0 channel-pressure event (32-bit pressure).
def midi2_channel_pressure(
ppq: float,
group: int,
channel: int,
pressure32: int,
) -> ProjectMidiEvent: ...
# Pack a MIDI 2.0 pitch-bend event (unsigned 32-bit).
def midi2_pitch_bend(ppq: float, group: int, channel: int, bend32: int) -> ProjectMidiEvent: ...
# Pack a MIDI 2.0 program-change event.
def midi2_program(
ppq: float,
group: int,
channel: int,
program: int,
bank_msb: int | None = None,
bank_lsb: int | None = None,
) -> ProjectMidiEvent: ...
# Pack a MIDI 2.0 registered controller (RPN) event (32-bit value).
def midi2_registered_controller(
ppq: float,
group: int,
channel: int,
bank: int,
index: int,
value32: int,
) -> ProjectMidiEvent: ...
# Pack a MIDI 2.0 assignable controller (NRPN) event (32-bit value).
def midi2_assignable_controller(
ppq: float,
group: int,
channel: int,
bank: int,
index: int,
value32: int,
) -> ProjectMidiEvent: ...
# Pack a MIDI 2.0 relative registered controller event (signed 32-bit delta).
def midi2_relative_registered_controller(
ppq: float,
group: int,
channel: int,
bank: int,
index: int,
delta32: int,
) -> ProjectMidiEvent: ...
# Pack a MIDI 2.0 relative assignable controller event (signed 32-bit delta).
def midi2_relative_assignable_controller(
ppq: float,
group: int,
channel: int,
bank: int,
index: int,
delta32: int,
) -> ProjectMidiEvent: ...
# Pack a MIDI 2.0 registered per-note controller event (32-bit value).
def midi2_registered_per_note_controller(
ppq: float,
group: int,
channel: int,
note: int,
index: int,
value32: int,
) -> ProjectMidiEvent: ...
# Pack a MIDI 2.0 assignable per-note controller event (32-bit value).
def midi2_assignable_per_note_controller(
ppq: float,
group: int,
channel: int,
note: int,
index: int,
value32: int,
) -> ProjectMidiEvent: ...
# Pack a MIDI 2.0 per-note pitch-bend event (unsigned 32-bit).
def midi2_per_note_pitch_bend(
ppq: float,
group: int,
channel: int,
note: int,
bend32: int,
) -> ProjectMidiEvent: ...
# Pack a MIDI 2.0 per-note management event.
def midi2_per_note_management(
ppq: float,
group: int,
channel: int,
note: int,
detach: bool = False,
reset: bool = False,
) -> ProjectMidiEvent: ...
# GM Level 1 instrument name for ``program``; every program in [0, 127] has one.
def gm_instrument_name(program: int) -> str: ...
# Reverse GM instrument lookup.
def gm_program_for_name(name: str) -> int: ...
# GM family name for ``family``; every family in [0, 15] has one.
def gm_family_name(family: int) -> str: ...
# First GM program in ``family`` [0,15].
def gm_family_first_program(family: int) -> int: ...
# GM2 melodic instrument name for ``bank_lsb`` + ``program``.
def gm2_instrument_name(bank_lsb: int, program: int) -> str | None: ...
# GM drum name for ``note``; ``None`` for a note outside the kit's [35, 81].
def gm_drum_name(note: int) -> str | None: ...
# Reverse GM drum lookup.
def gm_drum_note_for_name(name: str) -> int: ...
# GM2 drum-set name for ``bank_lsb``; ``None`` where GM2 defines no set.
def gm2_drum_set_name(bank_lsb: int) -> str | None: ...
# GM2 drum name for ``bank_lsb`` + ``note``; ``None`` where that set names nothing.
def gm2_drum_name(bank_lsb: int, note: int) -> str | None: ...
# Standard MIDI CC name for ``controller``; ``None`` for an unassigned controller.
def midi_cc_name(controller: int) -> str | None: ...
# Reverse standard MIDI CC lookup.
def midi_cc_index_for_name(name: str) -> int: ...
# MIDI 2.0 registered per-note controller name for ``index``.
def per_note_controller_name(index: int) -> str | None: ...
# Lower a bank/program selection to MIDI 1.0 bank-select + program events.
def midi_bank_program(
ppq: float,
group: int,
channel: int,
bank_msb: int,
bank_lsb: int,
program: int,
) -> list[ProjectMidiEvent]: ...
# Route events through the RT MidiRouter filter / remap / thru logic.
def midi_route_events(
events: Sequence[ProjectMidiEvent],
config: Mapping[str, int | None] | None = None,
) -> MidiRouteResult: ...
# Run MIDI learn over ``events`` and return the learned binding.
def midi_cc_learn(
events: Sequence[ProjectMidiEvent],
param_id: int,
min_value: float = 0.0,
max_value: float = 1.0,
min_movement: int = 0,
) -> MidiCcBinding | None: ...
# Convert one CC ``event`` to an automation breakpoint via a binding table.
def midi_cc_to_breakpoint(
bindings: Sequence[MidiCcBinding],
event: ProjectMidiEvent,
) -> AutomationPoint | None: ...
# Convert an automation parameter value back to a CC event.
def midi_param_to_cc(
bindings: Sequence[MidiCcBinding],
param_id: int,
unit_value: float,
group: int,
ppq: float = 0.0,
) -> ProjectMidiEvent | None: ...MIDI value conversions
The MIDI 1.0-to-2.0 helpers widen the full 7-bit or 14-bit domain to 16-bit velocity or 32-bit controller and bend values, preserving the center at the midpoint. The reverse helpers take the most significant 7 or 14 bits. MIDI 1.0 note-on velocity zero is refused; a MIDI 2.0 note-on that narrows to zero becomes MIDI 1.0 velocity one. Wrong types raise TypeError; values outside the source MIDI domain raise SonareValueError.
python
from libsonare import (
midi2_control_to_midi1,
midi2_control_to_midi1_control14,
midi2_note_on_velocity_to_midi1,
midi2_pitch_bend_to_midi1,
midi2_velocity_to_midi1,
midi_control14_to_midi2,
midi_control_to_midi2,
midi_note_on_velocity_to_midi2,
midi_pitch_bend_to_midi2,
midi_velocity_to_midi2,
)
assert midi_velocity_to_midi2(64) == 32768
assert midi_note_on_velocity_to_midi2(64) == 32768
assert midi_control_to_midi2(64) == 0x80000000
assert midi_control14_to_midi2(8192) == 0x80000000
assert midi_pitch_bend_to_midi2(8192) == 0x80000000
assert midi2_velocity_to_midi1(32768) == 64
assert midi2_note_on_velocity_to_midi1(1) == 1
assert midi2_control_to_midi1(0x80000000) == 64
assert midi2_control_to_midi1_control14(0x80000000) == 8192
assert midi2_pitch_bend_to_midi1(0x80000000) == 8192python
# Widen a MIDI 1.0 velocity (0..127) to MIDI 2.0's 16 bits; 0 stays 0.
def midi_velocity_to_midi2(velocity: int) -> int: ...
# Widen a MIDI 1.0 note-on velocity (1..127) to MIDI 2.0's 16 bits.
def midi_note_on_velocity_to_midi2(velocity: int) -> int: ...
# Narrow a MIDI 2.0 velocity to MIDI 1.0's 7 bits by truncation (the top 7 bits).
def midi2_velocity_to_midi1(velocity16: int) -> int: ...
# Narrow a MIDI 2.0 note-on velocity to MIDI 1.0's 7 bits; a result of 0 reads 1.
def midi2_note_on_velocity_to_midi1(velocity16: int) -> int: ...
# Widen a 7-bit controller value (0..127) to MIDI 2.0's 32 bits; 64 is 0x80000000.
def midi_control_to_midi2(value: int) -> int: ...
# Widen a 14-bit controller value (0..16383) to MIDI 2.0's 32 bits; 8192 is 0x80000000.
def midi_control14_to_midi2(value14: int) -> int: ...
# Narrow a MIDI 2.0 controller value to 7 bits by truncation (the top 7 bits).
def midi2_control_to_midi1(value32: int) -> int: ...
# Narrow a MIDI 2.0 controller value to 14 bits by truncation (the top 14 bits).
def midi2_control_to_midi1_control14(value32: int) -> int: ...
# Widen a 14-bit pitch bend (0..16383) to MIDI 2.0's 32 bits; the center 8192 is 0x80000000.
def midi_pitch_bend_to_midi2(bend14: int) -> int: ...
# Narrow a MIDI 2.0 pitch bend to 14 bits by truncation (the top 14 bits).
def midi2_pitch_bend_to_midi1(bend32: int) -> int: ...