-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds unfinished examples with callbacks
- Loading branch information
Showing
5 changed files
with
175 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CFLAGS=-Wall -O2 -g $(shell pkg-config --cflags alsa) $(shell pkg-config --cflags glib-2.0) -I../../include -I../include | ||
LIBS=-pthread $(shell pkg-config --libs glib-2.0) $(shell pkg-config --libs alsa) | ||
|
||
all: | ||
$(CC) -o input input.c $(CFLAGS) $(LIBS) | ||
|
||
clean: | ||
rm -f main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include <stdbool.h> | ||
// Keeps process running until Ctrl-C is pressed. | ||
// Contains a SIGINT handler and keep_process_running variable. | ||
#include "util/exit_handling.h" | ||
#include "util/output_handling.h" | ||
// Main RMR header file | ||
#include "midi/midi_handling.h" | ||
|
||
Alsa_MIDI_data * data; | ||
MIDI_in_data * input_data; | ||
|
||
MIDI_port * current_midi_port; | ||
|
||
RMR_Port_config * port_config; | ||
|
||
MIDI_message * msg; | ||
error_message * err_msg; | ||
|
||
void message_handler( | ||
double timestamp, | ||
unsigned char * buf, | ||
long count, | ||
void * user_data | ||
) { | ||
print_midi_msg_buf(buf, count); | ||
} | ||
|
||
int main() { | ||
// Allocate a MIDI_in_data instance, assign a | ||
// MIDI message queue and an error queue | ||
prepare_input_data_with_queues(&input_data); | ||
|
||
// Create a port configuration with default values | ||
setup_port_config(&port_config, MP_IN); | ||
// Start a port with a provided configruation | ||
start_port(&data, port_config); | ||
|
||
// Allocate memory for a MIDI_port instance | ||
init_midi_port(¤t_midi_port); | ||
|
||
// Assign amidi_data to input_data instance | ||
assign_midi_data(input_data, data); | ||
|
||
// Prepare to handle input through a callback | ||
set_MIDI_in_callback(input_data, message_handler, NULL); | ||
|
||
// Count the MIDI ports, | ||
// open if a port containing "Synth" is available | ||
if (find_midi_port(data, current_midi_port, "rmr", false) > 0) { | ||
print_midi_port(current_midi_port); | ||
open_port(true, data, current_midi_port->id, current_midi_port->port_info_name, input_data); | ||
// Don't exit until Ctrl-C is pressed; | ||
// Look up "output_handling.h" | ||
keep_process_running = 1; | ||
} | ||
|
||
// Add a SIGINT handler to set keep_process_running to 0 | ||
// so the program can exit | ||
signal(SIGINT, sigint_handler); | ||
|
||
// Run until SIGINT is received | ||
while (keep_process_running) { | ||
while (g_async_queue_length_unlocked(input_data->error_async_queue)) { | ||
// Read an error message from an error queue, | ||
// simply deallocate it for now | ||
err_msg = g_async_queue_try_pop(input_data->midi_async_queue); | ||
if (err_msg != NULL) free_error_message(err_msg); | ||
} | ||
} | ||
|
||
// Close a MIDI input port, | ||
// shutdown the input thread, | ||
// do cleanup | ||
destroy_midi_input(data, input_data); | ||
|
||
// Destroy a port configuration | ||
destroy_port_config(port_config); | ||
|
||
// Exit without an error | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CFLAGS=-Wall -O2 -g $(shell pkg-config --cflags alsa) $(shell pkg-config --cflags glib-2.0) -I../../include -I../include -lm | ||
LIBS=-pthread $(shell pkg-config --libs glib-2.0) $(shell pkg-config --libs alsa) | ||
|
||
all: | ||
$(CC) -o virtual_input virtual_input.c $(CFLAGS) $(LIBS) | ||
|
||
clean: | ||
rm -f main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#include <stdio.h> | ||
#include <stdbool.h> | ||
// Keeps process running until Ctrl-C is pressed. | ||
// Contains a SIGINT handler and keep_process_running variable. | ||
#include "util/exit_handling.h" | ||
#include "util/output_handling.h" | ||
#include "util/midi_parsing.h" | ||
// Main RMR header file | ||
#include "midi/midi_handling.h" | ||
|
||
Alsa_MIDI_data * data; | ||
MIDI_in_data * input_data; | ||
|
||
MIDI_message * msg; | ||
error_message * err_msg; | ||
|
||
RMR_Port_config * port_config; | ||
|
||
void message_handler( | ||
double timestamp, | ||
unsigned char * buf, | ||
long count, | ||
void * user_data | ||
) { | ||
print_midi_msg_buf(buf, count); | ||
} | ||
|
||
int main() { | ||
// Allocate a MIDI_in_data instance, assign a | ||
// MIDI message queue and an error queue | ||
prepare_input_data_with_queues(&input_data); | ||
|
||
// Create a port configuration with default values | ||
setup_port_config(&port_config, MP_VIRTUAL_IN); | ||
// Start a port with a provided configruation | ||
start_port(&data, port_config); | ||
|
||
// Assign amidi_data to input_data instance | ||
assign_midi_data(input_data, data); | ||
|
||
// Open a new port with a pre-set name | ||
open_virtual_port(data, "rmr", input_data); | ||
|
||
// Prepare to handle input through a callback | ||
set_MIDI_in_callback(input_data, message_handler, NULL); | ||
|
||
// Don't exit until Ctrl-C is pressed; | ||
// Look up "output_handling.h" | ||
keep_process_running = 1; | ||
|
||
// Add a SIGINT handler to set keep_process_running to 0 | ||
// so the program can exit | ||
signal(SIGINT, sigint_handler); | ||
|
||
// Run until SIGINT is received | ||
while (keep_process_running) { | ||
while (g_async_queue_length_unlocked(input_data->error_async_queue)) { | ||
// Read an error message from an error queue, | ||
// simply deallocate it for now | ||
err_msg = g_async_queue_try_pop(input_data->midi_async_queue); | ||
if (err_msg != NULL) free_error_message(err_msg); | ||
} | ||
} | ||
|
||
// Close a MIDI input port, shutdown the input thread, | ||
// do cleanup | ||
destroy_midi_input(data, input_data); | ||
|
||
// Destroy a port configuration | ||
destroy_port_config(port_config); | ||
|
||
// Exit without an error | ||
return 0; | ||
} |