2019-08-03 09:48:50 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014-2019 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2014-02-24 13:49:58 -05:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <getopt.h>
|
2019-07-04 16:35:07 -04:00
|
|
|
#include <iostream>
|
2014-02-24 13:49:58 -05:00
|
|
|
|
2019-07-04 16:02:52 -04:00
|
|
|
#ifndef PLATFORM_WINDOWS
|
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
|
|
|
|
2019-07-02 14:14:27 -04:00
|
|
|
#include <glibmm.h>
|
|
|
|
|
|
|
|
#include "pbd/convert.h"
|
2019-07-04 16:02:52 -04:00
|
|
|
#include "pbd/crossthread.h"
|
2014-02-24 13:49:58 -05:00
|
|
|
#include "pbd/debug.h"
|
2019-07-04 16:35:07 -04:00
|
|
|
#include "pbd/error.h"
|
|
|
|
#include "pbd/failed_constructor.h"
|
2014-02-24 13:49:58 -05:00
|
|
|
|
|
|
|
#include "ardour/ardour.h"
|
|
|
|
#include "ardour/audioengine.h"
|
2019-07-02 14:14:27 -04:00
|
|
|
#include "ardour/revision.h"
|
2014-02-24 13:49:58 -05:00
|
|
|
#include "ardour/session.h"
|
|
|
|
|
2019-07-02 14:14:27 -04:00
|
|
|
#include "control_protocol/control_protocol.h"
|
|
|
|
|
2014-02-24 13:49:58 -05:00
|
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace ARDOUR;
|
|
|
|
using namespace PBD;
|
|
|
|
|
|
|
|
static const char* localedir = LOCALEDIR;
|
|
|
|
|
2019-07-04 16:35:07 -04:00
|
|
|
static string backend_client_name;
|
2019-07-04 16:02:52 -04:00
|
|
|
static CrossThreadChannel xthread (true);
|
2019-07-04 16:35:07 -04:00
|
|
|
static TestReceiver test_receiver;
|
2014-02-24 13:49:58 -05:00
|
|
|
|
2024-07-30 22:44:04 -04:00
|
|
|
#if ! (defined(__APPLE__) || defined(PLATFORM_WINDOWS))
|
|
|
|
static string backend_name = "JACK/Pipewire";
|
|
|
|
#else
|
|
|
|
static string backend_name = "JACK";
|
|
|
|
#endif
|
|
|
|
|
2014-02-24 13:49:58 -05:00
|
|
|
/** @param dir Session directory.
|
|
|
|
* @param state Session state file, without .ardour suffix.
|
|
|
|
*/
|
2019-07-04 16:35:07 -04:00
|
|
|
static Session*
|
2014-02-24 13:49:58 -05:00
|
|
|
load_session (string dir, string state)
|
|
|
|
{
|
|
|
|
SessionEvent::create_per_thread_pool ("test", 512);
|
|
|
|
|
2020-10-13 15:46:52 -04:00
|
|
|
test_receiver.listen_to (warning);
|
2014-02-24 13:49:58 -05:00
|
|
|
test_receiver.listen_to (error);
|
|
|
|
test_receiver.listen_to (fatal);
|
|
|
|
|
|
|
|
AudioEngine* engine = AudioEngine::create ();
|
|
|
|
|
2019-07-02 14:14:27 -04:00
|
|
|
if (!engine->set_backend (backend_name, backend_client_name, "")) {
|
|
|
|
std::cerr << "Cannot set Audio/MIDI engine backend\n";
|
2019-07-04 16:21:14 -04:00
|
|
|
exit (EXIT_FAILURE);
|
2014-02-24 13:49:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (engine->start () != 0) {
|
|
|
|
std::cerr << "Cannot start Audio/MIDI engine\n";
|
2019-07-04 16:21:14 -04:00
|
|
|
exit (EXIT_FAILURE);
|
2014-02-24 13:49:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Session* session = new Session (*engine, dir, state);
|
|
|
|
engine->set_session (session);
|
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
2019-07-02 14:14:27 -04:00
|
|
|
static void
|
|
|
|
access_action (const std::string& action_group, const std::string& action_item)
|
|
|
|
{
|
|
|
|
if (action_group == "Common" && action_item == "Quit") {
|
2019-07-04 16:02:52 -04:00
|
|
|
xthread.deliver ('x');
|
2019-07-02 14:14:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
engine_halted (const char* reason)
|
|
|
|
{
|
2019-07-04 16:02:52 -04:00
|
|
|
cerr << "The audio backend has been shutdown";
|
2019-07-02 14:14:27 -04:00
|
|
|
if (reason && strlen (reason) > 0) {
|
|
|
|
cerr << ": " << reason;
|
|
|
|
} else {
|
|
|
|
cerr << ".";
|
|
|
|
}
|
|
|
|
cerr << endl;
|
2019-07-04 16:02:52 -04:00
|
|
|
xthread.deliver ('x');
|
2019-07-02 14:14:27 -04:00
|
|
|
}
|
2014-02-24 13:49:58 -05:00
|
|
|
|
2019-07-04 16:02:52 -04:00
|
|
|
#ifndef PLATFORM_WINDOWS
|
2019-07-04 16:35:07 -04:00
|
|
|
static void
|
|
|
|
wearedone (int)
|
|
|
|
{
|
2019-07-04 16:02:52 -04:00
|
|
|
cerr << "caught signal - terminating." << endl;
|
|
|
|
xthread.deliver ('x');
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-07-02 14:14:27 -04:00
|
|
|
static void
|
|
|
|
print_version ()
|
|
|
|
{
|
|
|
|
cout
|
2019-07-04 16:35:07 -04:00
|
|
|
<< PROGRAM_NAME
|
|
|
|
<< VERSIONSTRING
|
|
|
|
<< " (built using "
|
|
|
|
<< ARDOUR::revision
|
2019-07-02 14:14:27 -04:00
|
|
|
#ifdef __GNUC__
|
2019-07-04 16:35:07 -04:00
|
|
|
<< " and GCC version " << __VERSION__
|
2019-07-02 14:14:27 -04:00
|
|
|
#endif
|
2019-07-04 16:35:07 -04:00
|
|
|
<< ')'
|
|
|
|
<< endl;
|
2019-07-02 14:14:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-02-24 13:49:58 -05:00
|
|
|
print_help ()
|
|
|
|
{
|
|
|
|
cout << "Usage: hardour [OPTIONS]... DIR SNAPSHOT_NAME\n\n"
|
|
|
|
<< " DIR Directory/Folder to load session from\n"
|
|
|
|
<< " SNAPSHOT_NAME Name of session/snapshot to load (without .ardour at end\n"
|
|
|
|
<< " -v, --version Show version information\n"
|
|
|
|
<< " -h, --help Print this message\n"
|
|
|
|
<< " -c, --name <name> Use a specific backend client name, default is ardour\n"
|
|
|
|
<< " -d, --disable-plugins Disable all plugins in an existing session\n"
|
|
|
|
<< " -D, --debug <options> Set debug flags. Use \"-D list\" to see available options\n"
|
|
|
|
<< " -O, --no-hw-optimizations Disable h/w specific optimizations\n"
|
|
|
|
<< " -P, --no-connect-ports Do not connect any ports at startup\n"
|
|
|
|
#ifdef WINDOWS_VST_SUPPORT
|
|
|
|
<< " -V, --novst Do not use VST support\n"
|
|
|
|
#endif
|
2019-07-04 16:35:07 -04:00
|
|
|
;
|
2014-02-24 13:49:58 -05:00
|
|
|
}
|
|
|
|
|
2019-07-04 16:35:07 -04:00
|
|
|
int
|
|
|
|
main (int argc, char* argv[])
|
2014-02-24 13:49:58 -05:00
|
|
|
{
|
2021-08-10 09:54:37 -04:00
|
|
|
const char* optstring = "vhBdD:c:OU:P";
|
2014-02-24 13:49:58 -05:00
|
|
|
|
2019-07-04 16:35:07 -04:00
|
|
|
/* clang-format off */
|
2014-02-24 13:49:58 -05:00
|
|
|
const struct option longopts[] = {
|
2019-07-04 16:34:04 -04:00
|
|
|
{ "version", no_argument, 0, 'v' },
|
|
|
|
{ "help", no_argument, 0, 'h' },
|
|
|
|
{ "bypass-plugins", no_argument, 0, 'B' },
|
|
|
|
{ "disable-plugins", no_argument, 0, 'd' },
|
|
|
|
{ "debug", required_argument, 0, 'D' },
|
|
|
|
{ "name", required_argument, 0, 'c' },
|
|
|
|
{ "no-hw-optimizations", no_argument, 0, 'O' },
|
|
|
|
{ "no-connect-ports", no_argument, 0, 'P' },
|
2014-02-24 13:49:58 -05:00
|
|
|
{ 0, 0, 0, 0 }
|
|
|
|
};
|
2019-07-04 16:35:07 -04:00
|
|
|
/* clang-format on */
|
2014-02-24 13:49:58 -05:00
|
|
|
|
2019-07-02 14:14:27 -04:00
|
|
|
bool try_hw_optimization = true;
|
|
|
|
|
2019-07-04 16:35:07 -04:00
|
|
|
backend_client_name = PBD::downcase (std::string (PROGRAM_NAME));
|
2014-02-24 13:49:58 -05:00
|
|
|
|
2019-07-04 16:34:04 -04:00
|
|
|
int c;
|
|
|
|
while ((c = getopt_long (argc, argv, optstring, longopts, (int*)0)) != EOF) {
|
2014-02-24 13:49:58 -05:00
|
|
|
switch (c) {
|
2019-07-04 16:35:07 -04:00
|
|
|
case 0:
|
|
|
|
break;
|
2014-02-24 13:49:58 -05:00
|
|
|
|
2019-07-04 16:35:07 -04:00
|
|
|
case 'v':
|
|
|
|
print_version ();
|
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
break;
|
2014-02-24 13:49:58 -05:00
|
|
|
|
2019-07-04 16:35:07 -04:00
|
|
|
case 'h':
|
|
|
|
print_help ();
|
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
break;
|
2014-02-24 13:49:58 -05:00
|
|
|
|
2019-07-04 16:35:07 -04:00
|
|
|
case 'c':
|
|
|
|
backend_client_name = optarg;
|
|
|
|
break;
|
2014-02-24 13:49:58 -05:00
|
|
|
|
2019-07-04 16:35:07 -04:00
|
|
|
case 'B':
|
|
|
|
ARDOUR::Session::set_bypass_all_loaded_plugins (true);
|
|
|
|
break;
|
2015-09-01 07:27:48 -04:00
|
|
|
|
2019-07-04 16:35:07 -04:00
|
|
|
case 'd':
|
|
|
|
ARDOUR::Session::set_disable_all_loaded_plugins (true);
|
|
|
|
break;
|
2014-02-24 13:49:58 -05:00
|
|
|
|
2019-07-04 16:35:07 -04:00
|
|
|
case 'D':
|
|
|
|
if (PBD::parse_debug_options (optarg)) {
|
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
break;
|
2014-02-24 13:49:58 -05:00
|
|
|
|
2019-07-04 16:35:07 -04:00
|
|
|
case 'O':
|
|
|
|
try_hw_optimization = false;
|
|
|
|
break;
|
2014-02-24 13:49:58 -05:00
|
|
|
|
2019-07-04 16:35:07 -04:00
|
|
|
case 'P':
|
|
|
|
ARDOUR::Port::set_connecting_blocked (true);
|
|
|
|
break;
|
2014-02-24 13:49:58 -05:00
|
|
|
|
2019-07-04 16:35:07 -04:00
|
|
|
default:
|
|
|
|
print_help ();
|
|
|
|
exit (EXIT_FAILURE);
|
2014-02-24 13:49:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (argc < 3) {
|
|
|
|
print_help ();
|
2019-07-04 16:21:14 -04:00
|
|
|
exit (EXIT_FAILURE);
|
2014-02-24 13:49:58 -05:00
|
|
|
}
|
|
|
|
|
2021-08-10 09:54:37 -04:00
|
|
|
if (!ARDOUR::init (try_hw_optimization, localedir)) {
|
2019-07-04 16:35:07 -04:00
|
|
|
cerr << "Ardour failed to initialize\n"
|
|
|
|
<< endl;
|
2019-07-04 16:21:14 -04:00
|
|
|
exit (EXIT_FAILURE);
|
2014-02-24 13:49:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Session* s = 0;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-02-24 13:49:58 -05:00
|
|
|
try {
|
2019-07-04 16:35:07 -04:00
|
|
|
s = load_session (argv[optind], argv[optind + 1]);
|
2014-02-24 13:49:58 -05:00
|
|
|
} catch (failed_constructor& e) {
|
2019-07-04 16:35:07 -04:00
|
|
|
cerr << "failed_constructor: " << e.what () << "\n";
|
2014-02-24 13:49:58 -05:00
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
} catch (AudioEngine::PortRegistrationFailure& e) {
|
2019-07-04 16:35:07 -04:00
|
|
|
cerr << "PortRegistrationFailure: " << e.what () << "\n";
|
2014-02-24 13:49:58 -05:00
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
} catch (exception& e) {
|
2019-07-04 16:35:07 -04:00
|
|
|
cerr << "exception: " << e.what () << "\n";
|
2014-02-24 13:49:58 -05:00
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
} catch (...) {
|
|
|
|
cerr << "unknown exception.\n";
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2019-07-04 16:22:27 -04:00
|
|
|
/* allow signal propagation, callback/thread-pool setup, etc
|
|
|
|
* similar to to GUI "first idle"
|
|
|
|
*/
|
|
|
|
Glib::usleep (1000000); // 1 sec
|
|
|
|
|
|
|
|
if (!s) {
|
|
|
|
cerr << "failed_to load session\n";
|
|
|
|
exit (EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2019-07-02 14:14:27 -04:00
|
|
|
PBD::ScopedConnectionList con;
|
|
|
|
BasicUI::AccessAction.connect_same_thread (con, boost::bind (&access_action, _1, _2));
|
2019-07-04 16:35:07 -04:00
|
|
|
AudioEngine::instance ()->Halted.connect_same_thread (con, boost::bind (&engine_halted, _1));
|
2019-07-02 14:14:27 -04:00
|
|
|
|
2019-07-04 16:02:52 -04:00
|
|
|
#ifndef PLATFORM_WINDOWS
|
2019-07-04 16:35:07 -04:00
|
|
|
signal (SIGINT, wearedone);
|
|
|
|
signal (SIGTERM, wearedone);
|
2019-07-04 16:02:52 -04:00
|
|
|
#endif
|
|
|
|
|
2021-04-17 15:29:00 -04:00
|
|
|
s->request_roll ();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2019-07-04 16:02:52 -04:00
|
|
|
char msg;
|
2019-07-04 16:35:07 -04:00
|
|
|
do {
|
|
|
|
} while (0 == xthread.receive (msg, true));
|
2014-02-24 13:49:58 -05:00
|
|
|
|
2019-07-04 16:35:07 -04:00
|
|
|
AudioEngine::instance ()->remove_session ();
|
2014-02-24 13:49:58 -05:00
|
|
|
delete s;
|
2019-07-04 16:35:07 -04:00
|
|
|
AudioEngine::instance ()->stop ();
|
2014-02-24 13:49:58 -05:00
|
|
|
|
2023-06-30 14:58:43 -04:00
|
|
|
ARDOUR::cleanup ();
|
2014-02-24 13:49:58 -05:00
|
|
|
return 0;
|
|
|
|
}
|