Parcourir la source

Update documentation

Add README for testing.
master
TheoryOfNekomata il y a 1 an
Parent
révision
002f128a05
3 fichiers modifiés avec 42 ajouts et 21 suppressions
  1. +10
    -9
      CMakeLists.txt
  2. +14
    -0
      README.md
  3. +18
    -12
      test-note-names.c

+ 10
- 9
CMakeLists.txt Voir le fichier

@@ -5,15 +5,16 @@ set(CMAKE_C_STANDARD 11)

include_directories(.)

add_executable(test-note-names
test-note-names.c
midi-utils.c
midi-utils.h)

add_executable(
test-note-names
test-note-names.c
midi-utils.c
midi-utils.h
)

add_custom_command(
TARGET test-note-names POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_HOME_DIRECTORY}/cases.txt"
$<TARGET_FILE_DIR:test-note-names>
TARGET test-note-names POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
"${CMAKE_HOME_DIRECTORY}/cases.txt"
$<TARGET_FILE_DIR:test-note-names>
)

+ 14
- 0
README.md Voir le fichier

@@ -0,0 +1,14 @@
# `midi-utils`

Small library for MIDI-related functions.

## Testing

```shell
cmake -S . -B cmake-build-debug -G Ninja
cmake --build cmake-build-debug -t test-note-names
```

## License

[MIT](./LICENSE)

+ 18
- 12
test-note-names.c Voir le fichier

@@ -2,6 +2,22 @@
#include <assert.h>
#include "midi-utils.h"

void check_note_value(char* read_note_name, unsigned char read_note_value) {
unsigned int actual_note_value = MIDI_GetNoteFromName(read_note_name);
printf("MIDI_GetNoteFromName(\"%s\")...", read_note_name);
printf("(%d == %d) ", read_note_value, actual_note_value);
assert(read_note_value == actual_note_value);
printf("OK!\n");
}

void check_note_name(char* read_note_name, unsigned char read_note_value) {
printf("MIDI_GetNoteName(%d)...", read_note_value);
char* actual_note_name = MIDI_GetNoteName(read_note_value);
printf("(%s == %s) ", read_note_name, actual_note_name);
assert(!strcmp(read_note_name, actual_note_name));
printf("OK!\n");
}

int main(void) {
FILE* f = fopen("cases.txt", "r");
if (!f) {
@@ -11,20 +27,10 @@ int main(void) {
unsigned int read_note_value;
while (!feof(f)) {
fscanf(f, "%s %d\n", read_note_name, &read_note_value);
unsigned int actual_note_value = MIDI_GetNoteFromName(read_note_name);
printf("MIDI_GetNoteFromName(\"%s\")...", read_note_name);
printf("(%d == %d) ", read_note_value, actual_note_value);
assert(read_note_value == actual_note_value);
printf("OK!\n");
check_note_value(read_note_name, read_note_value);

if (read_note_value != 255u || !strcmp(read_note_name, "D#21")) {
printf("MIDI_GetNoteName(%d)...", read_note_value);
char* actual_note_name = MIDI_GetNoteName(read_note_value);

printf("(%s == %s) ", read_note_name, actual_note_name);
assert(!strcmp(read_note_name, actual_note_name));

printf("OK!\n");
check_note_name(read_note_name, read_note_value);
}
}



Chargement…
Annuler
Enregistrer