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 58 of file WaveTrackView.cpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
HotZoneSize 

Definition at line 60 of file WaveTrackView.cpp.

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

Constructor & Destructor Documentation

◆ SubViewAdjuster()

SubViewAdjuster::SubViewAdjuster ( WaveTrackView view)
inline

Definition at line 62 of file WaveTrackView.cpp.

63 : mwView{
64 std::static_pointer_cast<WaveTrackView>( view.shared_from_this() ) }
65 {
69 }
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 175 of file WaveTrackView.cpp.

176 {
177 // Compute integer-valued heights
178 float total = 0;
179 for (const auto index : mPermutation ) {
180 const auto &placement = mOrigPlacements[ index ];
181 total += std::max( 0.f, placement.fraction );
182 }
183 float partial = 0;
184 wxCoord lastCoord = 0;
185 std::vector<wxCoord> result;
186 for (const auto index : mPermutation ) {
187 const auto &placement = mOrigPlacements[ index ];
188 auto fraction = std::max( 0.f, placement.fraction );
189 wxCoord coord = ( (partial + fraction ) / total ) * totalHeight;
190 auto height = coord - lastCoord;
191 result.emplace_back( height );
192 mNewPlacements[ index ].fraction = height;
193 lastCoord = coord;
194 partial += fraction;
195 }
196 return result;
197 }
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 147 of file WaveTrackView.cpp.

148 {
149 const auto begin = mPermutation.begin(), end = mPermutation.end();
150 auto iter = std::find_if( begin, end, [&](size_t ii){
151 return mSubViews[ ii ].get() == &subView;
152 } );
153 return iter - begin;
154 }
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 71 of file WaveTrackView.cpp.

72 {
73 // Find a certain sort of the sub-views
74 auto size = mOrigPlacements.size();
75 wxASSERT( mSubViews.size() == size );
76 mPermutation.resize( size );
77 const auto begin = mPermutation.begin(), end = mPermutation.end();
78 std::iota( begin, end, 0 );
79 static auto invisible = []( const WaveTrackSubViewPlacement &placement ){
80 return placement.index < 0 || placement.fraction <= 0;
81 };
82 const auto comp = [this]( size_t ii, size_t jj ){
83 auto &pi = mOrigPlacements[ii];
84 bool iInvisible = invisible( pi );
85
86 auto &pj = mOrigPlacements[jj];
87 bool jInvisible = invisible( pj );
88
89 // Sort the invisibles to the front, rest by index
90 if ( iInvisible != jInvisible )
91 return iInvisible;
92 else if ( !iInvisible )
93 return pi.index < pj.index;
94 else
95 // Minor sort among the invisible views by their type
96 return mSubViews[ii]->SubViewType() < mSubViews[jj]->SubViewType();
97 };
98 std::sort( begin, end, comp );
99 // Find the start of visible sub-views
100 auto first = std::find_if( begin, end, [this](size_t ii){
101 return !invisible( mOrigPlacements[ii] );
102 } );
103 mFirstSubView = first - begin;
104 }

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 157 of file WaveTrackView.cpp.

159 {
160 const auto index = FindIndex( subView );
161 auto size = mPermutation.size();
162 if ( index < (int)size ) {
163 yy -= top;
164 if ( yy >= 0 && yy < HotZoneSize && index > 0 )
165 return { index, true }; // top hit
166 if ( yy < height && yy >= height - HotZoneSize &&
167 // Have not yet called ModifyPermutation; dragging bottom of
168 // bottommost view allowed only if at least one view is invisible
169 ( index < (int)size - 1 || mFirstSubView > 0 ) )
170 return { index, false }; // bottom hit
171 }
172 return { size, false }; // not hit
173 }
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 109 of file WaveTrackView.cpp.

110 {
111 bool rotated = false;
112 const auto pBegin = mPermutation.begin(), pEnd = mPermutation.end();
113 auto pFirst = pBegin + mFirstSubView;
114 if ( mFirstSubView > 0 ) {
115 // In case of dragging the top edge of the topmost view, or the
116 // bottom edge of the bottommost, decide which of the invisible
117 // views can become visible, and reassign the sequence.
118 // For definiteness, that choice depends on the subview type numbers;
119 // see the sorting criteria above.
121 --pFirst;
122 if ( top ) {
123 // If you drag down the top, the greatest-numbered invisible
124 // subview type will appear there.
125 mNewPlacements[ *pFirst ].fraction = 0;
126 }
127 else {
128 // If you drag up the bottom, let the least-numbered invisible
129 // subview type appear there.
130 mNewPlacements[ *pBegin ].fraction = 0;
131 std::rotate( pBegin, pBegin + 1, pEnd );
132 rotated = true;
133 }
134 }
135 // Reassign index numbers to all sub-views and 0 fraction to invisibles
136 for ( auto pIter = pBegin; pIter != pFirst; ++pIter ) {
137 auto &placement = mNewPlacements[ *pIter ];
138 placement.index = -1;
139 placement.fraction = 0;
140 }
141 size_t index = 0;
142 for ( auto pIter = pFirst; pIter != pEnd; ++pIter )
143 mNewPlacements[ *pIter ].index = index++;
144 return rotated;
145 }

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 106 of file WaveTrackView.cpp.

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

References mFirstSubView, and mPermutation.

◆ UpdateViews()

void SubViewAdjuster::UpdateViews ( bool  rollback)
inline

Definition at line 199 of file WaveTrackView.cpp.

200 {
201 auto pView = mwView.lock();
202 if ( pView ) {
203 auto pTrack = static_cast< WaveTrack* >( pView->FindTrack().get() );
204 for ( auto pChannel : TrackList::Channels<WaveTrack>( pTrack ) )
206 rollback ? mOrigPlacements : mNewPlacements );
207 }
208 }
A Track that contains audio waveform data.
Definition: WaveTrack.h:57
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 212 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 211 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: