Old 11-18-2016, 07:14 PM   #1
Hypex
Human being with feelings
 
Join Date: Mar 2015
Location: Australia
Posts: 214
Default Trying to get my head around SetTakeStretchMarker()

Hi guys. All right. I've been experimenting with SetTakeStretchMarker() and just can't get my head around it. I've looked on the forums here and can't see much info at all so it must be of those inner circle things. Known only to those with the hidden secret knowledge if the Reaper API. :-D

I read about some confusion regarding srcposInOptional. At first I thought it was a time position but from what I read it looks like a sample position from the media item. But I'm unsure on that either. It all seems a bit vague.

So all I want to do is use it to mark a point in the timeline and have it stretched to another point in the timeline. For example if a section of my item is off the grid I want to stretch it to fit in the grid. That is if selecting a whole measure to have the whole measure stretched to fit.

I've managed to do what I want in a script by splitting an item up into measures, then changing playback rate, length and position to match it to the grid. But I want to duplicate the process using stretch markers. By placing stretch markers at certain points on the timeline and stretching them to fit the grid.

Say I have the cursor on the item at the point I wish to stretch. And I know the time position I want to stretch it too. How do I figure out what to give to SetTakeStretchMarker() from these two time positions?

All I've ended up doing is adding weird stretch markers in Reaper that seem to clear the waveform, start on the left and have rates like -6. When it should be faster. Then Reaper goes funny and seems to lock up if I try and play it! :-D

I used GetTakeStretchMarker() to see why and srcposInOptional just looks confusing. Perhaps I misunderstand what SetTakeStretchMarker() is meant to do. Given I have time positions in my head.

I'm thinking I will just add a stretch marker to my start point. Then use GetTakeStretchMarker() to find the source position and move it to my end point. I would rather not move it when it should be added to where it is meant to be. But this looks like the simplest way unless I can extract srcposIn from a Take/Item.
Hypex is offline   Reply With Quote
Old 11-19-2016, 05:26 AM   #2
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 6,927
Default

Quote:
At first I thought it was a time position but from what I read it looks like a sample position from the media item.
You were close, it is time position from the source media, doesn't consider REAPER item section, or take rate change.

Here is a very simple exemple :
REAPER-ReaScripts/X-Raym_Reset selected items active take stretch markers position.lua at master · X-Raym/REAPER-ReaScripts

As you can see, by setting the srcpos as new pos of markers, it RESET it. :P
X-Raym is offline   Reply With Quote
Old 11-19-2016, 10:59 PM   #3
Hypex
Human being with feelings
 
Join Date: Mar 2015
Location: Australia
Posts: 214
Default

Hi and thanks for your response.

Quote:
You were close, it is time position from the source media, doesn't consider REAPER item section, or take rate change.
Okay now I understand. Like an absolute position from the source media sound. Without getting into source offset and other relative positions.

I realise what I've done now. While thinking "away" from it. I set up a small test project where I isolated a kick track and cut out a lead in before it but had forgotten those details.

So for starters this would have messed up my source position. As an example here is some test output. This is marker M, Timeline position T and source position P.

Code:
M:0 T:0.000000 P:10.605527
M:1 T:1.740771 P:12.346298
M:2 T:3.452902 P:14.084915
M:3 T:5.167098 P:15.823441
Quote:
As you can see, by setting the srcpos as new pos of markers, it RESET it. :P
All it looks like you've done is taken the source position of stretch markers and re-plotted that as the time position.

Well so far I've solved it setting it twice. First I mark it where my start point is on the timeline. Then I remark it at the end point. Since source position is reused I don't need to get it again. The following code sets a marker to NextTime and stretches it to Time+BPMTime which is simply next grid point.

Code:
		Marker = SetTakeStretchMarker(Take, -1, NextTime);
		Marker !=-1 ?
		(;
			NextTime = Time + BPMTime;
			Marker = SetTakeStretchMarker(Take, Marker, NextTime);
		);
Now the question is how does one find the item source position in the media? I've taken a look but nothing really stood out. You can get PCM_Source but I didn't see any offset from source for an item. Unless I missed it. But if it's more lines than the above not much use spending time on it. :-)
Hypex is offline   Reply With Quote
Old 11-20-2016, 12:43 AM   #4
mpl
Human being with feelings
 
mpl's Avatar
 
Join Date: Oct 2013
Location: Moscow, Russia
Posts: 2,847
Default

If I understood your question right, you can do custom action:
Result - after placing mouse pointer at some position on item and running this custom action by shortcut firstly the new stretch marker added to a given position (say, kick drum you want to stretch), then this stretch marker moved to closest grid

