Skip to content

Commit

Permalink
BR Mouse context: don't detect envelope segment when mouse cursor is …
Browse files Browse the repository at this point in the history
…outside of automation items bounds and underlying envelope is bypassed

fixes reaper-oss#1727, fixes reaper-oss#1488

# BR_EnvelopeUtil.h: add link to schwa's post listing AI tokens
  • Loading branch information
nofishonfriday committed Feb 21, 2023
1 parent a3693ad commit bf07281
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions Breeder/BR_EnvelopeUtil.h
Expand Up @@ -189,6 +189,7 @@ class BR_Envelope
EnvProperties& operator= (const EnvProperties& properties);
vector<WDL_FastString> automationItems;
//POOLEDENVINST id pos length offset rate timeBased baseline(.5=0) amplitude loop ? ?
// see https://forum.cockos.com/showpost.php?p=2198410&postcount=116
// For now we're just storing as strings in properties and not handling parsing of these
//struct AutomationItem
//{
Expand Down
40 changes: 40 additions & 0 deletions Breeder/BR_MouseUtil.cpp
Expand Up @@ -731,6 +731,18 @@ void BR_MouseInfo::GetContext (const POINT& p)
{
BR_Envelope envelope(mouseInfo.envelope);
trackEnvHit = this->IsMouseOverEnvelopeLine(envelope, height-2*ENV_GAP, offset+ENV_GAP, mouseDisplayX, mouseY, mousePos, arrangeStart, arrangeZoom, &mouseInfo.envPointId);

// if env is hit, check if underlying envelope outside of automation items is bypassed, #1727
if (trackEnvHit)
{
int bypassUnderlEnvProjDefault = *ConfigVar<int>("pooledenvattach") & 4;
int AIoptions = envelope.GetAIoptions(); // -1 == use project default
if ((bypassUnderlEnvProjDefault && AIoptions == -1) || (AIoptions & 4))
{
if (!this->IsMouseOverAI(envelope, height - 2 * ENV_GAP, offset + ENV_GAP, mouseDisplayX, mouseY, mousePos, arrangeStart, arrangeZoom))
trackEnvHit = 0;
}
}
}

if (trackEnvHit == 1) mouseInfo.details = "env_point";
Expand Down Expand Up @@ -778,6 +790,16 @@ void BR_MouseInfo::GetContext (const POINT& p)
{
if (trackEnvHit == 1) mouseInfo.details = "env_point";
else if (trackEnvHit == 2) mouseInfo.details = "env_segment";

// if env is hit, check if underlying envelope outside of automation items is bypassed, #1488
int bypassUnderlEnvProjDefault = *ConfigVar<int>("pooledenvattach") & 4;
BR_Envelope envelope(mouseInfo.envelope);
int AIoptions = envelope.GetAIoptions(); // -1 == use project default
if ((bypassUnderlEnvProjDefault && AIoptions == -1) || (AIoptions & 4))
{
if (!this->IsMouseOverAI(envelope, height - 2 * ENV_GAP, offset + ENV_GAP, mouseDisplayX, mouseY, mousePos, arrangeStart, arrangeZoom))
mouseInfo.details = "empty";
}
}
// Item and things inside it
else if (mouseInfo.item)
Expand Down Expand Up @@ -1311,6 +1333,24 @@ int BR_MouseInfo::IsMouseOverEnvelopeLine (BR_Envelope& envelope, int drawableEn
return mouseHit;
}

bool BR_MouseInfo::IsMouseOverAI(BR_Envelope & envelope, int drawableEnvHeight, int yOffset, int mouseDisplayX, int mouseY, double mousePos, double arrangeStart, double arrangeZoom)
{
// Check if mouse is in drawable part of envelope lane where line resides
if (mouseY >= yOffset && mouseY < yOffset + drawableEnvHeight)
{
TrackEnvelope* trEnv = envelope.GetPointer();
int AIcount = CountAutomationItems(trEnv);
for (int i = 0; i < AIcount; i++) {
double AIpos = GetSetAutomationItemInfo(trEnv, i, "D_POSITION", 0, false);
double AIlength = GetSetAutomationItemInfo(trEnv, i, "D_LENGTH", 0, false);;

if (mousePos >= AIpos && mousePos < AIpos + AIlength)
return true;
}
}
return false;
}

int BR_MouseInfo::IsMouseOverEnvelopeLineTrackLane (MediaTrack* track, int trackHeight, int trackOffset, list<TrackEnvelope*>& laneEnvs, int mouseDisplayX, int mouseY, double mousePos, double arrangeStart, double arrangeZoom, TrackEnvelope** trackEnvelope, int* pointUnderMouse)
{
/* laneEnv list should hold all track envelopes that have their own lane so *
Expand Down
1 change: 1 addition & 0 deletions Breeder/BR_MouseUtil.h
Expand Up @@ -159,6 +159,7 @@ class BR_MouseInfo
int IsMouseOverEnvelopeLine (BR_Envelope& envelope, int drawableEnvHeight, int yOffset, int mouseDisplayX, int mouseY, double mousePos, double arrangeStart, double arrangeZoom, int* pointUnderMouse);
int IsMouseOverEnvelopeLineTrackLane (MediaTrack* track, int trackHeight, int trackOffset, list<TrackEnvelope*>& laneEnvs, int mouseDisplayX, int mouseY, double mousePos, double arrangeStart, double arrangeZoom, TrackEnvelope** trackEnvelope, int* pointUnderMouse);
int IsMouseOverEnvelopeLineTake (MediaItem_Take* take, int takeHeight, int takeOffset, int mouseDisplayX, int mouseY, double mousePos, double arrangeStart, double arrangeZoom, TrackEnvelope** trackEnvelope, int* pointUnderMouse);
bool IsMouseOverAI(BR_Envelope& envelope, int drawableEnvHeight, int yOffset, int mouseDisplayX, int mouseY, double mousePos, double arrangeStart, double arrangeZoom);
int GetRulerLaneHeight (int rulerH, int lane);
int IsHwndMidiEditor (HWND hwnd, HWND* midiEditor, HWND* subView);
static bool SortEnvHeightsById (const pair<int,int>& left, const pair<int,int>& right);
Expand Down

0 comments on commit bf07281

Please sign in to comment.