Audacity  3.2.0
Public Types | Public Member Functions | Public Attributes | List of all members
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster Struct Reference
Collaboration diagram for anonymous_namespace{WaveTrackView.cpp}::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 60 of file WaveTrackView.cpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
HotZoneSize 

Definition at line 62 of file WaveTrackView.cpp.

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

Constructor & Destructor Documentation

◆ SubViewAdjuster()

anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::SubViewAdjuster ( WaveTrackView view)
inline

Definition at line 64 of file WaveTrackView.cpp.

65  : mwView{
66  std::static_pointer_cast<WaveTrackView>( view.shared_from_this() ) }
67  {
68  mSubViews = view.GetAllSubViews();
71  }

Member Function Documentation

◆ ComputeHeights()

std::vector<wxCoord> anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::ComputeHeights ( wxCoord  totalHeight)
inline

Definition at line 177 of file WaveTrackView.cpp.

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

◆ FindIndex()

size_t anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::FindIndex ( WaveTrackSubView subView) const
inline

Definition at line 149 of file WaveTrackView.cpp.

150  {
151  const auto begin = mPermutation.begin(), end = mPermutation.end();
152  auto iter = std::find_if( begin, end, [&](size_t ii){
153  return mSubViews[ ii ].get() == &subView;
154  } );
155  return iter - begin;
156  }

◆ FindPermutation()

void anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::FindPermutation ( )
inline

Definition at line 73 of file WaveTrackView.cpp.

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

References size.

◆ HitTest()

std::pair< size_t, bool > anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::HitTest ( WaveTrackSubView subView,
wxCoord  yy,
wxCoord  top,
wxCoord  height 
)
inline

Definition at line 159 of file WaveTrackView.cpp.

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

References size.

◆ ModifyPermutation()

bool anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::ModifyPermutation ( bool  top)
inline

Definition at line 111 of file WaveTrackView.cpp.

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

◆ NVisible()

size_t anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::NVisible ( ) const
inline

Definition at line 108 of file WaveTrackView.cpp.

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

◆ UpdateViews()

void anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::UpdateViews ( bool  rollback)
inline

Definition at line 201 of file WaveTrackView.cpp.

202  {
203  auto pView = mwView.lock();
204  if ( pView ) {
205  auto pTrack = static_cast< WaveTrack* >( pView->FindTrack().get() );
206  for ( auto pChannel : TrackList::Channels<WaveTrack>( pTrack ) )
208  rollback ? mOrigPlacements : mNewPlacements );
209  }
210  }

References WaveTrackView::Get(), and WaveTrackView::RestorePlacements().

Here is the call graph for this function:

Member Data Documentation

◆ mFirstSubView

size_t anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mFirstSubView {}

Definition at line 218 of file WaveTrackView.cpp.

◆ mNewPlacements

WaveTrackSubViewPlacements anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mNewPlacements

Definition at line 214 of file WaveTrackView.cpp.

◆ mOrigPlacements

WaveTrackSubViewPlacements anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mOrigPlacements

Definition at line 214 of file WaveTrackView.cpp.

◆ mPermutation

std::vector< size_t > anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mPermutation

Definition at line 216 of file WaveTrackView.cpp.

◆ mSubViews

WaveTrackSubViewPtrs anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mSubViews

Definition at line 213 of file WaveTrackView.cpp.

◆ mwView

std::weak_ptr< WaveTrackView > anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mwView

Definition at line 212 of file WaveTrackView.cpp.


The documentation for this struct was generated from the following file:
size
size_t size
Definition: ffmpeg-2.3.6-single-header.h:412
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::FindPermutation
void FindPermutation()
Definition: WaveTrackView.cpp:73
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:75
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mOrigPlacements
WaveTrackSubViewPlacements mOrigPlacements
Definition: WaveTrackView.cpp:214
WaveTrackView::GetAllSubViews
std::vector< std::shared_ptr< WaveTrackSubView > > GetAllSubViews()
Definition: WaveTrackView.cpp:1416
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::FindIndex
size_t FindIndex(WaveTrackSubView &subView) const
Definition: WaveTrackView.cpp:149
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mFirstSubView
size_t mFirstSubView
Definition: WaveTrackView.cpp:218
WaveTrackView::RestorePlacements
void RestorePlacements(const WaveTrackSubViewPlacements &placements)
Definition: WaveTrackView.h:140
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mNewPlacements
WaveTrackSubViewPlacements mNewPlacements
Definition: WaveTrackView.cpp:214
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mSubViews
WaveTrackSubViewPtrs mSubViews
Definition: WaveTrackView.cpp:213
WaveTrackView::SavePlacements
const WaveTrackSubViewPlacements & SavePlacements() const
Definition: WaveTrackView.h:138
WaveTrackSubViewPlacement
Definition: WaveTrackView.h:86
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::HotZoneSize
@ HotZoneSize
Definition: WaveTrackView.cpp:62
WaveTrackView::Get
static WaveTrackView & Get(WaveTrack &track)
Definition: WaveTrackView.cpp:858
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mPermutation
std::vector< size_t > mPermutation
Definition: WaveTrackView.cpp:216
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mwView
std::weak_ptr< WaveTrackView > mwView
Definition: WaveTrackView.cpp:212