5 #ifndef PLATFORM_WINDOWS
11 #include "pbd/convert.h"
12 #include "pbd/crossthread.h"
13 #include "pbd/debug.h"
14 #include "pbd/error.h"
15 #include "pbd/failed_constructor.h"
17 #include "ardour/ardour.h"
18 #include "ardour/audioengine.h"
19 #include "ardour/revision.h"
20 #include "ardour/session.h"
22 #include "control_protocol/control_protocol.h"
27 using namespace ARDOUR;
30 static const char* localedir = LOCALEDIR;
32 static string backend_client_name;
33 static string backend_name = "JACK";
34 static CrossThreadChannel xthread (true);
35 static TestReceiver test_receiver;
37 /** @param dir Session directory.
38 * @param state Session state file, without .ardour suffix.
41 load_session (string dir, string state)
43 SessionEvent::create_per_thread_pool ("test", 512);
45 test_receiver.listen_to (error);
46 test_receiver.listen_to (info);
47 test_receiver.listen_to (fatal);
48 test_receiver.listen_to (warning);
50 AudioEngine* engine = AudioEngine::create ();
52 if (!engine->set_backend (backend_name, backend_client_name, "")) {
53 std::cerr << "Cannot set Audio/MIDI engine backend\n";
57 if (engine->start () != 0) {
58 std::cerr << "Cannot start Audio/MIDI engine\n";
62 Session* session = new Session (*engine, dir, state);
63 engine->set_session (session);
68 access_action (const std::string& action_group, const std::string& action_item)
70 if (action_group == "Common" && action_item == "Quit") {
71 xthread.deliver ('x');
76 engine_halted (const char* reason)
78 cerr << "The audio backend has been shutdown";
79 if (reason && strlen (reason) > 0) {
80 cerr << ": " << reason;
85 xthread.deliver ('x');
88 #ifndef PLATFORM_WINDOWS
92 cerr << "caught signal - terminating." << endl;
93 xthread.deliver ('x');
106 << " and GCC version " << __VERSION__
115 cout << "Usage: hardour [OPTIONS]... DIR SNAPSHOT_NAME\n\n"
116 << " DIR Directory/Folder to load session from\n"
117 << " SNAPSHOT_NAME Name of session/snapshot to load (without .ardour at end\n"
118 << " -v, --version Show version information\n"
119 << " -h, --help Print this message\n"
120 << " -c, --name <name> Use a specific backend client name, default is ardour\n"
121 << " -d, --disable-plugins Disable all plugins in an existing session\n"
122 << " -D, --debug <options> Set debug flags. Use \"-D list\" to see available options\n"
123 << " -O, --no-hw-optimizations Disable h/w specific optimizations\n"
124 << " -P, --no-connect-ports Do not connect any ports at startup\n"
125 #ifdef WINDOWS_VST_SUPPORT
126 << " -V, --novst Do not use VST support\n"
132 main (int argc, char* argv[])
134 const char* optstring = "vhBdD:c:VOU:P";
136 /* clang-format off */
137 const struct option longopts[] = {
138 { "version", no_argument, 0, 'v' },
139 { "help", no_argument, 0, 'h' },
140 { "bypass-plugins", no_argument, 0, 'B' },
141 { "disable-plugins", no_argument, 0, 'd' },
142 { "debug", required_argument, 0, 'D' },
143 { "name", required_argument, 0, 'c' },
144 { "novst", no_argument, 0, 'V' },
145 { "no-hw-optimizations", no_argument, 0, 'O' },
146 { "no-connect-ports", no_argument, 0, 'P' },
149 /* clang-format on */
152 bool try_hw_optimization = true;
154 backend_client_name = PBD::downcase (std::string (PROGRAM_NAME));
157 while ((c = getopt_long (argc, argv, optstring, longopts, (int*)0)) != EOF) {
173 backend_client_name = optarg;
177 ARDOUR::Session::set_bypass_all_loaded_plugins (true);
181 ARDOUR::Session::set_disable_all_loaded_plugins (true);
185 if (PBD::parse_debug_options (optarg)) {
191 try_hw_optimization = false;
195 ARDOUR::Port::set_connecting_blocked (true);
199 #ifdef WINDOWS_VST_SUPPORT
201 #endif /* WINDOWS_VST_SUPPORT */
215 if (!ARDOUR::init (use_vst, try_hw_optimization, localedir)) {
216 cerr << "Ardour failed to initialize\n"
224 s = load_session (argv[optind], argv[optind + 1]);
225 } catch (failed_constructor& e) {
226 cerr << "failed_constructor: " << e.what () << "\n";
228 } catch (AudioEngine::PortRegistrationFailure& e) {
229 cerr << "PortRegistrationFailure: " << e.what () << "\n";
231 } catch (exception& e) {
232 cerr << "exception: " << e.what () << "\n";
235 cerr << "unknown exception.\n";
239 /* allow signal propagation, callback/thread-pool setup, etc
240 * similar to to GUI "first idle"
242 Glib::usleep (1000000); // 1 sec
245 cerr << "failed_to load session\n";
249 PBD::ScopedConnectionList con;
250 BasicUI::AccessAction.connect_same_thread (con, boost::bind (&access_action, _1, _2));
251 AudioEngine::instance ()->Halted.connect_same_thread (con, boost::bind (&engine_halted, _1));
253 #ifndef PLATFORM_WINDOWS
254 signal (SIGINT, wearedone);
255 signal (SIGTERM, wearedone);
258 s->request_transport_speed (1.0);
262 } while (0 == xthread.receive (msg, true));
264 AudioEngine::instance ()->remove_session ();
266 AudioEngine::instance ()->stop ();
268 AudioEngine::destroy ();