Closed 6r1d closed 3 years ago
Current idea for implementation: extend midi_message_t
.
Something along the lines of:
#include <stdint.h>
struct midi_note_message
{
uint8_t note;
double frequency;
uint8_t velocity;
uint8_t channel;
} midi_note_message;
struct midi_cc_message
{
uint8_t control_id;
uint8_t value;
uint8_t channel;
} midi_cc_message;
typedef struct {
uint8_t command_type;
uint8_t channel;
uint32_t bytes_length;
union data {
struct midi_note_message note_message;
struct midi_cc_message cc_message;
} msg_data;
uint8_t bytes[];
} midi_message_t;
Approach from these StackOverflow questions: 1, 2.
Note to frequency conversion from MusicDSP projects seems useful for the task.
#include <math.h>
double midi_note_to_freq(char keynum) {
return 440.0 * pow(2.0, ((double)keynum - 69.0) / 12.0);
}
I want this parser to be able to extract more data. To do that, I am considering using a struct, containing a
command_type
and a union of different structs for each of them.midi_note
,frequency
andvelocity
values fornote on
andnote off
messagesvalue
forcontrol change
messagesmidi_message_t
definition can be improvedmidi_note_message
andmidi_cc_message
to one header orunion