Old 07-18-2018, 09:30 AM   #1
tompad
Human being with feelings
 
Join Date: Jan 2010
Location: Fjugesta, Sweden
Posts: 244
Default Do something while in time selection - LUA [SOLVED]

Ok, it's time again - I smack my head against wall again.

I am writing a Reascript there I want something to be done
while the selected envelope point is inside of time selection.

This time I have no clue about how to do this - any help is welcome!
(Have checked the API but cant find anything, probably searching for wrong thing)

Code:
Pseudocode:

While (selected_point is inside timeselection) do

reaper.ShowConsoleMsg("You are still inside time selection") 

else

reaper.ShowConsoleMsg("You are outside the time selection you naughty little boy!")
__________________
Mark4Celest: Frid (i ditt hjärta)
Eve & the Fisherman on Spotify

Last edited by tompad; 07-20-2018 at 09:36 AM.
tompad is offline   Reply With Quote
Old 07-18-2018, 09:37 AM   #2
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 2,017
Default

You can use reaper.defer to check whether the given point is in the time selection 30 times per second (more or less). You can find the selected point with GetEnvelopePointEx.

Code:
pointPos = 3.1416

function testPointPos()
  local startPos, endPos = reaper.GetSet_LoopTimeRange(false, false, 0, 0, false)
  
  if startPos <= pointPos and endPos >= pointPos then
    reaper.ShowConsoleMsg("inside!\n")
  else
    reaper.ShowConsolemsg("outside!\n")
  end

  reaper.defer(testPointPos) -- recheck later
end

testPointPos()
cfillion is offline   Reply With Quote
Old 07-19-2018, 04:58 AM   #3
tompad
Human being with feelings
 
Join Date: Jan 2010
Location: Fjugesta, Sweden
Posts: 244
Default

Quote:
Originally Posted by cfillion View Post
You can use reaper.defer to check whether the given point is in the time selection 30 times per second (more or less). You can find the selected point with GetEnvelopePointEx.
Great! Thanks Cfillion!
I guess the reaper.defer is only needed if I want to run my script
in the background? I tried with GetSet_LoopTimeRange and the if-statement
and it all worked well (no need to run script in background - yet).
__________________
Mark4Celest: Frid (i ditt hjärta)
Eve & the Fisherman on Spotify
tompad is offline   Reply With Quote
Old 07-19-2018, 06:59 AM   #4
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 2,017
Default

Quote:
Originally Posted by tompad View Post
I guess the reaper.defer is only needed if I want to run my script in the background?
Exactly. I thought this was what you wanted to do (check points while the user changes the time selection).
cfillion is offline   Reply With Quote
Old 07-19-2018, 07:34 AM   #5
tompad
Human being with feelings
 
Join Date: Jan 2010
Location: Fjugesta, Sweden
Posts: 244
Default

Quote:
Originally Posted by cfillion View Post
Exactly. I thought this was what you wanted to do (check points while the user changes the time selection).
No I only needed the "startPos, endPos = reaper.GetSet_LoopTimeRange"-part.
I searched and searched and searched the API with wrong search words....
sometime its hard to find the proper search words. ;-)

Thanks again - with your help I just finished my first Reascript!
Its an "hybrid" with both lua-code and native actions.
__________________
Mark4Celest: Frid (i ditt hjärta)
Eve & the Fisherman on Spotify
tompad is offline   Reply With Quote
Old 07-20-2018, 06:26 AM   #6
tompad
Human being with feelings
 
Join Date: Jan 2010
Location: Fjugesta, Sweden
Posts: 244
Default

Hi again!

I checked the "reaper.GetSet_LoopTimeRange(false, false, 0, 0, false)" in API list
and I dont get it - how can parameter 3 and 4 be 0??

Shouldn't it be the start and end of selection?

I know it works with 0 and 0, but why/how? It puzzle me....
__________________
Mark4Celest: Frid (i ditt hjärta)
Eve & the Fisherman on Spotify
tompad is offline   Reply With Quote
Old 07-20-2018, 06:34 AM   #7
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: The vast, frozen wasteland of western Canadia.
Posts: 5,164
Default

It's a quirk - the same API functions are exposed to Lua, EEL, and Python, so most of them are designed to work for all three. Not sure about Python, but EEL takes the "returned" values as function arguments (might just be for functions with multiple return values).

In Lua we can do:
Code:
a, b, c = getvalues()
but EEL would be:
Code:
getvalues(a, b, c);
In this case, since you're using Lua, it doesn't matter what you specify for those values. They just have to be there (mostly*), and have to be of the correct type (integer, boolean, string).

* Some of the API functions don't seem to care. GetTrackName expects a string, for instance, but works fine if you don't provide it. When in doubt, you can always try calling the function with an argument set to nil and see if it gives you an error.
__________________
Currently working away from home; don't expect timely responses from me.
Default 5.0 Nitpicky Edition / GUI tutorial for Lua / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate / ReaPack
Lokasenna is online now   Reply With Quote
Old 07-20-2018, 06:40 AM   #8
DarkStar
Human being with feelings
 
DarkStar's Avatar
 
