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

Class arguments

examples/utils.hpp:194–306  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

192namespace libremidi::examples
193{
194struct arguments
195{
196 libremidi::API api{libremidi::API::UNSPECIFIED};
197 int input_port{0};
198 int output_port{0};
199 int count{50};
200 bool virtual_port{};
201
202 static std::string api_list()
203 {
204 std::string ret;
205 ret.reserve(64);
206 auto apis = libremidi::available_apis();
207 for (auto api : apis)
208 {
209 ret += libremidi::get_api_name(api);
210 ret += ", ";
211 }
212 if (apis.size() > 0)
213 ret.resize(ret.size() - 2);
214 return ret;
215 }
216
217 arguments(int argc, const char** argv)
218 {
219 args::ArgumentParser parser("libremidi example");
220 args::HelpFlag help(parser, "help", "Display this help menu", {'h', "help"});
221
222 args::ValueFlag<std::string> opt_api(parser, "api", "API to use (" + api_list() + ")", {'a'});
223 args::ValueFlag<int> opt_port(parser, "input", "Input port to open", {'i'});
224 args::ValueFlag<int> opt_out_port(parser, "output", "Output port to open", {'o'});
225 args::ValueFlag<int> opt_count(parser, "count", "Number of bytes", {'n'});
226 args::Flag opt_virt(
227 parser, "virtual", "Open a virtual port instead of an existing one", {'v'});
228
229 args::CompletionFlag completion(parser, {"complete"});
230
231 try
232 {
233 parser.ParseCLI(argc, argv);
234 }
235 catch (args::Help)
236 {
237 std::cout << parser;
238 std::exit(1);
239 }
240 catch (args::ParseError e)
241 {
242 std::cerr << e.what() << std::endl;
243 std::cerr << parser;
244 std::exit(1);
245 }
246 catch (args::ValidationError e)
247 {
248 std::cerr << e.what() << std::endl;
249 std::cerr << parser;
250 std::exit(1);
251 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected