more reorganization of implementations between Editor & EditingContext & PublicEditor

This commit is contained in:
Paul Davis 2023-11-17 14:34:51 -07:00
parent 7d5f575d61
commit 1bf2307137
7 changed files with 137 additions and 164 deletions

View file

@ -16,7 +16,10 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include <iostream>
#include "pbd/error.h" #include "pbd/error.h"
#include "pbd/stacktrace.h"
#include "ardour/rc_configuration.h" #include "ardour/rc_configuration.h"
@ -26,6 +29,8 @@
#include "editing_context.h" #include "editing_context.h"
#include "editor_drag.h" #include "editor_drag.h"
#include "midi_region_view.h" #include "midi_region_view.h"
#include "selection.h"
#include "selection_memento.h"
#include "pbd/i18n.h" #include "pbd/i18n.h"
@ -34,6 +39,7 @@ using namespace Glib;
using namespace Gtk; using namespace Gtk;
using namespace Gtkmm2ext; using namespace Gtkmm2ext;
using namespace PBD; using namespace PBD;
using std::string;
sigc::signal<void> EditingContext::DropDownKeys; sigc::signal<void> EditingContext::DropDownKeys;
@ -75,6 +81,12 @@ EditingContext::EditingContext ()
, _draw_channel (DRAW_CHAN_AUTO) , _draw_channel (DRAW_CHAN_AUTO)
, _drags (new DragManager (this)) , _drags (new DragManager (this))
, _leftmost_sample (0) , _leftmost_sample (0)
, _playhead_cursor (nullptr)
, _snapped_cursor (nullptr)
, _follow_playhead (false)
, selection (new Selection (this, true))
, cut_buffer (new Selection (this, false))
, _selection_memento (new SelectionMemento())
{ {
grid_type_strings = I18N (_grid_type_strings); grid_type_strings = I18N (_grid_type_strings);
} }
@ -1082,3 +1094,76 @@ EditingContext::time_domain () const
return Temporal::BeatTime; return Temporal::BeatTime;
} }
void
EditingContext::toggle_follow_playhead ()
{
RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Editor"), X_("toggle-follow-playhead"));
set_follow_playhead (tact->get_active());
}
/** @param yn true to follow playhead, otherwise false.
* @param catch_up true to reset the editor view to show the playhead (if yn == true), otherwise false.
*/
void
EditingContext::set_follow_playhead (bool yn, bool catch_up)
{
if (_follow_playhead != yn) {
if ((_follow_playhead = yn) == true && catch_up) {
/* catch up */
reset_x_origin_to_follow_playhead ();
}
instant_save ();
}
}
void
EditingContext::begin_reversible_command (string name)
{
if (_session) {
before.push_back (&_selection_memento->get_state ());
_session->begin_reversible_command (name);
}
}
void
EditingContext::begin_reversible_command (GQuark q)
{
if (_session) {
before.push_back (&_selection_memento->get_state ());
_session->begin_reversible_command (q);
}
}
void
EditingContext::abort_reversible_command ()
{
if (_session) {
while(!before.empty()) {
delete before.front();
before.pop_front();
}
_session->abort_reversible_command ();
}
}
void
EditingContext::commit_reversible_command ()
{
if (_session) {
if (before.size() == 1) {
_session->add_command (new MementoCommand<SelectionMemento>(*(_selection_memento), before.front(), &_selection_memento->get_state ()));
begin_selection_op_history ();
}
if (before.empty()) {
PBD::stacktrace (std::cerr, 30);
std::cerr << "Please call begin_reversible_command() before commit_reversible_command()." << std::endl;
} else {
before.pop_back();
}
_session->commit_reversible_command ();
}
}

View file

