Fix 64bit OSX/MacOS builds
[ardour.git] / session_utils / common.cc
index eb17cfdbeb21e0b4a76d04d1006a201945b04f29..3d197181cd037d756200c26682962692055fff80 100644 (file)
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2015-2017 Robin Gareus <robin@gareus.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
 #include <iostream>
 #include <cstdlib>
 #include <glibmm.h>
@@ -139,8 +157,6 @@ static Session * _load_session (string dir, string state)
                return 0;
        }
 
-       init_post_engine ();
-
        if (engine->start () != 0) {
                std::cerr << "Cannot start Audio/MIDI engine\n";
                return 0;
@@ -176,6 +192,44 @@ 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;
+       }
+
+       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)
 {