| 29 | #include <thread> |
| 30 | |
| 31 | int main() |
| 32 | { |
| 33 | #if defined(_WIN32) && __has_include(<winrt/base.h>) |
| 34 | winrt::init_apartment(); |
| 35 | #endif |
| 36 | |
| 37 | auto api = libremidi::API::ALSA_SEQ; |
| 38 | libremidi::observer observer{{.track_any = true}, api}; |
| 39 | if (observer.get_input_ports().empty()) |
| 40 | return 1; |
| 41 | if (observer.get_output_ports().empty()) |
| 42 | return 1; |
| 43 | |
| 44 | libremidi::input_port ip; |
| 45 | libremidi::output_port op; |
| 46 | |
| 47 | // Tested with https://github.com/NicoG60/TouchMCU |
| 48 | for (auto& p : observer.get_input_ports()) |
| 49 | if (p.port_name == "TouchOSC") |
| 50 | ip = p; |
| 51 | for (auto& p : observer.get_output_ports()) |
| 52 | if (p.port_name == "TouchOSC") |
| 53 | op = p; |
| 54 | |
| 55 | if (ip.port_name.empty() || op.port_name.empty()) |
| 56 | { |
| 57 | std::cerr << "No device found !"; |
| 58 | return 1; |
| 59 | } |
| 60 | |
| 61 | // Create the midi out port |
| 62 | libremidi::midi_out midi_out{{}, api}; |
| 63 | |
| 64 | // Set-up the remote control API. |
| 65 | // Here we only do some logging, this is where commands sqall be handled. |
| 66 | libremidi::remote_control_processor rcp{{.midi_out = [&](libremidi::message&& msg) { |
| 67 | midi_out.send_message(msg); |
| 68 | }, .on_command = [](libremidi::remote_control_protocol::mixer_command cmd, bool pressed) { |
| 69 | std::cerr << "command: " << magic_enum::enum_name(cmd) << " -> " |
| 70 | << (pressed ? "pressed" : "released") << "\n"; |
| 71 | }, .on_control = [](libremidi::remote_control_protocol::mixer_control ctl, int v) { |
| 72 | std::cerr << "control: " << magic_enum::enum_name(ctl) << " -> " << v << "\n"; |
| 73 | }, .on_fader = [](libremidi::remote_control_protocol::fader f, uint16_t v) { |
| 74 | std::cerr << "fader: " << magic_enum::enum_name(f) << " -> " << v << "\n"; |
| 75 | }}}; |
| 76 | |
| 77 | // Initialize the midi in port |
| 78 | libremidi::midi_in midi_in{ |
| 79 | {.on_message = [&](const libremidi::message& message) { rcp.on_midi(message); }}, api}; |
| 80 | |
| 81 | // Open the ports |
| 82 | if (auto err = midi_in.open_port(ip); err != stdx::error{}) |
| 83 | err.throw_exception(); |
| 84 | |
| 85 | if (auto err = midi_out.open_port(op); err != stdx::error{}) |
| 86 | err.throw_exception(); |
| 87 | |
| 88 | // Start communication |
nothing calls this directly
no test coverage detected