Old 12-13-2023, 11:34 AM   #1
More Sound
Human being with feelings
 
More Sound's Avatar
 
Join Date: Apr 2021
Location: Syracuse, NY
Posts: 103
Default Last selected track or item?

Hey hey,

I'm looking to find whether a track OR item was last touched via ReaScript/Lua.

There are ways to find last touched track or last touched item, but that's not what I need. I want to find the last context that was interacted with - either track or item.

I have a number of script concepts that I'd love to roll out but I'm waiting on this ability. One example is a script that will either add items to a group OR tracks to a group depending on what was selected last.

I'd rather not use a deferred script for this, I'd like a tidy solution.

Am I overthinking this? Is there a more elegant way to accomplish what I want?

As always, thanks in advance..
__________________
Jason "Jocko" Randall
More Sound Recording Studio
Syracuse, NY
More Sound is offline   Reply With Quote
Old 12-13-2023, 12:54 PM   #2
Buy One
Human being with feelings
 
Buy One's Avatar
 
Join Date: Sep 2019
Posts: 1,134
Default

Aren't the functions GetCursorContext() and GetCursorContext2 suitable for your use case?
__________________
https://github.com/Buy-One/REAPER-scripts (175)
REAPER is a DAW whose user guide file is larger than its installation file
Buy One is offline   Reply With Quote
Old 12-13-2023, 01:00 PM   #3
More Sound
Human being with feelings
 
More Sound's Avatar
 
Join Date: Apr 2021
Location: Syracuse, NY
Posts: 103
Default

It's a decent workaround, but is prone to error - if the user moves the mouse a little bit off the TCP area it's going to return the wrong data.
__________________
Jason "Jocko" Randall
More Sound Recording Studio
Syracuse, NY
More Sound is offline   Reply With Quote
Old 12-13-2023, 01:22 PM   #4
Buy One
Human being with feelings
 
Buy One's Avatar
 
Join Date: Sep 2019
Posts: 1,134
Default

Using a script a user does this with a certain purpose, so if they want to add an object to a group they will have to point out that object to the script, unless it's supposed to be added to a group without user direct involvement.
__________________
https://github.com/Buy-One/REAPER-scripts (175)
REAPER is a DAW whose user guide file is larger than its installation file
Buy One is offline   Reply With Quote
Old 12-13-2023, 02:41 PM   #5
More Sound
Human being with feelings
 
More Sound's Avatar
 
Join Date: Apr 2021
Location: Syracuse, NY
Posts: 103
Default

Let me explain another way.

Take action #40035 - "Select all items/tracks/envelope points (depending on focus)"

This action is great. If I've clicked on a track last, it selects all tracks. If I've clicked on an item last, it selects all items. It does not require my mouse to be in any specific position. It works by last selection.

This is what I want to do, except within my script.

Thoughts?
__________________
Jason "Jocko" Randall
More Sound Recording Studio
Syracuse, NY
More Sound is offline   Reply With Quote
Old 12-14-2023, 03:28 AM   #6
Buy One
Human being with feelings
 
Buy One's Avatar
 
Join Date: Sep 2019
Posts: 1,134
Default

OK, i guess this action can be used to suss out the last touched object.

The function or a series of functions to do so will include

1. Storing all selected objects of the type which the action is able to detect.
2. Deselecting all such objects.
3. Running the action.
4. Checking which of the deselected objects got selected and storing these data.
5. Restoring the original selection.
6. Returning the stored data.

The only PITA is writing the routine for storing and restoring envelope point selection which though tedious is still doable.

UPD: Actually the functions GetCursorContext return the last mouse click context regardless of the current mouse cursor position.
So the only context which needs validation with the action is item because they return 1 as long as Arrange was last clicked and not necessarily an item.
__________________
https://github.com/Buy-One/REAPER-scripts (175)
REAPER is a DAW whose user guide file is larger than its installation file

Last edited by Buy One; 12-14-2023 at 04:38 AM.
Buy One is offline   Reply With Quote
Old 12-16-2023, 10:40 AM   #7
More Sound
Human being with feelings
 
More Sound's Avatar
 
Join Date: Apr 2021
Location: Syracuse, NY
Posts: 103
Default

Thank you so much. I really appreciate you putting your mind to this. I'm working on some scripts now!
__________________
Jason "Jocko" Randall
More Sound Recording Studio
Syracuse, NY
More Sound 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 06:03 PM.


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