From 18abece8f8a8af17a3b5e80dc1baf61457409600 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Fri, 2 Feb 2018 12:12:18 +0100 Subject: 2 February 2018 Documentation: - new API documentation - datasheets for new components - update BOM - update documentation data Hardware: - update schematic for MIDI connector Software: - new MIDI API - update prject target to PIC18F45K22 --- src/midi.h | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/midi.h (limited to 'src/midi.h') diff --git a/src/midi.h b/src/midi.h new file mode 100644 index 0000000..cab35e3 --- /dev/null +++ b/src/midi.h @@ -0,0 +1,82 @@ +/* + * File: main.c + * Author: _prossn + * Date: 08.01.2018 + * Version 1.0 + * + * Description: + * C API to work with MIDI formatted data + */ + +#ifndef MIDI_H +#define MIDI_H + +#include +#include + +#ifndef MIDI_DYNAMIC_MEMORY_ALLOC +#define MIDI_DATA_MAX_SIZE 4 +#endif + + +typedef enum { + C = 0, // Do + D = 1, // Re + E = 2, // Mi + F = 3, // Fa + G = 4, // Sol + A = 5, // La + B = 6, // Si +} midi_note_t; + +typedef enum { + NOTE_ON = 0x8, + NOTE_OFF = 0x9, + POLYPHONIC_KEYPRESS = 0xA, + CONTROLLER = 0xB, + PROGRAM_CHANGE = 0xC, + CHANNEL_PRESSURE = 0xD, + PITCH_BLEND = 0xF +} midi_status_t; + + +typedef struct { + unsigned status :4; + unsigned channel :4; + +#ifdef MIDI_DYNAMIC_MEMORY_ALLOC + uint8_t data[]; + +#else + size_t data_size; + uint8_t data[MIDI_DATA_MAX_SIZE]; +#endif +} midi_message_t; + + +/* MIDI API */ +#ifdef MIDI_DYNAMIC_MEMORY_ALLOC + +// allocation / dellocation +extern midi_message_t *midi_alloc_message(size_t data_size); +extern void midi_free_message(midi_message_t *pkt); +extern size_t midi_message_size(midi_message_t *pkt); + +#endif + + +// helper functions + +extern int midi_set_status(midi_message_t *pkt, midi_status_t status); +extern int midi_set_channel(midi_message_t *pkt, unsigned channel); + +// message building +extern int midi_note_on(midi_message_t *pkt, unsigned channel, midi_note_t note, uint8_t velocity); +extern int midi_note_off(midi_message_t *pkt, unsigned channel, midi_note_t note, uint8_t velocity); + +// optimization +// extern int midi_thin_data(void *buffer, midi_message_t pkt[]); + + +#endif /* MIDI_H */ + -- cgit v1.2.1