Join Date: May 2006
Location: Surrey, UK
Posts: 17,339
Default

^^^
As the documentation is short, it would be clearer if it read:
Quote:
Lua: number start, number end = reaper.GetSet_LoopTimeRange(boolean isSet, boolean isLoop, 0, 0, boolean allowautoseek)
rather than
Quote:
Lua: number start, number end = reaper.GetSet_LoopTimeRange(boolean isSet, boolean isLoop, number start, number end, boolean allowautoseek)
__________________
DarkStar ... interesting, if true. Inspired by ...
DarkStar is offline   Reply With Quote
Old 07-20-2018, 06:44 AM   #9
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 2,017
Default

Quote:
Originally Posted by tompad View Post
how can parameter 3 and 4 be 0??
They are ignored because isSet=false (the first parameter). They would be used to modify the time selection if isSet was true.
cfillion is offline   Reply With Quote
Old 07-20-2018, 07:11 AM   #10
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: The vast, frozen wasteland of western Canadia.
Posts: 5,164
Default

Quote:
Originally Posted by DarkStar View Post
^^^
As the documentation is short, it would be clearer if it read:

rather than
There are a number of places where language-specific documentation would be helpful. Not holding my breath though.

This is Reaper - the forum IS the documentation.
__________________
Currently working away from home; don't expect timely responses from me.
Default 5.0 Nitpicky Edition / GUI tutorial for Lua / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate / ReaPack
Lokasenna is online now   Reply With Quote
Old 07-20-2018, 09:32 AM   #11
mespotine
Human being with feelings
 
Join Date: May 2017
Posts: 312
Default

Quote:
Originally Posted by Lokasenna View Post
This is Reaper - the forum IS the documentation.
I'll print that quote on a T-Shirt


@tompad
Could you elaborate much further, what you can do with the selected envelope-point?
Do you want it to be moveable or just
1) I click a point as selected,
2) I run the script
3) it writes into the console, whether the selected envelope-point is within time-selection or not

Another thing is: you can have multiple envelope-points selected at the same time, where some may be within the time-selection and some not. This could be a problem, as far as I understood your post...
mespotine is offline   Reply With Quote
Old 07-20-2018, 09:40 AM   #12
tompad
Human being with feelings
 
Join Date: Jan 2010
Location: Fjugesta, Sweden
Posts: 244
Default

Quote:
Originally Posted by cfillion View Post
They are ignored because isSet=false (the first parameter). They would be used to modify the time selection if isSet was true.
Ahaaaa... now I understand!

@cfillion and @Lokassena - thanks for all the help, must ask - are you programmers in every day work?
__________________
Mark4Celest: Frid (i ditt hjärta)
Eve & the Fisherman on Spotify
tompad is offline   Reply With Quote
Old 07-20-2018, 09:45 AM   #13
tompad
Human being with feelings
 
Join Date: Jan 2010
Location: Fjugesta, Sweden
Posts: 244
Default

Quote:
Originally Posted by mespotine View Post
I'll print that quote on a T-Shirt


@tompad
Could you elaborate much further, what you can do with the selected envelope-point?
Do you want it to be moveable or just
1) I click a point as selected,
2) I run the script
3) it writes into the console, whether the selected envelope-point is within time-selection or not

Another thing is: you can have multiple envelope-points selected at the same time, where some may be within the time-selection and some not. This could be a problem, as far as I understood your post...
Hi mespotine!

I was just doing a simple script that randomly was putting points in the volume envelope, and I wanted it to stop doing it outside the time selection. No fancy thing - just my first script built with actions and some lua-code.
__________________
Mark4Celest: Frid (i ditt hjärta)
Eve & the Fisherman on Spotify
tompad is offline   Reply With Quote
Old 07-20-2018, 10:12 AM   #14
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: The vast, frozen wasteland of western Canadia.
Posts: 5,164
Default

Quote:
Originally Posted by tompad View Post
Ahaaaa... now I understand!

@cfillion and @Lokassena - thanks for all the help, must ask - are you programmers in every day work?
I wish. Unemployed electrician.
__________________
Currently working away from home; don't expect timely responses from me.
Default 5.0 Nitpicky Edition / GUI tutorial for Lua / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate / ReaPack
Lokasenna is online now   Reply With Quote
Old 07-20-2018, 11:07 PM   #15
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 2,017
Default

Quote:
Originally Posted by tompad View Post
@cfillion and @Lokassena - thanks for all the help, must ask - are you programmers in every day work?
I'm not a programmer either.
cfillion is offline   Reply With Quote
Old 07-21-2018, 03:04 PM   #16
tompad
Human being with feelings
 
Join Date: Jan 2010
Location: Fjugesta, Sweden
Posts: 244
Default

@cfillion and @Lokassena

Are you sure? ;-) ....I mean, you both have made fantastic things
for Reaper (Reapack,GUI-library, Interactive Reascript, Radial Menu etc,etc)

Kudos to you!
__________________
Mark4Celest: Frid (i ditt hjärta)
Eve & the Fisherman on Spotify
tompad 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:53 AM.


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