Markers with negative cofficient will damage you project- Reaper will crash if you willn`t avoid that, or you`ll should find and clear some lines of your RPP ). Here is simplified scheme I`ve done it in some of my scripts:

Code:
      
-- negative coefficient SM protection
data_safety_distance = say, 0.001 second
for i = 2, SM_count do
  if SM[i].srcpos < SM[i-1].srcpos then
     difference = SM[i-1].srcpos - SM[i].srcpos
     SM[i].srcpos = SM[i].srcpos + (difference + data_safety_distance)/take_rate
     SM[i].pos = SM_t_raw[i].pos + difference + data_safety_distance
  end
end

Last edited by mpl; 11-20-2016 at 01:16 AM.
mpl is offline   Reply With Quote
Old 11-20-2016, 01:54 AM   #5
planetnine
Human being with feelings
 
planetnine's Avatar
 
Join Date: Oct 2007
Location: Lincoln, UK
Posts: 7,784
Default

You're welcome to use this to diagnose your SM script results if that helps: diagnostic tool02.


(Don't forget SMs are zero-indexed, so SM:1/15 with actually be SM[0] in Lua...)


I used it to bugfix scripts like this which can be quite involved to straighten out




I did write a few explanatory posts in this forum some time ago that explain how stretch markers work and how to manipulate the markers and the slopes. The main thing to watch is not to overlap them with moves, but calculate all in a take and batch apply.

http://forum.cockos.com/showthread.php?t=168878
http://forum.cockos.com/showthread.php?t=167155



I can help with specific SM theory or code next week if you can hang on that long (if you haven't worked it out by then)



>
__________________
Nathan, Lincoln, UK. | Item Marker Tool. (happily retired) | Source Time Position Tool. | CD Track Marker Tool. | Timer Recording Tool. | dB marks on MCP faders FR.

Last edited by planetnine; 11-20-2016 at 02:01 AM.
planetnine is offline   Reply With Quote
Old 11-21-2016, 05:58 AM   #6
Hypex
Human being with feelings
 
Join Date: Mar 2015
Location: Australia
Posts: 214
Default

Quote:
Originally Posted by mpl View Post
If I understood your question right, you can do custom action:
Okay, thanks, it looks like it is doing what I did. Repositioning an existing marker. Which does work well. :-)

Quote:
Markers with negative cofficient will damage you project- Reaper will crash if you willn`t avoid that, or you`ll should find and clear some lines of your RPP ). Here is simplified scheme I`ve done it in some of my scripts:
Yes I noticed that. The fault of that is from setting an incorrect source position. So with a correct one this should never happen.

Last edited by Hypex; 11-21-2016 at 06:45 AM.
Hypex is offline   Reply With Quote
Old 11-21-2016, 06:43 AM   #7
Hypex
Human being with feelings
 
Join Date: Mar 2015
Location: Australia
Posts: 214
Default

Quote:
Originally Posted by planetnine View Post
You're welcome to use this to diagnose your SM script results if that helps:
Nice one thanks.

Quote:
I did write a few explanatory posts in this forum some time ago that explain how stretch markers work and how to manipulate the markers and the slopes. The main thing to watch is not to overlap them with moves, but calculate all in a take and batch apply.
I've read the first thread. Didn't see the second.

Quote:
I can help with specific SM theory or code next week if you can hang on that long (if you haven't worked it out by then)
Well in theory the math for my SM should be simple. :-D

I've got it working right now by setting a marker to my start point and then resetting same marker to my end point while ignoring source position and letting Reaper figure that out. :-)

I did get somewhere. I found I can get the source offset from the D_STARTOFFS Take parameter. So just gotta take that into account and I should be able to calculate my source offset.
Hypex is offline   Reply With Quote
Old 11-22-2016, 10:53 PM   #8
Hypex
Human being with feelings
 
Join Date: Mar 2015
Location: Australia
Posts: 214
Default

Well after playing around a bit more while having the offset my math is still off. I suspect my marker planting is going whack because previous markers are stretching the timeline thus putting my time position out of line. Ideally I'd like to calculate it in one hit but it works perfectly fine just setting two markers, by marking one spot and moving it to another. I didn't notice any slowdown doing it that way. So I think I will just end up doing that and let Reaper sort it out. Kinda like the saying to shoot them all and let God sort it out. Here Reaper is the perfect judge so I can mark them all and let Reaper sort it out. :-D
Hypex is offline   Reply With Quote
Old 11-22-2020, 09:19 AM   #9
Hypex
Human being with feelings
 
Join Date: Mar 2015
Location: Australia
Posts: 214
Default These stretch markers are driving me crazy!

Okay so it's been four years and as it turns out I still don't have these figured out. It's been driving me nuts the last few days!


Finding out about the take offset was a happy accident years ago but now I've discovered things are a lot more complicated. I split an item and found it wrecks the time position when trying to add a marker.


So I have my item, take, offset and what not. How do I convert timeline position to take position so I can add a marker to that position? I had a nice little routine I just got working but I split an item and now find it won't work well any more.


Just to note, I don't need to calculate source position nor do I care to, since SetTakeStretchMarker() can do it for me. And I'm not interested in slopes, not yet. Basic stretch marks are bad enough. I don't want my head to explode. ;-)
Hypex is offline   Reply With Quote
Old 11-23-2020, 04:48 PM   #10
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 137
Default

Quote:
Originally Posted by Hypex View Post
How do I convert timeline position to take position so I can add a marker to that position?
The easiest way I know of is to have the timeline position and subtract it by the item's start position, giving you the timeline position over the item without any of the take adjustments.

For example, if I have my cursor at 59 seconds in the timeline and the item I am adjusting starts at 50 seconds then all I have to do is subtract the two to find out that my cursor is 9 seconds into the item.
jkooks is offline   Reply With Quote
Old 11-23-2020, 06:50 PM   #11
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: Apr 2020
Location: Leipzig
Posts: 1,637
Default

Quote:
Originally Posted by jkooks View Post
The easiest way I know of is to have the timeline position and subtract it by the item's start position, giving you the timeline position over the item without any of the take adjustments.

For example, if I have my cursor at 59 seconds in the timeline and the item I am adjusting starts at 50 seconds then all I have to do is subtract the two to find out that my cursor is 9 seconds into the item.
Maybe you need to take care of the startoffset of the take as well, but this is a wild guess. I never used stretchmarkers yet.
__________________
Use you/she/her, when contacting me, please. Thanks :) Not mentoring via PMs, sorry.
Ultraschall-API - 1351 ReaScript functions for Reaper - Reaper Internals - Developerdocs4Reaper - Donate, if you wish
Meo-Ada Mespotine is offline   Reply With Quote
Old 11-23-2020, 06:55 PM   #12
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 137
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
Maybe you need to take care of the startoffset of the take as well, but this is a wild guess. I never used stretchmarkers yet.
I haven't either but I think you just need to pass the source offset value to the function, since there is a value for the function that will automatically adjust the position if the offset is given. Not sure if it takes play rate into account, though.
jkooks is offline   Reply With Quote
Old 11-24-2020, 08:35 AM   #13
Hypex
Human being with feelings
 
