From 7a6918e2ff023c2468c5bea17c514161ca781a24 Mon Sep 17 00:00:00 2001
From: Thomas Brand <tom@trellis.ch>
Date: Tue, 6 Aug 2013 21:51:16 +0200
Subject: [PATCH] add select-all-at-playhead editor action

---
 gtk2_ardour/ardour.menus.in     |    1 +
 gtk2_ardour/editor.cc           |    4 +++-
 gtk2_ardour/editor.h            |    1 +
 gtk2_ardour/editor_actions.cc   |    4 +++-
 gtk2_ardour/editor_selection.cc |   37 +++++++++++++++++++++++++++++++++++++
 5 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/gtk2_ardour/ardour.menus.in b/gtk2_ardour/ardour.menus.in
index 15f1bde..6b38970 100644
--- a/gtk2_ardour/ardour.menus.in
+++ b/gtk2_ardour/ardour.menus.in
@@ -173,6 +173,7 @@
         <menuitem action='deselect-all'/>
         <menuitem action='invert-selection'/>
         <menuitem action='select-all-after-edit-cursor'/>
+        <menuitem action='select-all-at-playhead'/>
         <menuitem action='select-all-before-edit-cursor'/>
         <menuitem action='select-all-between-cursors'/>
         <menuitem action='select-all-within-cursors'/>
diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc
index 300e317..53ad7bc 100644
--- a/gtk2_ardour/editor.cc
+++ b/gtk2_ardour/editor.cc
@@ -1950,6 +1950,7 @@ Editor::add_dstream_context_items (Menu_Helpers::MenuList& edit_items)
 	select_items.push_back (MenuElem (_("Select All Before Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
 	select_items.push_back (MenuElem (_("Select All After Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
 	select_items.push_back (MenuElem (_("Select All Before Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
+	select_items.push_back (MenuElem (_("Select All At Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_at_cursor), playhead_cursor)));
 	select_items.push_back (MenuElem (_("Select All Between Playhead and Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_between), false)));
 	select_items.push_back (MenuElem (_("Select All Within Playhead and Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_between), true)));
 	select_items.push_back (MenuElem (_("Select Range Between Playhead and Edit Point"), sigc::mem_fun(*this, &Editor::select_range_between)));
@@ -2022,8 +2023,9 @@ Editor::add_bus_context_items (Menu_Helpers::MenuList& edit_items)
 	select_items.push_back (SeparatorElem());
 	select_items.push_back (MenuElem (_("Select All After Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), true)));
 	select_items.push_back (MenuElem (_("Select All Before Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), false)));
-	select_items.push_back (MenuElem (_("Select All After Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
 	select_items.push_back (MenuElem (_("Select All Before Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, false)));
+	select_items.push_back (MenuElem (_("Select All At Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_at_cursor), playhead_cursor)));
+	select_items.push_back (MenuElem (_("Select All After Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_cursor), playhead_cursor, true)));
 
 	edit_items.push_back (MenuElem (_("Select"), *select_menu));
 
diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h
index 033888c..bf79b30 100644
--- a/gtk2_ardour/editor.h
+++ b/gtk2_ardour/editor.h
@@ -956,6 +956,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
 	void    selected_marker_to_selection_end   ();
 
 	void    select_all_selectables_using_cursor (EditorCursor *, bool);
+	void    select_all_selectables_at_cursor (EditorCursor *);
 	void    select_all_selectables_using_edit (bool);
 	void    select_all_selectables_between (bool within);
 	void    select_range_between ();
diff --git a/gtk2_ardour/editor_actions.cc b/gtk2_ardour/editor_actions.cc
index a5e2e8a..d406655 100644
--- a/gtk2_ardour/editor_actions.cc
+++ b/gtk2_ardour/editor_actions.cc
@@ -185,8 +185,10 @@ Editor::register_actions ()
 	reg_sens (editor_actions, "select-all", _("Select All"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all), Selection::Set));
 	reg_sens (editor_actions, "deselect-all", _("Deselect All"), sigc::mem_fun(*this, &Editor::deselect_all));
 	reg_sens (editor_actions, "invert-selection", _("Invert Selection"), sigc::mem_fun(*this, &Editor::invert_selection));
-	reg_sens (editor_actions, "select-all-after-edit-cursor", _("Select All After Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), true));
 	reg_sens (editor_actions, "select-all-before-edit-cursor", _("Select All Before Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), false));
+	reg_sens (editor_actions, "select-all-at-playhead", _("Select All At Playhead"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_at_cursor), playhead_cursor));
+	reg_sens (editor_actions, "select-all-after-edit-cursor", _("Select All After Edit Point"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_using_edit), true));
+
 
 	reg_sens (editor_actions, "select-all-between-cursors", _("Select All Overlapping Edit Range"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_between), false));
 	reg_sens (editor_actions, "select-all-within-cursors", _("Select All Inside Edit Range"), sigc::bind (sigc::mem_fun(*this, &Editor::select_all_selectables_between), true));
diff --git a/gtk2_ardour/editor_selection.cc b/gtk2_ardour/editor_selection.cc
index e19afe3..c664aa5 100644
--- a/gtk2_ardour/editor_selection.cc
+++ b/gtk2_ardour/editor_selection.cc
@@ -1723,6 +1723,43 @@ Editor::select_all_selectables_using_cursor (EditorCursor *cursor, bool after)
 }
 
 void
+Editor::select_all_selectables_at_cursor (EditorCursor *cursor)
+{
+	framepos_t start;
+	framepos_t end;
+	list<Selectable *> touched;
+
+	start = cursor->current_frame;
+	end = cursor->current_frame+1;
+
+	if (_internal_editing) {
+		for (RegionSelection::iterator i = selection->regions.begin(); i != selection->regions.end(); ++i) {
+			MidiRegionView* mrv = dynamic_cast<MidiRegionView*>(*i);
+			if (mrv) {
+				mrv->select_range (start, end);
+			}
+		}
+		return;
+	}
+
+	TrackViewList* ts;
+
+	if (selection->tracks.empty()) {
+		ts = &track_views;
+	} else {
+		ts = &selection->tracks;
+	}
+
+	for (TrackViewList::iterator iter = ts->begin(); iter != ts->end(); ++iter) {
+		if ((*iter)->hidden()) {
+			continue;
+		}
+		(*iter)->get_selectables (start, end, 0, DBL_MAX, touched);
+	}
+	selection->set (touched);
+}
+
+void
 Editor::select_all_selectables_using_edit (bool after)
 {
 	framepos_t start;
-- 
1.7.9.5

