Workbench Library  0.1b
MIDI

MIDI system initialization, deinitialization, and processing for Workbench applications. More...

Typedefs

typedef int(* MidiCallback) (const void *, void *, unsigned long, void *)
 Type definition for MIDI callback functions. More...
 

Functions

void midi_init ()
 Initializes the MIDI system. More...
 
void midi_deinit ()
 Deinitializes the MIDI system. More...
 

Detailed Description

MIDI system initialization, deinitialization, and processing for Workbench applications.

This header file defines functions and macros for managing MIDI input and output using the PortMidi library. It includes type definitions for MIDI callback functions and a comprehensive set of MIDI message constants.

The midi_init function sets up the MIDI input and output streams, while the midi_deinit function closes the streams and terminates the MIDI system. The __midi_callback function processes incoming MIDI messages, and the process_midi function handles MIDI message parsing and logging.

Typedef Documentation

◆ MidiCallback

typedef int(* MidiCallback) (const void *, void *, unsigned long, void *)

Type definition for MIDI callback functions.

A MidiCallback function is called to handle incoming and outgoing MIDI messages. It takes the following parameters:

  • input_buffer: A pointer to the input MIDI buffer.
  • output_buffer: A pointer to the output MIDI buffer.
  • block_size: The number of MIDI events in the buffer.
  • user_data: A pointer to user-defined data passed to the callback function.

Example usage:

int my_midi_callback(const void *input_buffer, void *output_buffer, unsigned
long block_size, void *user_data) {
const PmEvent *in_buffer = (const PmEvent*)in;
for (unsigned long i = 0; i < length; ++i) {
PmEvent event = in_buffer[i];
PmMessage message = event.message;
log_i("%i", message);
}
return 0;
}
#define log_i(message,...)
Logs an info message.
Definition: workbench_logger.h:135

Function Documentation

◆ midi_deinit()

void midi_deinit ( )

Deinitializes the MIDI system.

This function stops the MIDI system, frees allocated buffers, and terminates the PortMidi library. It logs any errors that occur during the deinitialization process.

◆ midi_init()

void midi_init ( )

Initializes the MIDI system.

This function initializes the PortMidi library, sets up the MIDI input and output devices based on the configuration settings, and allocates buffers for MIDI events. It also starts the MIDI input and output streams if they are enabled in the configuration.

If an error occurs during initialization, it logs the error message and deinitializes the MIDI system.