From f92be1e34c7fa2f25f36c23974045bce22a5049f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 7 Aug 2007 00:09:22 +0000 Subject: [PATCH] Ridiculously CPU-chewey rect select (for sustained notes only ATM). git-svn-id: svn://localhost/ardour2/trunk@2261 d708f5d6-7413-0410-9779-e7cbd77b26cf --- gtk2_ardour/canvas-hit.h | 6 ++++++ gtk2_ardour/canvas-midi-event.h | 10 ++++++++++ gtk2_ardour/canvas-note.h | 5 +++++ gtk2_ardour/midi_region_view.cc | 25 ++++++++++++++++++++++--- gtk2_ardour/midi_region_view.h | 9 +++++---- 5 files changed, 48 insertions(+), 7 deletions(-) diff --git a/gtk2_ardour/canvas-hit.h b/gtk2_ardour/canvas-hit.h index 229d3cdd80..114d608a89 100644 --- a/gtk2_ardour/canvas-hit.h +++ b/gtk2_ardour/canvas-hit.h @@ -32,6 +32,12 @@ public: CanvasHit(MidiRegionView& region, Group& group, double size, const ARDOUR::MidiModel::Note* note=NULL) : Diamond(group, size), CanvasMidiEvent(region, this, note) {} + // FIXME + double x1() { return 0.0; } + double y1() { return 0.0; } + double x2() { return 0.0; } + double y2() { return 0.0; } + 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-midi-event.h b/gtk2_ardour/canvas-midi-event.h index 214c275bed..ce49b580b4 100644 --- a/gtk2_ardour/canvas-midi-event.h +++ b/gtk2_ardour/canvas-midi-event.h @@ -38,6 +38,8 @@ namespace Canvas { * * Note: Because of this, derived classes need to manually bounce events to * on_event, it won't happen automatically. + * + * A newer, better canvas should remove the need for all the ugly here. */ class CanvasMidiEvent { public: @@ -51,6 +53,14 @@ public: 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; + + const Item* item() const { return _item; } + Item* item() { return _item; } const ARDOUR::MidiModel::Note* note() { return _note; } diff --git a/gtk2_ardour/canvas-note.h b/gtk2_ardour/canvas-note.h index cd79b6d2ff..398d7d1abb 100644 --- a/gtk2_ardour/canvas-note.h +++ b/gtk2_ardour/canvas-note.h @@ -35,6 +35,11 @@ public: { } + double x1() { return property_x1(); } + double y1() { return property_y1(); } + double x2() { return property_x2(); } + double y2() { return property_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/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 64693c7e6f..49817a35a0 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -241,9 +241,12 @@ MidiRegionView::canvas_event(GdkEvent* ev) if (drag_rect) drag_rect->property_x2() = event_x; - if (drag_rect && _state == SelectDragging) + if (drag_rect && _state == SelectDragging) { drag_rect->property_y2() = event_y; + update_drag_selection(drag_start_x, event_x, drag_start_y, event_y); + } + last_x = event_x; last_y = event_y; @@ -335,7 +338,7 @@ MidiRegionView::create_note_at(double x, double y, double dur) void MidiRegionView::clear_events() { - for (std::vector::iterator i = _events.begin(); i != _events.end(); ++i) + for (std::vector::iterator i = _events.begin(); i != _events.end(); ++i) delete *i; _events.clear(); @@ -558,7 +561,7 @@ MidiRegionView::add_note (const MidiModel::Note& note) if (midi_view()->note_mode() == Sustained) { const double y1 = midi_stream_view()->note_to_y(note.note()); - ArdourCanvas::SimpleRect * ev_rect = new CanvasNote(*this, *group, ¬e); + CanvasNote* ev_rect = new CanvasNote(*this, *group, ¬e); ev_rect->property_x1() = trackview.editor.frame_to_pixel((nframes_t)note.time()); ev_rect->property_y1() = y1; ev_rect->property_x2() = trackview.editor.frame_to_pixel((nframes_t)(note.end_time())); @@ -641,3 +644,19 @@ MidiRegionView::note_deselected(ArdourCanvas::CanvasMidiEvent* ev, bool add) } +void +MidiRegionView::update_drag_selection(double last_x, double x, double last_y, double y) +{ + // FIXME: so, so, so much slower than this should be + for (std::vector::iterator i = _events.begin(); i != _events.end(); ++i) { + if ((*i)->x1() >= last_x && (*i)->x1() <= x && (*i)->y1() >= last_y && (*i)->y1() <= y) { + (*i)->selected(true); + _selection.insert(*i); + } else { + (*i)->selected(false); + _selection.erase(*i); + } + } +} + + diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h index f74272a409..c9195a2446 100644 --- a/gtk2_ardour/midi_region_view.h +++ b/gtk2_ardour/midi_region_view.h @@ -171,13 +171,14 @@ class MidiRegionView : public RegionView void clear_selection_except(ArdourCanvas::CanvasMidiEvent* ev); void clear_selection() { clear_selection_except(NULL); } + void update_drag_selection(double last_x, double x, double last_y, double y); double _default_note_length; - boost::shared_ptr _model; - std::vector _events; - ArdourCanvas::CanvasNote** _active_notes; - ARDOUR::MidiModel::DeltaCommand* _delta_command; + boost::shared_ptr _model; + std::vector _events; + ArdourCanvas::CanvasNote** _active_notes; + ARDOUR::MidiModel::DeltaCommand* _delta_command; typedef std::set Selection; Selection _selection;