Audacity 3.2.0
Public Types | Public Member Functions | Public Attributes | List of all members
SubViewAdjuster Struct Reference
Collaboration diagram for SubViewAdjuster:
[legend]

Public Types

enum  { HotZoneSize = 5 }
 

Public Member Functions

 SubViewAdjuster (WaveChannelView &view)
 
void FindPermutation ()
 
size_t NVisible () const
 
bool ModifyPermutation (bool top)
 
size_t FindIndex (WaveChannelSubView &subView) const
 
std::pair< size_t, bool > HitTest (WaveChannelSubView &subView, wxCoord yy, wxCoord top, wxCoord height)
 
std::vector< wxCoord > ComputeHeights (wxCoord totalHeight)
 
void UpdateViews (bool rollback)
 

Public Attributes

std::weak_ptr< WaveChannelViewmwView
 
WaveChannelSubViewPtrs mSubViews
 
WaveChannelSubViewPlacements mOrigPlacements
 
WaveChannelSubViewPlacements mNewPlacements
 
std::vector< size_t > mPermutation
 
size_t mFirstSubView {}
 

Detailed Description

Definition at line 108 of file WaveChannelView.cpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
HotZoneSize 

Definition at line 110 of file WaveChannelView.cpp.

110{ HotZoneSize = 5 }; // so many pixels at top and bottom of each subview

Constructor & Destructor Documentation

◆ SubViewAdjuster()

SubViewAdjuster::SubViewAdjuster ( WaveChannelView view)
inline

Definition at line 112 of file WaveChannelView.cpp.

113 : mwView{
114 std::static_pointer_cast<WaveChannelView>(view.shared_from_this()) }
115 {
116 mSubViews = view.GetAllSubViews();
119 }
std::vector< std::shared_ptr< WaveChannelSubView > > GetAllSubViews()
const WaveChannelSubViewPlacements & SavePlacements() const
WaveChannelSubViewPtrs mSubViews
WaveChannelSubViewPlacements mNewPlacements
WaveChannelSubViewPlacements mOrigPlacements
std::weak_ptr< WaveChannelView > mwView

References FindPermutation(), WaveChannelView::GetAllSubViews(), mNewPlacements, mOrigPlacements, mSubViews, and WaveChannelView::SavePlacements().

Here is the call graph for this function:

Member Function Documentation

◆ ComputeHeights()

std::vector< wxCoord > SubViewAdjuster::ComputeHeights ( wxCoord  totalHeight)
inline

Definition at line 225 of file WaveChannelView.cpp.

226 {
227 // Compute integer-valued heights
228 float total = 0;
229 for (const auto index : mPermutation ) {
230 const auto &placement = mOrigPlacements[ index ];
231 total += std::max( 0.f, placement.fraction );
232 }
233 float partial = 0;
234 wxCoord lastCoord = 0;
235 std::vector<wxCoord> result;
236 for (const auto index : mPermutation ) {
237 const auto &placement = mOrigPlacements[ index ];
238 auto fraction = std::max( 0.f, placement.fraction );
239 wxCoord coord = ( (partial + fraction ) / total ) * totalHeight;
240 auto height = coord - lastCoord;
241 result.emplace_back( height );
242 mNewPlacements[ index ].fraction = height;
243 lastCoord = coord;
244 partial += fraction;
245 }
246 return result;
247 }
std::vector< size_t > mPermutation

References mNewPlacements, mOrigPlacements, and mPermutation.

Referenced by SubViewAdjustHandle::Click(), and SubViewRearrangeHandle::Click().

Here is the caller graph for this function:

◆ FindIndex()

size_t SubViewAdjuster::FindIndex ( WaveChannelSubView subView) const
inline

Definition at line 197 of file WaveChannelView.cpp.

198 {
199 const auto begin = mPermutation.begin(), end = mPermutation.end();
200 auto iter = std::find_if( begin, end, [&](size_t ii){
201 return mSubViews[ ii ].get() == &subView;
202 } );
203 return iter - begin;
204 }
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101

References details::begin(), details::end(), mPermutation, and mSubViews.

Referenced by HitTest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindPermutation()

void SubViewAdjuster::FindPermutation ( )
inline

Definition at line 121 of file WaveChannelView.cpp.

122 {
123 // Find a certain sort of the sub-views
124 auto size = mOrigPlacements.size();
125 wxASSERT( mSubViews.size() == size );
126 mPermutation.resize( size );
127 const auto begin = mPermutation.begin(), end = mPermutation.end();
128 std::iota( begin, end, 0 );
129 static auto invisible = [](const WaveChannelSubViewPlacement &placement) {
130 return placement.index < 0 || placement.fraction <= 0;
131 };
132 const auto comp = [this]( size_t ii, size_t jj ){
133 auto &pi = mOrigPlacements[ii];
134 bool iInvisible = invisible( pi );
135
136 auto &pj = mOrigPlacements[jj];
137 bool jInvisible = invisible( pj );
138
139 // Sort the invisibles to the front, rest by index
140 if ( iInvisible != jInvisible )
141 return iInvisible;
142 else if ( !iInvisible )
143 return pi.index < pj.index;
144 else
145 // Minor sort among the invisible views by their type
146 return mSubViews[ii]->SubViewType() < mSubViews[jj]->SubViewType();
147 };
148 std::sort( begin, end, comp );
149 // Find the start of visible sub-views
150 auto first = std::find_if( begin, end, [this](size_t ii){
151 return !invisible( mOrigPlacements[ii] );
152 } );
153 mFirstSubView = first - begin;
154 }

