Skip to content

Commit

Permalink
fix track spacer handling in wol track height adjustment actions
Browse files Browse the repository at this point in the history
- SWS/wol: Adjust selected envelope or last touched track height
- SWS/wol: Adjust envelope or track height under mouse cursor

reaper-oss#1787 (comment)

Add GetTrackHeightWithSpacer()

GetTrackHeight() is now balanced to SetTrackHeight(), as previously -- it will get the 'content' portion height and offset of the track in the TCP. If you need the true track offset (- spacerSize) or height (+ spacerSize), use GetTrackHeightAndOffsetWithSpacers().

Updated a couple of Zoom.cpp functions to take the spacer size into account, missed on the first pass.
  • Loading branch information
jeremybernstein authored and cfillion committed Feb 13, 2024
1 parent 05a0d76 commit 9db37b8
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Breeder/BR_MouseUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static MediaTrack* GetTrackFromY (int y, int* trackHeight, int* offset, int* spa
MediaTrack* track = GetTrackAreaFromY(y, &trackOffset, &spacer);
if (track)
{
trackH = GetTrackHeight(track, NULL);
trackH = GetTrackHeightWithSpacer(track);
if (y < trackOffset || y >= trackOffset + trackH)
track = NULL;
}
Expand Down Expand Up @@ -1481,7 +1481,7 @@ void BR_MouseInfo::GetTrackOrEnvelopeFromY (int y, TrackEnvelope** _envelope, Me
TrackEnvelope* envelope = NULL;
if (track)
{
elementHeight = GetTrackHeight(track, NULL);
elementHeight = GetTrackHeightWithSpacer(track);
vector<pair<int,int>> envHeights;
bool yInTrack = (y < elementOffset + elementHeight) ? true : false;

Expand Down
33 changes: 26 additions & 7 deletions Breeder/BR_Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2142,17 +2142,36 @@ int GetMasterTcpGap ()
return TCP_MASTER_GAP;
}

int GetTrackHeight (MediaTrack* track, int* offsetY, int* topGap /*=NULL*/, int* bottomGap /*=NULL*/)
// this is not balanced with SetTrackHeight(), but provides accurate values for v7 tracks with spacers
int GetTrackHeightWithSpacer (MediaTrack* track, int* offsetY, int* topGap, int* bottomGap)
{
int spacerSize = GetTrackSpacerSize(track);
int height = GetTrackHeight(track, offsetY, topGap, bottomGap);
int trackSpacerSize = GetTrackSpacerSize(track);

if (height)
{
height += trackSpacerSize;
}

if (offsetY)
{
*offsetY -= trackSpacerSize;
}

return height;
}

// GetTrackHeight ignores v7 track spacers in its offset and height calculation for legacy reasons
// use GetTrackHeightWithSpacer() to get accurate offset and height values including spacers
int GetTrackHeight (MediaTrack* track, int* offsetY, int* topGap /*=NULL*/, int* bottomGap /*=NULL*/)
{
if (offsetY)
{
// Get track's start Y coordinate
SCROLLINFO si{sizeof(SCROLLINFO), SIF_POS};
CF_GetScrollInfo(GetArrangeWnd(), SB_VERT, &si);

*offsetY = si.nPos + static_cast<int>(GetMediaTrackInfo_Value(track, "I_TCPY")) - spacerSize;
*offsetY = si.nPos + static_cast<int>(GetMediaTrackInfo_Value(track, "I_TCPY"));
}

if (!TcpVis(track))
Expand All @@ -2162,7 +2181,7 @@ int GetTrackHeight (MediaTrack* track, int* offsetY, int* topGap /*=NULL*/, int*
if (compact == 2) // wrong value if track was resized prior to compacting so return here
return SNM_GetIconTheme()->tcp_supercollapsed_height;

const int height = static_cast<int>(GetMediaTrackInfo_Value(track, "I_TCPH")) + spacerSize;
const int height = static_cast<int>(GetMediaTrackInfo_Value(track, "I_TCPH"));

if (topGap || bottomGap)
GetTrackGap(height, topGap, bottomGap);
Expand All @@ -2173,7 +2192,7 @@ int GetTrackHeight (MediaTrack* track, int* offsetY, int* topGap /*=NULL*/, int*
int GetItemHeight (MediaItem* item, int* offsetY)
{
int trackOffsetY;
int trackH = GetTrackHeight(GetMediaItem_Track(item), &trackOffsetY);
int trackH = GetTrackHeightWithSpacer(GetMediaItem_Track(item), &trackOffsetY);
return GetItemHeight(item, offsetY, trackH, trackOffsetY);
}

Expand Down Expand Up @@ -2313,7 +2332,7 @@ void MoveArrangeToTarget (double target, double reference)
void ScrollToTrackIfNotInArrange (MediaTrack* track)
{
int offsetY;
int height = GetTrackHeight(track, &offsetY);
int height = GetTrackHeightWithSpacer(track, &offsetY);

HWND hwnd = GetArrangeWnd();
SCROLLINFO si = { sizeof(SCROLLINFO), };
Expand Down Expand Up @@ -3531,7 +3550,7 @@ int GetTakeHeight (MediaItem_Take* take, MediaItem* item, int id, int* offsetY,
{
MediaItem* validItem = (item) ? (item) : (GetMediaItemTake_Item(take));
int trackOffset;
int trackHeight = GetTrackHeight(GetMediaItem_Track(validItem), &trackOffset);
int trackHeight = GetTrackHeightWithSpacer(GetMediaItem_Track(validItem), &trackOffset);
return GetTakeHeight(take, item, id, offsetY, averagedLast, trackHeight, trackOffset);
}

Expand Down
1 change: 1 addition & 0 deletions Breeder/BR_Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ bool IsItemLocked (MediaItem* item);
int GetTrackHeightFromVZoomIndex (MediaTrack* track, int vZoom); // also takes track compacting into account
int GetEnvHeightFromTrackHeight (int trackHeight); // what is envelope height in case its height override is 0 ?
int GetMasterTcpGap ();
int GetTrackHeightWithSpacer (MediaTrack* track, int* offsetY = NULL, int* topGap = NULL, int* bottomGap = NULL);
int GetTrackHeight (MediaTrack* track, int* offsetY, int* topGap = NULL, int* bottomGap = NULL);
int GetItemHeight (MediaItem* item, int* offsetY);
int GetTakeHeight (MediaItem_Take* take, int* offsetY);
Expand Down
3 changes: 1 addition & 2 deletions SnM/SnM_Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ void GetVisibleTCPTracks(WDL_PtrList<MediaTrack>* _trList)
{
MediaTrack* tr = CSurf_TrackFromID(i, false);
TCPY = static_cast<int>(GetMediaTrackInfo_Value(tr, "I_TCPY"));
TCPH = static_cast<int>(GetMediaTrackInfo_Value(tr, "I_TCPH"));
GetTrackGap(TCPH, &topGap, &bottomGap);
TCPH = GetTrackHeight(tr, nullptr, &topGap, &bottomGap);
if ((TCPY + TCPH - bottomGap > 0) && (TCPY + topGap < arrangeHeight))
_trList->Add(tr);
}
Expand Down
2 changes: 1 addition & 1 deletion Wol/wol_Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void SetArrangeScroll(int offsetY, int height, VerticalZoomCenter center)
void SetArrangeScrollTo(MediaTrack* track, VerticalZoomCenter center)
{
int offsetY;
int height = GetTrackHeight(track, &offsetY);
int height = GetTrackHeightWithSpacer(track, &offsetY);
SetArrangeScroll(offsetY, height, center);
}

Expand Down
13 changes: 11 additions & 2 deletions Zoom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,12 @@ void VertZoomRange(int iFirst, int iNum, bool* bZoomed, bool bMinimizeOthers, bo
{
int trackHeight = 0;
if (obeyHeightLock && locked)
{
trackHeight = static_cast<int>(GetMediaTrackInfo_Value(tr, "I_HEIGHTOVERRIDE"));
trackHeight += GetTrackSpacerSize(tr);
}
else
trackHeight = GetTrackHeightFromVZoomIndex(tr, 0);
trackHeight = GetTrackHeightWithSpacer(tr);

trackHeight += CountTrackEnvelopePanels(tr) * GetEnvHeightFromTrackHeight(trackHeight);
iNotZoomedSize += trackHeight;
Expand Down Expand Up @@ -224,10 +227,13 @@ void VertZoomRange(int iFirst, int iNum, bool* bZoomed, bool bMinimizeOthers, bo
if (bZoomed[i])
{
if (i + 1 == iNum)
iEachHeight +=leftOverHeight;
iEachHeight += leftOverHeight;
MediaTrack* tr = CSurf_TrackFromID(i + iFirst, false);
if (!obeyHeightLock || !GetMediaTrackInfo_Value(tr, "B_HEIGHTLOCK"))
{
GetSetMediaTrackInfo(tr, "I_HEIGHTOVERRIDE", &iEachHeight);
iEachHeight += GetTrackSpacerSize(tr);
}
}
}
TrackList_AdjustWindows(false);
Expand Down Expand Up @@ -269,7 +275,10 @@ void VertZoomRange(int iFirst, int iNum, bool* bZoomed, bool bMinimizeOthers, bo
{
const bool locked = GetMediaTrackInfo_Value(tr, "B_HEIGHTLOCK");
if (obeyHeightLock && locked)
{
trackHeight = static_cast<int>(GetMediaTrackInfo_Value(tr, "I_HEIGHTOVERRIDE"));
trackHeight += GetTrackSpacerSize(tr);
}
else
trackHeight = GetTrackHeightFromVZoomIndex(tr, iZoom);

Expand Down

0 comments on commit 9db37b8

Please sign in to comment.