2 * Copyright (C) 2014-2019 Paul Davis <paul@linuxaudiosystems.com>
3 * Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #ifndef PLATFORM_WINDOWS
30 #include "pbd/convert.h"
31 #include "pbd/crossthread.h"
32 #include "pbd/debug.h"
33 #include "pbd/error.h"
34 #include "pbd/failed_constructor.h"
36 #include "ardour/ardour.h"
37 #include "ardour/audioengine.h"
38 #include "ardour/revision.h"
39 #include "ardour/session.h"
41 #include "control_protocol/control_protocol.h"
46 using namespace ARDOUR;
49 static const char* localedir = LOCALEDIR;
51 static string backend_client_name;
52 static string backend_name = "JACK";
53 static CrossThreadChannel xthread (true);
54 static TestReceiver test_receiver;
56 /** @param dir Session directory.
57 * @param state Session state file, without .ardour suffix.
60 load_session (string dir, string state)
62 SessionEvent::create_per_thread_pool ("test", 512);
64 test_receiver.listen_to (error);
65 test_receiver.listen_to (info);
66 test_receiver.listen_to (fatal);
67 test_receiver.listen_to (warning);
69 AudioEngine* engine = AudioEngine::create ();
71 if (!engine->set_backend (backend_name, backend_client_name, "")) {
72 std::cerr << "Cannot set Audio/MIDI engine backend\n";
76 if (engine->start () != 0) {
77 std::cerr << "Cannot start Audio/MIDI engine\n";
81 Session* session = new Session (*engine, dir, state);
82 engine->set_session (session);
87 access_action (const std::string& action_group, const std::string& action_item)
89 if (action_group == "Common" && action_item == "Quit") {
90 xthread.deliver ('x');
95 engine_halted (const char* reason)
97 cerr << "The audio backend has been shutdown";
98 if (reason && strlen (reason) > 0) {
99 cerr << ": " << reason;
104 xthread.deliver ('x');
107 #ifndef PLATFORM_WINDOWS
111 cerr << "caught signal - terminating." << endl;
112 xthread.deliver ('x');
125 << " and GCC version " << __VERSION__
134 cout << "Usage: hardour [OPTIONS]... DIR SNAPSHOT_NAME\n\n"
135 << " DIR Directory/Folder to load session from\n"
136 << " SNAPSHOT_NAME Name of session/snapshot to load (without .ardour at end\n"
137 << " -v, --version Show version information\n"
138 << " -h, --help Print this message\n"
139 << " -c, --name <name> Use a specific backend client name, default is ardour\n"
140 << " -d, --disable-plugins Disable all plugins in an existing session\n"
141 << " -D, --debug <options> Set debug flags. Use \"-D list\" to see available options\n"
142 << " -O, --no-hw-optimizations Disable h/w specific optimizations\n"
143 << " -P, --no-connect-ports Do not connect any ports at startup\n"
144 #ifdef WINDOWS_VST_SUPPORT
145 << " -V, --novst Do not use VST support\n"
151 main (int argc, char* argv[])
153 const char* optstring = "vhBdD:c:VOU:P";
155 /* clang-format off */
156 const struct option longopts[] = {
157 { "version", no_argument, 0, 'v' },
158 { "help", no_argument, 0, 'h' },
159 { "bypass-plugins", no_argument, 0, 'B' },
160 { "disable-plugins", no_argument, 0, 'd' },
161 { "debug", required_argument, 0, 'D' },
162 { "name", required_argument, 0, 'c' },
163 { "novst", no_argument, 0, 'V' },
164 { "no-hw-optimizations", no_argument, 0, 'O' },
165 { "no-connect-ports", no_argument, 0, 'P' },
168 /* clang-format on */
171 bool try_hw_optimization = true;
173 backend_client_name = PBD::downcase (std::string (PROGRAM_NAME));
176 while ((c = getopt_long (argc, argv, optstring, longopts, (int*)0)) != EOF) {
192 backend_client_name = optarg;
196 ARDOUR::Session::set_bypass_all_loaded_plugins (true);
200 ARDOUR::Session::set_disable_all_loaded_plugins (true);
204 if (PBD::parse_debug_options (optarg)) {
210 try_hw_optimization = false;
214 ARDOUR::Port::set_connecting_blocked (true);
218 #ifdef WINDOWS_VST_SUPPORT
220 #endif /* WINDOWS_VST_SUPPORT */
234 if (!ARDOUR::init (use_vst, try_hw_optimization, localedir)) {
235 cerr << "Ardour failed to initialize\n"
243 s = load_session (argv[optind], argv[optind + 1]);
244 } catch (failed_constructor& e) {
245 cerr << "failed_constructor: " << e.what () << "\n";
247 } catch (AudioEngine::PortRegistrationFailure& e) {
248 cerr << "PortRegistrationFailure: " << e.what () << "\n";
250 } catch (exception& e) {
251 cerr << "exception: " << e.what () << "\n";
254 cerr << "unknown exception.\n";
258 /* allow signal propagation, callback/thread-pool setup, etc
259 * similar to to GUI "first idle"
261 Glib::usleep (1000000); // 1 sec
264 cerr << "failed_to load session\n";
268 PBD::ScopedConnectionList con;
269 BasicUI::AccessAction.connect_same_thread (con, boost::bind (&access_action, _1, _2));
270 AudioEngine::instance ()->Halted.connect_same_thread (con, boost::bind (&engine_halted, _1));
272 #ifndef PLATFORM_WINDOWS
273 signal (SIGINT, wearedone);
274 signal (SIGTERM, wearedone);
277 s->request_transport_speed (1.0);
281 } while (0 == xthread.receive (msg, true));
283 AudioEngine::instance ()->remove_session ();
285 AudioEngine::instance ()->stop ();
287 AudioEngine::destroy ();