Skip to content

Commit

Permalink
Closes #14
Browse files Browse the repository at this point in the history
  • Loading branch information
6r1d committed Mar 8, 2021
1 parent 420f46e commit 2f63863
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/include/util/output_handling.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
15 changes: 15 additions & 0 deletions examples/input_bytes_callback/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
18 changes: 17 additions & 1 deletion examples/virtual_input_callback/virtual_input.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
// Keeps process running until Ctrl-C is pressed.
// Contains a SIGINT handler and keep_process_running variable.
Expand All @@ -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);
Expand All @@ -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"
Expand All @@ -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;
}

0 comments on commit 2f63863

Please sign in to comment.