Go Back   Cockos Incorporated Forums > REAPER Forums > ReaScript, JSFX, REAPER Plug-in Extensions, Developer Forum

Reply
 
Thread Tools Display Modes
Old 09-15-2018, 06:37 AM   #1
deeb
Human being with feelings
 
deeb's Avatar
 
Join Date: Feb 2017
Posts: 4,812
Default is there a way to know last clicked thing: MI, Envelope or AI?

i would like to have a shortcut that could do an action depending on the last clicked "thing" in project.
So if last clicked "thing" was MI do action A, if AI do Action B, if Envelope do action C.

is there a way to know?

Thank you!

Last edited by deeb; 09-15-2018 at 06:44 AM.
deeb is offline   Reply With Quote
Old 09-15-2018, 11:11 AM   #2
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,960
Default

Tracking this stuff in realtime.
This is how ReaPack/mpl_InteractiveToolbar works.
mpl is offline   Reply With Quote
Old 09-15-2018, 11:29 AM   #3
deeb
Human being with feelings
 
deeb's Avatar
 
Join Date: Feb 2017
Posts: 4,812
Default

ahh right! thanks! now that you told , yes makes sense! i didn't even remembered! : ) but i don't want it too happen in a GUI. I would like to apply an action based on which kind of thing was last selected.

my case example: arrow up shortcut:

if lastSelectedType=="Ai" doSomething()
else doSomethingElse()

Last edited by deeb; 09-15-2018 at 11:37 AM.
deeb is offline   Reply With Quote
Old 09-15-2018, 02:40 PM   #4
bFooz
Human being with feelings
 
Join Date: Jul 2010
Location: Slovakia
Posts: 2,588
Default

Just workarounds AFAIK. I miss this kind of feature as well, some kind of events.

Workaround could be that you would run a deferred master tracker script which would write the last clicked thing into the project with reaper.GetExtState( section, key ) and then the action itself would check that state and decide what to do.
bFooz is online now   Reply With Quote
Old 09-15-2018, 04:23 PM   #5
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

Well, your thread title has "last clicked", then you say:
Quote:
Originally Posted by deeb View Post
...based on which kind of thing was last selected.

my case example: arrow up shortcut:

if lastSelectedType=="Ai" doSomething()
else doSomethingElse()
so I'll mention that there are 3 "CursorContexts" (maybe a fourth would be "unknown") in the main section.

Track (panels) = 0
Item = 1
Envelope = 2
Unknown = -1

AI falls under envelope, more or less.

Code:
C: int GetCursorContext()

EEL: int GetCursorContext()

Lua: integer reaper.GetCursorContext()

Python: Int RPR_GetCursorContext()

return the current cursor context: 0 if track panels, 1 if items, 2 if envelopes, otherwise unknown
Code:
C: int GetCursorContext2(bool want_last_valid)

EEL: int GetCursorContext2(bool want_last_valid)

Lua: integer reaper.GetCursorContext2(boolean want_last_valid)

Python: Int RPR_GetCursorContext2(Boolean want_last_valid)

0 if track panels, 1 if items, 2 if envelopes, otherwise unknown (unlikely when want_last_valid is true)
I notice what seems like a bug. Double clicking Empty TCP area to insert track does not change context to 0, even though
Edit: Cut items/tracks/envelope points (depending on focus) ignoring time selection
will cut the track.

A lot of actions, and scripts especially, will not change it either.

A not necessarily prime example of GetCursorContext2 in use:
https://forum.cockos.com/showpost.ph...51&postcount=2

There's a function to set cursor context too.

I suppose there could be improvements to the system. Maybe some additional functions, like GetLastClickedItem(). Maybe developers could introduce "Skip next action if context = track panels" for custom action building or something like that.
FnA is offline   Reply With Quote
Old 09-15-2018, 11:57 PM   #6
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 3,960
Default

Quote:
Originally Posted by FnA View Post
Well, your thread title has "last clicked", then you say:

so I'll mention that there are 3 "CursorContexts" (maybe a fourth would be "unknown") in the main section.

Track (panels) = 0
Item = 1
Envelope = 2
Unknown = -1

AI falls under envelope, more or less.
in case he needs tracking "last clicked" means "last selected"
So checking context slightly useless and limited here. Double clicking Empty TCP to create new track in InteractiveToolbar reasonably changes context to track.

2OP:In deferred script check different stuff for being selected after changing ProjectStateChangeCount(), it also works for AI (I didn`t implement it yet in InteractiveToolbar).

like


Code:
function runloop()
   PCC = ProjectStateChangeCount
   if not last_PCC or (last_PCC and last_PCC ~= PCC ) then -- trigger update
    sometable = count_of_ALL_current_selected_objects
    if [somevalue] in [sometable] changed then do something with parent context end      
   end
   last_sometable = sometable
   last_PCC = PCC
end
mpl is offline   Reply With Quote
Old 09-16-2018, 08:55 AM   #7
deeb
Human being with feelings
 
deeb's Avatar
 
Join Date: Feb 2017
Posts: 4,812
Default

Quote:
Originally Posted by FnA View Post
...
thank you FNA! it seems this is exactly what i was looking for! except: any logical reason for AI falls under envelope(2) just like an envelope point? is it supposed to?

Quote:
Originally Posted by FnA View Post
I notice what seems like a bug. Double clicking Empty TCP area to insert track does not change context to 0
I confirm this here
Quote:
Originally Posted by FnA View Post
I suppose there could be improvements to the system. Maybe some additional functions, like GetLastClickedItem(). Maybe developers could introduce "Skip next action if context = track panels" for custom action building or something like that.
for my case since i will do by scripting i am good this way, i guess that would be cool for custom actions. But there some more thing to take in consideration like: which other types are selected in order to make some decisions based on this.
deeb is offline   Reply With Quote
Old 09-16-2018, 09:02 AM   #8
deeb
Human being with feelings
 
deeb's Avatar
 
Join Date: Feb 2017
Posts: 4,812
Default

Quote:
Originally Posted by mpl View Post
in case he needs tracking "last clicked" means "last selected"
So checking context slightly useless and limited here. Double clicking Empty TCP to create new track in InteractiveToolbar reasonably changes context to track.
i am not sure what you mean! it gives-me last clicked or selected every time


Quote:
Originally Posted by mpl View Post
2OP:In deferred script check different stuff for being selected after changing ProjectStateChangeCount(), it also works for AI (I didn`t implement it yet in InteractiveToolbar).