@ -42,6 +42,7 @@
#include "widgets/ardour_dropdown.h" #include "widgets/ardour_dropdown.h"
#include "axis_provider.h"
#include "editing.h" #include "editing.h"
#include "editor_items.h" #include "editor_items.h"
#include "selection.h" #include "selection.h"
@ -49,6 +50,8 @@
using ARDOUR::samplepos_t; using ARDOUR::samplepos_t;
using ARDOUR::samplecnt_t; using ARDOUR::samplecnt_t;
class XMLNode;
class CursorContext; class CursorContext;
class DragManager; class DragManager;
class EditorCursor; class EditorCursor;
@ -56,8 +59,10 @@ class MidiRegionView;
class MouseCursors; class MouseCursors;
class VerboseCursor; class VerboseCursor;
class TrackViewList; class TrackViewList;
class Selection;
class SelectionMemento;
class EditingContext : public ARDOUR::SessionHandlePtr class EditingContext : public ARDOUR::SessionHandlePtr, public AxisViewProvider
{ {
public: public:
/** Context for mouse entry (stored in a stack). */ /** Context for mouse entry (stored in a stack). */
@ -81,15 +86,24 @@ public:
bool preview_video_drag_active () const; bool preview_video_drag_active () const;
virtual void select_all_within (Temporal::timepos_t const &, Temporal::timepos_t const &, double, double, TrackViewList const &, Selection::Operation, bool) = 0; virtual void select_all_within (Temporal::timepos_t const &, Temporal::timepos_t const &, double, double, TrackViewList const &, Selection::Operation, bool) = 0;
virtual void get_per_region_note_selection (std::list<std::pair<PBD::ID, std::set<std::shared_ptr<Evoral::Note<Temporal::Beats> > > > >&) const = 0;
virtual void get_regionviews_by_id (PBD::ID const id, RegionSelection & regions) const = 0;
virtual StripableTimeAxisView* get_stripable_time_axis_by_id (const PBD::ID& id) const = 0;
virtual TrackViewList axis_views_from_routes (std::shared_ptr<ARDOUR::RouteList>) const = 0;
virtual EditorCursor* playhead_cursor () const = 0; virtual ARDOUR::Location* find_location_from_marker (ArdourMarker*, bool&) const = 0;
virtual EditorCursor* snapped_cursor () const = 0; virtual ArdourMarker* find_marker_from_location_id (PBD::ID const&, bool) const = 0;
virtual TempoMarker* find_marker_for_tempo (Temporal::TempoPoint const &) = 0;
virtual MeterMarker* find_marker_for_meter (Temporal::MeterPoint const &) = 0;
EditorCursor* playhead_cursor () const { return _playhead_cursor; }
EditorCursor* snapped_cursor () const { return _snapped_cursor; }
virtual void maybe_autoscroll (bool, bool, bool from_headers) = 0; virtual void maybe_autoscroll (bool, bool, bool from_headers) = 0;
virtual void stop_canvas_autoscroll () = 0; virtual void stop_canvas_autoscroll () = 0;
virtual bool autoscroll_active() const = 0; virtual bool autoscroll_active() const = 0;
virtual void instant_save() = 0;
virtual void redisplay_grid (bool immediate_redraw) = 0; virtual void redisplay_grid (bool immediate_redraw) = 0;
virtual Temporal::timecnt_t get_nudge_distance (Temporal::timepos_t const & pos, Temporal::timecnt_t& next) = 0; virtual Temporal::timecnt_t get_nudge_distance (Temporal::timepos_t const & pos, Temporal::timecnt_t& next) = 0;
@ -97,13 +111,15 @@ public:
* @param yn true to follow playhead, otherwise false. * @param yn true to follow playhead, otherwise false.
* @param catch_up true to reset the editor view to show the playhead (if yn == true), otherwise false. * @param catch_up true to reset the editor view to show the playhead (if yn == true), otherwise false.
*/ */
virtual void set_follow_playhead (bool yn, bool catch_up = true) = 0; void set_follow_playhead (bool yn, bool catch_up = true);
/** Toggle whether the editor is following the playhead */ /** Toggle whether the editor is following the playhead */
virtual void toggle_follow_playhead () = 0; void toggle_follow_playhead ();
/** @return true if the editor is following the playhead */ /** @return true if the editor is following the playhead */
virtual bool follow_playhead () const = 0; bool follow_playhead () const { return _follow_playhead; }
virtual void instant_save() = 0;
/** Get the topmost enter context for the given item type. /** Get the topmost enter context for the given item type.
* *
@ -119,10 +135,10 @@ public:
virtual void undo_selection_op () = 0; virtual void undo_selection_op () = 0;
virtual void redo_selection_op () = 0; virtual void redo_selection_op () = 0;
virtual void begin_reversible_command (std::string cmd_name) = 0; virtual void begin_reversible_command (std::string cmd_name);
virtual void begin_reversible_command (GQuark) = 0; virtual void begin_reversible_command (GQuark);
virtual void abort_reversible_command () = 0; virtual void abort_reversible_command ();
virtual void commit_reversible_command () = 0; virtual void commit_reversible_command ();
virtual void set_selected_midi_region_view (MidiRegionView&); virtual void set_selected_midi_region_view (MidiRegionView&);
@ -300,6 +316,23 @@ public:
virtual samplecnt_t current_page_samples() const = 0; virtual samplecnt_t current_page_samples() const = 0;
samplepos_t _leftmost_sample; samplepos_t _leftmost_sample;
/* playhead and edit cursor */
EditorCursor* _playhead_cursor;
EditorCursor* _snapped_cursor;
bool _follow_playhead;
virtual void reset_x_origin_to_follow_playhead () = 0;
/* selection process */
Selection* selection;
Selection* cut_buffer;
SelectionMemento* _selection_memento;
std::list<XMLNode*> before; /* used in *_reversible_command */
}; };
#endif /* __ardour_midi_editing_context_h__ */ #endif /* __ardour_midi_editing_context_h__ */

