From 2f63863c3481c3da32d00b048acadd9c84be3c0c Mon Sep 17 00:00:00 2001 From: Victor Gridnevsky Date: Mon, 8 Mar 2021 04:09:09 +0300 Subject: [PATCH] Closes #14 --- examples/include/util/output_handling.h | 2 +- examples/input_bytes_callback/input.c | 15 +++++++++++++++ .../virtual_input_callback/virtual_input.c | 18 +++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/examples/include/util/output_handling.h b/examples/include/util/output_handling.h index 0ebf1c1..0d7577e 100644 --- a/examples/include/util/output_handling.h +++ b/examples/include/util/output_handling.h @@ -7,7 +7,7 @@ void print_midi_msg_buf(unsigned char * buf, long count) { } printf(" | "); for (byte_id = 0; byte_id < count; byte_id++) { - printf("%d ", buf[byte_id]); + printf("%03d ", buf[byte_id]); } printf("\n"); fflush( stdout ); diff --git a/examples/input_bytes_callback/input.c b/examples/input_bytes_callback/input.c index f98316f..7a145f3 100644 --- a/examples/input_bytes_callback/input.c +++ b/examples/input_bytes_callback/input.c @@ -16,16 +16,28 @@ RMR_Port_config * port_config; MIDI_message * msg; error_message * err_msg; +// Currently will be used for one integer value to show +// how callback might interact with outside data. +uint8_t * callback_values; + void message_handler( double timestamp, unsigned char * buf, long count, void * user_data ) { + // Display a first value in "callback_values" contents + printf("%03d | ", ((uint8_t*)callback_values)[0]); + // Display MIDI message hex data print_midi_msg_buf(buf, count); + // Increment a first item in a pointer + ((uint8_t*)callback_values)[0]++; } int main() { + // Allocate a test variable to update periodically + callback_values = (uint8_t*) calloc(1, sizeof(uint8_t)); + // Allocate a MIDI_in_data instance, assign a // MIDI message queue and an error queue prepare_input_data_with_queues(&input_data); @@ -76,6 +88,9 @@ int main() { // Destroy a port configuration destroy_port_config(port_config); + // Free pointer values + free(callback_values); + // Exit without an error return 0; } diff --git a/examples/virtual_input_callback/virtual_input.c b/examples/virtual_input_callback/virtual_input.c index 4d012cd..9afac70 100644 --- a/examples/virtual_input_callback/virtual_input.c +++ b/examples/virtual_input_callback/virtual_input.c @@ -1,4 +1,5 @@ #include +#include #include // Keeps process running until Ctrl-C is pressed. // Contains a SIGINT handler and keep_process_running variable. @@ -16,16 +17,28 @@ error_message * err_msg; RMR_Port_config * port_config; +// Currently will be used for one integer value to show +// how callback might interact with outside data. +uint8_t * callback_values; + void message_handler( double timestamp, unsigned char * buf, long count, void * user_data ) { + // Display a first value in "callback_values" contents + printf("%03d | ", ((uint8_t*)callback_values)[0]); + // Display MIDI message hex data print_midi_msg_buf(buf, count); + // Increment a first item in a pointer + ((uint8_t*)callback_values)[0]++; } int main() { + // Allocate a test variable to update periodically + callback_values = (uint8_t*) calloc(1, sizeof(uint8_t)); + // Allocate a MIDI_in_data instance, assign a // MIDI message queue and an error queue prepare_input_data_with_queues(&input_data); @@ -42,7 +55,7 @@ int main() { open_virtual_port(data, "rmr", input_data); // Prepare to handle input through a callback - set_MIDI_in_callback(input_data, message_handler, NULL); + set_MIDI_in_callback(input_data, message_handler, callback_values); // Don't exit until Ctrl-C is pressed; // Look up "output_handling.h" @@ -69,6 +82,9 @@ int main() { // Destroy a port configuration destroy_port_config(port_config); + // Free pointer values + free(callback_values); + // Exit without an error return 0; }