Audacity  3.0.3
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 47 of file WaveTrackView.cpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
HotZoneSize 

Definition at line 49 of file WaveTrackView.cpp.

49 { 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 51 of file WaveTrackView.cpp.

52  : mwView{
53  std::static_pointer_cast<WaveTrackView>( view.shared_from_this() ) }
54  {
55  mSubViews = view.GetAllSubViews();
58  }

Member Function Documentation

◆ ComputeHeights()

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

Definition at line 164 of file WaveTrackView.cpp.

165  {
166  // Compute integer-valued heights
167  float total = 0;
168  for (const auto index : mPermutation ) {
169  const auto &placement = mOrigPlacements[ index ];
170  total += std::max( 0.f, placement.fraction );
171  }
172  float partial = 0;
173  wxCoord lastCoord = 0;
174  std::vector<wxCoord> result;
175  for (const auto index : mPermutation ) {
176  const auto &placement = mOrigPlacements[ index ];
177  auto fraction = std::max( 0.f, placement.fraction );
178  wxCoord coord = ( (partial + fraction ) / total ) * totalHeight;
179  auto height = coord - lastCoord;
180  result.emplace_back( height );
181  mNewPlacements[ index ].fraction = height;
182  lastCoord = coord;
183  partial += fraction;
184  }
185  return result;
186  }

◆ FindIndex()

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

Definition at line 136 of file WaveTrackView.cpp.

137  {
138  const auto begin = mPermutation.begin(), end = mPermutation.end();
139  auto iter = std::find_if( begin, end, [&](size_t ii){
140  return mSubViews[ ii ].get() == &subView;
141  } );
142  return iter - begin;
143  }

◆ FindPermutation()

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

Definition at line 60 of file WaveTrackView.cpp.

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

◆ HitTest()

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

Definition at line 146 of file WaveTrackView.cpp.

148  {
149  const auto index = FindIndex( subView );
150  auto size = mPermutation.size();
151  if ( index < (int)size ) {
152  yy -= top;
153  if ( yy >= 0 && yy < HotZoneSize && index > 0 )
154  return { index, true }; // top hit
155  if ( yy < height && yy >= height - HotZoneSize &&
156  // Have not yet called ModifyPermutation; dragging bottom of
157  // bottommost view allowed only if at least one view is invisible
158  ( index < (int)size - 1 || mFirstSubView > 0 ) )
159  return { index, false }; // bottom hit
160  }
161  return { size, false }; // not hit
162  }

◆ ModifyPermutation()

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

Definition at line 98 of file WaveTrackView.cpp.

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

◆ NVisible()

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

Definition at line 95 of file WaveTrackView.cpp.

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

◆ UpdateViews()

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

Definition at line 188 of file WaveTrackView.cpp.

189  {
190  auto pView = mwView.lock();
191  if ( pView ) {
192  auto pTrack = static_cast< WaveTrack* >( pView->FindTrack().get() );
193  for ( auto pChannel : TrackList::Channels<WaveTrack>( pTrack ) )
195  rollback ? mOrigPlacements : mNewPlacements );
196  }
197  }

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

◆ mNewPlacements

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

Definition at line 201 of file WaveTrackView.cpp.

◆ mOrigPlacements

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

Definition at line 201 of file WaveTrackView.cpp.

◆ mPermutation

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

Definition at line 203 of file WaveTrackView.cpp.

◆ mSubViews

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

Definition at line 200 of file WaveTrackView.cpp.

◆ mwView

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

Definition at line 199 of file WaveTrackView.cpp.


The documentation for this struct was generated from the following file:
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::FindPermutation
void FindPermutation()
Definition: WaveTrackView.cpp:60
WaveTrack
A Track that contains audio waveform data.
Definition: WaveTrack.h:68
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mOrigPlacements
WaveTrackSubViewPlacements mOrigPlacements
Definition: WaveTrackView.cpp:201
WaveTrackView::GetAllSubViews
std::vector< std::shared_ptr< WaveTrackSubView > > GetAllSubViews()
Definition: WaveTrackView.cpp:1009
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::FindIndex
size_t FindIndex(WaveTrackSubView &subView) const
Definition: WaveTrackView.cpp:136
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mFirstSubView
size_t mFirstSubView
Definition: WaveTrackView.cpp:205
WaveTrackView::RestorePlacements
void RestorePlacements(const WaveTrackSubViewPlacements &placements)
Definition: WaveTrackView.h:108
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mNewPlacements
WaveTrackSubViewPlacements mNewPlacements
Definition: WaveTrackView.cpp:201
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mSubViews
WaveTrackSubViewPtrs mSubViews
Definition: WaveTrackView.cpp:200
WaveTrackView::SavePlacements
const WaveTrackSubViewPlacements & SavePlacements() const
Definition: WaveTrackView.h:106
WaveTrackSubViewPlacement
Definition: WaveTrackView.h:58
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::HotZoneSize
@ HotZoneSize
Definition: WaveTrackView.cpp:49
WaveTrackView::Get
static WaveTrackView & Get(WaveTrack &track)
Definition: WaveTrackView.cpp:763
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mPermutation
std::vector< size_t > mPermutation
Definition: WaveTrackView.cpp:203
anonymous_namespace{WaveTrackView.cpp}::SubViewAdjuster::mwView
std::weak_ptr< WaveTrackView > mwView
Definition: WaveTrackView.cpp:199