1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-16 16:10:06 +02:00

Bug2279 fix reimplemented...

... Don't hard-code the number of sub-views as two.

This modifies the fix at commit 596fd7c02f487aac65046c0ec46d680d69ee21e8
This commit is contained in:
Paul Licameli 2020-01-09 13:38:25 -05:00
parent 7f8905be8e
commit d50dae4dd2
3 changed files with 39 additions and 33 deletions

View File

@ -770,10 +770,10 @@ void WaveTrackMenuTable::OnMultiView(wxCommandEvent & event)
{
const auto pTrack = static_cast<WaveTrack*>(mpData->pTrack);
const auto &view = WaveTrackView::Get( *pTrack );
const int nViewTypes = 2;
bool multi = !view.GetMultiView();
WaveTrackView::WaveTrackDisplay display;
display = *view.GetDisplays().begin();
const auto &displays = view.GetDisplays();
const auto display = displays.empty()
? WaveTrackViewConstants::Waveform : *displays.begin();
for (const auto channel : TrackList::Channels(pTrack)) {
auto &channelView = WaveTrackView::Get( *channel );
channelView.SetMultiView( multi );
@ -781,7 +781,7 @@ void WaveTrackMenuTable::OnMultiView(wxCommandEvent & event)
// Whichever sub-view was on top stays on top
// If going into Multi-view, it will be 1/nth the height.
// If exiting multi-view, it will be full height.
channelView.SetDisplay(display, multi ? 1.0/nViewTypes :1.0);
channelView.SetDisplay(display, !multi);
}
}

View File

@ -540,10 +540,10 @@ auto WaveTrackView::GetDisplays() const -> std::vector<WaveTrackDisplay>
return results;
}
void WaveTrackView::SetDisplay(WaveTrackDisplay display, float frac)
void WaveTrackView::SetDisplay(WaveTrackDisplay display, bool exclusive)
{
BuildSubViews();
DoSetDisplay( display, frac );
DoSetDisplay( display, exclusive );
}
void WaveTrackView::ToggleSubView(WaveTrackDisplay display)
@ -572,7 +572,7 @@ void WaveTrackView::ToggleSubView(WaveTrackDisplay display)
// if removing the last one, then don't!
// Switch to radio-button view instead.
if (nn <= 1) {
DoSetDisplay(display, 1.0);
DoSetDisplay(display);
SetMultiView(false);
}
else
@ -610,32 +610,38 @@ void WaveTrackView::ToggleSubView(WaveTrackDisplay display)
}
}
// frac sets proportion/height of the chosen display, which will be first.
// use 1.0 to take up entire space
// use some fraction to take up that proportion, leaving the rest for
// one each of the other types.
// use 1.0/number-of-types for equal spacing.
void WaveTrackView::DoSetDisplay(WaveTrackDisplay display,float frac)
// If exclusive, make the chosen view take up all the height. Else,
// partition equally, putting the specified view on top.
// Be sure the sequence in which the other views appear is determinate.
void WaveTrackView::DoSetDisplay(WaveTrackDisplay display, bool exclusive)
{
// Some generality here anticipating more than two views.
// The order of sub-views in the array is not specified, so make it definite
// by sorting by the view type constants.
size_t ii = 0;
size_t jj = 1;
const int nViewTypes = 2;
WaveTrackSubViews::ForEach( [&,display]( WaveTrackSubView &subView ){
auto viewType = subView.SubViewType();
if (viewType == display) {
// 0 for first view
mPlacements[ii] = { 0, frac };
--jj;
}
else if( frac > 0.999)
// -1 for not displayed
mPlacements[ii] = { -1, 0.0 };
else
// jj for positions excluding the first.
mPlacements[ii] = { (int)jj, (1.0f-frac)/(nViewTypes-1) };
++ii;
++jj;
std::vector< std::pair< WaveTrackViewConstants::Display, size_t > > pairs;
WaveTrackSubViews::ForEach( [&pairs, &ii]( WaveTrackSubView &subView ){
pairs.push_back( { subView.SubViewType(), ii++ } );
} );
std::sort( pairs.begin(), pairs.end() );
int jj = 1;
for ( const auto &pair : pairs ) {
auto &placement = mPlacements[ pair.second ];
if (pair.first == display) {
// 0 for first view
placement = { 0, 1.0 };
}
else if( exclusive )
// -1 for not displayed
placement = { -1, 0.0 };
else
// positions other than the first.
// (Note that the fractions in the placement don't need to be
// denominated to 1. Just make them all equal to get an equal
// partitioning of the sub-views.)
placement = { jj++, 1.0 };
}
}
auto WaveTrackView::GetSubViews( const wxRect &rect ) -> Refinement
@ -943,7 +949,7 @@ void WaveTrackView::BuildSubViews() const
settings.scaleType = WaveformSettings::stLogarithmic;
}
pThis->DoSetDisplay( display, 1.0 );
pThis->DoSetDisplay( display );
}
}
}

View File

@ -84,7 +84,7 @@ public:
using WaveTrackDisplay = WaveTrackViewConstants::Display;
std::vector<WaveTrackDisplay> GetDisplays() const;
void SetDisplay(WaveTrackDisplay display, float frac=1.0);
void SetDisplay(WaveTrackDisplay display, bool exclusive = true);
const WaveTrackSubViewPlacements &SavePlacements() const
{ return mPlacements; }
@ -105,7 +105,7 @@ public:
private:
void BuildSubViews() const;
void DoSetDisplay(WaveTrackDisplay display, float frac);
void DoSetDisplay(WaveTrackDisplay display, bool exclusive = true);
// TrackPanelDrawable implementation
void Draw(