Old 07-22-2019, 09:39 AM   #1
foxAsteria
Human being with feelings
 
foxAsteria's Avatar
 
Join Date: Dec 2009
Location: Oblivion
Posts: 10,271
Default Can someone smart improve these simple scripts?

Hi. Once upon a time I fancied myself clever enough to learn script. I needed two scripts to move the edit cursor to and view the beginning and end of the time selection but without moving the play cursor. Here's what I got:

Code:
GetSet_LoopTimeRange(0, 0, TimeStart, TimeEnd, 0);
TimeStart!=TimeEnd ? SetEditCurPos(TimeStart, 0, 0);
Undo_OnStateChange("Edit Cursor to start of Time Selection");
Code:
GetSet_LoopTimeRange(0, 0, TimeStart, TimeEnd, 0);
TimeStart != TimeEnd ? SetEditCurPos(TimeEnd, 0, 0); 
Undo_OnStateChange("Edit Cursor to end of Time Selection");
So the help I'm requesting is to make sure these scripts aren't storing some hidden cursor position when I hit pause. If I hit pause and then use these scripts, recordings start from the pause position instead of the edit cursor position. It would be great if they could be made to also move the view to the start/end at the same time so I don't have to make custom actions to get the complete behavior.

Thanks!
__________________
foxyyymusic

Last edited by foxAsteria; 07-24-2019 at 09:11 AM.
foxAsteria is offline   Reply With Quote
Old 07-22-2019, 01:53 PM   #2
Nostrap
Human being with feelings
 
Join Date: Dec 2017
Posts: 179
Default

There are issues with SetEditCurPos

this is in lua, but try the equivalent of:

cur_pos = reaper.GetCursorPosition()
reaper.MoveEditCursor(TimeStart - cur_pos, false )
Nostrap is offline   Reply With Quote
Old 07-23-2019, 09:31 AM   #3
foxAsteria
Human being with feelings
 
foxAsteria's Avatar
 
Join Date: Dec 2009
Location: Oblivion
Posts: 10,271
Default

So it's not possible atm? Thanks for the tip, but my script skills have fallen to decay.

I'd have no idea how to translate this to lua, but was rather hoping someone capable would have an easy time to make them work properly....
__________________
foxyyymusic
foxAsteria is offline   Reply With Quote
Old 07-23-2019, 09:55 AM   #4
Nostrap
Human being with feelings
 
Join Date: Dec 2017
Posts: 179
Default

reaper.Undo_BeginBlock()
startOut, endOut = reaper.GetSet_LoopTimeRange(false, false, 0, 0, false)
if startOut ~= endOut then
cur_pos = reaper.GetCursorPosition()
reaper.MoveEditCursor(startOut - cur_pos, false)
end
reaper.Undo_EndBlock("Move edit cursor to start of time selection",0)



reaper.Undo_BeginBlock()
startOut, endOut = reaper.GetSet_LoopTimeRange(false, false, 0, 0, false)
if startOut ~= endOut then
cur_pos = reaper.GetCursorPosition()
reaper.MoveEditCursor(endOut - cur_pos, false)
end
reaper.Undo_EndBlock("Move edit cursor to end of time selection",0)
Nostrap is offline   Reply With Quote
Old 07-23-2019, 10:02 AM   #5
foxAsteria
Human being with feelings
 
foxAsteria's Avatar
 
Join Date: Dec 2009
Location: Oblivion
Posts: 10,271
Default

Seems to be working. Will check it out more thoroughly during a recording session later, but thank you kindly, my friend! This should cut down on a lot of false starts...

EDIT: D'oh, I spoke too soon. Problem still exists, but I think I see how to reproduce: Play, pause, move edit cursor with script, record (recording starts from pause position.

Maybe I just need to make a custom record action to get around this. Is there something to ensure the cursor position gets updated properly? Reaper seems to think it's somewhere it isn't when the cursor is moved in this way.
__________________
foxyyymusic

Last edited by foxAsteria; 07-23-2019 at 10:08 AM.
foxAsteria is offline   Reply With Quote
Old 07-23-2019, 11:25 AM   #6
jrengmusic
Human being with feelings
 
jrengmusic's Avatar
 
Join Date: Jun 2015
Location: Indonesia Raya
Posts: 684
Default

