Skip to content
modkitv0.2

midi.h

#include <modkit/midi.h>40 functions · 11 structs · 2 enums · 9 typedefs · 5 macros

Optional MIDI device I/O and SoundFont synthesis package.

Functions

mk_midi_desc_initfunction

mk_midi_desc mk_midi_desc_init(void)

Initialize the MIDI desc.

Returns The resulting value.

mk_midi_device_io_availablefunction

bool mk_midi_device_io_available(void)

Perform the MIDI device I/O available operation.

Returns True when the operation succeeds.

mk_midi_initfunction

mk_result mk_midi_init(const mk_midi_desc *desc)

Initialize the MIDI.

ParameterTypeDescription
descconst mk_midi_desc *Configuration descriptor.

Returns MK_SUCCESS or an error result.

mk_midi_input_closefunction

mk_result mk_midi_input_close(mk_midi_input_t input)

Close MIDI input.

ParameterTypeDescription
inputmk_midi_input_tValue for input.

Returns MK_SUCCESS or an error result.

mk_midi_input_openfunction

mk_result mk_midi_input_open(uint32_t port_index, mk_midi_input_t *out_input)

Open MIDI input.

ParameterTypeDescription
port_indexuint32_tValue for port index.
out_inputmk_midi_input_t *Receives the input.

Returns MK_SUCCESS or an error result.

mk_midi_input_pollfunction

mk_result mk_midi_input_poll(mk_midi_input_t input, mk_midi_message *out_message)

Poll MIDI input.

ParameterTypeDescription
inputmk_midi_input_tValue for input.
out_messagemk_midi_message *Receives the message.

Returns MK_SUCCESS or an error result.

mk_midi_input_port_countfunction

uint32_t mk_midi_input_port_count(void)

Perform the MIDI input port count operation.

Returns The resulting value.

mk_midi_input_port_infofunction

mk_result mk_midi_input_port_info(uint32_t index, mk_midi_port_info *out_info)

Perform the MIDI input port info operation.

ParameterTypeDescription
indexuint32_tZero-based index.
out_infomk_midi_port_info *Receives the info.

Returns MK_SUCCESS or an error result.

mk_midi_is_initializedfunction

bool mk_midi_is_initialized(void)

Test whether the MIDI is initialized.

Returns True when the condition holds.

mk_midi_output_closefunction

mk_result mk_midi_output_close(mk_midi_output_t output)

Close MIDI output.

ParameterTypeDescription
outputmk_midi_output_tValue for output.

Returns MK_SUCCESS or an error result.

mk_midi_output_openfunction

mk_result mk_midi_output_open(uint32_t port_index, mk_midi_output_t *out_output)

Open MIDI output.

ParameterTypeDescription
port_indexuint32_tValue for port index.
out_outputmk_midi_output_t *Receives the output.

Returns MK_SUCCESS or an error result.

mk_midi_output_port_countfunction

uint32_t mk_midi_output_port_count(void)

Perform the MIDI output port count operation.

Returns The resulting value.

mk_midi_output_port_infofunction

mk_result mk_midi_output_port_info(uint32_t index, mk_midi_port_info *out_info)

Perform the MIDI output port info operation.

ParameterTypeDescription
indexuint32_tZero-based index.
out_infomk_midi_port_info *Receives the info.

Returns MK_SUCCESS or an error result.

mk_midi_output_sendfunction

mk_result mk_midi_output_send(mk_midi_output_t output, const uint8_t *bytes, size_t size)

Send MIDI output.

ParameterTypeDescription
outputmk_midi_output_tValue for output.
bytesconst uint8_t *Value for bytes.
sizesize_tSize in bytes.

Returns MK_SUCCESS or an error result.

mk_midi_player_createfunction

mk_result mk_midi_player_create(const mk_midi_player_desc *desc, mk_midi_player_t *out_player)

Create MIDI player.

ParameterTypeDescription
descconst mk_midi_player_desc *Configuration descriptor.
out_playermk_midi_player_t *Receives the player.

Returns MK_SUCCESS or an error result.

mk_midi_player_desc_initfunction

mk_midi_player_desc mk_midi_player_desc_init(mk_midi_sequence_t sequence, mk_midi_synth_t synth)

