code refactoring and action name handling to make follow-playhead work in multiple editing contexts

This commit is contained in:
Paul Davis
2025-06-15 21:17:42 -06:00
parent f48fe3f740
commit ea1695dbc0
11 changed files with 100 additions and 102 deletions

View File

@@ -209,7 +209,7 @@ This mode provides many different operations on both regions and control points,
@edit|Editor/multi-duplicate| <@SECONDARY@>d|duplicate (multi)
@select|Editor/select-all-in-punch-range| <@TERTIARY@>d|select all in punch range
@vis|Editor/fit-selection| f|fit selection vertically
@edit|Editor/toggle-follow-playhead| <@PRIMARY@>f|toggle playhead tracking
@edit|Editing/toggle-follow-playhead| <@PRIMARY@>f|toggle playhead tracking
@edit|Editor/toggle-stationary-playhead| <@TERTIARY@>f|toggle stationary playhead
@rop|Region/show-rhythm-ferret| <@SECONDARY@>f|show rhythm ferret window
@wvis|Common/ToggleMaximalEditor| <@PRIMARY@><@SECONDARY@>f|maximise editor space

View File

@@ -186,7 +186,7 @@
<menuitem action='ToggleAutoPlay'/>
<menuitem action='ToggleAutoReturn'/>
<menuitem action='ToggleClick'/>
<menuitem action='toggle-follow-playhead'/>
<menuitem action='EditorEditing/toggle-follow-playhead'/>
<menuitem action='toggle-stationary-playhead'/>
<menuitem action='ToggleFollowEdits'/>
<menuitem action='ToggleExternalSync'/>

View File

