uMIDI
The swiss army knife for quick and easy developement of MIDI applications.
Functions | Variables
midi.c File Reference

MIDI message transceiver. More...

#include <stddef.h>
#include <avr/interrupt.h>
#include <avr/io.h>
#include "gpio.h"
#include "midi.h"
#include "leds.h"
Include dependency graph for midi.c:

Functions

void init_midi_module (const struct midi_config *const config)
 Initializes the MIDI transceiver module. More...
 
enum midi_channel read_midi_channel_from_jumpers (const struct jumpers *jumpers)
 Reads the MIDI channel configuration from the solder jumpers. More...
 
void send_control_change (midi_value_t controller, midi_value_t value)
 Sends a control change message. More...
 
void send_midi_message (enum midi_channel channel, enum midi_message_type type, midi_value_t data0, midi_value_t data1)
 Sends an arbitrary MIDI message. More...
 
void send_note_off (midi_value_t note, midi_value_t velocity)
 Sends a note off message. More...
 
void send_note_on (midi_value_t note, midi_value_t velocity)
 Sends a note on message. More...
 
void send_program_change (midi_value_t pnum)
 Sends a program change message. More...
 
void set_midi_rx_channel (enum midi_channel channel)
 Updates the midi receive channel. More...
 
void set_midi_tx_channel (enum midi_channel channel)
 Updates the midi transmit channel. More...
 
void set_omni_mode (bool enable)
 Puts the device into Omni mode. More...
 
static void handle_status_byte (midi_value_t data)
 Updates the MIDI state machine according to the supplied data byte. More...
 
 ISR (USARTE0_RXC_vect)
 Main interrupt service routine for incoming MIDI messages. More...
 

Variables

static struct midi_event_handlersevent_handlers
 The MIDI event handlers. More...
 
static enum midi_state midi_state = MIDI_STATE_IDLE
 Current state of the MIDI state machine. More...
 
static bool omni_mode
 Omni mode state. More...
 
static enum midi_channel rx_channel
 The MIDI receive channel. More...
 
static enum midi_channel tx_channel
 The MIDI transmit channel. More...
 
static bool signal_rx
 If set to true, the red on-board LED flashes on every received MIDI message. More...
 

Detailed Description

MIDI message transceiver.

Function Documentation

◆ handle_status_byte()

static void handle_status_byte ( midi_value_t  data)
static

Updates the MIDI state machine according to the supplied data byte.

Parameters
datathe MIDI data byte to be parsed

◆ init_midi_module()

void init_midi_module ( const struct midi_config config)

Initializes the MIDI transceiver module.

Configures the UART, enables the RXC interrupt and registers MIDI message handlers.

Parameters
configthe MIDI module configuration to apply

◆ ISR()

ISR ( USARTE0_RXC_vect  )

Main interrupt service routine for incoming MIDI messages.

This routine reads and parses MIDI data arriving on the USART and calls the callback functions registered during module initialization. For the time being, all MIDI packets are handled, regardless of the MIDI channel, so uMIDI devices are effectively in OMNI mode.

See also
init_midi_module

◆ read_midi_channel_from_jumpers()

enum midi_channel read_midi_channel_from_jumpers ( const struct jumpers jumpers)

Reads the MIDI channel configuration from the solder jumpers.

Parameters
jumpersthe the solder jumpers configuration struct
Returns
the selected MIDI channel

◆ send_control_change()

void send_control_change ( midi_value_t  controller,
midi_value_t  value 
)

Sends a control change message.

Parameters
controllerthe MIDI controller number
valuethe new value for the controller

◆ send_midi_message()

void send_midi_message ( enum midi_channel  channel,
enum midi_message_type  type,
midi_value_t  data0,
midi_value_t  data1 
)

Sends an arbitrary MIDI message.

If the second data byte is not required for the specified message type, the parameter is simply ignored.

Parameters
channelthe MIDI channel to send on
typethe type of the MIDI message to send
data0the first data byte (e.g. MIDI controller number for a control change)
data1the second data byte (optional, e.g. value for a control change)

◆ send_note_off()

void send_note_off ( midi_value_t  note,
midi_value_t  velocity 
)

Sends a note off message.

Parameters
notethe MIDI note number
velocityvelocity of the key press

◆ send_note_on()

void send_note_on ( midi_value_t  note,
midi_value_t  velocity 
)

Sends a note on message.

Parameters
notethe MIDI note number
velocityvelocity of the key press

◆ send_program_change()

void send_program_change ( midi_value_t  program)

Sends a program change message.

Parameters
programthe new MIDI program to load

◆ set_midi_rx_channel()

void set_midi_rx_channel ( enum midi_channel  channel)

Updates the midi receive channel.

Parameters
channelthe channel to listen on

◆ set_midi_tx_channel()

void set_midi_tx_channel ( enum midi_channel  channel)

Updates the midi transmit channel.

Parameters
channelthe channel to talk on

◆ set_omni_mode()

void set_omni_mode ( bool  enable)

Puts the device into Omni mode.

In Omni mode the device handles all received MIDI messages regardless of the channel. When not in Omni mode, only messages on the configured receive channel are processed.

Parameters
enableif true, Omni mode is enabled; if false, it is disabled

Variable Documentation

◆ event_handlers

struct midi_event_handlers* event_handlers
static

The MIDI event handlers.

See also
init_midi_module

◆ midi_state

Current state of the MIDI state machine.

◆ omni_mode

bool omni_mode
static

Omni mode state.

See also
init_midi_module

◆ rx_channel

enum midi_channel rx_channel
static

The MIDI receive channel.

See also
init_midi_module

◆ signal_rx

bool signal_rx
static

If set to true, the red on-board LED flashes on every received MIDI message.

See also
init_midi_module

◆ tx_channel

enum midi_channel tx_channel
static

The MIDI transmit channel.

See also
init_midi_module