Skip to content

Commit

Permalink
Closes #19
Browse files Browse the repository at this point in the history
  • Loading branch information
6r1d committed Mar 4, 2021
1 parent ab5b65d commit 55b9f4f
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 62 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ examples/virtual_input_bytes/virtual_input
examples/virtual_output/virtual_output
test/set_client_name/main
test/set_port_name/main
test/test_last_bytearray_byte/main
45 changes: 31 additions & 14 deletions doc/starting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,37 @@ Think about virtual MIDI input and ouptut in terms of endpoints you connect to.
is a nice analogy, as well. In this analogy, a server is a "virtual port"
and a client is "just a port".

Calling wrappers
----------------

+----------------+--------------------+------------------------------------------------+
| MIDI port type | Use | Init function |
+================+====================+================================================+
| Input | Connect to | :cc:`start_port(&amidi_data, MP_IN);` |
+----------------+--------------------+------------------------------------------------+
| Output | Connect to | :cc:`start_port(&amidi_data, MP_OUT);` |
+----------------+--------------------+------------------------------------------------+
| Virtual input | Create an endpoint | :cc:`start_port(&amidi_data, MP_VIRTUAL_IN);` |
+----------------+--------------------+------------------------------------------------+
| Virtual output | Create an endpoint | :cc:`start_port(&amidi_data, MP_VIRTUAL_OUT);` |
+----------------+--------------------+------------------------------------------------+
Calling a wrapper
-----------------

There is a single wrapper that is made of two parts: a port configurator (:c:func:`setup_port_config`)
and a port starter (:c:func:`start_port`).

The table below shows some init examples and there's more info in the examples section.

+----------------+--------------------+-----------------------------------------------------+
| MIDI port type | Use | Init function |
+================+====================+=====================================================+
| Input | Connect to | .. code-block:: c |
| | | |
| | | setup_port_config(&port_config, MP_IN); |
| | | start_port(&amidi, port_config); |
+----------------+--------------------+-----------------------------------------------------+
| Output | Connect to | .. code-block:: c |
| | | |
| | | setup_port_config(&port_config, MP_OUT); |
| | | start_port(&amidi, port_config); |
+----------------+--------------------+-----------------------------------------------------+
| Virtual input | Create an endpoint | .. code-block:: c |
| | | |
| | | setup_port_config(&port_config, MP_VIRTUAL_IN); |
| | | start_port(&amidi, port_config); |
+----------------+--------------------+-----------------------------------------------------+
| Virtual output | Create an endpoint | .. code-block:: c |
| | | |
| | | setup_port_config(&port_config, MP_VIRTUAL_OUT); |
| | | start_port(&amidi, port_config); |
+----------------+--------------------+-----------------------------------------------------+

Installation
------------
Expand Down
13 changes: 11 additions & 2 deletions examples/input_bytes/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ MIDI_in_data * input_data;

MIDI_port * current_midi_port;

RMR_Port_config * port_config;

MIDI_message * msg;
error_message * err_msg;