@@ -198,13 +198,6 @@ CueEditor::step_mouse_mode (bool next)
{
}
void
CueEditor::reset_x_origin_to_follow_playhead ()
{
}
Gdk::Cursor*
CueEditor::get_canvas_cursor () const
{

View File

@@ -97,8 +97,6 @@ class CueEditor : public EditingContext, public PBD::HistoryOwner
void end_local_tempo_map (std::shared_ptr<Temporal::TempoMap const>);
protected:
void reset_x_origin_to_follow_playhead ();
void do_undo (uint32_t n);
void do_redo (uint32_t n);

View File

@@ -40,6 +40,7 @@
#include "edit_note_dialog.h"
#include "editing_context.h"
#include "editing_convert.h"
#include "editor_cursors.h"
#include "editor_drag.h"
#include "grid_lines.h"
#include "gui_thread.h"
@@ -310,6 +311,8 @@ EditingContext::register_common_actions (Bindings* common_bindings, std::string
reg_sens (_common_actions, "temporal-zoom-out", _("Zoom Out"), sigc::bind (sigc::mem_fun (*this, &EditingContext::temporal_zoom_step), true));
reg_sens (_common_actions, "temporal-zoom-in", _("Zoom In"), sigc::bind (sigc::mem_fun (*this, &EditingContext::temporal_zoom_step), false));
toggle_reg_sens (_common_actions, "toggle-follow-playhead", _("Follow Playhead"), (sigc::mem_fun(*this, &EditingContext::toggle_follow_playhead)));
undo_action = reg_sens (_common_actions, "undo", S_("Command|Undo"), sigc::bind (sigc::mem_fun (*this, &EditingContext::undo), 1U));
redo_action = reg_sens (_common_actions, "redo", _("Redo"), sigc::bind (sigc::mem_fun (*this, &EditingContext::redo), 1U));
alternate_redo_action = reg_sens (_common_actions, "alternate-redo", _("Redo"), sigc::bind (sigc::mem_fun (*this, &EditingContext::redo), 1U));
@@ -1315,7 +1318,7 @@ EditingContext::time_domain () const
void
EditingContext::toggle_follow_playhead ()
{
RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Editor"), X_("toggle-follow-playhead"));
RefPtr<ToggleAction> tact = ActionManager::get_toggle_action ((_name + X_("Editing")).c_str(), X_("toggle-follow-playhead"));
set_follow_playhead (tact->get_active());
}
@@ -2166,7 +2169,7 @@ EditingContext::bind_mouse_mode_buttons ()
act = ActionManager::get_action ((_name + X_("Editing")).c_str(), X_("temporal-zoom-out"));
zoom_out_button.set_related_action (act);
act = ActionManager::get_action (X_("Editor"), X_("toggle-follow-playhead"));
act = ActionManager::get_action ((_name + X_("Editing")).c_str(), X_("toggle-follow-playhead"));
follow_playhead_button.set_related_action (act);
act = ActionManager::get_action (X_("Transport"), X_("ToggleFollowEdits"));
@@ -3395,3 +3398,83 @@ EditingContext::allow_trim_cursors () const
{
return mouse_mode == MouseContent || mouse_mode == MouseTimeFX || mouse_mode == MouseDraw;
}
/** Queue a change for the Editor viewport x origin to follow the playhead */
void
EditingContext::reset_x_origin_to_follow_playhead ()
{
assert (_session);
samplepos_t const sample = _playhead_cursor->current_sample ();
if (sample < _leftmost_sample || sample > _leftmost_sample + current_page_samples()) {
if (_session->transport_speed() < 0) {
if (sample > (current_page_samples() / 2)) {
center_screen (sample-(current_page_samples()/2));
} else {
center_screen (current_page_samples()/2);
}
} else {
samplepos_t l = 0;
if (sample < _leftmost_sample) {
/* moving left */
if (_session->transport_rolling()) {
/* rolling; end up with the playhead at the right of the page */
l = sample - current_page_samples ();
} else {
/* not rolling: end up with the playhead 1/4 of the way along the page */
l = sample - current_page_samples() / 4;
}
} else {
/* moving right */
if (_session->transport_rolling()) {
/* rolling: end up with the playhead on the left of the page */
l = sample;
} else {
/* not rolling: end up with the playhead 3/4 of the way along the page */
l = sample - 3 * current_page_samples() / 4;
}
}
if (l < 0) {
l = 0;
}
center_screen_internal (l + (current_page_samples() / 2), current_page_samples ());
}
}
}
void
EditingContext::center_screen (samplepos_t sample)
{
samplecnt_t const page = _visible_canvas_width * samples_per_pixel;
/* if we're off the page, then scroll.
*/
if (sample < _leftmost_sample || sample >= _leftmost_sample + page) {
center_screen_internal (sample, page);
}
}
void
EditingContext::center_screen_internal (samplepos_t sample, float page)
{
page /= 2;
if (sample > page) {
sample -= (samplepos_t) page;
} else {
sample = 0;
}
reset_x_origin (sample);
}

View File

@@ -494,6 +494,9 @@ class EditingContext : public ARDOUR::SessionHandlePtr, public AxisViewProvider,
virtual bool allow_trim_cursors () const;
virtual void make_a_region() {}
void center_screen (samplepos_t);
void reset_x_origin_to_follow_playhead ();
protected:
std::string _name;
bool within_track_canvas;
@@ -592,7 +595,6 @@ class EditingContext : public ARDOUR::SessionHandlePtr, public AxisViewProvider,
EditorCursor* _snapped_cursor;
bool _follow_playhead;
virtual void reset_x_origin_to_follow_playhead () = 0;
/* selection process */
@@ -813,4 +815,7 @@ class EditingContext : public ARDOUR::SessionHandlePtr, public AxisViewProvider,
static Glib::RefPtr<Gtk::Action> reg_sens (Glib::RefPtr<Gtk::ActionGroup> group, char const* name, char const* label, sigc::slot<void> slot);
static void toggle_reg_sens (Glib::RefPtr<Gtk::ActionGroup> group, char const* name, char const* label, sigc::slot<void> slot);
static void radio_reg_sens (Glib::RefPtr<Gtk::ActionGroup> action_group, Gtk::RadioAction::Group& radio_group, char const* name, char const* label, sigc::slot<void> slot);
void center_screen_internal (samplepos_t, float);
};

View File

@@ -661,6 +661,7 @@ Editor::Editor ()
load_bindings ();
register_actions ();
bind_mouse_mode_buttons ();
setup_toolbar ();
@@ -1161,34 +1162,6 @@ Editor::map_position_change (samplepos_t sample)
update_section_box ();
}
void
Editor::center_screen (samplepos_t sample)
{
samplecnt_t const page = _visible_canvas_width * samples_per_pixel;
/* if we're off the page, then scroll.
*/
if (sample < _leftmost_sample || sample >= _leftmost_sample + page) {
center_screen_internal (sample, page);
}
}
void
Editor::center_screen_internal (samplepos_t sample, float page)
{
page /= 2;
if (sample > page) {
sample -= (samplepos_t) page;
} else {
sample = 0;
}
reset_x_origin (sample);
}
void
Editor::update_title ()
{
@@ -2360,7 +2333,7 @@ Editor::set_state (const XMLNode& node, int version)
*/
RefPtr<ToggleAction> tact;
tact = ActionManager::get_toggle_action (X_("Editor"), X_("toggle-follow-playhead"));
tact = ActionManager::get_toggle_action ((editor_name () + X_("Editing")).c_str(), X_("toggle-follow-playhead"));
yn = _follow_playhead;
if (tact->get_active() != yn) {
tact->set_active (yn);
@@ -5223,55 +5196,6 @@ Editor::scroll_release ()
_scroll_connection.disconnect ();
}
/** Queue a change for the Editor viewport x origin to follow the playhead */
void
Editor::reset_x_origin_to_follow_playhead ()
{
samplepos_t const sample = _playhead_cursor->current_sample ();
if (sample < _leftmost_sample || sample > _leftmost_sample + current_page_samples()) {
if (_session->transport_speed() < 0) {
if (sample > (current_page_samples() / 2)) {
center_screen (sample-(current_page_samples()/2));
} else {
center_screen (current_page_samples()/2);
}
} else {
samplepos_t l = 0;
if (sample < _leftmost_sample) {
/* moving left */
if (_session->transport_rolling()) {
/* rolling; end up with the playhead at the right of the page */
l = sample - current_page_samples ();
} else {
/* not rolling: end up with the playhead 1/4 of the way along the page */
l = sample - current_page_samples() / 4;
}
} else {
/* moving right */
if (_session->transport_rolling()) {
/* rolling: end up with the playhead on the left of the page */
l = sample;
} else {
/* not rolling: end up with the playhead 3/4 of the way along the page */
l = sample - 3 * current_page_samples() / 4;
}
}
if (l < 0) {
l = 0;
}
center_screen_internal (l + (current_page_samples() / 2), current_page_samples ());
}
}
}
void
Editor::super_rapid_screen_update ()
{

View File

@@ -372,8 +372,6 @@ public:
double get_y_origin () const;
void reposition_and_zoom (samplepos_t, double);
void reset_x_origin_to_follow_playhead ();
void toggle_meter_updating();
void show_rhythm_ferret();
@@ -408,8 +406,6 @@ public:
void get_regionviews_by_id (PBD::ID const id, RegionSelection & regions) const;
void get_per_region_note_selection (std::list<std::pair<PBD::ID, std::set<std::shared_ptr<Evoral::Note<Temporal::Beats> > > > >&) const;
void center_screen (samplepos_t);
TrackViewList axis_views_from_routes (std::shared_ptr<ARDOUR::RouteList>) const;
void set_snapped_cursor_position (Temporal::timepos_t const & pos);
@@ -1099,7 +1095,6 @@ private:
sigc::connection _tvl_redisplay_connection;
sigc::connection super_rapid_screen_update_connection;
void center_screen_internal (samplepos_t, float);
void super_rapid_screen_update ();

View File

@@ -472,7 +472,6 @@ Editor::register_actions ()
sigc::bind (sigc::mem_fun (*this, &Editor::move_range_selection_start_or_end_to_region_boundary), true, true)
);
toggle_reg_sens (editor_actions, "toggle-follow-playhead", _("Follow Playhead"), (sigc::mem_fun(*this, &Editor::toggle_follow_playhead)));
act = reg_sens (editor_actions, "remove-last-capture", _("Remove Last Capture"), (sigc::mem_fun(*this, &Editor::remove_last_capture)));
act = reg_sens (editor_actions, "tag-last-capture", _("Tag Last Capture"), (sigc::mem_fun(*this, &Editor::tag_last_capture)));
@@ -545,8 +544,6 @@ Editor::register_actions ()
act->set_sensitive (false);
}
bind_mouse_mode_buttons ();
ActionManager::register_action (editor_actions, "step-mouse-mode", _("Step Mouse Mode"), sigc::bind (sigc::mem_fun(*this, &Editor::step_mouse_mode), true));
RadioAction::Group edit_point_group;

View File

@@ -92,6 +92,7 @@ Pianoroll::Pianoroll (std::string const & name, bool with_transport)
load_bindings ();
register_actions ();
bind_mouse_mode_buttons ();
set_mouse_mode (Editing::MouseContent, true);
}
@@ -755,6 +756,10 @@ Pianoroll::maybe_update ()
} else {
_playhead_cursor->set_position (0);
}
if (_follow_playhead) {
reset_x_origin_to_follow_playhead ();
}
}
bool

View File

@@ -397,8 +397,6 @@ public:
virtual void set_current_trimmable (std::shared_ptr<ARDOUR::Trimmable>) = 0;
virtual void set_current_movable (std::shared_ptr<ARDOUR::Movable>) = 0;
virtual void center_screen (samplepos_t) = 0;
virtual TrackViewList const & get_track_views () const = 0;
virtual MixerStrip* get_current_mixer_strip () const = 0;