From 88f8fa7d75d53e5b582350af26c2704db3b11501 Mon Sep 17 00:00:00 2001 From: Robert Bendun Date: Sat, 14 Jan 2023 23:01:51 +0100 Subject: [PATCH] remove unnesesary commandline params; :ports command --- CHANGELOG.md | 2 ++ musique/main.cc | 37 ++++++++++++------------------------- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d64d89e..2452534 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Printing version number on non-quiet launch, or when provided `--version` or `:version` - Builtin function documentation generation from C++ Musique implementation source code - New builtins: digits +- Connection with MIDI ports via parameters dropped in favour of function using context system: `port` +- Listing ports via REPL command: `:ports` instead of commandline parameter ### Removed diff --git a/musique/main.cc b/musique/main.cc index d6dbe2d..39bf64d 100644 --- a/musique/main.cc +++ b/musique/main.cc @@ -68,11 +68,6 @@ static T pop(std::span &span) "usage: musique [filename]\n" " where filename is path to file with Musique code that will be executed\n" " where options are:\n" - " -o,--output PORT\n" - " provides output port, a place where Musique produces MIDI messages\n" - " -l,--list\n" - " lists all available MIDI ports and quit\n" - "\n" " -c,--run CODE\n" " executes given code\n" " -I,--interactive,--repl\n" @@ -101,6 +96,7 @@ void print_repl_help() ":! - allows for execution of any shell command\n" ":clear - clears screen\n" ":load - loads file into Musique session\n" + ":ports - print list available ports" ; } @@ -163,13 +159,13 @@ struct Runner Interpreter interpreter; /// Setup interpreter and midi connection with given port - explicit Runner(std::optional output_port) + explicit Runner() : interpreter{} { ensure(the == nullptr, "Only one instance of runner is supported"); the = this; - interpreter.current_context->connect(output_port); + interpreter.current_context->connect(std::nullopt); Env::global->force_define("say", +[](Interpreter &interpreter, std::vector args) -> Result { for (auto it = args.begin(); it != args.end(); ++it) { @@ -313,6 +309,14 @@ static Result handle_repl_session_commands(std::string_view input, Runner return std::nullopt; } }, + + Command { + "ports", + +[](Runner&, std::optional) -> std::optional { + midi::Rt_Midi{}.list_ports(std::cout); + return {}; + }, + }, }; if (input.starts_with('!')) { @@ -357,9 +361,6 @@ static std::optional Main(std::span args) std::string_view argument; }; - // Arbitraly chosen for conviniance of the author - std::optional output_port{}; - std::vector runnables; while (not args.empty()) { @@ -370,11 +371,6 @@ static std::optional Main(std::span args) continue; } - if (arg == "-l" || arg == "--list") { - midi::Rt_Midi{}.list_ports(std::cout); - return {}; - } - if (arg == "-c" || arg == "--run") { if (args.empty()) { std::cerr << "musique: error: option " << arg << " requires an argument" << std::endl; @@ -407,15 +403,6 @@ static std::optional Main(std::span args) continue; } - if (arg == "-o" || arg == "--output") { - if (args.empty()) { - std::cerr << "musique: error: option " << arg << " requires an argument" << std::endl; - std::exit(1); - } - output_port = pop(args); - continue; - } - if (arg == "-h" || arg == "--help") { usage(); } @@ -424,7 +411,7 @@ static std::optional Main(std::span args) std::exit(1); } - Runner runner{output_port}; + Runner runner; for (auto const& [type, argument] : runnables) { if (type == Run::Argument) {