References details::begin(), details::end(), mFirstSubView, mOrigPlacements, mPermutation, mSubViews, MIR::anonymous_namespace{MirUtils.cpp}::pi, and size.

Referenced by SubViewAdjuster().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HitTest()

std::pair< size_t, bool > SubViewAdjuster::HitTest ( WaveChannelSubView subView,
wxCoord  yy,
wxCoord  top,
wxCoord  height 
)
inline

Definition at line 207 of file WaveChannelView.cpp.

209 {
210 const auto index = FindIndex( subView );
211 auto size = mPermutation.size();
212 if ( index < (int)size ) {
213 yy -= top;
214 if ( yy >= 0 && yy < HotZoneSize && index > 0 )
215 return { index, true }; // top hit
216 if ( yy < height && yy >= height - HotZoneSize &&
217 // Have not yet called ModifyPermutation; dragging bottom of
218 // bottommost view allowed only if at least one view is invisible
219 ( index < (int)size - 1 || mFirstSubView > 0 ) )
220 return { index, false }; // bottom hit
221 }
222 return { size, false }; // not hit
223 }
size_t FindIndex(WaveChannelSubView &subView) const

References FindIndex(), HotZoneSize, mFirstSubView, mPermutation, and size.

Here is the call graph for this function:

◆ ModifyPermutation()

bool SubViewAdjuster::ModifyPermutation ( bool  top)
inline

Definition at line 159 of file WaveChannelView.cpp.

160 {
161 bool rotated = false;
162 const auto pBegin = mPermutation.begin(), pEnd = mPermutation.end();
163 auto pFirst = pBegin + mFirstSubView;
164 if ( mFirstSubView > 0 ) {
165 // In case of dragging the top edge of the topmost view, or the
166 // bottom edge of the bottommost, decide which of the invisible
167 // views can become visible, and reassign the sequence.
168 // For definiteness, that choice depends on the subview type numbers;
169 // see the sorting criteria above.
171 --pFirst;
172 if ( top ) {
173 // If you drag down the top, the greatest-numbered invisible
174 // subview type will appear there.
175 mNewPlacements[ *pFirst ].fraction = 0;
176 }
177 else {
178 // If you drag up the bottom, let the least-numbered invisible
179 // subview type appear there.
180 mNewPlacements[ *pBegin ].fraction = 0;
181 std::rotate( pBegin, pBegin + 1, pEnd );
182 rotated = true;
183 }
184 }
185 // Reassign index numbers to all sub-views and 0 fraction to invisibles
186 for ( auto pIter = pBegin; pIter != pFirst; ++pIter ) {
187 auto &placement = mNewPlacements[ *pIter ];
188 placement.index = -1;
189 placement.fraction = 0;
190 }
191 size_t index = 0;
192 for ( auto pIter = pFirst; pIter != pEnd; ++pIter )
193 mNewPlacements[ *pIter ].index = index++;
194 return rotated;
195 }
void rotate(const float *oldPhase, const float *newPhase, std::complex< float > *dst, int32_t n)
Definition: VectorOps.h:140

References mFirstSubView, mNewPlacements, mPermutation, and staffpad::vo::rotate().

Referenced by SubViewAdjustHandle::SubViewAdjustHandle().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ NVisible()

size_t SubViewAdjuster::NVisible ( ) const
inline

Definition at line 156 of file WaveChannelView.cpp.

157 { return mPermutation.size() - mFirstSubView; }

References mFirstSubView, and mPermutation.

◆ UpdateViews()

void SubViewAdjuster::UpdateViews ( bool  rollback)
inline

Definition at line 249 of file WaveChannelView.cpp.

250 {
251 auto pView = mwView.lock();
252 if ( pView ) {
253 WaveChannelView::Get(*pView->FindWaveChannel()).RestorePlacements(
254 rollback ? mOrigPlacements : mNewPlacements);
255 }
256 }
static WaveChannelView & Get(WaveChannel &channel)
void RestorePlacements(const WaveChannelSubViewPlacements &placements)

References WaveChannelView::Get(), mNewPlacements, mOrigPlacements, mwView, and WaveChannelView::RestorePlacements().

Referenced by SubViewAdjustHandle::Cancel(), SubViewRearrangeHandle::Cancel(), SubViewAdjustHandle::Click(), SubViewCloseHandle::CommitChanges(), SubViewAdjustHandle::Drag(), and SubViewRearrangeHandle::Drag().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mFirstSubView

size_t SubViewAdjuster::mFirstSubView {}

◆ mNewPlacements

WaveChannelSubViewPlacements SubViewAdjuster::mNewPlacements

◆ mOrigPlacements

WaveChannelSubViewPlacements SubViewAdjuster::mOrigPlacements

Definition at line 260 of file WaveChannelView.cpp.

Referenced by ComputeHeights(), FindPermutation(), SubViewAdjuster(), and UpdateViews().

◆ mPermutation

std::vector< size_t > SubViewAdjuster::mPermutation

◆ mSubViews

WaveChannelSubViewPtrs SubViewAdjuster::mSubViews

Definition at line 259 of file WaveChannelView.cpp.

Referenced by FindIndex(), FindPermutation(), and SubViewAdjuster().

◆ mwView

std::weak_ptr<WaveChannelView> SubViewAdjuster::mwView

The documentation for this struct was generated from the following file: