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

Function main

examples/client.cpp:7–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#include <thread>
6
7int main()
8{
9 namespace lm = libremidi::midi1;
10 int input_k = 1;
11 int output_k = 1;
12
13 lm::client client{
14 {.api = libremidi::API::ALSA_RAW,
15 .client_name = "my client",
16 .on_message =
17 [&](const libremidi::input_port& port, const libremidi::message& mess) {
18 std::cerr << port.display_name << ": " << mess.bytes.size() << std::endl;
19
20 client.send_message(mess.bytes.data(), mess.bytes.size());
21 },
22 .input_added =
23 [&](const libremidi::input_port& port) {
24 std::cerr << "Input added: " << port.display_name << " | " << port.port_name << std::endl;
25 client.add_input(port, "input_" + std::to_string(input_k++));
26 },
27 .input_removed =
28 [&](const libremidi::input_port& port) {
29 std::cerr << "Input removed: " << port.display_name << std::endl;
30 client.remove_input(port);
31 },
32 .output_added =
33 [&](const libremidi::output_port& port) {
34 std::cerr << "Output added: " << port.display_name << std::endl;
35 client.add_output(port, "output_" + std::to_string(output_k++));
36 },
37 .output_removed = [&](const libremidi::output_port& port) {
38 std::cerr << "Output removed: " << port.display_name << std::endl;
39 client.remove_output(port);
40 }}};
41
42 auto inputs = client.get_input_ports();
43 auto outputs = client.get_output_ports();
44
45 for (const auto& port : inputs)
46 {
47 client.add_input(port, "input_" + std::to_string(input_k++));
48 }
49
50 for (const auto& port : outputs)
51 {
52 client.add_output(port, "output_" + std::to_string(output_k++));
53 }
54
55 std::this_thread::sleep_for(std::chrono::seconds(1));
56}

Callers

nothing calls this directly

Calls 5

sizeMethod · 0.45
send_messageMethod · 0.45
dataMethod · 0.45
get_input_portsMethod · 0.45
get_output_portsMethod · 0.45

Tested by

no test coverage detected