like
[CODE...[/CODE]
will keep this as a reference! By context seems simpler except AI and Envelope can't be distinguished. I will have to test!
Thanks a lot!
deeb is offline   Reply With Quote
Old 09-16-2018, 11:42 AM   #9
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

I think the other guys are thinking about a more advanced/comprehensive system, but I figured you might like to know about the simple function, if you didn't already. Maybe it can only give a fraction of what you want it for. Someone else can make FRs for the additional things. I don't intend on doing so myself. I think it's primarily the mouse and maybe a few other actions that will set the context integer. For example, "Select and move to next item" will not change it from 0 to 1. Neither will "Select all items in track".
FnA is offline   Reply With Quote
Old 09-16-2018, 04:27 PM   #10
deeb
Human being with feelings
 
deeb's Avatar
 
Join Date: Feb 2017
Posts: 4,812
Default

Quote:
Originally Posted by FnA View Post
I think the other guys are thinking about a more advanced/comprehensive system, but I figured you might like to know about the simple function, if you didn't already. Maybe it can only give a fraction of what you want it for.
yep! thanks both useful as i didn't know any!

Quote:
Originally Posted by FnA View Post
Someone else can make FRs for the additional things. I don't intend on doing so myself. I think it's primarily the mouse and maybe a few other actions that will set the context integer. For example, "Select and move to next item" will not change it from 0 to 1. Neither will "Select all items in track".
i tested in others actions i tend to use and they don't work either.
Item: Select all items in current time selection
Item: Select all items on selected tracks in current time selection

If the 4 actions talked could update the context, scripts probably would automatically update context too, since probably they are based on this actions.

And The same logic should be applied to AI, and a distinguished reaper.GetCursorContext2() from Envelopes.

Maybe it's a lot of things : / but i'll probably request
deeb is offline   Reply With Quote
Old 09-16-2018, 06:30 PM   #11
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

Something strange. There is

SWS/BR: Focus tracks
SWS/BR: Focus arrange

and
Code:
C: void SetCursorContext(int mode, TrackEnvelope* envInOptional)

EEL: SetCursorContext(int mode, TrackEnvelope envIn)

Lua: reaper.SetCursorContext(integer mode, TrackEnvelope envIn)

Python: RPR_SetCursorContext(Int mode, TrackEnvelope envInOptional)

You must use this to change the focus programmatically. mode=0 to focus track panels, 1 to focus the arrange window, 2 to focus the arrange window and select env (or env==NULL to clear the current track/take envelope selection)
but using these (track action or 0 in script function) does not appear to set cursor context integer to 0, as it will be returned by GetCursorContext(). BUT, Control+A (Select all items/tracks/envelope points (depending on focus)) will select all tracks after using the actions or SetCursorContext(0,nil).

This script returns 1 after using those, even after Control+A to select all tracks. Returns 0 after clicking the track or it's buttons with mouse. (maybe other things I didn't look for)

Code:
gcc = reaper.GetCursorContext()
reaper.MB(tostring(gcc),"bla",0)
FnA is offline   Reply With Quote
Old 09-17-2018, 07:29 PM   #12
deeb
Human being with feelings
 
deeb's Avatar
 
Join Date: Feb 2017
Posts: 4,812
Default

maybe there's a chance that everything (.. or a big part) could be solved if setContext was updating what getContext gets?
deeb is offline   Reply With Quote
Old 09-18-2018, 03:48 AM   #13
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

I think it’s a bug and will lead to errors. I think it should be able to return 0 if tracks are focused. Cockos has used this somewhat obscure term “cursor context”, but I think the “depending on focus” type action is the most basic thing that people want from a function like this, and I don’t think anything else is available. ( Juliansader is making ReaScript functions that can retrieve more advanced window focus info.)
FnA is offline   Reply With Quote
Old 09-19-2018, 05:45 PM   #14
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

Maybe there is some technical reason for GetCursorContext() and GetCursorContext2(false) to return 1 unless the mouse is used to focus tracks? GetCursorContext2(true) seems to behave more logically.

Was going to report bug...

Code:
-- GetCursorContext bug report test script 5-95.lua

--reaper.SetCursorContext(0,nil)
reaper.Main_OnCommand(reaper.NamedCommandLookup("_BR_FOCUS_TRACKS"),0)
reaper.Main_OnCommand(40035,0) -- Select all items/tracks/envelope points (depending on focus)
gcc = reaper.GetCursorContext2(true)
reaper.MB(tostring(gcc),"Value returned by GetCursorContext2",0)
FnA is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 10:58 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.