Quote:
Originally Posted by foxAsteria View Post
Problem still exists, but I think I see how to reproduce: Play, pause, move edit cursor with script, record (recording starts from pause position.
What if you add Transport : Stop action into your script before moving the edit cursor?
__________________
JRENG! | M E T R I C
jrengmusic is offline   Reply With Quote
Old 07-23-2019, 03:02 PM   #7
foxAsteria
Human being with feelings
 
foxAsteria's Avatar
 
Join Date: Dec 2009
Location: Oblivion
Posts: 10,271
Default

Quote:
Originally Posted by jrengmusic View Post
What if you add Transport : Stop action into your script before moving the edit cursor?
Yea seems like it would work and that I probably should have thought of that. You know how to write it in lua?
__________________
foxyyymusic
foxAsteria is offline   Reply With Quote
Old 07-23-2019, 05:08 PM   #8
jrengmusic
Human being with feelings
 
jrengmusic's Avatar
 
Join Date: Jun 2015
Location: Indonesia Raya
Posts: 684
Default LUA

PHP Code:
reaper.Main_OnCommand(10160) -- TransportStop
reaper
.Undo_BeginBlock()
startOutendOut reaper.GetSet_LoopTimeRange(falsefalse00false)
if 
startOut ~= endOut then
cur_pos 
reaper.GetCursorPosition()
reaper.MoveEditCursor(startOut cur_posfalse)
end
reaper
.Undo_EndBlock("Move edit cursor to start of time selection",0

PHP Code:
reaper.Main_OnCommand(10160) -- TransportStop
reaper
.Undo_BeginBlock()
startOutendOut reaper.GetSet_LoopTimeRange(falsefalse00false)
if 
startOut ~= endOut then
cur_pos 
reaper.GetCursorPosition()
reaper.MoveEditCursor(endOut cur_posfalse)
end
reaper
.Undo_EndBlock("Move edit cursor to end of time selection",0
__________________
JRENG! | M E T R I C
jrengmusic is offline   Reply With Quote
Old 07-23-2019, 05:36 PM   #9
foxAsteria
Human being with feelings
 
foxAsteria's Avatar
 
Join Date: Dec 2009
Location: Oblivion
Posts: 10,271
Default

Arrghh, I'm such a dingbat. Thanks for doing that, but I'd somehow forgotten my whole purpose to these scripts was to be able to move the view and the edit cursor quickly to the start and end of time selection without disturbing the play cursor; 'go to' actions do interrupt playback and stop definitely does. Sorry, I wasn't thinking clearly...
__________________
foxyyymusic
foxAsteria is offline   Reply With Quote
Old 07-24-2019, 09:12 AM   #10
foxAsteria
Human being with feelings
 
foxAsteria's Avatar
 
Join Date: Dec 2009
Location: Oblivion
Posts: 10,271
Default

OP edited for clarity. Thanks for any help!
__________________
foxyyymusic
foxAsteria is offline   Reply With Quote
Old 07-25-2019, 01:34 PM   #11
foxAsteria
Human being with feelings
 
foxAsteria's Avatar
 
Join Date: Dec 2009
Location: Oblivion
Posts: 10,271
Default

Hi guys, so it's just not possible to move edit cursor via scripts\actions without interrupting playback then?
__________________
foxyyymusic
foxAsteria is offline   Reply With Quote
Old 07-25-2019, 08:29 PM   #12
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

But that's not really the problem right? (In other words it IS possible, at least, to move the cursor) You were having a problem with recording starting at the last play position where Pause was hit? This appears to me to not be a problem with scripts per se, because you can do the same by Pausing, then clicking somewhere else in arrange, then hitting Record. Is that the only problem?

Maybe you can get around it with a cycle action that does -- if Pause then Stop.

It seems that this variation on your script gets around the problem in a way too, by "seeking" when transport is paused.
Code:
// goto start of TS.eel

GetSet_LoopTimeRange(0, 0, TimeStart, TimeEnd, 0);
TimeStart!=TimeEnd ? (
  GetPlayState() & 2 == 2 ? (  
    SetEditCurPos(TimeStart, 1, 1);
  ):(
    SetEditCurPos(TimeStart, 1, 0);  
  );
);

function NoUndo()(abs(0));
defer ("NoUndo()");
IDK. It does seem possible you might find some other issue depending on all the various ways you might move the cursor.
FnA is offline   Reply With Quote
Old 07-26-2019, 02:43 PM   #13
foxAsteria
Human being with feelings
 
foxAsteria's Avatar
 
Join Date: Dec 2009
Location: Oblivion
Posts: 10,271
Default Clarity is elusive...

Hmm, yea I dunno why I'm struggling to explain this clearly...

So, often I'll have a loop going and I'll need to see the beginning or end, but the normal actions to go to time selection move the playhead. These actions work for that case, but when I'm recording, I'll often stop playback with pause, move the edit cursor and then hit record, it doesn't start at the edit cursor.

Adding stop anywhere I don't think is gonna work. I could add a stop to the record action first, but this is not always desired because sometimes I want recording to start immediately at the play position.

So pretty much, I was just hoping to get these scripts to work around the problem with pause. If I move the edit cursor after pause using these scripts, it doesn't update the position of the last pause.

That would cover all my use cases, 99% sure.

Thanks for all the assistance!
__________________
foxyyymusic
foxAsteria is offline   Reply With Quote
Old 07-26-2019, 06:14 PM   #14
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

Quote:
Originally Posted by foxAsteria View Post
So, often I'll have a loop going and I'll need to see the beginning or end, but the normal actions to go to time selection move the playhead.
I think that’s the same thing as “seeking” when you click somewhere, if you have that pref enabled. The script function SetEditCurPos’s third parameter is to seek or not from the new edit cursor position. I set it so it would seek if the transport pause button was engaged/lit up, and to move without seeking otherwise.

Quote:
These actions work for that case, but when I'm recording, I'll often stop playback with pause, move the edit cursor and then hit record, it doesn't start at the edit cursor.



Adding stop anywhere I don't think is gonna work. I could add a stop to the record action first, but this is not always desired because sometimes I want recording to start immediately at the play position.
That’s why I suggest making stop dependent on the state of the pause button as well.




It’s probably possible to make scroll to start of time selection without moving cursor if that was desired.
FnA is offline   Reply With Quote
Old 07-26-2019, 06:27 PM   #15
foxAsteria
Human being with feelings
 
foxAsteria's Avatar
 
Join Date: Dec 2009
Location: Oblivion
Posts: 10,271
Default

Man, I can't believe how hard it is for me to understand exactly what's going on. I think I just have a mental block about script because my mind blanks out when I try to grasp it. Thanks for bearing with me. Ok lemme test it out.

EDIT: Ok, you're a pro. That seems to be working, I don't know why I didn't try it before. I'll modify my stop action as well and then this problem can finally leave me be! Thank you FnA!
__________________
foxyyymusic

Last edited by foxAsteria; 07-26-2019 at 06:44 PM.
foxAsteria is offline   Reply With Quote
Old 07-26-2019, 06:41 PM   #16
FnA
Human being with feelings
 
FnA's Avatar
 
Join Date: Jun 2012
Posts: 2,173
Default

Quote:
Originally Posted by foxAsteria View Post
it doesn't update the position of the last pause.
I’m not aware of any possibility to do that other than the things we are all trying so far. There is a function called GetPlayPosition that has a different value than edit cursor sometimes even when not playing. Some people have requested moving the playead via script but I believe they were told no basically if they were told anything at all.



Edit.
Quote:
Originally Posted by foxAsteria View Post
I'll modify my stop action as well
I was thinking you might make that little cycle action part of your record action but I don’t know for sure if that will be all good...

Last edited by FnA; 07-26-2019 at 06:51 PM.
FnA is offline   Reply With Quote
Old 07-26-2019, 07:41 PM   #17
foxAsteria
Human being with feelings
 
foxAsteria's Avatar
 
Join Date: Dec 2009
Location: Oblivion
Posts: 10,271
Default

It's funny, I think I started this script in eel and then got some help and it became lua, but now it's back to eel. And I still can hardly read any script...
__________________
foxyyymusic

Last edited by foxAsteria; 07-26-2019 at 09:09 PM.
foxAsteria is offline   Reply With Quote
Old 07-26-2019, 09:31 PM   #18
foxAsteria
Human being with feelings
 
foxAsteria's Avatar
 
Join Date: Dec 2009
Location: Oblivion
Posts: 10,271
Default

Quote:
Originally Posted by FnA View Post
I was thinking you might make that little cycle action part of your record action but I don’t know for sure if that will be all good...
Heheh, yea that's actually what I meant and it totally works. Man, my brain's so jumbled lately.
__________________
foxyyymusic
foxAsteria 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 09:30 PM.


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