From 1ed98764463dfffcb6275d89a466da711b0224e6 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Mon, 2 Jun 2025 19:28:10 -0600 Subject: [PATCH] Change various positions and dimensions to integer from double This includes note heights, note positions, contents height for streamviews, positions of tracks. It makes zero sense to think of these as having potentially fractional positions. In addition, fractional note heights and positions lead to numerous errors drawing MIDI stuff at the pixel level. --- gtk2_ardour/automation_streamview.h | 2 +- gtk2_ardour/editor_drag.cc | 6 +++--- gtk2_ardour/editor_ops.cc | 2 +- gtk2_ardour/midi_region_view.h | 2 +- gtk2_ardour/midi_streamview.cc | 2 +- gtk2_ardour/midi_streamview.h | 6 +++--- gtk2_ardour/midi_view.cc | 14 +++++++------- gtk2_ardour/midi_view.h | 8 ++++---- gtk2_ardour/midi_view_background.cc | 6 +++--- gtk2_ardour/midi_view_background.h | 20 +++++++++++--------- gtk2_ardour/pianoroll_background.h | 12 ++++++------ gtk2_ardour/time_axis_view.cc | 2 +- gtk2_ardour/time_axis_view.h | 6 +++--- gtk2_ardour/view_background.h | 8 ++++---- 14 files changed, 49 insertions(+), 47 deletions(-) diff --git a/gtk2_ardour/automation_streamview.h b/gtk2_ardour/automation_streamview.h index 7dff07076a..fd607d5458 100644 --- a/gtk2_ardour/automation_streamview.h +++ b/gtk2_ardour/automation_streamview.h @@ -51,7 +51,7 @@ public: void redisplay_track (); - double contents_height() const { + int contents_height() const { return (_trackview.current_height() - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 2); } diff --git a/gtk2_ardour/editor_drag.cc b/gtk2_ardour/editor_drag.cc index e74928f3d5..ccb616828d 100644 --- a/gtk2_ardour/editor_drag.cc +++ b/gtk2_ardour/editor_drag.cc @@ -6815,9 +6815,9 @@ NoteCreateDrag::start_grab (GdkEvent* event, Gdk::Cursor* cursor) double const x0 = editing_context.sample_to_pixel (rrp1.samples ()); double const x1 = editing_context.sample_to_pixel (rrp2.samples ()); - double const y = _midi_view->note_to_y (_midi_view->y_to_note (y_to_region (event->button.y))); + int const y = _midi_view->note_to_y (_midi_view->y_to_note (y_to_region (event->button.y))); - _drag_rect->set (ArdourCanvas::Rect (x0, y, x1, y + floor (_midi_view->midi_context ().note_height ()))); + _drag_rect->set (ArdourCanvas::Rect (x0, y, x1, y + _midi_view->midi_context ().note_height ())); _drag_rect->set_outline_all (); _drag_rect->set_outline_color (0xffffff99); _drag_rect->set_fill_color (0xffffff66); @@ -6896,7 +6896,7 @@ HitCreateDrag::HitCreateDrag (EditingContext& ec, ArdourCanvas::Item* i, MidiVie : Drag (ec, i, Temporal::BeatTime, ec.get_trackview_group()) , _midi_view (mv) , _last_pos (Temporal::Beats ()) - , _y (0.0) + , _y (0) { } diff --git a/gtk2_ardour/editor_ops.cc b/gtk2_ardour/editor_ops.cc index 20b98c82d7..16141ea3e4 100644 --- a/gtk2_ardour/editor_ops.cc +++ b/gtk2_ardour/editor_ops.cc @@ -8442,7 +8442,7 @@ Editor::fit_tracks (TrackViewList & tracks) * - height of the ruler/hscroll area */ uint32_t h = (uint32_t) floor ((trackviews_height() - child_heights) / visible_tracks); - double first_y_pos = DBL_MAX; + int first_y_pos = std::numeric_limits::max(); if (h < TimeAxisView::preset_height (HeightSmall)) { ArdourMessageDialog msg (_("There are too many tracks to fit in the current window")); diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h index 9c5af44d1c..a411595f8f 100644 --- a/gtk2_ardour/midi_region_view.h +++ b/gtk2_ardour/midi_region_view.h @@ -177,7 +177,7 @@ public: void leave_internal (); void mouse_mode_changed (); - double contents_height() const { return (_height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 2); } + int contents_height() const { return (_height - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 2); } void connect_to_diskstream (); bool pianoroll_window_deleted (GdkEventAny*); diff --git a/gtk2_ardour/midi_streamview.cc b/gtk2_ardour/midi_streamview.cc index 94fb25af50..97c08b8a6c 100644 --- a/gtk2_ardour/midi_streamview.cc +++ b/gtk2_ardour/midi_streamview.cc @@ -531,7 +531,7 @@ MidiStreamView::record_layer_check (std::shared_ptr r, samplepos check_record_layers (r, t); } -double +int MidiStreamView::y_position () const { return _trackview.y_position(); diff --git a/gtk2_ardour/midi_streamview.h b/gtk2_ardour/midi_streamview.h index 190f8a18ff..9cc0c103ca 100644 --- a/gtk2_ardour/midi_streamview.h +++ b/gtk2_ardour/midi_streamview.h @@ -69,11 +69,11 @@ public: //bool can_change_layer_display() const { return false; } // revert this change for now. Although stacked view is weirdly implemented wrt the "scroomer", it is still necessary to be able to manage layered regions. void redisplay_track (); - double contents_height() const { - return (child_height() - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 2); + int contents_height() const { + return child_height() - TimeAxisViewItem::NAME_HIGHLIGHT_SIZE - 2; } - double y_position () const; + int y_position () const; RegionView* create_region_view (std::shared_ptr, bool, bool); diff --git a/gtk2_ardour/midi_view.cc b/gtk2_ardour/midi_view.cc index 34755e2bc4..5f61aede6f 100644 --- a/gtk2_ardour/midi_view.cc +++ b/gtk2_ardour/midi_view.cc @@ -1483,7 +1483,7 @@ MidiView::display_sysexes() const double x = _editing_context.time_to_pixel (_midi_region->source_beats_to_region_time (time.beats())); - double height = _midi_context.contents_height(); + int height = _midi_context.contents_height(); // CAIROCANVAS: no longer passing *i (the sysex event) to the // SysEx canvas object!!! @@ -1513,7 +1513,7 @@ MidiView::update_sysexes () return; } - double height = _midi_context.contents_height(); + int height = _midi_context.contents_height(); for (SysExes::iterator s = _sys_exes.begin(); s != _sys_exes.end(); ++s) { @@ -1844,7 +1844,7 @@ MidiView::clip_capture_update_sustained (Note *ev, double& x0, double& x1, doubl timepos_t note_end (note->end_time()); x0 = _editing_context.sample_to_pixel (note_start.samples()); - y0 = 1 + floor(note_to_y(note->note())); + y0 = 1 + note_to_y (note->note()); if (note->length() == Temporal::Beats()) { @@ -1873,7 +1873,7 @@ MidiView::clip_capture_update_sustained (Note *ev, double& x0, double& x1, doubl x1 = x0 + std::max (1., _editing_context.duration_to_pixels (note_start.distance (active_note_end.end()))); } - y1 = y0 + std::max (1., floor(note_height()) - 1); + y1 = y0 + std::max (1., note_height() - 1.); } void @@ -1903,7 +1903,7 @@ MidiView::region_update_sustained (Note *ev, double& x0, double& x1, double& y0, const samplepos_t note_start_samples = _midi_region->position().distance ((note_start + session_source_start)).samples(); x0 = _editing_context.sample_to_pixel (note_start_samples); - y0 = 1 + floor(note_to_y(note->note())); + y0 = 1 + note_to_y (note->note()); if (note->length() == Temporal::Beats()) { @@ -1954,7 +1954,7 @@ MidiView::update_hit (Hit* ev) } const double diamond_size = std::max(1., floor(note_height()) - 2.); - const double y = 1.5 + floor(note_to_y(note->note())) + diamond_size * .5; + double y = 1.5 + note_to_y (note->note()) + diamond_size * .5; if (y <= 0 || y >= height()) { ev->hide(); @@ -2090,7 +2090,7 @@ MidiView::add_canvas_patch_change (MidiModel::PatchChangePtr patch) timecnt_t off (_midi_region->source_beats_to_region_time (patch->time()), _midi_region->position()); const double x = _editing_context.duration_to_pixels (off); - double const height = _midi_context.contents_height(); + int const height = _midi_context.contents_height(); // CAIROCANVAS: active_channel info removed from PatcChange constructor // so we need to do something more sophisticated to keep its color diff --git a/gtk2_ardour/midi_view.h b/gtk2_ardour/midi_view.h index ba89c5108a..8409a26842 100644 --- a/gtk2_ardour/midi_view.h +++ b/gtk2_ardour/midi_view.h @@ -630,11 +630,11 @@ class MidiView : public virtual sigc::trackable, public LineMerger virtual double height() const; - virtual double contents_height() const { return height() - 2; } - inline double note_height() const { return contents_height() / _midi_context.contents_note_range(); } + virtual int contents_height() const { return height() - 2; } + inline int note_height() const { return contents_height() / _midi_context.contents_note_range(); } - double note_to_y (uint8_t note) const { return _midi_context.note_to_y (note); } - uint8_t y_to_note (double y) const { return _midi_context.y_to_note (y); } + int note_to_y (uint8_t note) const { return _midi_context.note_to_y (note); } + uint8_t y_to_note (int y) const { return _midi_context.y_to_note (y); } void update_patch_changes (); void update_sysexes (); diff --git a/gtk2_ardour/midi_view_background.cc b/gtk2_ardour/midi_view_background.cc index 61251db213..bbcf853b72 100644 --- a/gtk2_ardour/midi_view_background.cc +++ b/gtk2_ardour/midi_view_background.cc @@ -107,9 +107,9 @@ MidiViewBackground::note_range_adjustment_changed() } uint8_t -MidiViewBackground::y_to_note (double y) const +MidiViewBackground::y_to_note (int y) const { - int const n = ((contents_height() - y) / contents_height() * (double)contents_note_range()) + int const n = floor (((contents_height() - (double) y) / contents_height() * (double) contents_note_range())) + lowest_note(); if (n < 0) { @@ -286,7 +286,7 @@ MidiViewBackground::apply_note_range (uint8_t lowest, uint8_t highest, bool to_c int const max_note_height = std::max (mnh, mnh * uiscale); int const range = _highest_note - _lowest_note; - int const available_note_range = floor (contents_height() / max_note_height); + int const available_note_range = contents_height() / max_note_height; int additional_notes = available_note_range - range; /* distribute additional notes to higher and lower ranges, clamp at 0 and 127 */ diff --git a/gtk2_ardour/midi_view_background.h b/gtk2_ardour/midi_view_background.h index 889d2bf882..bc5b83adcd 100644 --- a/gtk2_ardour/midi_view_background.h +++ b/gtk2_ardour/midi_view_background.h @@ -93,32 +93,34 @@ class MidiViewBackground : public virtual ViewBackground void maybe_extend_note_range (uint8_t note_num); - double note_to_y (uint8_t note) const { - return contents_height() - (note + 1 - lowest_note()) * note_height() + 1; + int note_height() const { + /* Note: this effectively rounds down (truncates) due to integer arithmetic */ + return contents_height() / contents_note_range(); } - uint8_t y_to_note(double y) const; + int note_to_y (uint8_t note) const { + /* Note: this effectively rounds down (truncates) due to integer arithmetic */ + return contents_height() - ((note - lowest_note()) * note_height()); + } + + uint8_t y_to_note (int y) const; uint8_t contents_note_range() const { return highest_note() - lowest_note() + 1; } - double note_height() const { - return contents_height() / (double)contents_note_range(); - } - sigc::signal NoteRangeChanged; void apply_note_range (uint8_t lowest, uint8_t highest, bool to_children); void maybe_apply_note_range (uint8_t lowest, uint8_t highest, bool to_children); /** @return y position, or -1 if hidden */ - virtual double y_position () const { return 0.; } + virtual int y_position () const { return 0; } virtual uint8_t get_preferred_midi_channel () const = 0; virtual void set_note_highlight (bool) = 0; virtual void record_layer_check (std::shared_ptr, samplepos_t) = 0; - virtual void set_size (double w, double h) {} + virtual void set_size (int w, int h) {} PBD::Signal HeightChanged; virtual ARDOUR::InstrumentInfo* instrument_info() const = 0; diff --git a/gtk2_ardour/pianoroll_background.h b/gtk2_ardour/pianoroll_background.h index c6c4eb1fc2..53be8a8fbb 100644 --- a/gtk2_ardour/pianoroll_background.h +++ b/gtk2_ardour/pianoroll_background.h @@ -39,15 +39,15 @@ class PianorollMidiBackground : public MidiViewBackground PianorollMidiBackground (ArdourCanvas::Item* parent, Pianoroll&); ~PianorollMidiBackground (); - double height() const; - double width() const; - double contents_height() const; + int height() const; + int width() const; + int contents_height() const; uint8_t get_preferred_midi_channel () const; void set_note_highlight (bool); void record_layer_check (std::shared_ptr, samplepos_t); - void set_size (double w, double h); + void set_size (int w, int h); void set_view (MidiView*); ARDOUR::InstrumentInfo* instrument_info() const; @@ -55,8 +55,8 @@ class PianorollMidiBackground : public MidiViewBackground protected: MidiView* view; Pianoroll& pianoroll; - double _width; - double _height; + int _width; + int _height; void apply_note_range_to_children(); }; diff --git a/gtk2_ardour/time_axis_view.cc b/gtk2_ardour/time_axis_view.cc index 7f140bd75f..23365ccd14 100644 --- a/gtk2_ardour/time_axis_view.cc +++ b/gtk2_ardour/time_axis_view.cc @@ -316,7 +316,7 @@ TimeAxisView::hide () * @return height of this TimeAxisView. */ guint32 -TimeAxisView::show_at (double y, int& nth, VBox *parent) +TimeAxisView::show_at (int y, int& nth, VBox *parent) { if (control_parent) { control_parent->reorder_child (TOP_LEVEL_WIDGET, nth); diff --git a/gtk2_ardour/time_axis_view.h b/gtk2_ardour/time_axis_view.h index d7158b4555..e027bae48a 100644 --- a/gtk2_ardour/time_axis_view.h +++ b/gtk2_ardour/time_axis_view.h @@ -124,7 +124,7 @@ public: uint32_t effective_height () const { return _effective_height; } /** @return y position, or -1 if hidden */ - double y_position () const { return _y_position; } + int y_position () const { return _y_position; } /** @return our Editor */ PublicEditor& editor () const { return _editor; } @@ -133,7 +133,7 @@ public: void idle_resize (int32_t); - virtual guint32 show_at (double y, int& nth, Gtk::VBox *parent); + virtual guint32 show_at (int y, int& nth, Gtk::VBox *parent); virtual void hide (); bool touched (double top, double bot); @@ -260,7 +260,7 @@ protected: Gtk::Menu* _size_menu; ArdourCanvas::Line* _canvas_separator; ArdourCanvas::Container* _canvas_display; - double _y_position; + int _y_position; PublicEditor& _editor; virtual bool can_edit_name() const; diff --git a/gtk2_ardour/view_background.h b/gtk2_ardour/view_background.h index 4602fddd53..8d0c6393ea 100644 --- a/gtk2_ardour/view_background.h +++ b/gtk2_ardour/view_background.h @@ -40,12 +40,12 @@ class ViewBackground : public sigc::trackable ViewBackground (); virtual ~ViewBackground (); - virtual double height() const { return 0.; } - virtual double width() const { return 0.; } - virtual double contents_height() const { return 0.; } + virtual int height() const { return 0; } + virtual int width() const { return 0; } + virtual int contents_height() const { return 0; } /** @return y position, or -1 if hidden */ - virtual double y_position () const { return 0.; } + virtual int y_position () const { return 0; } protected: virtual void update_contents_height () {}