summaryrefslogtreecommitdiff
path: root/luasession
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2020-04-29 20:15:22 +0200
committerRobin Gareus <robin@gareus.org>2020-04-29 20:15:22 +0200
commitb42c72e49f209b1cf6640913f2ac55cb7ff8cfd5 (patch)
tree202f12c4f23dcbf2e6bd31078dce0b7f1b3155a2 /luasession
parent551be058f24cd6aa9742ef2e7022a28f8c5a4c8e (diff)
Add "exit-when-halted" halted option for arlua
This is useful when when the ardour-lua is started by a command based wrapper that cannot poll the engine state.
Diffstat (limited to 'luasession')
-rw-r--r--luasession/luasession.cc37
1 files changed, 27 insertions, 10 deletions
diff --git a/luasession/luasession.cc b/luasession/luasession.cc
index 74bd2030bf..31da85e08a 100644
--- a/luasession/luasession.cc
+++ b/luasession/luasession.cc
@@ -50,7 +50,9 @@ static PBD::ScopedConnectionList engine_connections;
static PBD::ScopedConnectionList session_connections;
static Session* session = NULL;
static LuaState* lua;
-static bool keep_running = true;
+
+static bool keep_running = true;
+static bool terminate_when_halted = false;
/* extern VST functions */
int vstfx_init (void*) { return 0; }
@@ -83,9 +85,7 @@ protected:
}
/* note: iostreams are already thread-safe: no external
- lock required.
- */
-
+ * lock required. */
std::cout << prefix << str << std::endl;
if (chn == Transmitter::Fatal) {
@@ -139,8 +139,7 @@ static void
init ()
{
if (!ARDOUR::init (false, true, localedir)) {
- cerr << "Ardour failed to initialize\n"
- << endl;
+ cerr << "Ardour failed to initialize\n" << endl;
::exit (EXIT_FAILURE);
}
@@ -380,6 +379,15 @@ do_quit (lua_State* L)
return 0;
}
+static void
+engine_halted (const char* err)
+{
+ if (terminate_when_halted) {
+ cerr << "Engine halted: " << err << "\n";
+ ::exit (EXIT_FAILURE);
+ }
+}
+
/* ****************************************************************************/
static void
@@ -425,6 +433,8 @@ setup_lua ()
lua_setglobal (L, "AudioEngine");
AudioEngine::instance ()->stop ();
+
+ AudioEngine::instance()->Halted.connect_same_thread (engine_connections, boost::bind (&engine_halted, _1));
}
static int
@@ -523,6 +533,8 @@ usage ()
-h, --help display this help and exit\n\
-i, --interactive enter interactive mode after executing 'script',\n\
force the interpreter to run interactively\n\
+ -X, --exit-when-halted terminate when the audio-engine halts\n\
+ unexpectedly.\n\
-V, --version print version information and exit\n\
\n");
printf ("\n\
@@ -536,12 +548,13 @@ Ardour at your finger tips...\n\
int
main (int argc, char** argv)
{
- const char* optstring = "hiV";
+ const char* optstring = "hiVX";
const struct option longopts[] = {
- { "help", 0, 0, 'h' },
- { "interactive", 0, 0, 'i' },
- { "version", 0, 0, 'V' },
+ { "help", 0, 0, 'h' },
+ { "interactive", 0, 0, 'i' },
+ { "version", 0, 0, 'V' },
+ { "exit-when-halted", 0, 0, 'X' },
};
bool interactive = false;
@@ -564,6 +577,10 @@ main (int argc, char** argv)
exit (EXIT_SUCCESS);
break;
+ case 'X':
+ terminate_when_halted = true;
+ break;
+
default:
cerr << "Error: unrecognized option. See --help for usage information.\n";
::exit (EXIT_FAILURE);