MCPcopy Create free account
hub / github.com/audacity/audacity / FindAdjustedChannelHeights

Function FindAdjustedChannelHeights

src/TrackPanel.cpp:913–955  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

911
912namespace {
913std::vector<int> FindAdjustedChannelHeights(Track &t)
914{
915 auto channels = t.Channels();
916 assert(!channels.empty());
917
918 // Collect heights, and count affordances
919 int nAffordances = 0;
920 int totalHeight = 0;
921 std::vector<int> oldHeights;
922 for (auto pChannel : channels) {
923 auto &view = ChannelView::Get(*pChannel);
924 const auto height = view.GetHeight();
925 totalHeight += height;
926 oldHeights.push_back(height);
927 if (view.GetAffordanceControls())
928 ++nAffordances;
929 }
930
931 // Allocate results
932 auto nChannels = static_cast<int>(oldHeights.size());
933 std::vector<int> results;
934 results.reserve(nChannels);
935
936 // Now reallocate the channel heights for the presence of affordances
937 // and separators
938 auto availableHeight = totalHeight
939 - nAffordances * kAffordancesAreaHeight
940 - (nChannels - 1) * kChannelSeparatorThickness
941 - kTrackSeparatorThickness;
942 int cumulativeOldHeight = 0;
943 int cumulativeNewHeight = 0;
944 for (const auto &oldHeight : oldHeights) {
945 // Preserve the porportions among the stored heights
946 cumulativeOldHeight += oldHeight;
947 const auto newHeight =
948 cumulativeOldHeight * availableHeight / totalHeight
949 - cumulativeNewHeight;
950 cumulativeNewHeight += newHeight;
951 results.push_back(newHeight);
952 }
953
954 return results;
955}
956}
957
958void TrackPanel::UpdateVRulers()

Callers 3

UpdateTrackVRulerMethod · 0.85
ChildrenMethod · 0.85
DrawMethod · 0.85

Calls 7

GetFunction · 0.85
ChannelsMethod · 0.80
GetHeightMethod · 0.80
emptyMethod · 0.45
push_backMethod · 0.45
GetAffordanceControlsMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected