From 002f128a0532826811f6c30029e5567e38acf3c3 Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Fri, 3 Mar 2023 12:20:57 +0800 Subject: [PATCH] Update documentation Add README for testing. --- CMakeLists.txt | 19 ++++++++++--------- README.md | 14 ++++++++++++++ test-note-names.c | 30 ++++++++++++++++++------------ 3 files changed, 42 insertions(+), 21 deletions(-) create mode 100644 README.md diff --git a/CMakeLists.txt b/CMakeLists.txt index 4130365..2f9d0a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 test-note-names POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy + "${CMAKE_HOME_DIRECTORY}/cases.txt" + $ ) diff --git a/README.md b/README.md new file mode 100644 index 0000000..5fe59fa --- /dev/null +++ b/README.md @@ -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) diff --git a/test-note-names.c b/test-note-names.c index fa9deb9..0d3b23b 100644 --- a/test-note-names.c +++ b/test-note-names.c @@ -2,6 +2,22 @@ #include #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); } }