single action punch in 5.2
authorPaul Davis <paul@linuxaudiosystems.com>
Sat, 27 Aug 2016 23:57:40 +0000 (19:57 -0400)
committerPaul Davis <paul@linuxaudiosystems.com>
Sat, 27 Aug 2016 23:57:40 +0000 (19:57 -0400)
Consecutive execution (e.g. from a control surface button) engages punch in, then punch out, then clears both.
Patch by Nathan Stewart

gtk2_ardour/editor.h
gtk2_ardour/editor_actions.cc
gtk2_ardour/editor_ops.cc

index 7d754ed1b01abb05651c659d075d705ed7ac98b8..75ba6863e96e9016a53217d8442182050e8d0348 100644 (file)
@@ -1451,6 +1451,7 @@ class Editor : public PublicEditor, public PBD::ScopedConnectionList, public ARD
        void set_loop_from_selection (bool play);
        void set_punch_from_selection ();
        void set_punch_from_region ();
+       void set_auto_punch_range();
 
        void set_session_start_from_playhead ();
        void set_session_end_from_playhead ();
index 44c66e36c8d5a4f26b1413c88c4fd518e00b6dbb..660a05160048d7192700161b73e4db75d6864a7a 100644 (file)
@@ -330,6 +330,7 @@ Editor::register_actions ()
 
        reg_sens (editor_actions, "set-playhead", _("Playhead to Mouse"), sigc::mem_fun(*this, &Editor::set_playhead_cursor));
        reg_sens (editor_actions, "set-edit-point", _("Active Marker to Mouse"), sigc::mem_fun(*this, &Editor::set_edit_point));
+       reg_sens (editor_actions, "set-auto-punch-range", _("Set Auto Punch In/Out from Playhead"), sigc::mem_fun(*this, &Editor::set_auto_punch_range));
 
        reg_sens (editor_actions, "duplicate-range", _("Duplicate Range"), sigc::bind (sigc::mem_fun(*this, &Editor::duplicate_range), false));
 
index f7bbf2a16666d68d05b06d67d4fee6196156ad79..35415c8f2e6cd535221e6cf66573b27eb57ded89 100644 (file)
@@ -6358,6 +6358,59 @@ Editor::set_punch_from_selection ()
        set_punch_range (start, end,  _("set punch range from selection"));
 }
 
+void
+Editor::set_auto_punch_range ()
+{
+       // auto punch in/out button from a single button
+       // If Punch In is unset, set punch range from playhead to end, enable punch in
+       // If Punch In is set, the next punch sets Punch Out, unless the playhead has been
+       //   rewound beyond the Punch In marker, in which case that marker will be moved back
+       //   to the current playhead position.
+       // If punch out is set, it clears the punch range and Punch In/Out buttons
+
+       if (_session == 0) {
+               return;
+       }
+
+       Location* tpl = transport_punch_location();
+       framepos_t now = playhead_cursor->current_frame();
+       framepos_t begin = now;
+       framepos_t end = _session->current_end_frame();
+
+       if (!_session->config.get_punch_in()) {
+               // First Press - set punch in and create range from here to eternity
+               set_punch_range (begin, end, _("Auto Punch In"));
+               _session->config.set_punch_in(true);
+       } else if (tpl && !_session->config.get_punch_out()) {
+               // Second press - update end range marker and set punch_out
+               if (now < tpl->start()) {
+                       // playhead has been rewound - move start back  and pretend nothing happened
+                       begin = now;
+                       set_punch_range (begin, end, _("Auto Punch In/Out"));
+               } else {
+                       // normal case for 2nd press - set the punch out
+                       end = playhead_cursor->current_frame ();
+                       set_punch_range (tpl->start(), now, _("Auto Punch In/Out"));
+                       _session->config.set_punch_out(true);
+               }
+       } else  {
+               if (_session->config.get_punch_out()) {
+                       _session->config.set_punch_out(false);
+               }
+
+               if (_session->config.get_punch_in()) {
+                       _session->config.set_punch_in(false);
+               }
+
+               if (tpl)
+               {
+                       // third press - unset punch in/out and remove range
+                       _session->locations()->remove(tpl);
+               }
+       }
+
+}
+
 void
 Editor::set_session_extents_from_selection ()
 {