mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-16 15:41:11 +02:00
Rewrite WaveTrackView::GetSubViews to cache last computed heights
This commit is contained in:
@@ -923,6 +923,7 @@ void TrackPanel::UpdateTrackVRuler(Track *t)
|
|||||||
for (auto channel : TrackList::Channels(t)) {
|
for (auto channel : TrackList::Channels(t)) {
|
||||||
auto &view = TrackView::Get( *channel );
|
auto &view = TrackView::Get( *channel );
|
||||||
const auto height = view.GetHeight() - (kTopMargin + kBottomMargin);
|
const auto height = view.GetHeight() - (kTopMargin + kBottomMargin);
|
||||||
|
rect.SetHeight( height );
|
||||||
const auto subViews = view.GetSubViews( rect );
|
const auto subViews = view.GetSubViews( rect );
|
||||||
if (subViews.empty())
|
if (subViews.empty())
|
||||||
continue;
|
continue;
|
||||||
@@ -1142,7 +1143,7 @@ struct ChannelGroup final : TrackPanelGroup {
|
|||||||
auto &view = TrackView::Get( *channel );
|
auto &view = TrackView::Get( *channel );
|
||||||
auto height = view.GetHeight();
|
auto height = view.GetHeight();
|
||||||
rect.SetTop( yy );
|
rect.SetTop( yy );
|
||||||
rect.SetHeight( height );
|
rect.SetHeight( height - kSeparatorThickness );
|
||||||
const auto subViews = TrackView::Get( *channel ).GetSubViews( rect );
|
const auto subViews = TrackView::Get( *channel ).GetSubViews( rect );
|
||||||
auto y1 = yy;
|
auto y1 = yy;
|
||||||
for ( const auto &subView : subViews ) {
|
for ( const auto &subView : subViews ) {
|
||||||
|
@@ -159,18 +159,20 @@ void WaveTrackView::SetDisplay(WaveTrackDisplay display)
|
|||||||
|
|
||||||
auto WaveTrackView::GetSubViews( const wxRect &rect ) -> Refinement
|
auto WaveTrackView::GetSubViews( const wxRect &rect ) -> Refinement
|
||||||
{
|
{
|
||||||
// Collect the visible views
|
Refinement results;
|
||||||
using Pair = std::pair< float, std::shared_ptr< TrackView > >;
|
|
||||||
|
// Collect the visible views in the right sequence
|
||||||
|
using Pair = std::pair< float*, std::shared_ptr< TrackView > >;
|
||||||
std::vector< Pair > pairs( mPlacements.size() );
|
std::vector< Pair > pairs( mPlacements.size() );
|
||||||
size_t ii = 0;
|
size_t ii = 0;
|
||||||
float total = 0;
|
float total = 0;
|
||||||
WaveTrackSubViews::ForEach( [&]( WaveTrackSubView &subView ){
|
WaveTrackSubViews::ForEach( [&]( WaveTrackSubView &subView ){
|
||||||
const auto &placement = mPlacements[ii];
|
auto &placement = mPlacements[ii];
|
||||||
auto index = placement.index;
|
auto index = placement.index;
|
||||||
auto fraction = placement.fraction;
|
auto &fraction = placement.fraction;
|
||||||
if ( index >= 0 && fraction > 0.0 )
|
if ( index >= 0 && fraction > 0.0 )
|
||||||
total += fraction,
|
total += fraction,
|
||||||
pairs[ index ] = { fraction, subView.shared_from_this() };
|
pairs[ index ] = { &fraction, subView.shared_from_this() };
|
||||||
++ii;
|
++ii;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
@@ -179,17 +181,27 @@ auto WaveTrackView::GetSubViews( const wxRect &rect ) -> Refinement
|
|||||||
newEnd = std::remove_if( begin, end,
|
newEnd = std::remove_if( begin, end,
|
||||||
[]( const Pair &item ){ return !item.second; } );
|
[]( const Pair &item ){ return !item.second; } );
|
||||||
pairs.erase( newEnd, end );
|
pairs.erase( newEnd, end );
|
||||||
|
results.reserve( pairs.size() );
|
||||||
|
|
||||||
// Assign coordinates
|
// Assign coordinates
|
||||||
Refinement results;
|
// Also update the stored placements, redenominating to the total height,
|
||||||
results.reserve( pairs.size() );
|
// storing integer values
|
||||||
float partial = 0;
|
|
||||||
const auto top = rect.GetTop();
|
const auto top = rect.GetTop();
|
||||||
const auto height = rect.GetHeight();
|
const auto height = rect.GetHeight();
|
||||||
|
float partial = 0;
|
||||||
|
wxCoord lastCoord = 0;
|
||||||
|
float *lastFraction = nullptr;
|
||||||
for ( const auto &pair : pairs ) {
|
for ( const auto &pair : pairs ) {
|
||||||
results.emplace_back( top + (partial / total) * height, pair.second );
|
wxCoord newCoord = top + (partial / total) * height;
|
||||||
partial += pair.first;
|
results.emplace_back( newCoord, pair.second );
|
||||||
|
partial += *pair.first;
|
||||||
|
if (lastFraction)
|
||||||
|
*lastFraction = newCoord - lastCoord;
|
||||||
|
lastFraction = pair.first;
|
||||||
|
lastCoord = newCoord;
|
||||||
}
|
}
|
||||||
|
if ( lastFraction )
|
||||||
|
*lastFraction = top + height - lastCoord;
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user