Initialize the MIDI player desc.

ParameterTypeDescription
sequencemk_midi_sequence_tValue for sequence.
synthmk_midi_synth_tValue for synth.

Returns The resulting value.

mk_midi_player_destroyfunction

mk_result mk_midi_player_destroy(mk_midi_player_t player)

Destroy the MIDI player.

ParameterTypeDescription
playermk_midi_player_tValue for player.

Returns MK_SUCCESS or an error result.

mk_midi_player_get_durationfunction

double mk_midi_player_get_duration(mk_midi_player_t player)

Get duration from the MIDI player.

ParameterTypeDescription
playermk_midi_player_tValue for player.

Returns The resulting value.

mk_midi_player_get_positionfunction

double mk_midi_player_get_position(mk_midi_player_t player)

Get position from the MIDI player.

ParameterTypeDescription
playermk_midi_player_tValue for player.

Returns The resulting value.

mk_midi_player_get_statefunction

mk_midi_player_state mk_midi_player_get_state(mk_midi_player_t player)

Get state from the MIDI player.

ParameterTypeDescription
playermk_midi_player_tValue for player.

Returns The resulting value.

mk_midi_player_pausefunction

mk_result mk_midi_player_pause(mk_midi_player_t player)

Pause the MIDI player.

ParameterTypeDescription
playermk_midi_player_tValue for player.

Returns MK_SUCCESS or an error result.

mk_midi_player_playfunction

mk_result mk_midi_player_play(mk_midi_player_t player)

Play MIDI player.

ParameterTypeDescription
playermk_midi_player_tValue for player.

Returns MK_SUCCESS or an error result.

mk_midi_player_restartfunction

mk_result mk_midi_player_restart(mk_midi_player_t player)

Perform the MIDI player restart operation.

ParameterTypeDescription
playermk_midi_player_tValue for player.

Returns MK_SUCCESS or an error result.

mk_midi_player_stopfunction

mk_result mk_midi_player_stop(mk_midi_player_t player)

Stop the MIDI player.

ParameterTypeDescription
playermk_midi_player_tValue for player.

Returns MK_SUCCESS or an error result.

mk_midi_player_updatefunction

mk_result mk_midi_player_update(mk_midi_player_t player, double elapsed_seconds)

Advance frame-driven MIDI playback.

Events are submitted on the first call that reaches their timestamp, so timing is quantized to the caller's frame interval and is not sample-accurate against the audio clock.

ParameterTypeDescription
playermk_midi_player_tValue for player.
elapsed_secondsdoubleValue for elapsed seconds.

Returns MK_SUCCESS or an error result.

mk_midi_sequence_destroyfunction

mk_result mk_midi_sequence_destroy(mk_midi_sequence_t sequence)

Destroy the MIDI sequence.

ParameterTypeDescription
sequencemk_midi_sequence_tValue for sequence.

Returns MK_SUCCESS or an error result.

mk_midi_sequence_get_infofunction

mk_result mk_midi_sequence_get_info(mk_midi_sequence_t sequence, mk_midi_sequence_info *out_info)

Get info from the MIDI sequence.

ParameterTypeDescription
sequencemk_midi_sequence_tValue for sequence.
out_infomk_midi_sequence_info *Receives the info.

Returns MK_SUCCESS or an error result.

mk_midi_sequence_load_filefunction

mk_result mk_midi_sequence_load_file(const char *path, mk_midi_sequence_t *out_sequence)

Load file for the MIDI sequence.

ParameterTypeDescription
pathconst char *Value for path.
out_sequencemk_midi_sequence_t *Receives the sequence.

Returns MK_SUCCESS or an error result.

mk_midi_sequence_load_memoryfunction

mk_result mk_midi_sequence_load_memory(const void *data, size_t size, mk_midi_sequence_t *out_sequence)

Load memory for the MIDI sequence.

ParameterTypeDescription
dataconst void *Data buffer.
sizesize_tSize in bytes.
out_sequencemk_midi_sequence_t *Receives the sequence.

Returns MK_SUCCESS or an error result.

mk_midi_shutdownfunction

void mk_midi_shutdown(void)

Perform the MIDI shutdown operation.

mk_midi_synth_all_notes_offfunction

