From f75dde7fbc46116d1b9ff1b6ad1e938381a546a8 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Thu, 4 Jan 2024 19:02:59 -0700 Subject: [PATCH] constification of EditingContext/{Public}Editor time+snap methods --- gtk2_ardour/cue_editor.cc | 2 +- gtk2_ardour/cue_editor.h | 2 +- gtk2_ardour/editing_context.cc | 10 +++++----- gtk2_ardour/editing_context.h | 27 +++++++++++++++------------ gtk2_ardour/editor.cc | 21 +++++++++++---------- gtk2_ardour/editor.h | 22 +++++++++++----------- gtk2_ardour/midi_cue_editor.cc | 4 ++-- gtk2_ardour/midi_cue_editor.h | 14 ++++++++------ gtk2_ardour/midi_region_view.cc | 16 +++++++++------- 9 files changed, 63 insertions(+), 55 deletions(-) diff --git a/gtk2_ardour/cue_editor.cc b/gtk2_ardour/cue_editor.cc index 00e9475092..40adb5fa62 100644 --- a/gtk2_ardour/cue_editor.cc +++ b/gtk2_ardour/cue_editor.cc @@ -94,7 +94,7 @@ CueEditor::redisplay_grid (bool immediate_redraw) } Temporal::timecnt_t -CueEditor::get_nudge_distance (Temporal::timepos_t const & pos, Temporal::timecnt_t& next) +CueEditor::get_nudge_distance (Temporal::timepos_t const & pos, Temporal::timecnt_t& next) const { return Temporal::timecnt_t (Temporal::AudioTime); } diff --git a/gtk2_ardour/cue_editor.h b/gtk2_ardour/cue_editor.h index bd079405fd..46706c57ab 100644 --- a/gtk2_ardour/cue_editor.h +++ b/gtk2_ardour/cue_editor.h @@ -46,7 +46,7 @@ class CueEditor : public EditingContext bool autoscroll_active() const; void redisplay_grid (bool immediate_redraw); - Temporal::timecnt_t get_nudge_distance (Temporal::timepos_t const & pos, Temporal::timecnt_t& next); + Temporal::timecnt_t get_nudge_distance (Temporal::timepos_t const & pos, Temporal::timecnt_t& next) const; void instant_save(); diff --git a/gtk2_ardour/editing_context.cc b/gtk2_ardour/editing_context.cc index 1d2b8bfac0..7e0e877e68 100644 --- a/gtk2_ardour/editing_context.cc +++ b/gtk2_ardour/editing_context.cc @@ -1218,7 +1218,7 @@ EditingContext::duration_to_pixels_unrounded (timecnt_t const & dur) const * @param event Event to get current key modifier information from, or 0. */ void -EditingContext::snap_to_with_modifier (timepos_t& start, GdkEvent const * event, Temporal::RoundMode direction, SnapPref pref, bool ensure_snap) +EditingContext::snap_to_with_modifier (timepos_t& start, GdkEvent const * event, Temporal::RoundMode direction, SnapPref pref, bool ensure_snap) const { if (!_session || !event) { return; @@ -1240,7 +1240,7 @@ EditingContext::snap_to_with_modifier (timepos_t& start, GdkEvent const * event, } void -EditingContext::snap_to (timepos_t& start, Temporal::RoundMode direction, SnapPref pref, bool ensure_snap) +EditingContext::snap_to (timepos_t& start, Temporal::RoundMode direction, SnapPref pref, bool ensure_snap) const { if (!_session || (_snap_mode == SnapOff && !ensure_snap)) { return; @@ -1250,13 +1250,13 @@ EditingContext::snap_to (timepos_t& start, Temporal::RoundMode direction, SnapPr } timepos_t -EditingContext::snap_to_bbt (timepos_t const & presnap, Temporal::RoundMode direction, SnapPref gpref) +EditingContext::snap_to_bbt (timepos_t const & presnap, Temporal::RoundMode direction, SnapPref gpref) const { return _snap_to_bbt (presnap, direction, gpref, _grid_type); } timepos_t -EditingContext::_snap_to_bbt (timepos_t const & presnap, Temporal::RoundMode direction, SnapPref gpref, GridType grid_type) +EditingContext::_snap_to_bbt (timepos_t const & presnap, Temporal::RoundMode direction, SnapPref gpref, GridType grid_type) const { timepos_t ret(presnap); TempoMap::SharedPtr tmap (TempoMap::use()); @@ -1373,7 +1373,7 @@ EditingContext::_snap_to_bbt (timepos_t const & presnap, Temporal::RoundMode dir } void -EditingContext::check_best_snap (timepos_t const & presnap, timepos_t &test, timepos_t &dist, timepos_t &best) +EditingContext::check_best_snap (timepos_t const & presnap, timepos_t &test, timepos_t &dist, timepos_t &best) const { timepos_t diff = timepos_t (presnap.distance (test).abs ()); if (diff < dist) { diff --git a/gtk2_ardour/editing_context.h b/gtk2_ardour/editing_context.h index fd4dea6097..edddd1a7e1 100644 --- a/gtk2_ardour/editing_context.h +++ b/gtk2_ardour/editing_context.h @@ -106,7 +106,8 @@ public: virtual bool autoscroll_active() const = 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) const = 0; + Temporal::timecnt_t relative_distance (Temporal::timepos_t const & origin, Temporal::timecnt_t const & duration, Temporal::TimeDomain domain); Temporal::timecnt_t snap_relative_time_to_relative_time (Temporal::timepos_t const & origin, Temporal::timecnt_t const & x, bool ensure_snap) const; @@ -194,11 +195,13 @@ public: */ samplepos_t canvas_event_sample (GdkEvent const * event, double* pcx = nullptr, double* pcy = nullptr) const; - virtual Temporal::Beats get_grid_type_as_beats (bool& success, Temporal::timepos_t const & position) = 0; - virtual Temporal::Beats get_draw_length_as_beats (bool& success, Temporal::timepos_t const & position) = 0; + virtual bool canvas_note_event (GdkEvent* event, ArdourCanvas::Item*) = 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 Temporal::Beats get_grid_type_as_beats (bool& success, Temporal::timepos_t const & position) const = 0; + virtual Temporal::Beats get_draw_length_as_beats (bool& success, Temporal::timepos_t const & position) const = 0; + + virtual int32_t get_grid_beat_divisions (Editing::GridType gt) const = 0; + virtual int32_t get_grid_music_divisions (Editing::GridType gt, uint32_t event_state) const = 0; Editing::GridType grid_type () const; bool grid_type_is_musical (Editing::GridType) const; @@ -223,17 +226,17 @@ public: virtual void snap_to (Temporal::timepos_t & first, Temporal::RoundMode direction = Temporal::RoundNearest, ARDOUR::SnapPref pref = ARDOUR::SnapToAny_Visual, - bool ensure_snap = false); + bool ensure_snap = false) const; virtual void snap_to_with_modifier (Temporal::timepos_t & first, GdkEvent const* ev, Temporal::RoundMode direction = Temporal::RoundNearest, ARDOUR::SnapPref gpref = ARDOUR::SnapToAny_Visual, - bool ensure_snap = false); + bool ensure_snap = false) const; virtual Temporal::timepos_t snap_to_bbt (Temporal::timepos_t const & start, Temporal::RoundMode direction, - ARDOUR::SnapPref gpref); + ARDOUR::SnapPref gpref) const; virtual double get_y_origin () const = 0; virtual void reset_x_origin (samplepos_t) = 0; @@ -383,18 +386,18 @@ public: Temporal::timepos_t _snap_to_bbt (Temporal::timepos_t const & start, Temporal::RoundMode direction, ARDOUR::SnapPref gpref, - Editing::GridType grid_type); + Editing::GridType grid_type) const; virtual Temporal::timepos_t snap_to_grid (Temporal::timepos_t const & start, Temporal::RoundMode direction, - ARDOUR::SnapPref gpref) = 0; + ARDOUR::SnapPref gpref) const = 0; virtual void snap_to_internal (Temporal::timepos_t& first, Temporal::RoundMode direction = Temporal::RoundNearest, ARDOUR::SnapPref gpref = ARDOUR::SnapToAny_Visual, - bool ensure_snap = false) = 0; + bool ensure_snap = false) const = 0; - void check_best_snap (Temporal::timepos_t const & presnap, Temporal::timepos_t &test, Temporal::timepos_t &dist, Temporal::timepos_t &best); + void check_best_snap (Temporal::timepos_t const & presnap, Temporal::timepos_t &test, Temporal::timepos_t &dist, Temporal::timepos_t &best) const; virtual double visible_canvas_width() const = 0; enum BBTRulerScale { diff --git a/gtk2_ardour/editor.cc b/gtk2_ardour/editor.cc index 6834ae77a5..4c0ad6f46c 100644 --- a/gtk2_ardour/editor.cc +++ b/gtk2_ardour/editor.cc @@ -2552,7 +2552,7 @@ Editor::set_snapped_cursor_position (timepos_t const & pos) timepos_t -Editor::snap_to_timecode (timepos_t const & presnap, Temporal::RoundMode direction, SnapPref gpref) +Editor::snap_to_timecode (timepos_t const & presnap, Temporal::RoundMode direction, SnapPref gpref) const { timepos_t start = presnap; samplepos_t start_sample = presnap.samples(); @@ -2629,7 +2629,7 @@ Editor::snap_to_timecode (timepos_t const & presnap, Temporal::RoundMode directi } timepos_t -Editor::snap_to_minsec (timepos_t const & presnap, Temporal::RoundMode direction, SnapPref gpref) +Editor::snap_to_minsec (timepos_t const & presnap, Temporal::RoundMode direction, SnapPref gpref) const { samplepos_t presnap_sample = presnap.samples (); @@ -2679,7 +2679,7 @@ Editor::snap_to_minsec (timepos_t const & presnap, Temporal::RoundMode direction } timepos_t -Editor::snap_to_cd_frames (timepos_t const & presnap, Temporal::RoundMode direction, SnapPref gpref) +Editor::snap_to_cd_frames (timepos_t const & presnap, Temporal::RoundMode direction, SnapPref gpref) const { if ((gpref != SnapToGrid_Unscaled) && (minsec_ruler_scale != minsec_show_msecs)) { return snap_to_minsec (presnap, direction, gpref); @@ -2702,7 +2702,7 @@ Editor::snap_to_cd_frames (timepos_t const & presnap, Temporal::RoundMode direct } timepos_t -Editor::snap_to_grid (timepos_t const & presnap, Temporal::RoundMode direction, SnapPref gpref) +Editor::snap_to_grid (timepos_t const & presnap, Temporal::RoundMode direction, SnapPref gpref) const { timepos_t ret(presnap); @@ -2728,7 +2728,7 @@ Editor::snap_to_grid (timepos_t const & presnap, Temporal::RoundMode direction, } timepos_t -Editor::snap_to_marker (timepos_t const & presnap, Temporal::RoundMode direction) +Editor::snap_to_marker (timepos_t const & presnap, Temporal::RoundMode direction) const { timepos_t before; timepos_t after; @@ -3729,7 +3729,7 @@ Editor::get_paste_offset (Temporal::timepos_t const & pos, unsigned paste_count, } int32_t -Editor::get_grid_beat_divisions (GridType gt) +Editor::get_grid_beat_divisions (GridType gt) const { switch (gt) { case GridTypeBeatDiv32: return 32; @@ -3766,13 +3766,13 @@ Editor::get_grid_beat_divisions (GridType gt) * @return Music grid beat divisions */ int32_t -Editor::get_grid_music_divisions (Editing::GridType gt, uint32_t event_state) +Editor::get_grid_music_divisions (Editing::GridType gt, uint32_t event_state) const { return get_grid_beat_divisions (gt); } Temporal::Beats -Editor::get_grid_type_as_beats (bool& success, timepos_t const & position) +Editor::get_grid_type_as_beats (bool& success, timepos_t const & position) const { success = true; @@ -3814,6 +3814,7 @@ Editor::get_grid_type_as_beats (bool& success, timepos_t const & position) case GridTypeBeatDiv3: //Triplet eighth return Temporal::Beats::from_double (tmap->meter_at (position).note_value() / 12.0); + case GridTypeBeatDiv6: return Temporal::Beats::from_double (tmap->meter_at (position).note_value() / 24.0); @@ -3850,7 +3851,7 @@ Editor::get_grid_type_as_beats (bool& success, timepos_t const & position) } Temporal::Beats -Editor::get_draw_length_as_beats (bool& success, timepos_t const & position) +Editor::get_draw_length_as_beats (bool& success, timepos_t const & position) const { success = true; GridType grid_to_use = draw_length() == DRAW_LEN_AUTO ? grid_type() : draw_length(); @@ -3865,7 +3866,7 @@ Editor::get_draw_length_as_beats (bool& success, timepos_t const & position) } timecnt_t -Editor::get_nudge_distance (timepos_t const & pos, timecnt_t& next) +Editor::get_nudge_distance (timepos_t const & pos, timecnt_t& next) const { timecnt_t ret; diff --git a/gtk2_ardour/editor.h b/gtk2_ardour/editor.h index 541c1c3788..ffc945f630 100644 --- a/gtk2_ardour/editor.h +++ b/gtk2_ardour/editor.h @@ -319,14 +319,14 @@ public: /* nudge is initiated by transport controls owned by ARDOUR_UI */ - Temporal::timecnt_t get_nudge_distance (Temporal::timepos_t const & pos, Temporal::timecnt_t& next); + Temporal::timecnt_t get_nudge_distance (Temporal::timepos_t const & pos, Temporal::timecnt_t& next) const; Temporal::timecnt_t get_paste_offset (Temporal::timepos_t const & pos, unsigned paste_count, Temporal::timecnt_t const & duration); - Temporal::Beats get_grid_type_as_beats (bool& success, Temporal::timepos_t const & position); - Temporal::Beats get_draw_length_as_beats (bool& success, Temporal::timepos_t const & position); + Temporal::Beats get_grid_type_as_beats (bool& success, Temporal::timepos_t const & position) const; + Temporal::Beats get_draw_length_as_beats (bool& success, Temporal::timepos_t const & position) const; - int32_t get_grid_beat_divisions (Editing::GridType gt); - int32_t get_grid_music_divisions (Editing::GridType gt, uint32_t event_state); + int32_t get_grid_beat_divisions (Editing::GridType gt) const; + int32_t get_grid_music_divisions (Editing::GridType gt, uint32_t event_state) const; void nudge_forward (bool next, bool force_playhead); void nudge_backward (bool next, bool force_playhead); @@ -2204,27 +2204,27 @@ private: Temporal::timepos_t snap_to_minsec (Temporal::timepos_t const & start, Temporal::RoundMode direction, - ARDOUR::SnapPref gpref); + ARDOUR::SnapPref gpref) const; Temporal::timepos_t snap_to_cd_frames (Temporal::timepos_t const & start, Temporal::RoundMode direction, - ARDOUR::SnapPref gpref); + ARDOUR::SnapPref gpref) const; Temporal::timepos_t snap_to_timecode (Temporal::timepos_t const & start, Temporal::RoundMode direction, - ARDOUR::SnapPref gpref); + ARDOUR::SnapPref gpref) const; Temporal::timepos_t snap_to_grid (Temporal::timepos_t const & start, Temporal::RoundMode direction, - ARDOUR::SnapPref gpref); + ARDOUR::SnapPref gpref) const; void snap_to_internal (Temporal::timepos_t & first, Temporal::RoundMode direction = Temporal::RoundNearest, ARDOUR::SnapPref gpref = ARDOUR::SnapToAny_Visual, - bool for_mark = false); + bool for_mark = false) const; Temporal::timepos_t snap_to_marker (Temporal::timepos_t const & presnap, - Temporal::RoundMode direction = Temporal::RoundNearest); + Temporal::RoundMode direction = Temporal::RoundNearest) const; double visible_canvas_width() const { return _visible_canvas_width; } diff --git a/gtk2_ardour/midi_cue_editor.cc b/gtk2_ardour/midi_cue_editor.cc index 431f9019a2..c643fcef9a 100644 --- a/gtk2_ardour/midi_cue_editor.cc +++ b/gtk2_ardour/midi_cue_editor.cc @@ -97,7 +97,7 @@ MidiCueEditor::build_canvas () timepos_t -MidiCueEditor::snap_to_grid (timepos_t const & presnap, Temporal::RoundMode direction, SnapPref gpref) +MidiCueEditor::snap_to_grid (timepos_t const & presnap, Temporal::RoundMode direction, SnapPref gpref) const { /* BBT time only */ return snap_to_bbt (presnap, direction, gpref); @@ -105,7 +105,7 @@ MidiCueEditor::snap_to_grid (timepos_t const & presnap, Temporal::RoundMode dire void -MidiCueEditor::snap_to_internal (timepos_t& start, Temporal::RoundMode direction, SnapPref pref, bool ensure_snap) +MidiCueEditor::snap_to_internal (timepos_t& start, Temporal::RoundMode direction, SnapPref pref, bool ensure_snap) const { UIConfiguration const& uic (UIConfiguration::instance ()); const timepos_t presnap = start; diff --git a/gtk2_ardour/midi_cue_editor.h b/gtk2_ardour/midi_cue_editor.h index d63e9a4cd5..c2850099fb 100644 --- a/gtk2_ardour/midi_cue_editor.h +++ b/gtk2_ardour/midi_cue_editor.h @@ -48,11 +48,13 @@ class MidiCueEditor : public CueEditor void get_per_region_note_selection (std::list > > > >&) const {} - Temporal::Beats get_grid_type_as_beats (bool& success, Temporal::timepos_t const & position) { return Temporal::Beats (1, 0); } - Temporal::Beats get_draw_length_as_beats (bool& success, Temporal::timepos_t const & position) { return Temporal::Beats (1, 0); } + Temporal::Beats get_grid_type_as_beats (bool& success, Temporal::timepos_t const & position) const { return Temporal::Beats (1, 0); } + Temporal::Beats get_draw_length_as_beats (bool& success, Temporal::timepos_t const & position) const { return Temporal::Beats (1, 0); } - int32_t get_grid_beat_divisions (Editing::GridType gt) { return 1; } - int32_t get_grid_music_divisions (Editing::GridType gt, uint32_t event_state) { return 1; } + bool canvas_note_event (GdkEvent* event, ArdourCanvas::Item*); + + int32_t get_grid_beat_divisions (Editing::GridType gt) const { return 1; } + int32_t get_grid_music_divisions (Editing::GridType gt, uint32_t event_state) const { return 1; } void apply_midi_note_edit_op (ARDOUR::MidiOperator& op, const RegionSelection& rs); PBD::Command* apply_midi_note_edit_op_to_region (ARDOUR::MidiOperator& op, MidiRegionView& mrv); @@ -60,12 +62,12 @@ class MidiCueEditor : public CueEditor protected: Temporal::timepos_t snap_to_grid (Temporal::timepos_t const & start, Temporal::RoundMode direction, - ARDOUR::SnapPref gpref); + ARDOUR::SnapPref gpref) const; void snap_to_internal (Temporal::timepos_t& first, Temporal::RoundMode direction = Temporal::RoundNearest, ARDOUR::SnapPref gpref = ARDOUR::SnapToAny_Visual, - bool ensure_snap = false); + bool ensure_snap = false) const; private: Gtk::Adjustment vertical_adjustment; diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 0d5995db79..7bf4a39940 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -1933,7 +1933,7 @@ MidiRegionView::add_note(const std::shared_ptr note, bool visible) if (midi_view()->note_mode() == Sustained) { - Note* ev_rect = new Note (*this, _note_group, note); // XXX may leak + Note* ev_rect; // XXXX = new Note (*this, _note_group, note); // XXX may leak update_sustained (ev_rect); @@ -1943,7 +1943,7 @@ MidiRegionView::add_note(const std::shared_ptr note, bool visible) const double diamond_size = std::max(1., floor(note_height()) - 2.); - Hit* ev_diamond = new Hit (*this, _note_group, diamond_size, note); // XXX may leak + Hit* ev_diamond; // XXXX = new Hit (*this, _note_group, diamond_size, note); // XXX may leak update_hit (ev_diamond); @@ -2045,6 +2045,8 @@ MidiRegionView::add_canvas_patch_change (MidiModel::PatchChangePtr patch) // so we need to do something more sophisticated to keep its color // appearance (MidiPatchChangeFill/MidiPatchChangeInactiveChannelFill) // up to date. +#warning paul fix MRV/MV +#if 0 std::shared_ptr patch_change = std::shared_ptr( new PatchChange(*this, group, height, x, 1.0, @@ -2053,8 +2055,8 @@ MidiRegionView::add_canvas_patch_change (MidiModel::PatchChangePtr patch) _patch_change_outline, _patch_change_fill) ); - _patch_changes.insert (make_pair (patch, patch_change)); +#endif } void @@ -2772,11 +2774,11 @@ MidiRegionView::copy_selection (NoteBase* primary) for (Selection::iterator i = _selection.begin(); i != _selection.end(); ++i) { std::shared_ptr g (new NoteType (*((*i)->note()))); if (midi_view()->note_mode() == Sustained) { - Note* n = new Note (*this, _note_group, g); + Note* n; // XXXX = new Note (*this, _note_group, g); update_sustained (n, false); note = n; } else { - Hit* h = new Hit (*this, _note_group, 10, g); + Hit* h; // XXXX = new Hit (*this, _note_group, 10, g); update_hit (h, false); note = h; } @@ -4257,9 +4259,9 @@ MidiRegionView::create_ghost_note (double x, double y, uint32_t state) std::shared_ptr g (new NoteType); if (midi_view()->note_mode() == Sustained) { - _ghost_note = new Note (*this, _note_group, g); + // XXXX _ghost_note = new Note (*this, _note_group, g); } else { - _ghost_note = new Hit (*this, _note_group, 10, g); + // XXXX _ghost_note = new Hit (*this, _note_group, 10, g); } _ghost_note->set_ignore_events (true); _ghost_note->set_outline_color (0x000000aa);