X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=session_utils%2Fcommon.cc;h=86e945f616387e190ef3f7708690f9babb8fb212;hb=5ada17eba0195d90f0685776251b384efdf5168e;hp=9353c760bdc07c1a4d67efb353808dc7691d037a;hpb=53d8b454579a2343c0976d9aafb3013e2a9d432a;p=ardour.git diff --git a/session_utils/common.cc b/session_utils/common.cc index 9353c760bd..86e945f616 100644 --- a/session_utils/common.cc +++ b/session_utils/common.cc @@ -86,7 +86,7 @@ class MyEventLoop : public sigc::trackable, public EventLoop static MyEventLoop *event_loop; void -SessionUtils::init () +SessionUtils::init (bool print_log) { if (!ARDOUR::init (false, true, localedir)) { cerr << "Ardour failed to initialize\n" << endl; @@ -97,10 +97,12 @@ SessionUtils::init () EventLoop::set_event_loop_for_thread (event_loop); SessionEvent::create_per_thread_pool ("util", 512); - test_receiver.listen_to (error); - test_receiver.listen_to (info); - test_receiver.listen_to (fatal); - test_receiver.listen_to (warning); + if (print_log) { + test_receiver.listen_to (error); + test_receiver.listen_to (info); + test_receiver.listen_to (fatal); + test_receiver.listen_to (warning); + } } // TODO return NULL, rather than exit() ?! @@ -113,25 +115,35 @@ static Session * _load_session (string dir, string state) ::exit (EXIT_FAILURE); } + engine->set_input_channels (256); + engine->set_output_channels (256); + 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"; - ::exit (EXIT_FAILURE); + return 0; } } else { std::cerr << "Cannot get samplerate from session.\n"; - ::exit (EXIT_FAILURE); + return 0; } init_post_engine (); if (engine->start () != 0) { std::cerr << "Cannot start Audio/MIDI engine\n"; - ::exit (EXIT_FAILURE); + return 0; } Session* session = new Session (*engine, dir, state); @@ -140,7 +152,7 @@ static Session * _load_session (string dir, string state) } Session * -SessionUtils::load_session (string dir, string state) +SessionUtils::load_session (string dir, string state, bool exit_at_failure) { Session* s = 0; try { @@ -158,9 +170,52 @@ SessionUtils::load_session (string dir, string state) cerr << "unknown exception.\n"; ::exit (EXIT_FAILURE); } + if (!s && exit_at_failure) { + ::exit (EXIT_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) {