mk_result mk_midi_synth_all_notes_off(mk_midi_synth_t synth)

Perform the MIDI synth all notes off operation.

ParameterTypeDescription
synthmk_midi_synth_tValue for synth.

Returns MK_SUCCESS or an error result.

mk_midi_synth_clonefunction

mk_result mk_midi_synth_clone(mk_midi_synth_t source, mk_midi_synth_t *out_synth)

Perform the MIDI synth clone operation.

ParameterTypeDescription
sourcemk_midi_synth_tValue for source.
out_synthmk_midi_synth_t *Receives the synth.

Returns MK_SUCCESS or an error result.

mk_midi_synth_destroyfunction

mk_result mk_midi_synth_destroy(mk_midi_synth_t synth)

Destroy the MIDI synth.

ParameterTypeDescription
synthmk_midi_synth_tValue for synth.

Returns MK_SUCCESS or an error result.

mk_midi_synth_load_filefunction

mk_result mk_midi_synth_load_file(const char *soundfont_path, mk_midi_synth_t *out_synth)

Load file for the MIDI synth.

ParameterTypeDescription
soundfont_pathconst char *Value for soundfont path.
out_synthmk_midi_synth_t *Receives the synth.

Returns MK_SUCCESS or an error result.

mk_midi_synth_load_memoryfunction

mk_result mk_midi_synth_load_memory(const void *data, size_t size, mk_midi_synth_t *out_synth)

Load memory for the MIDI synth.

ParameterTypeDescription
dataconst void *Data buffer.
sizesize_tSize in bytes.
out_synthmk_midi_synth_t *Receives the synth.

Returns MK_SUCCESS or an error result.

mk_midi_synth_note_offfunction

mk_result mk_midi_synth_note_off(mk_midi_synth_t synth, uint8_t channel, uint8_t note)

Perform the MIDI synth note off operation.

ParameterTypeDescription
synthmk_midi_synth_tValue for synth.
channeluint8_tValue for channel.
noteuint8_tValue for note.

Returns MK_SUCCESS or an error result.

mk_midi_synth_note_onfunction

mk_result mk_midi_synth_note_on(mk_midi_synth_t synth, uint8_t channel, uint8_t note, float velocity)

Perform the MIDI synth note on operation.

ParameterTypeDescription
synthmk_midi_synth_tValue for synth.
channeluint8_tValue for channel.
noteuint8_tValue for note.
velocityfloatValue for velocity.

Returns MK_SUCCESS or an error result.

mk_midi_synth_sendfunction

mk_result mk_midi_synth_send(mk_midi_synth_t synth, const uint8_t *bytes, size_t size)

Send MIDI synth.

ParameterTypeDescription
synthmk_midi_synth_tValue for synth.
bytesconst uint8_t *Value for bytes.
sizesize_tSize in bytes.

Returns MK_SUCCESS or an error result.

mk_midi_synth_set_programfunction

mk_result mk_midi_synth_set_program(mk_midi_synth_t synth, uint8_t channel, uint8_t program, bool drums)

Set program on the MIDI synth.

ParameterTypeDescription
synthmk_midi_synth_tValue for synth.
channeluint8_tValue for channel.
programuint8_tValue for program.
drumsboolValue for drums.

Returns MK_SUCCESS or an error result.

mk_midi_synth_set_volumefunction

mk_result mk_midi_synth_set_volume(mk_midi_synth_t synth, float volume)

Set volume on the MIDI synth.

ParameterTypeDescription
synthmk_midi_synth_tValue for synth.
volumefloatValue for volume.

Returns MK_SUCCESS or an error result.

Structs

mk_midi_descstruct

Data for MIDI desc.

FieldTypeDescription
max_inputsuint32_tThe max inputs.
max_outputsuint32_tThe max outputs.
max_synthsuint32_tThe max synths.
max_sequencesuint32_tThe max sequences.
max_playersuint32_tThe max players.

mk_midi_input_tstruct

Data for MIDI input.

FieldTypeDescription
iduint32_tThe ID.

mk_midi_messagestruct

Data for MIDI message.

FieldTypeDescription
timestamp_secondsdoubleThe timestamp seconds.
bytesuint8_tThe bytes.
sizeuint8_tThe size.

