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

Function main

examples/qmidiin.cpp:156–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

154}
155
156int main(int argc, const char** argv)
157{
158#if defined(_WIN32) && __has_include(<winrt/base.h>)
159 // Necessary for using WinUWP and WinMIDI, must be done as early as possible in your main()
160 winrt::init_apartment();
161#endif
162
163 using namespace std::literals;
164 // Read command line arguments
165 libremidi::examples::arguments args{argc, argv};
166
167 libremidi::observer obs;
168 auto ports = obs.get_input_ports();
169
170 libremidi::queued_midi_in midiin{
171 1024,
172 libremidi::input_configuration{
173 // Don't ignore sysex, timing, or active sensing messages.
174 .ignore_sysex = false,
175 .ignore_timing = false,
176 .ignore_sensing = false,
177 },
178 libremidi::midi_in_configuration_for(obs)};
179
180 if (!args.open_port(midiin))
181 return 1;
182
183 // Install an interrupt handler function.
184 static std::atomic_bool done{};
185 signal(SIGINT, [](int) { done = true; });
186
187 // Periodically check input queue.
188 std::cout << "Reading MIDI from port " << ports[args.input_port].display_name
189 << " ... quit with Ctrl-C.\n";
190 while (!done)
191 {
192 for (;;)
193 {
194 auto msg = midiin.get_message();
195 if (msg.empty())
196 break;
197 std::cout << msg << std::endl;
198 }
199
200 std::this_thread::sleep_for(10ms);
201 }
202
203 return 0;
204}

Callers

nothing calls this directly

Calls 4

get_messageMethod · 0.80
get_input_portsMethod · 0.45
open_portMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected