use new action map API instead of ActionManager::get_action
[ardour.git] / session_utils / common.cc
index 61a3a69f65a1dd809ed5c03cb67158d3342886f3..86e945f616387e190ef3f7708690f9babb8fb212 100644 (file)
@@ -77,12 +77,10 @@ class MyEventLoop : public sigc::trackable, public EventLoop
                }
 
                Glib::Threads::Mutex& slot_invalidation_mutex() { return request_buffer_map_lock; }
-               Glib::Threads::Mutex& request_invalidation_mutex() { return request_invalidation_lock; }
 
        private:
                Glib::Threads::Thread* run_loop_thread;
                Glib::Threads::Mutex   request_buffer_map_lock;
-               Glib::Threads::Mutex   request_invalidation_lock;
 };
 
 static MyEventLoop *event_loop;
@@ -122,9 +120,16 @@ static Session * _load_session (string dir, string state)
 
        float sr;
        SampleFormat sf;
+       std::string v;
 
        std::string s = Glib::build_filename (dir, state + statefile_suffix);
-       if (Session::get_info_from_path (s, sr, sf) == 0) {
+
+       if (!Glib::file_test (s, Glib::FILE_TEST_EXISTS | Glib::FILE_TEST_IS_REGULAR)) {
+               std::cerr << "Cannot read session '"<< s << "'\n";
+               return 0;
+       }
+
+       if (Session::get_info_from_path (s, sr, sf, v) == 0) {
                if (engine->set_sample_rate (sr)) {
                        std::cerr << "Cannot set session's samplerate.\n";
                        return 0;
@@ -171,6 +176,46 @@ SessionUtils::load_session (string dir, string state, bool exit_at_failure)
        return s;
 }
 
+Session *
+SessionUtils::create_session (string dir, string state, float sample_rate)
+{
+       AudioEngine* engine = AudioEngine::create ();
+
+       if (!engine->set_backend ("None (Dummy)", "Unit-Test", "")) {
+               std::cerr << "Cannot create Audio/MIDI engine\n";
+               ::exit (EXIT_FAILURE);
+       }
+
+       engine->set_input_channels (256);
+       engine->set_output_channels (256);
+
+       if (engine->set_sample_rate (sample_rate)) {
+               std::cerr << "Cannot set session's samplerate.\n";
+               return 0;
+       }
+
+       init_post_engine ();
+
+       if (engine->start () != 0) {
+               std::cerr << "Cannot start Audio/MIDI engine\n";
+               return 0;
+       }
+
+       std::string s = Glib::build_filename (dir, state + statefile_suffix);
+
+       if (Glib::file_test (dir, Glib::FILE_TEST_EXISTS)) {
+               std::cerr << "Session folder already exists '"<< dir << "'\n";
+       }
+       if (Glib::file_test (s, Glib::FILE_TEST_EXISTS)) {
+               std::cerr << "Session file exists '"<< s << "'\n";
+               return 0;
+       }
+
+       Session* session = new Session (*engine, dir, state);
+       engine->set_session (session);
+       return session;
+}
+
 void
 SessionUtils::unload_session (Session *s)
 {