6 #include "pbd/event_loop.h"
8 #include "pbd/failed_constructor.h"
9 #include "pbd/pthread_utils.h"
11 #include "ardour/audioengine.h"
16 using namespace ARDOUR;
19 static const char* localedir = LOCALEDIR;
20 TestReceiver test_receiver;
23 TestReceiver::receive (Transmitter::Channel chn, const char * str)
25 const char *prefix = "";
28 case Transmitter::Error:
29 prefix = ": [ERROR]: ";
31 case Transmitter::Info:
34 case Transmitter::Warning:
35 prefix = ": [WARNING]: ";
37 case Transmitter::Fatal:
38 prefix = ": [FATAL]: ";
40 case Transmitter::Throw:
41 /* this isn't supposed to happen */
45 /* note: iostreams are already thread-safe: no external
49 std::cout << prefix << str << std::endl;
51 if (chn == Transmitter::Fatal) {
56 /* temporarily required due to some code design confusion (Feb 2014) */
58 #include "ardour/vst_types.h"
60 int vstfx_init (void*) { return 0; }
62 void vstfx_destroy_editor (VSTState*) {}
64 class MyEventLoop : public sigc::trackable, public EventLoop
67 MyEventLoop (std::string const& name) : EventLoop (name) {
68 run_loop_thread = Glib::Threads::Thread::self();
71 void call_slot (InvalidationRecord*, const boost::function<void()>& f) {
72 if (Glib::Threads::Thread::self() == run_loop_thread) {
77 Glib::Threads::Mutex& slot_invalidation_mutex() { return request_buffer_map_lock; }
80 Glib::Threads::Thread* run_loop_thread;
81 Glib::Threads::Mutex request_buffer_map_lock;
84 static MyEventLoop *event_loop;
89 if (!ARDOUR::init (false, true, localedir)) {
90 cerr << "Ardour failed to initialize\n" << endl;
94 event_loop = new MyEventLoop ("util");
95 EventLoop::set_event_loop_for_thread (event_loop);
96 SessionEvent::create_per_thread_pool ("util", 512);
98 test_receiver.listen_to (error);
99 test_receiver.listen_to (info);
100 test_receiver.listen_to (fatal);
101 test_receiver.listen_to (warning);
104 static Session * _load_session (string dir, string state)
106 AudioEngine* engine = AudioEngine::create ();
108 if (!engine->set_backend ("None (Dummy)", "Unit-Test", "")) {
109 std::cerr << "Cannot create Audio/MIDI engine\n";
110 ::exit (EXIT_FAILURE);
115 if (engine->start () != 0) {
116 std::cerr << "Cannot start Audio/MIDI engine\n";
117 ::exit (EXIT_FAILURE);
120 Session* session = new Session (*engine, dir, state);
121 engine->set_session (session);
126 SessionUtils::load_session (string dir, string state)
130 s = _load_session (dir, state);
131 } catch (failed_constructor& e) {
132 cerr << "failed_constructor: " << e.what() << "\n";
134 } catch (AudioEngine::PortRegistrationFailure& e) {
135 cerr << "PortRegistrationFailure: " << e.what() << "\n";
137 } catch (exception& e) {
138 cerr << "exception: " << e.what() << "\n";
141 cerr << "unknown exception.\n";
148 SessionUtils::unload_session (Session *s)
151 AudioEngine::instance()->stop ();
152 AudioEngine::destroy ();
156 SessionUtils::cleanup ()
160 pthread_cancel_all ();