diff --git a/midi-utils.c b/midi-utils.c index 0ac1efd..f2d07f8 100644 --- a/midi-utils.c +++ b/midi-utils.c @@ -1,6 +1,10 @@ #include "midi-utils.h" #if !defined _WIN32 +/** + * Converts a string to lowercase. + * @param dest - The string to convert. + */ void _strlwr(char* dest) { for (unsigned int i = 0; i < strlen(dest); i += 1) { if ('A' <= dest[i] && dest[i] <= 'Z') { @@ -10,6 +14,13 @@ void _strlwr(char* dest) { } #endif +/** + * Gets the name of a MIDI note value. + * @param midi_note - The MIDI note value. + * @note Valid values are from 0-127. + * @return The MIDI note name. + * @see MIDI_GetNoteFromName() + */ char* MIDI_GetNoteName(unsigned char midi_note) { static const char* pitch_names[] = { "C", @@ -33,7 +44,17 @@ char* MIDI_GetNoteName(unsigned char midi_note) { return note_name; } +/** + * Gets the note value from a MIDI note name + * @param name - The MIDI note name. + * @return The MIDI note value, or 255 if an invalid name is passed. + * @see MIDI_GetNoteName() + */ unsigned char MIDI_GetNoteFromName(const char* name) { + if (!name) { + return 255u; + } + char name_copy[8]; strcpy(name_copy, name); _strlwr(name_copy); diff --git a/midi-utils.h b/midi-utils.h index 3251bf1..eec5deb 100644 --- a/midi-utils.h +++ b/midi-utils.h @@ -4,20 +4,48 @@ #include #include +/** + * MIDI message type for note on. + */ #define MIDI_MESSAGE_NOTEON 0x90u + +/** + * MIDI message type for note off. + */ #define MIDI_MESSAGE_NOTEOFF 0x80u +/** + * Continuous control number for sustain, or damper (right pedal). + */ #define MIDI_CC_SUSTAIN 0x40u + +/** + * Continuous control number for sostenuto (center pedal). + */ #define MIDI_CC_SOSTENUTO 0x42u + +/** + * Continuous control number for una corda (left pedal). + */ #define MIDI_CC_UNACORDA 0x43u #if defined __cplusplus extern "C" { #endif -char *MIDI_GetNoteName(unsigned char); - -unsigned char MIDI_GetNoteFromName(const char *); +/** + * Gets the name of a MIDI note value. + * @return The MIDI note name. + * @see MIDI_GetNoteFromName() + */ +char* MIDI_GetNoteName(unsigned char); + +/** + * Gets the note value from a MIDI note name + * @return The MIDI note value. + * @see MIDI_GetNoteName() + */ +unsigned char MIDI_GetNoteFromName(const char*); #if defined __cplusplus }