From d3c7c3fdfa1aafd1c9feb61550d2fd73df1382f7 Mon Sep 17 00:00:00 2001 From: Greg Zharun Date: Sun, 31 Aug 2014 16:36:55 +0300 Subject: [PATCH] [Summary] Session will try to switch the device to the sample rate it was created with. --- gtk2_ardour/ardour_ui.cc | 8 +++--- libs/ardour/ardour/engine_state_controller.h | 5 ++++ libs/ardour/ardour/session.h | 3 +++ libs/ardour/engine_state_controller.cc | 28 ++++++++++++++++++++ libs/ardour/session.cc | 4 +++ 5 files changed, 45 insertions(+), 3 deletions(-) diff --git a/gtk2_ardour/ardour_ui.cc b/gtk2_ardour/ardour_ui.cc index ce018adbf8..af7b7b6cf8 100644 --- a/gtk2_ardour/ardour_ui.cc +++ b/gtk2_ardour/ardour_ui.cc @@ -4016,15 +4016,17 @@ ARDOUR_UI::sr_mismatch_dialog (framecnt_t desired, framecnt_t actual) ArdourDialog dialog (_("Sample Rate Mismatch"), true); Label message (string_compose (_("\ This session was created with a sample rate of %1 Hz, but\n\ -%2 is currently running at %3 Hz. If you load this session,\n\ +%2 is currently running at %3 Hz. If you load this session,\n\ +device will be switched to the session sample rate value. \n\ +If an attemp to switch the device is unsuccessful\n\ audio may be played at the wrong sample rate.\n"), desired, PROGRAM_NAME, actual)); image->set_alignment(ALIGN_CENTER, ALIGN_TOP); hbox->pack_start (*image, PACK_EXPAND_WIDGET, 12); hbox->pack_end (message, PACK_EXPAND_PADDING, 12); dialog.get_vbox()->pack_start(*hbox, PACK_EXPAND_PADDING, 6); - dialog.add_button (_("Do not load session"), RESPONSE_REJECT); - dialog.add_button (_("Load session anyway"), RESPONSE_ACCEPT); + dialog.add_button (_("Cancel"), RESPONSE_REJECT); + dialog.add_button (_("Accept"), RESPONSE_ACCEPT); dialog.set_default_response (RESPONSE_ACCEPT); dialog.set_position (WIN_POS_CENTER); message.show(); diff --git a/libs/ardour/ardour/engine_state_controller.h b/libs/ardour/ardour/engine_state_controller.h index 252b2724fa..fddcf93532 100644 --- a/libs/ardour/ardour/engine_state_controller.h +++ b/libs/ardour/ardour/engine_state_controller.h @@ -48,6 +48,9 @@ public: static EngineStateController* instance(); + void set_session(Session* session); + void remove_session (); + //Interfaces void available_backends(std::vector&); @@ -286,6 +289,8 @@ private: ARDOUR::framecnt_t _desired_sample_rate; bool _have_control; + Session* _session; + // Engine connections stuff PBD::ScopedConnectionList update_connections; PBD::ScopedConnectionList session_connections; diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 7501a0fcab..ad73cf864e 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -291,6 +291,9 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop PBD::Signal0 RecordStateChanged; + /* Emited when session is loaded */ + PBD::Signal0 SessionLoaded; + /* Transport mechanism signals */ /** Emitted on the following changes in transport state: diff --git a/libs/ardour/engine_state_controller.cc b/libs/ardour/engine_state_controller.cc index 5c506cca1a..88c3cde408 100644 --- a/libs/ardour/engine_state_controller.cc +++ b/libs/ardour/engine_state_controller.cc @@ -9,6 +9,7 @@ #include "ardour/engine_state_controller.h" #include "ardour/audioengine.h" +#include "ardour/session.h" #include "ardour/rc_configuration.h" #include "ardour/data_type.h" @@ -81,6 +82,22 @@ EngineStateController::~EngineStateController() } +void +EngineStateController::set_session(Session* session) +{ + _session = session; + _session->SessionLoaded.connect_same_thread (session_connections, boost::bind (&EngineStateController::_on_session_loaded, this) ); +} + + +void +EngineStateController::remove_session () +{ + session_connections.drop_connections (); + _session = 0; +} + + XMLNode& EngineStateController::serialize_audio_midi_settings() { @@ -1176,6 +1193,17 @@ EngineStateController::get_physical_midi_output_states (std::vector& } +void +EngineStateController::_on_session_loaded () +{ + if (_session && _desired_sample_rate && set_new_sample_rate_in_controller(_desired_sample_rate) ) + { + push_current_state_to_backend(false); + SampleRateChanged(); // emit a signal + } +} + + void EngineStateController::_on_sample_rate_change(framecnt_t new_sample_rate) { diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 310e57692f..319c5a7ae0 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -357,6 +357,8 @@ Session::Session (AudioEngine &eng, _engine.set_session (this); _engine.reset_timebase (); + EngineStateController::instance()->set_session(this); + // Waves Tracks: always create master track if ( ARDOUR::Profile->get_trx () ) { create_master_track(); @@ -407,6 +409,7 @@ Session::Session (AudioEngine &eng, _is_new = false; + SessionLoaded(); BootMessage (_("Session loading complete")); } @@ -512,6 +515,7 @@ Session::destroy () drop_connections (); _engine.remove_session (); + EngineStateController::instance()->remove_session(); /* deregister all ports - there will be no process or any other * callbacks from the engine any more.