MCPcopy Create free account
hub / github.com/celtera/libremidi / main

Function main

examples/midi1_to_midi2.cpp:16–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14 */
15
16int main()
17try
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}
44catch (const std::exception& error)
45{
46 std::cerr << error.what() << std::endl;
47 return EXIT_FAILURE;
48}

Callers

nothing calls this directly

Calls 6

get_input_portsMethod · 0.45
get_output_portsMethod · 0.45
emptyMethod · 0.45
open_portMethod · 0.45
throw_exceptionMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected