6 #include "pbd/event_loop.h"
8 #include "pbd/failed_constructor.h"
9 #include "pbd/pthread_utils.h"
11 #include "ardour/audioengine.h"
12 #include "ardour/filename_extensions.h"
13 #include "ardour/types.h"
18 using namespace ARDOUR;
21 static const char* localedir = LOCALEDIR;
22 TestReceiver test_receiver;
25 TestReceiver::receive (Transmitter::Channel chn, const char * str)
27 const char *prefix = "";
30 case Transmitter::Error:
31 prefix = ": [ERROR]: ";
33 case Transmitter::Info:
36 case Transmitter::Warning:
37 prefix = ": [WARNING]: ";
39 case Transmitter::Fatal:
40 prefix = ": [FATAL]: ";
42 case Transmitter::Throw:
43 /* this isn't supposed to happen */
47 /* note: iostreams are already thread-safe: no external
51 std::cout << prefix << str << std::endl;
53 if (chn == Transmitter::Fatal) {
58 /* temporarily required due to some code design confusion (Feb 2014) */
60 #include "ardour/vst_types.h"
62 int vstfx_init (void*) { return 0; }
64 void vstfx_destroy_editor (VSTState*) {}
66 class MyEventLoop : public sigc::trackable, public EventLoop
69 MyEventLoop (std::string const& name) : EventLoop (name) {
70 run_loop_thread = Glib::Threads::Thread::self();
73 void call_slot (InvalidationRecord*, const boost::function<void()>& f) {
74 if (Glib::Threads::Thread::self() == run_loop_thread) {
79 Glib::Threads::Mutex& slot_invalidation_mutex() { return request_buffer_map_lock; }
82 Glib::Threads::Thread* run_loop_thread;
83 Glib::Threads::Mutex request_buffer_map_lock;
86 static MyEventLoop *event_loop;
89 SessionUtils::init (bool print_log)
91 if (!ARDOUR::init (false, true, localedir)) {
92 cerr << "Ardour failed to initialize\n" << endl;
93 ::exit (EXIT_FAILURE);
96 event_loop = new MyEventLoop ("util");
97 EventLoop::set_event_loop_for_thread (event_loop);
98 SessionEvent::create_per_thread_pool ("util", 512);
101 test_receiver.listen_to (error);
102 test_receiver.listen_to (info);
103 test_receiver.listen_to (fatal);
104 test_receiver.listen_to (warning);
108 // TODO return NULL, rather than exit() ?!
109 static Session * _load_session (string dir, string state)
111 AudioEngine* engine = AudioEngine::create ();
113 if (!engine->set_backend ("None (Dummy)", "Unit-Test", "")) {
114 std::cerr << "Cannot create Audio/MIDI engine\n";
115 ::exit (EXIT_FAILURE);
118 engine->set_input_channels (256);
119 engine->set_output_channels (256);
125 std::string s = Glib::build_filename (dir, state + statefile_suffix);
126 if (Session::get_info_from_path (s, sr, sf, v) == 0) {
127 if (engine->set_sample_rate (sr)) {
128 std::cerr << "Cannot set session's samplerate.\n";
132 std::cerr << "Cannot get samplerate from session.\n";
138 if (engine->start () != 0) {
139 std::cerr << "Cannot start Audio/MIDI engine\n";
143 Session* session = new Session (*engine, dir, state);
144 engine->set_session (session);
149 SessionUtils::load_session (string dir, string state, bool exit_at_failure)
153 s = _load_session (dir, state);
154 } catch (failed_constructor& e) {
155 cerr << "failed_constructor: " << e.what() << "\n";
156 ::exit (EXIT_FAILURE);
157 } catch (AudioEngine::PortRegistrationFailure& e) {
158 cerr << "PortRegistrationFailure: " << e.what() << "\n";
159 ::exit (EXIT_FAILURE);
160 } catch (exception& e) {
161 cerr << "exception: " << e.what() << "\n";
162 ::exit (EXIT_FAILURE);
164 cerr << "unknown exception.\n";
165 ::exit (EXIT_FAILURE);
167 if (!s && exit_at_failure) {
168 ::exit (EXIT_FAILURE);
174 SessionUtils::unload_session (Session *s)
177 AudioEngine::instance()->stop ();
178 AudioEngine::destroy ();
182 SessionUtils::cleanup ()
186 pthread_cancel_all ();