int main() {
prepare_input_data_with_queues(&input_data);
start_port(&data, MP_IN);

// 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);

init_midi_port(&current_midi_port);

Expand All @@ -22,7 +28,7 @@ int main() {

// Count the MIDI ports,
// open if a port containing "Synth" is available
if (find_midi_port(data, current_midi_port, "Bonsai", false) > 0) {
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);
keep_process_running = 1;
Expand All @@ -48,6 +54,9 @@ int main() {

destroy_midi_input(data, input_data);

// Destroy a port configuration
destroy_port_config(port_config);

// Exit without an error
return 0;
}
12 changes: 10 additions & 2 deletions examples/output/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
Alsa_MIDI_data * data;
MIDI_port * current_midi_port;

RMR_Port_config * port_config;

// Send "note on" or "note off" signal
bool msg_mode = false;
// Last recorded time in milliseconds
Expand All @@ -19,14 +21,17 @@ int main() {
// Record initial time to a timer
timer_msec_last = millis();

start_port(&data, MP_OUT);
// Create a port configuration with default values
setup_port_config(&port_config, MP_VIRTUAL_OUT);
// Start a port with a provided configruation
start_port(&data, port_config);

// Allocate memory for a midi port struct to fill TODO elaborate
init_midi_port(&current_midi_port);

// Count the MIDI ports,
// open if a port containing a certain word is available
if (find_midi_port(data, current_midi_port, "Bonsai", true) > 0) {
if (find_midi_port(data, current_midi_port, "rmr", true) > 0) {
print_midi_port(current_midi_port);
open_port(false, data, current_midi_port->id, current_midi_port->port_info_name, NULL);
keep_process_running = 1;
Expand Down Expand Up @@ -54,6 +59,9 @@ int main() {

if (destroy_midi_output(data, NULL) != 0) slog("destructor", "destructor error");

// Destroy a port configuration
destroy_port_config(port_config);

// Exit without an error
return 0;
}
14 changes: 11 additions & 3 deletions examples/virtual_input_bytes/virtual_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ MIDI_in_data * input_data;
MIDI_message * msg;
error_message * err_msg;

RMR_Port_config * port_config;

int main() {
//
prepare_input_data_with_queues(&input_data);
// TODO look through each required call
start_port(&data, MP_VIRTUAL_IN);
// 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_midi_data(input_data, data);
// Open a new port with a pre-set name
open_virtual_port(data, "Synth", input_data);
open_virtual_port(data, "rmr", input_data);

keep_process_running = 1;

Expand All @@ -41,8 +45,12 @@ int main() {
}
}

// TODO
destroy_midi_input(data, input_data);

// Destroy a port configuration
destroy_port_config(port_config);

// Exit without an error
return 0;
}
14 changes: 11 additions & 3 deletions examples/virtual_input_detailed/virtual_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ MIDI_in_data * input_data;
MIDI_message * msg;
error_message * err_msg;

RMR_Port_config * port_config;

unsigned char MIDI_MSG_NOTE_OFF = 0x80;
unsigned char MIDI_MSG_NOTE_ON = 0x90;
unsigned char MIDI_MSG_CONT_CTR = 0xB0;
Expand Down Expand Up @@ -47,12 +49,14 @@ void print_midi_msg_buf(unsigned char * buf, long count) {
int main() {
//
prepare_input_data_with_queues(&input_data);
//
start_port(&data, MP_VIRTUAL_IN);
// 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_midi_data(input_data, data);
// Open a new port with a pre-set name
open_virtual_port(data, "Synth", input_data);
open_virtual_port(data, "rmr", input_data);

keep_process_running = 1;

Expand All @@ -74,8 +78,12 @@ int main() {
}
}

// TODO
destroy_midi_input(data, input_data);

// Destroy a port configuration
destroy_port_config(port_config);

// Exit without an error
return 0;
}
10 changes: 9 additions & 1 deletion examples/virtual_output/virtual_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

Alsa_MIDI_data * amidi_data;

RMR_Port_config * port_config;

// Send "note on" or "note off" signal
bool msg_mode = false;
// Last recorded time in milliseconds
Expand All @@ -18,7 +20,10 @@ int main() {
// Record initial time to a timer
timer_msec_last = millis();

start_port(&amidi_data, MP_VIRTUAL_OUT);
// Create a port configuration with default values
setup_port_config(&port_config, MP_VIRTUAL_OUT);
// Start a port with a provided configruation
start_port(&amidi_data, port_config);

// Send out a series of MIDI messages.
send_midi_message(amidi_data, MIDI_PROGRAM_CHANGE_MSG, 2);
Expand All @@ -43,6 +48,9 @@ int main() {

if (destroy_midi_output(amidi_data, NULL) != 0) slog("destructor", "destructor error");

// Destroy a port configuration
destroy_port_config(port_config);

// Exit without an error
return 0;
}
Loading

0 comments on commit 55b9f4f

Please sign in to comment.