From f649d775bc4f1e8721214e81619099de46810783 Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sat, 5 Mar 2011 23:00:49 +0000 Subject: [PATCH] prevent trim cursors appearing, and prevent note trimming, when in a MIDI note that is too small on-screen. avoids silliness with trim cursors appearing while drawing small notes on screen, though really, it would nice to avoid them appearing ever in a note that was just added. not sure how to do that. git-svn-id: svn://localhost/ardour2/branches/3.0@9077 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/canvas-hit.h | 8 ++++---- gtk2_ardour/canvas-note-event.cc | 15 ++++++++++++++- gtk2_ardour/canvas-note-event.h | 11 ++++++----- gtk2_ardour/canvas-note.h | 8 ++++---- gtk2_ardour/editor_mouse.cc | 3 +-- gtk2_ardour/midi_region_view.cc | 2 +- 6 files changed, 30 insertions(+), 17 deletions(-) diff --git a/gtk2_ardour/canvas-hit.h b/gtk2_ardour/canvas-hit.h index e6be076aa8..af64413884 100644 --- a/gtk2_ardour/canvas-hit.h +++ b/gtk2_ardour/canvas-hit.h @@ -41,10 +41,10 @@ public: void show() { Diamond::show(); } void hide() { Diamond::hide(); } - double x1() { double x1, y1, x2, y2; get_bounds(x1,y1,x2,y2); return x1; } - double y1() { double x1, y1, x2, y2; get_bounds(x1,y1,x2,y2); return y1; } - double x2() { double x1, y1, x2, y2; get_bounds(x1,y1,x2,y2); return x2; } - double y2() { double x1, y1, x2, y2; get_bounds(x1,y1,x2,y2); return y2; } + double x1() const { double x1, y1, x2, y2; get_bounds(x1,y1,x2,y2); return x1; } + double y1() const { double x1, y1, x2, y2; get_bounds(x1,y1,x2,y2); return y1; } + double x2() const { double x1, y1, x2, y2; get_bounds(x1,y1,x2,y2); return x2; } + double y2() const { double x1, y1, x2, y2; get_bounds(x1,y1,x2,y2); return y2; } void set_outline_color(uint32_t c) { property_outline_color_rgba() = c; } void set_fill_color(uint32_t c) { property_fill_color_rgba() = c; } diff --git a/gtk2_ardour/canvas-note-event.cc b/gtk2_ardour/canvas-note-event.cc index 0e1afcc017..e05c6956ad 100644 --- a/gtk2_ardour/canvas-note-event.cc +++ b/gtk2_ardour/canvas-note-event.cc @@ -292,7 +292,14 @@ CanvasNoteEvent::set_mouse_fractions (GdkEvent* ev) _mouse_y_fraction = yf; if (notify) { - _region.note_mouse_position (_mouse_x_fraction, _mouse_y_fraction, set_cursor); + if (big_enough_to_trim()) { + _region.note_mouse_position (_mouse_x_fraction, _mouse_y_fraction, set_cursor); + } else { + /* pretend the mouse is in the middle, because this is not big enough + to trim right now. + */ + _region.note_mouse_position (0.5, 0.5, set_cursor); + } } } @@ -347,6 +354,12 @@ CanvasNoteEvent::mouse_near_ends () const (_mouse_x_fraction >= 0.75 && _mouse_x_fraction < 1.0); } +bool +CanvasNoteEvent::big_enough_to_trim () const +{ + return (x2() - x1()) > 10; /* canvas units, really pixels */ +} + } // namespace Canvas } // namespace Gnome diff --git a/gtk2_ardour/canvas-note-event.h b/gtk2_ardour/canvas-note-event.h index 191b9e2ad8..24e7c78834 100644 --- a/gtk2_ardour/canvas-note-event.h +++ b/gtk2_ardour/canvas-note-event.h @@ -95,10 +95,10 @@ class CanvasNoteEvent : virtual public sigc::trackable virtual void set_outline_color(uint32_t c) = 0; virtual void set_fill_color(uint32_t c) = 0; - virtual double x1() = 0; - virtual double y1() = 0; - virtual double x2() = 0; - virtual double y2() = 0; + virtual double x1() const = 0; + virtual double y1() const = 0; + virtual double x2() const = 0; + virtual double y2() const = 0; float mouse_x_fraction() const { return _mouse_x_fraction; } float mouse_y_fraction() const { return _mouse_y_fraction; } @@ -143,7 +143,8 @@ class CanvasNoteEvent : virtual public sigc::trackable static const uint32_t midi_channel_colors[16]; bool mouse_near_ends () const; - + bool big_enough_to_trim () const; + protected: enum State { None, Pressed, Dragging }; diff --git a/gtk2_ardour/canvas-note.h b/gtk2_ardour/canvas-note.h index 49a37c17c9..3148a38c95 100644 --- a/gtk2_ardour/canvas-note.h +++ b/gtk2_ardour/canvas-note.h @@ -39,10 +39,10 @@ class CanvasNote : public SimpleRect, public CanvasNoteEvent const boost::shared_ptr note = boost::shared_ptr(), bool with_events = true); - double x1() { return property_x1(); } - double y1() { return property_y1(); } - double x2() { return property_x2(); } - double y2() { return property_y2(); } + double x1() const { return property_x1(); } + double y1() const { return property_y1(); } + double x2() const { return property_x2(); } + double y2() const { return property_y2(); } void set_outline_color(uint32_t c) { property_outline_color_rgba() = c; hide(); show(); } void set_fill_color(uint32_t c) { property_fill_color_rgba() = c; hide(); show(); } diff --git a/gtk2_ardour/editor_mouse.cc b/gtk2_ardour/editor_mouse.cc index 2733280dac..8a1f3dfe73 100644 --- a/gtk2_ardour/editor_mouse.cc +++ b/gtk2_ardour/editor_mouse.cc @@ -713,8 +713,7 @@ Editor::button_press_handler_1 (ArdourCanvas::Item* item, GdkEvent* event, ItemT if (internal_editing()) { /* trim notes if we're in internal edit mode and near the ends of the note */ ArdourCanvas::CanvasNote* cn = dynamic_cast (item); - cerr << "NoteItem button press, cursor = " << current_canvas_cursor << endl; - if (cn->mouse_near_ends()) { + if (cn->big_enough_to_trim() && cn->mouse_near_ends()) { _drags->set (new NoteResizeDrag (this, item), event, current_canvas_cursor); } else { _drags->set (new NoteDrag (this, item), event); diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 1d4d420258..b97f250914 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -2849,7 +2849,7 @@ void MidiRegionView::note_mouse_position (float x_fraction, float /*y_fraction*/, bool can_set_cursor) { Editor* editor = dynamic_cast(&trackview.editor()); - + if (x_fraction > 0.0 && x_fraction < 0.25) { editor->set_canvas_cursor (editor->cursors()->left_side_trim); } else if (x_fraction >= 0.75 && x_fraction < 1.0) {