From cf88db7fe2433a3a53c5fdce9248c7a6078b7a95 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 16 Oct 2023 10:09:16 -0600 Subject: [PATCH] PublicEditor IS-A MidiEditingContext --- gtk2_ardour/editor.h | 1 - gtk2_ardour/midi_editing_context.cc | 33 ++++++++++++++ gtk2_ardour/midi_editing_context.h | 59 ++++++++++++++++++++----- gtk2_ardour/mini_timeline.cc | 2 +- gtk2_ardour/public_editor.h | 67 ++--------------------------- gtk2_ardour/wscript | 1 + 6 files changed, 86 insertions(+), 77 deletions(-) create mode 100644 gtk2_ardour/midi_editing_context.cc diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index e9d1ccd3ba..1f5271ad29 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -216,7 +216,6 @@ public: void set_mouse_mode (Editing::MouseMode, bool force = false); void step_mouse_mode (bool next); Editing::MouseMode current_mouse_mode () const { return mouse_mode; } - Editing::MidiEditMode current_midi_edit_mode () const; bool internal_editing() const; void remove_midi_note (ArdourCanvas::Item*, GdkEvent*); diff --git a/gtk2_ardour/midi_editing_context.cc b/gtk2_ardour/midi_editing_context.cc new file mode 100644 index 0000000000..12487bbc73 --- /dev/null +++ b/gtk2_ardour/midi_editing_context.cc @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2023 Paul Davis + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "midi_editing_context.h" + +MidiEditingContext::MidiEditingContext () +{ +} + +MidiEditingContext::~MidiEditingContext() +{ +} + +void +MidiEditingContext::set_session (ARDOUR::Session* s) +{ + SessionHandlePtr::set_session (s); +} diff --git a/gtk2_ardour/midi_editing_context.h b/gtk2_ardour/midi_editing_context.h index 5ecbb65930..d6fda4afb8 100644 --- a/gtk2_ardour/midi_editing_context.h +++ b/gtk2_ardour/midi_editing_context.h @@ -33,8 +33,23 @@ #ifndef __ardour_midi_editing_context_h__ #define __ardour_midi_editing_context_h__ +#include "pbd/signals.h" -class MidiEditingContext : public SessionHandlePtr, public PBD::ScopedConnectionList +#include "temporal/timeline.h" + +#include "ardour/session_handle.h" +#include "ardour/types.h" + +#include "editing.h" +#include "selection.h" + +using ARDOUR::samplepos_t; +using ARDOUR::samplecnt_t; + +class VerboseCursor; +class MouseCursors; + +class MidiEditingContext : public ARDOUR::SessionHandlePtr { public: MidiEditingContext (); @@ -57,6 +72,19 @@ public: virtual int32_t get_grid_beat_divisions (Editing::GridType gt) = 0; virtual int32_t get_grid_music_divisions (Editing::GridType gt, uint32_t event_state) = 0; + /** Set the snap type. + * @param t Snap type (defined in editing_syms.h) + */ + virtual void set_grid_to (Editing::GridType t) = 0; + + virtual Editing::GridType grid_type () const = 0; + virtual Editing::SnapMode snap_mode () const = 0; + + /** Set the snap mode. + * @param m Snap mode (defined in editing_syms.h) + */ + virtual void set_snap_mode (Editing::SnapMode m) = 0; + virtual void snap_to (Temporal::timepos_t & first, Temporal::RoundMode direction = Temporal::RoundNearest, ARDOUR::SnapPref pref = ARDOUR::SnapToAny_Visual, @@ -75,26 +103,35 @@ public: virtual double get_y_origin () const = 0; virtual void reset_x_origin (samplepos_t) = 0; virtual void reset_y_origin (double) = 0; + + virtual void set_zoom_focus (Editing::ZoomFocus) = 0; + virtual Editing::ZoomFocus get_zoom_focus () const = 0; + virtual samplecnt_t get_current_zoom () const = 0; virtual void reset_zoom (samplecnt_t) = 0; virtual void reposition_and_zoom (samplepos_t, double) = 0; virtual Selection& get_selection() const = 0; + /** Set the mouse mode (gain, object, range, timefx etc.) + * @param m Mouse mode (defined in editing_syms.h) + * @param force Perform the effects of the change even if no change is required + * (ie even if the current mouse mode is equal to @p m) + */ virtual void set_mouse_mode (Editing::MouseMode, bool force = false) = 0; + /** Step the mouse mode onto the next or previous one. + * @param next true to move to the next, otherwise move to the previous + */ virtual void step_mouse_mode (bool next) = 0; + /** @return The current mouse mode (gain, object, range, timefx etc.) + * (defined in editing_syms.h) + */ virtual Editing::MouseMode current_mouse_mode () const = 0; - virtual Editing::MidiEditMode current_midi_edit_mode () const = 0; + /** @return Whether the current mouse mode is an "internal" editing mode. */ virtual bool internal_editing() const = 0; - Gdk::Cursor* get_canvas_cursor () const; - - MouseCursors const* cursors () const { - return _cursors; - } - - VerboseCursor* verbose_cursor () const { - return _verbose_cursor; - } + virtual Gdk::Cursor* get_canvas_cursor () const = 0; + virtual MouseCursors const* cursors () const = 0; + virtual VerboseCursor* verbose_cursor () const = 0; }; #endif /* __ardour_midi_editing_context_h__ */ diff --git a/gtk2_ardour/mini_timeline.cc b/gtk2_ardour/mini_timeline.cc index be778941f7..33972aff2b 100644 --- a/gtk2_ardour/mini_timeline.cc +++ b/gtk2_ardour/mini_timeline.cc @@ -609,7 +609,7 @@ MiniTimeline::render (Cairo::RefPtr const& ctx, cairo_rectangle_ timepos_t rounded = timepos_t (tmap->quarters_at (tmap->round_to_bar (tmap->bbt_at (timepos_t(when))))); when = tmap->sample_at(rounded); } - + double xpos = width * .5 + (when - phead) * _px_per_sample; // TODO round to nearest display TC in +/- 1px diff --git a/gtk2_ardour/public_editor.h b/gtk2_ardour/public_editor.h index e474b95dfb..5e7ad98eeb 100644 --- a/gtk2_ardour/public_editor.h +++ b/gtk2_ardour/public_editor.h @@ -62,6 +62,7 @@ #include "axis_provider.h" #include "editing.h" +#include "midi_editing_context.h" #include "selection.h" namespace Temporal { @@ -123,7 +124,7 @@ using ARDOUR::samplecnt_t; * of PublicEditor need not be recompiled if private methods or member variables * change. */ -class PublicEditor : public ArdourWidgets::Tabbable, public ARDOUR::SessionHandlePtr, public AxisViewProvider +class PublicEditor : public ArdourWidgets::Tabbable, public MidiEditingContext, public AxisViewProvider { public: PublicEditor (Gtk::Widget& content); @@ -147,27 +148,7 @@ public: */ virtual void set_session (ARDOUR::Session* s) = 0; - /** Set the snap type. - * @param t Snap type (defined in editing_syms.h) - */ - virtual void set_grid_to (Editing::GridType t) = 0; - - virtual Editing::GridType grid_type () const = 0; - virtual Editing::SnapMode snap_mode () const = 0; - - /** Set the snap mode. - * @param m Snap mode (defined in editing_syms.h) - */ - virtual void set_snap_mode (Editing::SnapMode m) = 0; - - /** - * Snap a value according to the current snap setting. - * ensure_snap overrides SnapOff and magnetic snap - */ - virtual void snap_to (Temporal::timepos_t & first, - Temporal::RoundMode direction = Temporal::RoundNearest, - ARDOUR::SnapPref gpref = ARDOUR::SnapToAny_Visual, - bool ensure_snap = false) = 0; + virtual samplepos_t playhead_cursor_sample () const = 0; /** Undo some transactions. * @param n Number of transactions to undo. @@ -180,26 +161,6 @@ public: */ virtual void redo (uint32_t n = 1) = 0; - /** Set the mouse mode (gain, object, range, timefx etc.) - * @param m Mouse mode (defined in editing_syms.h) - * @param force Perform the effects of the change even if no change is required - * (ie even if the current mouse mode is equal to @p m) - */ - virtual void set_mouse_mode (Editing::MouseMode m, bool force = false) = 0; - - /** Step the mouse mode onto the next or previous one. - * @param next true to move to the next, otherwise move to the previous - */ - virtual void step_mouse_mode (bool next) = 0; - - /** @return The current mouse mode (gain, object, range, timefx etc.) - * (defined in editing_syms.h) - */ - virtual Editing::MouseMode current_mouse_mode () const = 0; - - /** @return Whether the current mouse mode is an "internal" editing mode. */ - virtual bool internal_editing() const = 0; - /** Possibly start the audition of a region. * * If \p r is 0, or not an AudioRegion any current audition is cancelled. @@ -226,16 +187,7 @@ public: virtual void pitch_shift_region () = 0; virtual void transition_to_rolling (bool fwd) = 0; - virtual samplepos_t pixel_to_sample (double pixel) const = 0; - virtual samplepos_t playhead_cursor_sample () const = 0; - virtual double sample_to_pixel (samplepos_t sample) const = 0; - virtual double sample_to_pixel_unrounded (samplepos_t sample) const = 0; - virtual double time_to_pixel (Temporal::timepos_t const &) const = 0; - virtual double time_to_pixel_unrounded (Temporal::timepos_t const &) const = 0; - virtual double duration_to_pixels (Temporal::timecnt_t const &) const = 0; - virtual double duration_to_pixels_unrounded (Temporal::timecnt_t const &) const = 0; - virtual Selection& get_selection () const = 0; virtual bool get_selection_extents (Temporal::timepos_t &start, Temporal::timepos_t &end) const = 0; virtual Selection& get_cut_buffer () const = 0; @@ -317,10 +269,6 @@ public: virtual void loudness_assistant (bool) = 0; virtual void register_actions () = 0; - virtual void set_zoom_focus (Editing::ZoomFocus) = 0; - virtual Editing::ZoomFocus get_zoom_focus () const = 0; - virtual samplecnt_t get_current_zoom () const = 0; - virtual void reset_zoom (samplecnt_t) = 0; virtual void clear_playlist (std::shared_ptr) = 0; virtual void clear_grouped_playlists (RouteUI*) = 0; @@ -379,9 +327,6 @@ public: virtual void cleanup_regions () = 0; virtual void prepare_for_cleanup () = 0; virtual void finish_cleanup () = 0; - virtual void reset_x_origin (samplepos_t sample) = 0; - virtual double get_y_origin () const = 0; - virtual void reset_y_origin (double pos) = 0; virtual void set_visible_track_count (int32_t) = 0; virtual void fit_selection () = 0; virtual void remove_last_capture () = 0; @@ -403,9 +348,6 @@ public: virtual int draw_velocity () const = 0; virtual int draw_channel () const = 0; - virtual int32_t get_grid_beat_divisions (Editing::GridType gt) = 0; - virtual int32_t get_grid_music_divisions (Editing::GridType gt, uint32_t event_state) = 0; - virtual void edit_notes (MidiRegionView*) = 0; virtual void queue_visual_videotimeline_update () = 0; @@ -539,9 +481,6 @@ public: virtual void access_action (const std::string&, const std::string&) = 0; virtual void set_toggleaction (const std::string&, const std::string&, bool) = 0; - virtual MouseCursors const* cursors () const = 0; - virtual VerboseCursor* verbose_cursor () const = 0; - virtual EditorCursor* playhead_cursor () const = 0; virtual EditorCursor* snapped_cursor () const = 0; diff --git a/gtk2_ardour/wscript b/gtk2_ardour/wscript index 0869f99a23..0c5f368ea8 100644 --- a/gtk2_ardour/wscript +++ b/gtk2_ardour/wscript @@ -159,6 +159,7 @@ gtk2_ardour_sources = [ 'midi_channel_selector.cc', 'midi_clip_editor.cc', 'midi_cut_buffer.cc', + 'midi_editing_context.cc', 'midi_export_dialog.cc', 'midi_list_editor.cc', 'midi_region_view.cc',