| 14 | */ |
| 15 | |
| 16 | int main() |
| 17 | try |
| 18 | { |
| 19 | #if defined(_WIN32) && __has_include(<winrt/base.h>) |
| 20 | // Necessary for using WinUWP and WinMIDI, must be done as early as possible in your main() |
| 21 | winrt::init_apartment(); |
| 22 | #endif |
| 23 | |
| 24 | // The observer object enumerates available inputs and outputs |
| 25 | // jack is a MIDI 1 API (there's also jack_ump which leverages the newer |
| 26 | // JACK / PipeWire MIDI 2 support). |
| 27 | libremidi::observer obs{{}, libremidi::jack_observer_configuration{}}; |
| 28 | auto pi = obs.get_input_ports(); |
| 29 | auto po = obs.get_output_ports(); |
| 30 | if (pi.empty() || po.empty()) |
| 31 | throw std::runtime_error("No MIDI in / out pair available"); |
| 32 | |
| 33 | // Create a midi in |
| 34 | auto on_ump = [&](const libremidi::ump& message) { std::cerr << message << "\n"; }; |
| 35 | libremidi::midi_in midiin{{.on_message = on_ump}, libremidi::jack_input_configuration{}}; |
| 36 | |
| 37 | if (auto err = midiin.open_port(pi[0]); err != stdx::error{}) |
| 38 | err.throw_exception(); |
| 39 | |
| 40 | // Wait until we exit |
| 41 | char input; |
| 42 | std::cin.get(input); |
| 43 | } |
| 44 | catch (const std::exception& error) |
| 45 | { |
| 46 | std::cerr << error.what() << std::endl; |
| 47 | return EXIT_FAILURE; |
| 48 | } |
nothing calls this directly
no test coverage detected