Join Date: Mar 2015
Location: Australia
Posts: 214
Default

Quote:
Originally Posted by jkooks View Post
The easiest way I know of is to have the timeline position and subtract it by the item's start position, giving you the timeline position over the item without any of the take adjustments.

For example, if I have my cursor at 59 seconds in the timeline and the item I am adjusting starts at 50 seconds then all I have to do is subtract the two to find out that my cursor is 9 seconds into the item.

You are right! I confirmed this last night when I was checking all the offsets. I purposely cut four seconds off an item so the start offset wasn't zero. Added some stretches to cursor positions. Then split and checked the numbers. I noticed that they started from zero position.


In the meantime I had also written a stretch marker list script to list marks in an item. Surely there must be a manager in Reaper or a script for it but I didn't see anything. A few of my items were totally messed up. And had negative positions! Kinda funny and I don't know how to delete it. Working with stretch markers is harder than working with tempo markers. I can click one for info, drag it but cannot figure out how to delete any. Keep reading Alt click but it does nothing here. It would be good if both tempo and stretch markers could be managed from the marker manager.


Thanks for confirming the answer.
Hypex is offline   Reply With Quote
Old 11-24-2020, 08:48 AM   #14
Hypex
Human being with feelings
 
Join Date: Mar 2015
Location: Australia
Posts: 214
Default

Quote:
Originally Posted by Meo-Ada Mespotine View Post
Maybe you need to take care of the startoffset of the take as well, but this is a wild guess. I never used stretchmarkers yet.

You do if you set source offset by hand. Or need to calculate it yourself. But it gets complicated if there are other markers to take into account and take rates. There's no simple function to get a source offset from any time position. Except from an existing marker. I found this had to be taken into account if, for example, you wanted to re-plot stretch markers across a section. So, in this case, I just find it easier to set a start and end point and move the end point to where I want I want it to be.
Hypex is offline   Reply With Quote
Old 11-24-2020, 11:45 AM   #15
jkooks
Human being with feelings
 
Join Date: May 2020
Posts: 137
Default

Quote:
Originally Posted by Hypex View Post
A few of my items were totally messed up. And had negative positions!
Was the item looped at all? Having a looped item can mess with offset calculations since the length of the item is longer than the source's actual length, which may lead to negative positions. I know when I used to work with offsets I would always get negative positions whenever an item had been looped, so it may be worth checking out if that was the case.
jkooks is offline   Reply With Quote
Old 11-25-2020, 09:37 AM   #16
Hypex
Human being with feelings
 
Join Date: Mar 2015
Location: Australia
Posts: 214
Default

Quote:
Originally Posted by jkooks View Post
Was the item looped at all?

No. All I had done was split the item in several sections. And for completeness also split other items in different positions on other tracks. But I can see your point about the looping.


I just tested with a looped item. And the offsets were all normal looking. Though I used "Item: Fit items to time selection, looping if needed" to create a loop if it indeed worked but it did extend it.


My negative offsets would be from me trying to figure out what it needed and giving an overflow. That is I used direct timeline position. So if an item sat at 50 seconds I used 50 and above as the position, which was too large, but ended up in all these negative markers being added in. Quite possibly over the item length as well.
Hypex 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 11:24 AM.


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