mk_midi_output_tstruct

Data for MIDI output.

FieldTypeDescription
iduint32_tThe ID.

mk_midi_player_descstruct

Data for MIDI player desc.

FieldTypeDescription
sequencemk_midi_sequence_tThe sequence.
synthmk_midi_synth_tThe synth.
loopboolThe loop.
event_cbmk_midi_player_event_fnThe event.
user_datavoid *The user data.

mk_midi_player_eventstruct

Data for MIDI player event.

FieldTypeDescription
time_secondsdoubleThe time seconds.
bytesuint8_tThe bytes.
sizeuint8_tThe size.
flagsuint32_tThe flags.

mk_midi_player_tstruct

Data for MIDI player.

FieldTypeDescription
iduint32_tThe ID.

mk_midi_port_infostruct

Data for MIDI port info.

FieldTypeDescription
indexuint32_tThe index.
namecharThe name.

mk_midi_sequence_infostruct

Data for MIDI sequence info.

FieldTypeDescription
used_channelsuint32_tThe used channels.
used_programsuint32_tThe used programs.
total_notesuint32_tThe total notes.
first_note_secondsdoubleThe first note seconds.
duration_secondsdoubleThe duration seconds.

mk_midi_sequence_tstruct

Data for MIDI sequence.

FieldTypeDescription
iduint32_tThe ID.

mk_midi_synth_tstruct

Data for MIDI synth.

FieldTypeDescription
iduint32_tThe ID.

Enums

mk_midi_player_event_flagsenum

Values for MIDI player event flags.

ValueDescription
MK_MIDI_PLAYER_EVENT_NONESelects none.
MK_MIDI_PLAYER_EVENT_PROGRAM_UNAVAILABLESelects program unavailable.
MK_MIDI_PLAYER_EVENT_SYNTHETICSelects synthetic.

mk_midi_player_stateenum

Values for MIDI player state.

ValueDescription
MK_MIDI_PLAYER_STOPPEDSelects stopped.
MK_MIDI_PLAYER_PLAYINGSelects playing.
MK_MIDI_PLAYER_PAUSEDSelects paused.
MK_MIDI_PLAYER_FINISHEDSelects finished.

Typedefs

mk_midi_desctypedef

typedef struct mk_midi_desc mk_midi_desc

Data for MIDI desc.

mk_midi_messagetypedef

typedef struct mk_midi_message mk_midi_message

Data for MIDI message.

mk_midi_player_desctypedef

typedef struct mk_midi_player_desc mk_midi_player_desc

Data for MIDI player desc.

mk_midi_player_eventtypedef

typedef struct mk_midi_player_event mk_midi_player_event

Data for MIDI player event.

mk_midi_player_event_flagstypedef

typedef enum mk_midi_player_event_flags mk_midi_player_event_flags

Values for MIDI player event flags.

mk_midi_player_event_fntypedef

typedef void(*) mk_midi_player_event_fn(mk_midi_player_t player, const mk_midi_player_event *event, void *user_data)

Callback used for MIDI player event.

mk_midi_player_statetypedef

typedef enum mk_midi_player_state mk_midi_player_state

Values for MIDI player state.

mk_midi_port_infotypedef

typedef struct mk_midi_port_info mk_midi_port_info

Data for MIDI port info.

mk_midi_sequence_infotypedef

typedef struct mk_midi_sequence_info mk_midi_sequence_info

Data for MIDI sequence info.

Macros

MK_MIDI_INPUT_INVALIDdefine

MK_MIDI_INPUT_INVALID

Invalid sentinel for MIDI input.

MK_MIDI_OUTPUT_INVALIDdefine

MK_MIDI_OUTPUT_INVALID

Invalid sentinel for MIDI output.

MK_MIDI_PLAYER_INVALIDdefine

MK_MIDI_PLAYER_INVALID

Invalid sentinel for MIDI player.

MK_MIDI_SEQUENCE_INVALIDdefine

MK_MIDI_SEQUENCE_INVALID

Invalid sentinel for MIDI sequence.

MK_MIDI_SYNTH_INVALIDdefine

MK_MIDI_SYNTH_INVALID

Invalid sentinel for MIDI synth.