Factor out region layering.

Correctly layer automation regions to match the stacking of their 'real' counterparts.


git-svn-id: svn://localhost/ardour2/branches/3.0@4585 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
David Robillard 2009-02-15 20:31:05 +00:00
parent 9c89a93e4f
commit 59972b5550
8 changed files with 83 additions and 131 deletions

View File

@ -365,13 +365,16 @@ AudioStreamView::remove_crossfade (boost::shared_ptr<Region> r)
void
AudioStreamView::redisplay_diskstream ()
{
list<RegionView *>::iterator i, tmp;
list<RegionView *>::iterator i;
list<CrossfadeView*>::iterator xi, tmpx;
// Flag region views as invalid and disable drawing
for (i = region_views.begin(); i != region_views.end(); ++i) {
(*i)->set_valid (false);
(*i)->enable_display (false);
}
// Flag crossfade views as invalid
for (xi = crossfade_views.begin(); xi != crossfade_views.end(); ++xi) {
(*xi)->set_valid (false);
if ((*xi)->visible() && _layer_display != Stacked) {
@ -379,6 +382,7 @@ AudioStreamView::redisplay_diskstream ()
}
}
// Add and display region and crossfade views, and flag them as valid
if (_trackview.is_audio_track()) {
_trackview.get_diskstream()->playlist()->foreach_region(
static_cast<StreamView*>(this),
@ -389,53 +393,8 @@ AudioStreamView::redisplay_diskstream ()
if (apl)
apl->foreach_crossfade (this, &AudioStreamView::add_crossfade);
}
RegionViewList copy;
// Build a list of region views sorted by layer, and remove invalids
for (i = region_views.begin(); i != region_views.end(); ) {
tmp = i;
tmp++;
if (!(*i)->is_valid()) {
delete *i;
region_views.erase (i);
i = tmp;
continue;
} else {
(*i)->enable_display(true);
}
if (copy.size() == 0) {
copy.push_front((*i));
i = tmp;
continue;
}
RegionViewList::iterator k = copy.begin();
RegionViewList::iterator l = copy.end();
l--;
if ((*i)->region()->layer() <= (*k)->region()->layer()) {
copy.push_front((*i));
i = tmp;
continue;
} else if ((*i)->region()->layer() >= (*l)->region()->layer()) {
copy.push_back((*i));
i = tmp;
continue;
}
for (RegionViewList::iterator j = copy.begin(); j != copy.end(); ++j) {
if ((*j)->region()->layer() >= (*i)->region()->layer()) {
copy.insert(j, (*i));
break;
}
}
i = tmp;
}
// Remove invalid crossfade views
for (xi = crossfade_views.begin(); xi != crossfade_views.end();) {
tmpx = xi;
tmpx++;
@ -447,11 +406,9 @@ AudioStreamView::redisplay_diskstream ()
xi = tmpx;
}
// Fix canvas layering by raising each in the sorted list order
for (RegionViewList::iterator i = copy.begin(); i != copy.end(); ++i) {
region_layered (*i);
}
// Stack regions by layer, and remove invalid regions
layer_regions();
}
void

View File

@ -158,35 +158,20 @@ AutomationStreamView::redisplay_diskstream ()
{
list<RegionView *>::iterator i, tmp;
// Flag region views as invalid and disable drawing
for (i = region_views.begin(); i != region_views.end(); ++i) {
(*i)->set_valid (false);
(*i)->enable_display(false);
}
// Add and display region views, and flag them as valid
if (_trackview.is_track()) {
_trackview.get_diskstream()->playlist()->foreach_region (
static_cast<StreamView*>(this), &StreamView::add_region_view);
}
for (i = region_views.begin(); i != region_views.end(); ) {
tmp = i;
tmp++;
if (!(*i)->is_valid()) {
delete *i;
region_views.erase (i);
} else {
(*i)->enable_display(true);
(*i)->set_height(height);
}
i = tmp;
}
/* now fix layering */
for (RegionViewList::iterator i = region_views.begin(); i != region_views.end(); ++i) {
region_layered (*i);
}
// Stack regions by layer, and remove invalid regions
layer_regions();
}

View File

@ -236,7 +236,7 @@ MidiStreamView::redisplay_diskstream ()
return;
}
list<RegionView*>::iterator i, tmp;
list<RegionView*>::iterator i;
// Load models if necessary, and find note range of all our contents
_range_dirty = false;
@ -264,60 +264,15 @@ MidiStreamView::redisplay_diskstream ()
(*i)->enable_display(false);
}
// Add and display region views, and flag existing ones as valid
// Add and display region views, and flag them as valid
_trackview.get_diskstream()->playlist()->foreach_region(
static_cast<StreamView*>(this),
&StreamView::add_region_view);
// Build a list of region views sorted by layer, and remove invalids
RegionViewList copy;
for (i = region_views.begin(); i != region_views.end(); ) {
tmp = i;
tmp++;
// Stack regions by layer, and remove invalid regions
layer_regions();
if (!(*i)->is_valid()) {
delete *i;
region_views.erase (i);
i = tmp;
continue;
}
if (copy.size() == 0) {
copy.push_front((*i));
i = tmp;
continue;
}
RegionViewList::iterator k = copy.begin();
RegionViewList::iterator l = copy.end();
l--;
if ((*i)->region()->layer() <= (*k)->region()->layer()) {
copy.push_front((*i));
i = tmp;
continue;
} else if ((*i)->region()->layer() >= (*l)->region()->layer()) {
copy.push_back((*i));
i = tmp;
continue;
}
for (RegionViewList::iterator j = copy.begin(); j != copy.end(); ++j) {
if ((*j)->region()->layer() >= (*i)->region()->layer()) {
copy.insert(j, (*i));
break;
}
}
i = tmp;
}
// Fix canvas layering by raising each in the sorted list order
for (RegionViewList::iterator j = copy.begin(); j != copy.end(); ++j) {
region_layered (*j);
}
// Update note range (not to regions which are already good) and draw note lines
// Update note range (not regions which are correct) and draw note lines
apply_note_range(_lowest_note, _highest_note, false);
}

