From e66752cec1dd19e674b9a2c87436c937c4886295 Mon Sep 17 00:00:00 2001 From: Ben Loftis Date: Tue, 9 Dec 2014 16:17:47 -0600 Subject: [PATCH] add set-session-extents-from-edit-range --- gtk2_ardour/editor.cc | 1 + gtk2_ardour/editor.h | 2 ++ gtk2_ardour/editor_actions.cc | 1 + gtk2_ardour/editor_ops.cc | 28 ++++++++++++++++++++++++++++ libs/ardour/ardour/session.h | 1 + libs/ardour/session.cc | 19 +++++++++++++++++++ 6 files changed, 52 insertions(+) diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 0b2f091fa4..13d6f90498 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -1845,6 +1845,7 @@ Editor::add_selection_context_items (Menu_Helpers::MenuList& edit_items) edit_items.push_back (SeparatorElem()); edit_items.push_back (MenuElem (_("Set Loop from Range"), sigc::bind (sigc::mem_fun(*this, &Editor::set_loop_from_selection), false))); edit_items.push_back (MenuElem (_("Set Punch from Range"), sigc::mem_fun(*this, &Editor::set_punch_from_selection))); + edit_items.push_back (MenuElem (_("Set Session Start/End from Range"), sigc::mem_fun(*this, &Editor::set_session_extents_from_selection))); edit_items.push_back (SeparatorElem()); edit_items.push_back (MenuElem (_("Add Range Markers"), sigc::mem_fun (*this, &Editor::add_location_from_selection))); diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 5147749ae9..f4c8dd51cb 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -1347,6 +1347,8 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD void set_punch_from_selection (); void set_punch_from_region (); + void set_session_extents_from_selection (); + void set_loop_from_edit_range (bool play); void set_loop_from_region (bool play); void set_punch_from_edit_range (); diff --git a/gtk2_ardour/editor_actions.cc b/gtk2_ardour/editor_actions.cc index 817d69be7b..befd2fa1ae 100644 --- a/gtk2_ardour/editor_actions.cc +++ b/gtk2_ardour/editor_actions.cc @@ -299,6 +299,7 @@ Editor::register_actions () reg_sens (editor_actions, "set-loop-from-edit-range", _("Set Loop from Edit Range"), sigc::bind (sigc::mem_fun(*this, &Editor::set_loop_from_edit_range), false)); reg_sens (editor_actions, "set-punch-from-edit-range", _("Set Punch from Edit Range"), sigc::mem_fun(*this, &Editor::set_punch_from_edit_range)); + reg_sens (editor_actions, "set-session-from-edit-range", _("Set Session Start/End from Edit Range"), sigc::mem_fun(*this, &Editor::set_session_extents_from_selection)); /* this is a duplicated action so that the main menu can use a different label */ reg_sens (editor_actions, "main-menu-play-selected-regions", _("Play Selected Regions"), sigc::mem_fun (*this, &Editor::play_selected_region)); diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index f975c8df7f..aa0f316467 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -5901,6 +5901,34 @@ Editor::set_punch_from_selection () set_punch_range (start, end, _("set punch range from selection")); } +void +Editor::set_session_extents_from_selection () +{ + if (_session == 0 || selection->time.empty()) { + return; + } + + begin_reversible_command (_("set session start/stop from selection")); + + framepos_t start = selection->time[clicked_selection].start; + framepos_t end = selection->time[clicked_selection].end; + + Location* loc; + if ((loc = _session->locations()->session_range_location()) == 0) { + _session->set_session_extents ( start, end ); // this will create a new session range; no need for UNDO + } else { + XMLNode &before = loc->get_state(); + + _session->set_session_extents ( start, end ); + + XMLNode &after = loc->get_state(); + + _session->add_command (new MementoCommand(*loc, &before, &after)); + + commit_reversible_command (); + } +} + void Editor::set_punch_from_edit_range () { diff --git a/libs/ardour/ardour/session.h b/libs/ardour/ardour/session.h index 86d8c66593..9af744e2ec 100644 --- a/libs/ardour/ardour/session.h +++ b/libs/ardour/ardour/session.h @@ -384,6 +384,7 @@ class LIBARDOUR_API Session : public PBD::StatefulDestructible, public PBD::Scop void set_auto_punch_location (Location *); void set_auto_loop_location (Location *); + void set_session_extents (framepos_t start, framepos_t end); int location_name(std::string& result, std::string base = std::string("")); pframes_t get_block_size() const { return current_block_size; } diff --git a/libs/ardour/session.cc b/libs/ardour/session.cc index 9c5b6fdccf..4710ea1534 100644 --- a/libs/ardour/session.cc +++ b/libs/ardour/session.cc @@ -1246,6 +1246,25 @@ Session::set_auto_punch_location (Location* location) auto_punch_location_changed (location); } +void +Session::set_session_extents (framepos_t start, framepos_t end) +{ + Location* existing; + if ((existing = _locations->session_range_location()) == 0) { + //if there is no existing session, we need to make a new session location (should never happen) + existing = new Location (*this, 0, 0, _("session"), Location::IsSessionRange); + } + + if (end <= start) { + error << _("Session: you can't use that location for session start/end)") << endmsg; + return; + } + + existing->set( start, end ); + + set_dirty(); +} + void Session::set_auto_loop_location (Location* location) { -- 2.30.2