1- #include < jni.h>
2- #include < string>
3- #include < vector>
4- #include < sstream>
51#include < libremidi/libremidi.hpp>
62
73#include < android/log.h>
4+
5+ #include < jni.h>
6+
7+ #include < sstream>
8+ #include < string>
9+ #include < vector>
810extern " C" JNIEXPORT jstring JNICALL
9- Java_com_libremidi_example_MainActivity_getMidiDevices (JNIEnv* env, jobject /* this */ ) {
10- std::stringstream result;
11- __android_log_print (ANDROID_LOG_WARN, " libremidi" , " Java_com_libremidi_example_MainActivity_getMidiDevices!!" );
12-
13- try {
14- auto api = libremidi::API::ANDROID_AMIDI;
15- libremidi::observer obs{{.track_any = true }, libremidi::observer_configuration_for (api)};
16-
17- result << " === MIDI Input Devices ===\n " ;
18- auto inputs = obs.get_input_ports ();
19- if (inputs.empty ()) {
20- result << " No input devices found\n " ;
21- } else {
22- for (const auto & port : inputs) {
23- result << " Port " << port.port << " : " << port.port_name ;
24- if (!port.device_name .empty () && port.device_name != port.port_name ) {
25- result << " (Device: " << port.device_name << " )" ;
26- }
27- if (!port.display_name .empty () && port.display_name != port.port_name ) {
28- result << " [" << port.display_name << " ]" ;
29- }
30- result << " \n " ;
11+ Java_com_libremidi_example_MainActivity_getMidiDevices (JNIEnv* env, jobject /* this */ )
12+ {
13+ std::stringstream result;
14+ __android_log_print (
15+ ANDROID_LOG_WARN, " libremidi" , " Java_com_libremidi_example_MainActivity_getMidiDevices!!" );
16+
17+ try
18+ {
19+ auto api = libremidi::API::ANDROID_AMIDI;
20+ libremidi::observer obs{{.track_any = true }, libremidi::observer_configuration_for (api)};
3121
32- __android_log_print (ANDROID_LOG_WARN, " libremidi" , " opening: %s" , port.port_name .c_str ());
33- auto midi_in = new libremidi::midi_in{{.on_message {[](const libremidi::message& m) {
34- __android_log_print (ANDROID_LOG_WARN, " libremidi" , " ayy!!" );
35- }}}, libremidi::midi_in_configuration_for (api)};
22+ result << " === MIDI Input Devices ===\n " ;
23+ auto inputs = obs.get_input_ports ();
24+ if (inputs.empty ())
25+ {
26+ result << " No input devices found\n " ;
27+ }
28+ else
29+ {
30+ for (const auto & port : inputs)
31+ {
32+ result << " Port " << port.port << " : " << port.port_name ;
33+ if (!port.device_name .empty () && port.device_name != port.port_name )
34+ {
35+ result << " (Device: " << port.device_name << " )" ;
36+ }
37+ if (!port.display_name .empty () && port.display_name != port.port_name )
38+ {
39+ result << " [" << port.display_name << " ]" ;
40+ }
41+ result << " \n " ;
3642
37- auto p = midi_in->get_current_api ();
43+ __android_log_print (ANDROID_LOG_WARN, " libremidi" , " opening: %s" , port.port_name .c_str ());
44+ auto midi_in = new libremidi::midi_in{
45+ {.on_message {[](const libremidi::message& m) {
46+ __android_log_print (ANDROID_LOG_WARN, " libremidi" , " ayy!!" );
47+ }}},
48+ libremidi::midi_in_configuration_for (api)};
3849
39- __android_log_print (ANDROID_LOG_WARN, " libremidi" , " >> ??! %s" , libremidi::get_api_name (p).data ());
40- __android_log_print (ANDROID_LOG_WARN, " libremidi" , " >> open port?!" );
41- midi_in->open_port (port);
42- }
50+ auto p = midi_in->get_current_api ();
51+
52+ __android_log_print (
53+ ANDROID_LOG_WARN, " libremidi" , " >> ??! %s" , libremidi::get_api_name (p).data ());
54+ __android_log_print (ANDROID_LOG_WARN, " libremidi" , " >> open port?!" );
55+ midi_in->open_port (port);
56+ }
57+ }
58+
59+ result << " \n === MIDI Output Devices ===\n " ;
60+ auto outputs = obs.get_output_ports ();
61+ if (outputs.empty ())
62+ {
63+ result << " No output devices found\n " ;
64+ }
65+ else
66+ {
67+ for (const auto & port : outputs)
68+ {
69+ result << " Port " << port.port << " : " << port.port_name ;
70+ if (!port.device_name .empty () && port.device_name != port.port_name )
71+ {
72+ result << " (Device: " << port.device_name << " )" ;
4373 }
44-
45- result << " \n === MIDI Output Devices ===\n " ;
46- auto outputs = obs.get_output_ports ();
47- if (outputs.empty ()) {
48- result << " No output devices found\n " ;
49- } else {
50- for (const auto & port : outputs) {
51- result << " Port " << port.port << " : " << port.port_name ;
52- if (!port.device_name .empty () && port.device_name != port.port_name ) {
53- result << " (Device: " << port.device_name << " )" ;
54- }
55- if (!port.display_name .empty () && port.display_name != port.port_name ) {
56- result << " [" << port.display_name << " ]" ;
57- }
58- result << " \n " ;
59- }
74+ if (!port.display_name .empty () && port.display_name != port.port_name )
75+ {
76+ result << " [" << port.display_name << " ]" ;
6077 }
61-
62- } catch (const std::exception& e) {
63- result << " Error: " << e.what () << " \n " ;
78+ result << " \n " ;
79+ }
6480 }
81+ }
82+ catch (const std::exception& e)
83+ {
84+ result << " Error: " << e.what () << " \n " ;
85+ }
6586
66- __android_log_print (ANDROID_LOG_WARN, " libremidi" , " FINITO!!" );
67- return env->NewStringUTF (result.str ().c_str ());
87+ __android_log_print (ANDROID_LOG_WARN, " libremidi" , " FINITO!!" );
88+ return env->NewStringUTF (result.str ().c_str ());
6889}
6990
7091extern " C" JNIEXPORT jstring JNICALL
71- Java_com_libremidi_example_MainActivity_getLibremidiVersion (JNIEnv* env, jobject /* this */ ) {
72- return env->NewStringUTF (" libremidi Android example" );
92+ Java_com_libremidi_example_MainActivity_getLibremidiVersion (JNIEnv* env, jobject /* this */ )
93+ {
94+ return env->NewStringUTF (" libremidi Android example" );
7395}
0 commit comments