View file

@ -341,7 +341,6 @@ Editor::Editor ()
, last_event_time { 0, 0 } , last_event_time { 0, 0 }
, _dragging_playhead (false) , _dragging_playhead (false)
, ignore_map_change (false) , ignore_map_change (false)
, _follow_playhead (true)
, _stationary_playhead (false) , _stationary_playhead (false)
, _maximised (false) , _maximised (false)
, grid_lines (0) , grid_lines (0)
@ -357,9 +356,6 @@ Editor::Editor ()
, _visible_track_count (-1) , _visible_track_count (-1)
, toolbar_selection_clock_table (2,3) , toolbar_selection_clock_table (2,3)
, automation_mode_button (_("mode")) , automation_mode_button (_("mode"))
, selection (new Selection (this, true))
, cut_buffer (new Selection (this, false))
, _selection_memento (new SelectionMemento())
, _all_region_actions_sensitized (false) , _all_region_actions_sensitized (false)
, _ignore_region_action (false) , _ignore_region_action (false)
, _last_region_menu_was_main (false) , _last_region_menu_was_main (false)
@ -960,7 +956,7 @@ Editor::instant_save ()
return; return;
} }
_session->add_instant_xml(get_state()); _session->add_instant_xml (get_state());
} }
void void
@ -3574,56 +3570,6 @@ Editor::redo_selection_op ()
} }
} }
void
Editor::begin_reversible_command (string name)
{
if (_session) {
before.push_back (&_selection_memento->get_state ());
_session->begin_reversible_command (name);
}
}
void
Editor::begin_reversible_command (GQuark q)
{
if (_session) {
before.push_back (&_selection_memento->get_state ());
_session->begin_reversible_command (q);
}
}
void
Editor::abort_reversible_command ()
{
if (_session) {
while(!before.empty()) {
delete before.front();
before.pop_front();
}
_session->abort_reversible_command ();
}
}
void
Editor::commit_reversible_command ()
{
if (_session) {
if (before.size() == 1) {
_session->add_command (new MementoCommand<SelectionMemento>(*(_selection_memento), before.front(), &_selection_memento->get_state ()));
begin_selection_op_history ();
}
if (before.empty()) {
PBD::stacktrace(cerr, 30);
cerr << "Please call begin_reversible_command() before commit_reversible_command()." << endl;
} else {
before.pop_back();
}
_session->commit_reversible_command ();
}
}
void void
Editor::history_changed () Editor::history_changed ()
{ {
@ -4118,28 +4064,6 @@ Editor::update_grid ()
} }
} }
void
Editor::toggle_follow_playhead ()
{
RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Editor"), X_("toggle-follow-playhead"));
set_follow_playhead (tact->get_active());
}
/** @param yn true to follow playhead, otherwise false.
* @param catch_up true to reset the editor view to show the playhead (if yn == true), otherwise false.
*/
void
Editor::set_follow_playhead (bool yn, bool catch_up)
{
if (_follow_playhead != yn) {
if ((_follow_playhead = yn) == true && catch_up) {
/* catch up */
reset_x_origin_to_follow_playhead ();
}
instant_save ();
}
}
void void
Editor::toggle_stationary_playhead () Editor::toggle_stationary_playhead ()
{ {
@ -6759,35 +6683,6 @@ Editor::duration_to_pixels_unrounded (timecnt_t const & dur) const
return sample_to_pixel_unrounded (dur.samples()); return sample_to_pixel_unrounded (dur.samples());
} }
Temporal::TimeDomain
Editor::default_time_domain () const
{
if (_session) {
return _session->config.get_default_time_domain();
}
/* Probably never reached */
if (_snap_mode == SnapOff) {
return AudioTime;
}
switch (_grid_type) {
case GridTypeNone:
/* fallthrough */
case GridTypeMinSec:
/* fallthrough */
case GridTypeCDFrame:
/* fallthrough */
case GridTypeTimecode:
/* fallthrough */
return AudioTime;
default:
break;
}
return BeatTime;
}
void void
Editor::start_track_drag (TimeAxisView& tav, int y, Gtk::Widget& w, bool can_change_cursor) Editor::start_track_drag (TimeAxisView& tav, int y, Gtk::Widget& w, bool can_change_cursor)
{ {
@ -6888,3 +6783,4 @@ Editor::track_dragging() const
{ {
return (bool) track_drag; return (bool) track_drag;
} }

View file

@ -52,7 +52,6 @@
#include "gtkmm2ext/dndtreeview.h" #include "gtkmm2ext/dndtreeview.h"
#include "pbd/controllable.h" #include "pbd/controllable.h"
#include "pbd/stateful.h"
#include "pbd/signals.h" #include "pbd/signals.h"
#include "ardour/import_status.h" #include "ardour/import_status.h"
@ -379,9 +378,6 @@ public:
void toggle_stationary_playhead (); void toggle_stationary_playhead ();
bool stationary_playhead() const { return _stationary_playhead; } bool stationary_playhead() const { return _stationary_playhead; }
void set_follow_playhead (bool yn, bool catch_up = true);
void toggle_follow_playhead ();
bool follow_playhead() const { return _follow_playhead; }
bool dragging_playhead () const { return _dragging_playhead; } bool dragging_playhead () const { return _dragging_playhead; }
void toggle_zero_line_visibility (); void toggle_zero_line_visibility ();
@ -499,11 +495,6 @@ public:
void undo_selection_op (); void undo_selection_op ();
void redo_selection_op (); void redo_selection_op ();
void begin_reversible_command (std::string cmd_name);
void begin_reversible_command (GQuark);
void abort_reversible_command ();
void commit_reversible_command ();
MixerStrip* get_current_mixer_strip () const { MixerStrip* get_current_mixer_strip () const {
return current_mixer_strip; return current_mixer_strip;
} }
@ -606,8 +597,7 @@ protected:
private: private:
void color_handler (); void color_handler ();
bool constructed;
bool constructed;
// to keep track of the playhead position for control_scroll // to keep track of the playhead position for control_scroll
boost::optional<samplepos_t> _control_scroll_target; boost::optional<samplepos_t> _control_scroll_target;
@ -1077,9 +1067,6 @@ private:
int get_videotl_bar_height () const { return videotl_bar_height; } int get_videotl_bar_height () const { return videotl_bar_height; }
void toggle_region_video_lock (); void toggle_region_video_lock ();
EditorCursor* playhead_cursor () const { return _playhead_cursor; }
EditorCursor* snapped_cursor () const { return _snapped_cursor; }
samplepos_t playhead_cursor_sample () const; samplepos_t playhead_cursor_sample () const;
Temporal::timepos_t get_region_boundary (Temporal::timepos_t const & pos, int32_t dir, bool with_selection, bool only_onscreen); Temporal::timepos_t get_region_boundary (Temporal::timepos_t const & pos, int32_t dir, bool with_selection, bool only_onscreen);
@ -1803,8 +1790,6 @@ private:
/* display control */ /* display control */
/// true if the editor should follow the playhead, otherwise false
bool _follow_playhead;
/// true if we scroll the tracks rather than the playhead /// true if we scroll the tracks rather than the playhead
bool _stationary_playhead; bool _stationary_playhead;
/// true if we are in fullscreen mode /// true if we are in fullscreen mode
@ -2025,12 +2010,6 @@ private:
void setup_midi_toolbar (); void setup_midi_toolbar ();
/* selection process */
Selection* selection;
Selection* cut_buffer;
SelectionMemento* _selection_memento;
void time_selection_changed (); void time_selection_changed ();
void track_selection_changed (); void track_selection_changed ();
void update_time_selection_display (); void update_time_selection_display ();
@ -2063,11 +2042,6 @@ private:
SectionBox* _section_box; SectionBox* _section_box;
/* playhead and edit cursor */
EditorCursor* _playhead_cursor;
EditorCursor* _snapped_cursor;
/* transport range select process */ /* transport range select process */
ArdourCanvas::Rectangle* range_bar_drag_rect; ArdourCanvas::Rectangle* range_bar_drag_rect;
@ -2183,7 +2157,6 @@ private:
uint32_t selection_op_history_it; uint32_t selection_op_history_it;
std::list<XMLNode*> selection_op_history; /* used in *_reversible_selection_op */ std::list<XMLNode*> selection_op_history; /* used in *_reversible_selection_op */
std::list<XMLNode*> before; /* used in *_reversible_command */
void update_title (); void update_title ();
void update_title_s (const std::string & snapshot_name); void update_title_s (const std::string & snapshot_name);

View file

@ -60,7 +60,6 @@
#include "widgets/tabbable.h" #include "widgets/tabbable.h"
#include "axis_provider.h"
#include "editing.h" #include "editing.h"
#include "editing_context.h" #include "editing_context.h"
#include "selection.h" #include "selection.h"
@ -124,7 +123,7 @@ using ARDOUR::samplecnt_t;
* of PublicEditor need not be recompiled if private methods or member variables * of PublicEditor need not be recompiled if private methods or member variables
* change. * change.
*/ */
class PublicEditor : public ArdourWidgets::Tabbable, public EditingContext, public AxisViewProvider class PublicEditor : public ArdourWidgets::Tabbable, public EditingContext
{ {
public: public:
PublicEditor (Gtk::Widget& content); PublicEditor (Gtk::Widget& content);
@ -350,8 +349,6 @@ public:
virtual bool track_selection_change_without_scroll () const = 0; virtual bool track_selection_change_without_scroll () const = 0;
virtual bool show_touched_automation () const = 0; virtual bool show_touched_automation () const = 0;
virtual StripableTimeAxisView* get_stripable_time_axis_by_id (const PBD::ID& id) const = 0;
virtual TimeAxisView* time_axis_view_from_stripable (std::shared_ptr<ARDOUR::Stripable> s) const = 0; virtual TimeAxisView* time_axis_view_from_stripable (std::shared_ptr<ARDOUR::Stripable> s) const = 0;
virtual void get_equivalent_regions (RegionView* rv, std::vector<RegionView*>&, PBD::PropertyID) const = 0; virtual void get_equivalent_regions (RegionView* rv, std::vector<RegionView*>&, PBD::PropertyID) const = 0;
@ -431,7 +428,6 @@ public:
virtual void center_screen (samplepos_t) = 0; virtual void center_screen (samplepos_t) = 0;
virtual TrackViewList axis_views_from_routes (std::shared_ptr<ARDOUR::RouteList>) const = 0;
virtual TrackViewList const & get_track_views () const = 0; virtual TrackViewList const & get_track_views () const = 0;
virtual MixerStrip* get_current_mixer_strip () const = 0; virtual MixerStrip* get_current_mixer_strip () const = 0;
@ -450,20 +446,12 @@ public:
virtual void access_action (const std::string&, const std::string&) = 0; virtual void access_action (const std::string&, const std::string&) = 0;
virtual void set_toggleaction (const std::string&, const std::string&, bool) = 0; virtual void set_toggleaction (const std::string&, const std::string&, bool) = 0;
virtual EditorCursor* playhead_cursor () const = 0;
virtual EditorCursor* snapped_cursor () const = 0;
virtual bool get_smart_mode () const = 0; virtual bool get_smart_mode () const = 0;
virtual void get_pointer_position (double &, double &) const = 0; virtual void get_pointer_position (double &, double &) const = 0;
virtual std::pair <Temporal::timepos_t, Temporal::timepos_t> session_gui_extents (bool use_extra = true) const = 0; virtual std::pair <Temporal::timepos_t, Temporal::timepos_t> session_gui_extents (bool use_extra = true) const = 0;
virtual ARDOUR::Location* find_location_from_marker (ArdourMarker*, bool&) const = 0;
virtual ArdourMarker* find_marker_from_location_id (PBD::ID const&, bool) const = 0;
virtual TempoMarker* find_marker_for_tempo (Temporal::TempoPoint const &) = 0;
virtual MeterMarker* find_marker_for_meter (Temporal::MeterPoint const &) = 0;
virtual void snap_to_with_modifier (Temporal::timepos_t & first, virtual void snap_to_with_modifier (Temporal::timepos_t & first,
GdkEvent const* ev, GdkEvent const* ev,
Temporal::RoundMode direction = Temporal::RoundNearest, Temporal::RoundMode direction = Temporal::RoundNearest,
@ -474,8 +462,6 @@ public:
virtual void get_regions_at (RegionSelection &, Temporal::timepos_t const & where, TrackViewList const &) const = 0; virtual void get_regions_at (RegionSelection &, Temporal::timepos_t const & where, TrackViewList const &) const = 0;
virtual void get_regions_after (RegionSelection&, Temporal::timepos_t const & where, const TrackViewList& ts) const = 0; virtual void get_regions_after (RegionSelection&, Temporal::timepos_t const & where, const TrackViewList& ts) const = 0;
virtual RegionSelection get_regions_from_selection_and_mouse (Temporal::timepos_t const &) = 0; virtual RegionSelection get_regions_from_selection_and_mouse (Temporal::timepos_t const &) = 0;
virtual void get_regionviews_by_id (PBD::ID const id, RegionSelection & regions) const = 0;
virtual void get_per_region_note_selection (std::list<std::pair<PBD::ID, std::set<std::shared_ptr<Evoral::Note<Temporal::Beats> > > > >&) const = 0;
virtual void build_region_boundary_cache () = 0; virtual void build_region_boundary_cache () = 0;
virtual void mark_region_boundary_cache_dirty () = 0; virtual void mark_region_boundary_cache_dirty () = 0;

View file

@ -63,7 +63,7 @@ struct TimelineRangeComparator {
} }
}; };
Selection::Selection (const PublicEditor* e, bool mls) Selection::Selection (const EditingContext* e, bool mls)
: editor (e) : editor (e)
, next_time_id (0) , next_time_id (0)
, manage_libardour_selection (mls) , manage_libardour_selection (mls)

View file

@ -50,7 +50,7 @@
class TimeAxisView; class TimeAxisView;
class RegionView; class RegionView;
class Selectable; class Selectable;
class PublicEditor; class EditingContext;
class MidiRegionView; class MidiRegionView;
class AutomationLine; class AutomationLine;
class ControlPoint; class ControlPoint;
@ -97,7 +97,7 @@ public:
*/ */
MidiRegionSelection midi_regions(); MidiRegionSelection midi_regions();
Selection (PublicEditor const * e, bool manage_libardour_selection); Selection (EditingContext const * e, bool manage_libardour_selection);
// Selection& operator= (const Selection& other); // Selection& operator= (const Selection& other);
@ -245,7 +245,7 @@ public:
void core_selection_changed (PBD::PropertyChange const & pc); void core_selection_changed (PBD::PropertyChange const & pc);
private: private:
PublicEditor const * editor; EditingContext const * editor;
uint32_t next_time_id; uint32_t next_time_id;
bool manage_libardour_selection; bool manage_libardour_selection;
}; };