Browse Source

Add documentation

Document the exported functions and constants.
master
TheoryOfNekomata 1 year ago
parent
commit
97f65a8f0a
2 changed files with 52 additions and 3 deletions
  1. +21
    -0
      midi-utils.c
  2. +31
    -3
      midi-utils.h

+ 21
- 0
midi-utils.c View File

@@ -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);


+ 31
- 3
midi-utils.h View File

@@ -4,20 +4,48 @@
#include <stdio.h>
#include <string.h>

/**
* 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
}


Loading…
Cancel
Save