13
0

session-utils: use session's sample-rate

This commit is contained in:
Robin Gareus 2015-12-16 18:46:44 +01:00
parent 8bb4ac0ac7
commit 53d8b45457

View File

@ -1,6 +1,6 @@
#include <iostream>
#include <cstdlib>
#include <glibmm.h>
#include "pbd/debug.h"
#include "pbd/event_loop.h"
@ -9,6 +9,8 @@
#include "pbd/pthread_utils.h"
#include "ardour/audioengine.h"
#include "ardour/filename_extensions.h"
#include "ardour/types.h"
#include "common.h"
@ -88,7 +90,7 @@ SessionUtils::init ()
{
if (!ARDOUR::init (false, true, localedir)) {
cerr << "Ardour failed to initialize\n" << endl;
::exit (1);
::exit (EXIT_FAILURE);
}
event_loop = new MyEventLoop ("util");
@ -101,6 +103,7 @@ SessionUtils::init ()
test_receiver.listen_to (warning);
}
// TODO return NULL, rather than exit() ?!
static Session * _load_session (string dir, string state)
{
AudioEngine* engine = AudioEngine::create ();
@ -110,6 +113,20 @@ static Session * _load_session (string dir, string state)
::exit (EXIT_FAILURE);
}
float sr;
SampleFormat sf;
std::string s = Glib::build_filename (dir, state + statefile_suffix);
if (Session::get_info_from_path (s, sr, sf) == 0) {
if (engine->set_sample_rate (sr)) {
std::cerr << "Cannot set session's samplerate.\n";
::exit (EXIT_FAILURE);
}
} else {
std::cerr << "Cannot get samplerate from session.\n";
::exit (EXIT_FAILURE);
}
init_post_engine ();
if (engine->start () != 0) {
@ -130,16 +147,16 @@ SessionUtils::load_session (string dir, string state)
s = _load_session (dir, state);
} catch (failed_constructor& e) {
cerr << "failed_constructor: " << e.what() << "\n";
exit (EXIT_FAILURE);
::exit (EXIT_FAILURE);
} catch (AudioEngine::PortRegistrationFailure& e) {
cerr << "PortRegistrationFailure: " << e.what() << "\n";
exit (EXIT_FAILURE);
::exit (EXIT_FAILURE);
} catch (exception& e) {
cerr << "exception: " << e.what() << "\n";
exit (EXIT_FAILURE);
::exit (EXIT_FAILURE);
} catch (...) {
cerr << "unknown exception.\n";
exit (EXIT_FAILURE);
::exit (EXIT_FAILURE);
}
return s;
}