13
0

GhostEvent wrangling.

- update_range() solely looks after visibility.
	- update_note/hit() positions both x and y using code stolen from
	  update_range()
	- add update_contents_height() for when we just change the GR height.
	- find_event() is now used rather than map::find()
	- use temp canvas items to avoid constructor overhead.
This commit is contained in:
nick_m 2016-12-22 04:39:53 +11:00
parent e75788614a
commit 05c3850ac1
2 changed files with 65 additions and 37 deletions

View File

@ -179,7 +179,7 @@ MidiGhostRegion::MidiGhostRegion(RegionView& rv,
TimeAxisView& source_tv, TimeAxisView& source_tv,
double initial_unit_pos) double initial_unit_pos)
: GhostRegion(rv, tv.ghost_group(), tv, source_tv, initial_unit_pos) : GhostRegion(rv, tv.ghost_group(), tv, source_tv, initial_unit_pos)
, _optimization_iterator(events.end()) , _tmp_rect (NULL), _tmp_poly (NULL), _optimization_iterator(events.end())
{ {
_outline = UIConfiguration::instance().color ("ghost track midi outline"); _outline = UIConfiguration::instance().color ("ghost track midi outline");
@ -203,7 +203,7 @@ MidiGhostRegion::MidiGhostRegion(RegionView& rv,
msv.trackview(), msv.trackview(),
source_tv, source_tv,
initial_unit_pos) initial_unit_pos)
, _optimization_iterator(events.end()) , _tmp_rect (NULL), _tmp_poly (NULL), _optimization_iterator(events.end())
{ {
_outline = UIConfiguration::instance().color ("ghost track midi outline"); _outline = UIConfiguration::instance().color ("ghost track midi outline");
@ -262,7 +262,7 @@ void
MidiGhostRegion::set_height () MidiGhostRegion::set_height ()
{ {
GhostRegion::set_height(); GhostRegion::set_height();
update_range(); set_contents_height ();
} }
void void
@ -305,8 +305,6 @@ MidiGhostRegion::update_range ()
return; return;
} }
double const h = note_height(trackview, mv);
for (EventList::iterator it = events.begin(); it != events.end(); ++it) { for (EventList::iterator it = events.begin(); it != events.end(); ++it) {
uint8_t const note_num = (*it).second->event->note()->note(); uint8_t const note_num = (*it).second->event->note()->note();
@ -314,17 +312,33 @@ MidiGhostRegion::update_range ()
(*it).second->item->hide(); (*it).second->item->hide();
} else { } else {
(*it).second->item->show(); (*it).second->item->show();
double const y = note_y(trackview, mv, note_num); }
ArdourCanvas::Rectangle* rect = NULL; }
ArdourCanvas::Polygon* poly = NULL; }
if ((rect = dynamic_cast<ArdourCanvas::Rectangle*>((*it).second->item))) {
rect->set (ArdourCanvas::Rect (rect->x0(), y, rect->x1(), y + h)); void
} else if ((poly = dynamic_cast<ArdourCanvas::Polygon*>((*it).second->item))) { MidiGhostRegion::set_contents_height ()
Duple position = poly->position(); {
position.y = y; MidiStreamView* mv = midi_view();
poly->set_position(position);
poly->set(Hit::points(h)); if (!mv) {
} return;
}
double const h = note_height(trackview, mv);
for (EventList::iterator it = events.begin(); it != events.end(); ++it) {
uint8_t const note_num = (*it).second->event->note()->note();
double const y = note_y(trackview, mv, note_num);
if ((_tmp_rect = dynamic_cast<ArdourCanvas::Rectangle*>((*it).second->item))) {
_tmp_rect->set (ArdourCanvas::Rect (_tmp_rect->x0(), y, _tmp_rect->x1(), y + h));
} else if ((_tmp_poly = dynamic_cast<ArdourCanvas::Polygon*>((*it).second->item))) {
Duple position = _tmp_poly->position();
position.y = y;
_tmp_poly->set_position(position);
_tmp_poly->set(Hit::points(h));
} }
} }
} }
@ -348,15 +362,13 @@ MidiGhostRegion::add_note (NoteBase* n)
if (note_num < mv->lowest_note() || note_num > mv->highest_note()) { if (note_num < mv->lowest_note() || note_num > mv->highest_note()) {
event->item->hide(); event->item->hide();
} else { } else {
ArdourCanvas::Rectangle* rect = NULL; if ((_tmp_rect = dynamic_cast<ArdourCanvas::Rectangle*>(event->item))) {
ArdourCanvas::Polygon* poly = NULL; _tmp_rect->set (ArdourCanvas::Rect (_tmp_rect->x0(), y, _tmp_rect->x1(), y + h));
if ((rect = dynamic_cast<ArdourCanvas::Rectangle*>(event->item))) { } else if ((_tmp_poly = dynamic_cast<ArdourCanvas::Polygon*>(event->item))) {
rect->set (ArdourCanvas::Rect (rect->x0(), y, rect->x1(), y + h)); Duple position = _tmp_poly->position();
} else if ((poly = dynamic_cast<ArdourCanvas::Polygon*>(event->item))) {
Duple position = poly->position();
position.y = y; position.y = y;
poly->set_position(position); _tmp_poly->set_position(position);
poly->set(Hit::points(h)); _tmp_poly->set(Hit::points(h));
} }
} }
} }
@ -379,21 +391,27 @@ MidiGhostRegion::clear_events()
void void
MidiGhostRegion::update_note (Note* note) MidiGhostRegion::update_note (Note* note)
{ {
EventList::iterator f = events.find (note->note()); MidiStreamView* mv = midi_view();
if (f == events.end()) {
if (!mv) {
return; return;
} }
GhostEvent* ev = (*f).second; GhostEvent* ev = find_event (note);
if (!ev) { if (!ev) {
return; return;
} }
ArdourCanvas::Rectangle* rect = NULL; uint8_t const note_num = note->note()->note();
if ((rect = dynamic_cast<ArdourCanvas::Rectangle*>(ev->item))) {
rect->set (ArdourCanvas::Rect (note->x0(), rect->y0(), note->x1(), rect->y1())); double const y = note_y(trackview, mv, note_num);
double const h = note_height(trackview, mv);
if ((_tmp_rect = dynamic_cast<ArdourCanvas::Rectangle*>(ev->item))) {
_tmp_rect->set (ArdourCanvas::Rect (note->x0(), y, note->x1(), y + h));
} }
} }
/** Update the x positions of our representation of a parent's hit. /** Update the x positions of our representation of a parent's hit.
@ -402,23 +420,30 @@ MidiGhostRegion::update_note (Note* note)
void void
MidiGhostRegion::update_hit (Hit* hit) MidiGhostRegion::update_hit (Hit* hit)
{ {
EventList::iterator f = events.find (hit->note()); MidiStreamView* mv = midi_view();
if (f == events.end()) {
if (!mv) {
return; return;
} }
GhostEvent* ev = (*f).second; GhostEvent* ev = find_event (hit);
if (!ev) { if (!ev) {
return; return;
} }
ArdourCanvas::Polygon* poly = NULL; uint8_t const note_num = ev->event->note()->note();
if ((poly = dynamic_cast<ArdourCanvas::Polygon*>(ev->item))) {
double const h = note_height(trackview, mv);
double const y = note_y(trackview, mv, note_num);
if ((_tmp_poly = dynamic_cast<ArdourCanvas::Polygon*>(ev->item))) {
ArdourCanvas::Duple ppos = hit->position(); ArdourCanvas::Duple ppos = hit->position();
ArdourCanvas::Duple gpos = poly->position(); ArdourCanvas::Duple gpos = _tmp_poly->position();
gpos.x = ppos.x; gpos.x = ppos.x;
poly->set_position(gpos); gpos.y = y;
_tmp_poly->set_position(gpos);
_tmp_poly->set(Hit::points(h));
} }
} }

View File

@ -107,6 +107,7 @@ public:
void set_colors(); void set_colors();
void update_range(); void update_range();
void set_contents_height();
void add_note(NoteBase*); void add_note(NoteBase*);
void update_note (Note*); void update_note (Note*);
@ -117,6 +118,8 @@ public:
private: private:
ArdourCanvas::Color _outline; ArdourCanvas::Color _outline;
ArdourCanvas::Rectangle* _tmp_rect;
ArdourCanvas::Polygon* _tmp_poly;
MidiGhostRegion::GhostEvent* find_event (NoteBase*); MidiGhostRegion::GhostEvent* find_event (NoteBase*);
typedef Evoral::Note<Evoral::Beats> NoteType; typedef Evoral::Note<Evoral::Beats> NoteType;