View File

@ -70,11 +70,7 @@ StreamView::StreamView (RouteTimeAxisView& tv, ArdourCanvas::Group* group)
canvas_rect->property_y2() = (double) tv.current_height();
canvas_rect->raise(1); // raise above tempo lines
// DR-way
canvas_rect->property_outline_what() = (guint32) (0x2|0x8); // outline RHS and bottom
// 2.0 way
//canvas_rect->property_outline_what() = (guint32) (0x1|0x2|0x8); // outline ends and bottom
// (Fill/Outline colours set in derived classes)
canvas_rect->signal_event().connect (bind (mem_fun (_trackview.editor(), &PublicEditor::canvas_stream_view_event), canvas_rect, &_trackview));
@ -225,6 +221,63 @@ StreamView::playlist_modified_weak (boost::weak_ptr<Diskstream> ds)
playlist_modified (sp);
}
void
StreamView::layer_regions()
{
// In one traversal of the region view list:
// - Build a list of region views sorted by layer
// - Remove invalid views from the actual region view list
RegionViewList copy;
list<RegionView*>::iterator i, tmp;
for (i = region_views.begin(); i != region_views.end(); ) {
tmp = i;
tmp++;
if (!(*i)->is_valid()) {
delete *i;
region_views.erase (i);
i = tmp;
continue;
} else {
(*i)->enable_display(true);
}
if (copy.size() == 0) {
copy.push_front((*i));
i = tmp;
continue;
}
RegionViewList::iterator k = copy.begin();
RegionViewList::iterator l = copy.end();
l--;
if ((*i)->region()->layer() <= (*k)->region()->layer()) {
copy.push_front((*i));
i = tmp;
continue;
} else if ((*i)->region()->layer() >= (*l)->region()->layer()) {
copy.push_back((*i));
i = tmp;
continue;
}
for (RegionViewList::iterator j = copy.begin(); j != copy.end(); ++j) {
if ((*j)->region()->layer() >= (*i)->region()->layer()) {
copy.insert(j, (*i));
break;
}
}
i = tmp;
}
// Fix canvas layering by raising each in the sorted list order
for (RegionViewList::iterator i = copy.begin(); i != copy.end(); ++i) {
region_layered (*i);
}
}
void
StreamView::playlist_modified (boost::shared_ptr<Diskstream> ds)
{

View File

@ -124,6 +124,7 @@ protected:
void display_diskstream (boost::shared_ptr<ARDOUR::Diskstream>);
virtual void undisplay_diskstream ();
void diskstream_changed ();
void layer_regions ();
virtual void playlist_changed (boost::shared_ptr<ARDOUR::Diskstream>);
virtual void playlist_modified_weak (boost::weak_ptr<ARDOUR::Diskstream>);

View File

@ -1508,3 +1508,4 @@ MidiDiskstream::get_playback(MidiBuffer& dst, nframes_t start, nframes_t end, nf
_midi_state_tracker.resolve_notes(dst, end-start - 1 + offset);
}
}

View File

@ -26,7 +26,7 @@
namespace Evoral {
/** Return the size of the given event including the status byte,
* or -1 if unknown (eg sysex)
* or -1 if unknown (e.g. sysex)
*/
static inline int
midi_event_size(unsigned char status)

View File

@ -134,7 +134,7 @@ Sequence<Time>::const_iterator::const_iterator(const Sequence<Time>& seq, Time t
<< "], event ignored" << endl;
continue;
}
#endif
#endif
const ControlIterator new_iter(i->second->list(), x, y);
@ -265,7 +265,7 @@ Sequence<Time>::const_iterator::operator++()
if (! (ev.is_note() || ev.is_cc() || ev.is_pgm_change()
|| ev.is_pitch_bender() || ev.is_channel_pressure() || ev.is_sysex()) ) {
cerr << "Unknown event type: " << hex << int(ev.buffer()[0])
cerr << "WARNING: Unknown event type: " << hex << int(ev.buffer()[0])
<< int(ev.buffer()[1]) << int(ev.buffer()[2]) << endl;
}