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 (WaveTrackView &view)
 
void FindPermutation ()
 
size_t NVisible () const
 
bool ModifyPermutation (bool top)
 
size_t FindIndex (WaveTrackSubView &subView) const
 
std::pair< size_t, bool > HitTest (WaveTrackSubView &subView, wxCoord yy, wxCoord top, wxCoord height)
 
std::vector< wxCoord > ComputeHeights (wxCoord totalHeight)
 
void UpdateViews (bool rollback)
 

Public Attributes

std::weak_ptr< WaveTrackViewmwView
 
WaveTrackSubViewPtrs mSubViews
 
WaveTrackSubViewPlacements mOrigPlacements
 
WaveTrackSubViewPlacements mNewPlacements
 
std::vector< size_t > mPermutation
 
size_t mFirstSubView {}
 

Detailed Description

Definition at line 107 of file WaveTrackView.cpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
HotZoneSize 

Definition at line 109 of file WaveTrackView.cpp.

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

Constructor & Destructor Documentation

◆ SubViewAdjuster()

SubViewAdjuster::SubViewAdjuster ( WaveTrackView view)
inline

Definition at line 111 of file WaveTrackView.cpp.

112 : mwView{
113 std::static_pointer_cast<WaveTrackView>( view.shared_from_this() ) }
114 {
115 mSubViews = view.GetAllSubViews();
118 }
std::vector< std::shared_ptr< WaveTrackSubView > > GetAllSubViews()
const WaveTrackSubViewPlacements & SavePlacements() const
WaveTrackSubViewPlacements mNewPlacements
WaveTrackSubViewPtrs mSubViews
std::weak_ptr< WaveTrackView > mwView
WaveTrackSubViewPlacements mOrigPlacements

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

Here is the call graph for this function:

Member Function Documentation

◆ ComputeHeights()

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

Definition at line 224 of file WaveTrackView.cpp.

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

Definition at line 196 of file WaveTrackView.cpp.

197 {
198 const auto begin = mPermutation.begin(), end = mPermutation.end();
199 auto iter = std::find_if( begin, end, [&](size_t ii){
200 return mSubViews[ ii ].get() == &subView;
201 } );
202 return iter - begin;
203 }
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:150

References PackedArray::begin(), PackedArray::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 120 of file WaveTrackView.cpp.

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

References PackedArray::begin(), PackedArray::end(), mFirstSubView, mOrigPlacements, mPermutation, mSubViews, 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 ( WaveTrackSubView subView,
wxCoord  yy,
wxCoord  top,
wxCoord  height 
)
inline

Definition at line 206 of file WaveTrackView.cpp.

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

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

References mFirstSubView, mNewPlacements, and mPermutation.

Referenced by SubViewAdjustHandle::SubViewAdjustHandle().

Here is the caller graph for this function:

◆ NVisible()

size_t SubViewAdjuster::NVisible ( ) const
inline

Definition at line 155 of file WaveTrackView.cpp.

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

References mFirstSubView, and mPermutation.

◆ UpdateViews()

void SubViewAdjuster::UpdateViews ( bool  rollback)
inline

Definition at line 248 of file WaveTrackView.cpp.

249 {
250 auto pView = mwView.lock();
251 if ( pView ) {
252 auto pTrack = static_cast< WaveTrack* >( pView->FindTrack().get() );
254 rollback ? mOrigPlacements : mNewPlacements);
255 }
256 }
A Track that contains audio waveform data.
Definition: WaveTrack.h:51
void RestorePlacements(const WaveTrackSubViewPlacements &placements)
static WaveTrackView & Get(WaveTrack &track)

References WaveTrackView::Get(), mNewPlacements, mOrigPlacements, mwView, and WaveTrackView::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

WaveTrackSubViewPlacements SubViewAdjuster::mNewPlacements

◆ mOrigPlacements

WaveTrackSubViewPlacements SubViewAdjuster::mOrigPlacements

Definition at line 260 of file WaveTrackView.cpp.

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

◆ mPermutation

std::vector< size_t > SubViewAdjuster::mPermutation

◆ mSubViews

WaveTrackSubViewPtrs SubViewAdjuster::mSubViews

Definition at line 259 of file WaveTrackView.cpp.

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

◆ mwView

std::weak_ptr< WaveTrackView > SubViewAdjuster::mwView

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