|
|
|
08-12-2019, 03:43 PM
|
#1
|
Human being with feelings
Join Date: Jun 2018
Posts: 375
|
Is there a script that can tell Reaper if a time selection is active or not?
I'm not sure if this makes any sense but basically I'm looking for a way to tell REAPER if a time selection is ON or OFF, like a toggle state. It could be useful in some cycle actions with the "IF" statements, so for example if a time selection is 'ON' then the action duplicates the selected area, else it duplicates the selected item (or whatever).
Thanks!
|
|
|
08-13-2019, 08:54 AM
|
#2
|
Human being with feelings
Join Date: Mar 2013
Posts: 5,844
|
Here's an example for checking the time selection state via LUA script:
Code:
starttime, endtime = reaper.GetSet_LoopTimeRange2(0, false, false, 0, 0, false)
if starttime == endtime then
reaper.ShowMessageBox("No Time selection", "Info", 0)
else
reaper.ShowMessageBox("Time selection exists", "Info", 0)
end
And another version which toggles the state of the action:
Code:
local self = ({reaper.get_action_context()})[4]
starttime, endtime = reaper.GetSet_LoopTimeRange2(0, false, false, 0, 0, false)
if starttime == endtime then
reaper.SetToggleCommandState(0, self, 0)
else
reaper.SetToggleCommandState(0, self, 1)
end
But I can't remember right now if it's also possible to use such a script as IF condition in a Cycle Action.
|
|
|
08-13-2019, 08:58 AM
|
#3
|
Human being with feelings
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
|
Cycle actions can check the state of other actions that are registered as a toggle (i.e. the ones that show On/Off in the action list). I think you could have the cycle action run a script prior to the If, the script would update its own state in the list based on the time selection as above, and then the cycle action could check it for the If.
However, I've never used cycle actions or the API command above so I'm not sure exactly how to do it.
|
|
|
08-13-2019, 10:55 AM
|
#4
|
Human being with feelings
Join Date: Jun 2018
Posts: 375
|
Quote:
Originally Posted by solger
Here's an example for checking the time selection state via LUA script:
Code:
starttime, endtime = reaper.GetSet_LoopTimeRange2(0, false, false, 0, 0, false)
if starttime == endtime then
reaper.ShowMessageBox("No Time selection", "Info", 0)
else
reaper.ShowMessageBox("Time selection exists", "Info", 0)
end
And another version which toggles the state of the action:
Code:
local self = ({reaper.get_action_context()})[4]
starttime, endtime = reaper.GetSet_LoopTimeRange2(0, false, false, 0, 0, false)
if starttime == endtime then
reaper.SetToggleCommandState(0, self, 0)
else
reaper.SetToggleCommandState(0, self, 1)
end
But I can't remember right now if it's also possible to use such a script as IF condition in a Cycle Action.
|
Nice, so it is possible! Now I just need to figure out how to implement it in to cycle actions since it seems like they can't register the toggle states of scripts.
|
|
|
09-16-2020, 07:19 AM
|
#5
|
Human being with feelings
Join Date: Sep 2015
Location: Paris
Posts: 544
|
Hello !
Have you managed to make the script work as a toggle ? Right now I'm not sure how to use this script.
|
|
|
09-16-2020, 07:33 AM
|
#6
|
Human being with feelings
Join Date: Mar 2013
Posts: 5,844
|
Quote:
Originally Posted by Loulou92
Hello !
Have you managed to make the script work as a toggle ? Right now I'm not sure how to use this script.
|
Hi,
can you post more details about what you're trying to do?
|
|
|
09-16-2020, 08:18 AM
|
#7
|
Human being with feelings
Join Date: Sep 2015
Location: Paris
Posts: 544
|
Hello ! I have a cycle action that works great, but if by mistake I launch it without a time selection, it deletes many items (it's supposed to work with a time selection, but sometimes I forget). I reviewed the action in detail, and there is no way around this, even with convoluted techniques using what's available in the Reaper action list, SWS and scripts.
The only way to avoid the action to be destructive without a time selection would be to have a check at the beginning of the cycle action :
If the next action is on :
"is there a time selection.lua"
it proceeds and do all the rest of the action
Else
No-op
End of conditional
With the script as is, sometimes the action is executed even if there is no time sel, it's not realiable, I don't know why.
Thanks !
xxxxxx
Edit : I'll add that usually, such problems (misbehaving custom actions that have side effects under some circumstances) are easily solved by a Ctrlr + z. The thing is... The deleted items are deleted on hidden tracks. So basically the damage is "invisible", and then this little problem can be a ticking bomb if I don't realize the action misbehaved and I go on with the work. This is why I try to find a way to have time selection as a toggle, to avoid catastrophy on my hidden tracks.
Last edited by Loulou92; 09-16-2020 at 09:07 AM.
|
|
|
09-17-2020, 04:45 PM
|
#8
|
Human being with feelings
Join Date: Sep 2015
Location: Paris
Posts: 544
|
Well I guess I'll have to do without it then .
|
|
|
09-18-2020, 01:56 PM
|
#9
|
Human being with feelings
Join Date: Jan 2014
Posts: 923
|
scripts can run actions from action list. just copy command ID from action list and paste to script.
Code:
-- lua script
-- run action from action list (if time selection exist)
-- copy command ID from action list
local sws_cycle_action_id = "_S&M_CYCLACTION_5" -- example
local command_id = reaper.NamedCommandLookup(sws_cycle_action_id)
if command_id == 0 then reaper.ShowConsoleMsg("Error: action does not exist.. ") return end -- exit
local time_sel_start, time_sel_end = reaper.GetSet_LoopTimeRange(false, false, 0, 0, false)
if time_sel_start ~= time_sel_end then
-- if time selection exist run action
reaper.Main_OnCommand(command_id, 0)
else
-- do nothing..
end
Last edited by Embass; 09-18-2020 at 02:53 PM.
|
|
|
09-18-2020, 02:48 PM
|
#10
|
Human being with feelings
Join Date: Sep 2015
Location: Paris
Posts: 544
|
That's super badass !!! I'm testing in a few minutes.
|
|
|
09-18-2020, 02:55 PM
|
#11
|
Human being with feelings
Join Date: Sep 2015
Location: Paris
Posts: 544
|
Ok it works perfectly. Thanks Embass !!
Even if it's unrelated to what's being discussed here, I wonder : is it possible to have other conditions ?
example :
do the action only if an item is selected
do the action only if track is in group x
Anyway, that's out of curiosity, and potential use also I confess, but thanks anyway for the script shared . Will be used a lot !
Last edited by Loulou92; 09-18-2020 at 03:02 PM.
|
|
|
09-22-2020, 10:16 AM
|
#12
|
Human being with feelings
Join Date: Mar 2013
Posts: 5,844
|
Quote:
Originally Posted by Loulou92
Even if it's unrelated to what's being discussed here, I wonder : is it possible to have other conditions ?
example :
do the action only if an item is selected
|
Have a look at the GetSelectedMediaItem function for this: https://www.extremraym.com/cloud/rea...ectedMediaItem
Code:
if reaper.GetSelectedMediaItem(0,0) then
-- an item is selected
...
else
-- no item selected
...
end
Quote:
Originally Posted by Loulou92
do the action only if track is in group x
|
Not sure, but maybe it's possible to get the group via the GetSetTrackGroupMembership function:
Or via the GROUP_FLAGS parameter of the GetTrackStateChunk function: You might also find some hints when looking at the code of the me2beats_Select all tracks in selected track groups script mentioned in this thread: https://forum.cockos.com/showthread.php?t=194910
Last edited by solger; 09-22-2020 at 11:06 AM.
|
|
|
09-23-2020, 08:59 AM
|
#13
|
Human being with feelings
Join Date: Sep 2015
Location: Paris
Posts: 544
|
Ok, thank you very much !! I'll have a look this evening at the links you posted & hopefully it's going to work out fine !!!
|
|
|
09-24-2020, 01:02 PM
|
#14
|
Human being with feelings
Join Date: Sep 2015
Location: Paris
Posts: 544
|
As of now I have sucesfully created the script that checks if an item is selected before doing an action, it's implemented in many of my custom action now, super cool ! COuld you please tell me what I should put in the code to make sure that the action works only if ONE item is selected, not 0 or not 2 and more ?
|
|
|
09-25-2020, 10:58 AM
|
#15
|
Human being with feelings
Join Date: Mar 2013
Posts: 5,844
|
Quote:
Originally Posted by Loulou92
COuld you please tell me what I should put in the code to make sure that the action works only if ONE item is selected, not 0 or not 2 and more ?
|
Should be possible with the CountSelectedMediaItems function:
Code:
if reaper.CountSelectedMediaItems(0) == 1 then
-- only one item is selected
...
else
-- no or more than one item(s) selected
...
end
Another example (if you want to do different things depending on how many items are selected):
Code:
local selectedItemCount = reaper.CountSelectedMediaItems(0)
if selectedItemCount == 1 then
-- only one item is selected
...
elseif selectedItemCount == 2 then
-- two items are selected
...
else
-- no or more than two item(s) selected
end
And so on ...
Last edited by solger; 09-25-2020 at 11:08 AM.
|
|
|
09-25-2020, 11:16 AM
|
#16
|
Human being with feelings
Join Date: Sep 2015
Location: Paris
Posts: 544
|
Ok Solger, thank you, I'll try all these leads this evening. I should start lua or Python, potential seems infinite compared to the logical operations available in the SWS extension...
xxxx
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 02:07 AM.
|