Ridiculously CPU-chewey rect select (for sustained notes only ATM).

git-svn-id: svn://localhost/ardour2/trunk@2261 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
David Robillard 2007-08-07 00:09:22 +00:00
parent d07f541cdf
commit f92be1e34c
5 changed files with 48 additions and 7 deletions

View File

@ -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; }

View File

@ -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; }

View File

@ -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; }

View File

@ -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<ArdourCanvas::Item*>::iterator i = _events.begin(); i != _events.end(); ++i)
for (std::vector<CanvasMidiEvent*>::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, &note);
CanvasNote* ev_rect = new CanvasNote(*this, *group, &note);
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<CanvasMidiEvent*>::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);
}
}
}

View File

@ -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<ARDOUR::MidiModel> _model;
std::vector<ArdourCanvas::Item*> _events;
ArdourCanvas::CanvasNote** _active_notes;
ARDOUR::MidiModel::DeltaCommand* _delta_command;
boost::shared_ptr<ARDOUR::MidiModel> _model;
std::vector<ArdourCanvas::CanvasMidiEvent*> _events;
ArdourCanvas::CanvasNote** _active_notes;
ARDOUR::MidiModel::DeltaCommand* _delta_command;
typedef std::set<ArdourCanvas::CanvasMidiEvent*> Selection;
Selection _selection;