Old 12-18-2018, 06:50 PM   #1
tXShooter
Human being with feelings
 
tXShooter's Avatar
 
Join Date: Aug 2017
Posts: 336
Default Lua: How do you get Marker Time?

I had thought that I had seen this answered somewhere before, but if I had I can't recall where.

How do you get the Marker Time when you have markrgnidx?
__________________
"But be ye doers of the word, and not hearers only, deceiving your own selves."
tXShooter is offline   Reply With Quote
Old 12-18-2018, 06:57 PM   #2
cfillion
Human being with feelings
 
cfillion's Avatar
 
Join Date: May 2015
Location: Québec, Canada
Posts: 4,970
Default

With EnumProjectMarkers.
cfillion is offline   Reply With Quote
Old 12-18-2018, 10:58 PM   #3
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 565
Default

Code:
markrgnidx=xx

local num=reaper.CountProjectMarkers(0)

local MarkerTime

for i=0, num-1 do

	local _1, _2, pos, _3, _4, index=reaper.EnumProjectMarkers(i)

	if index==markrgnidx then 

		MarkerTime=pos

		break

	end

end

reaper.ShowConsoleMsg("The Marker Time is: "..tostring(MarkerTime) .. "\n")
Just change the "xx" in first line to the number you want
dsyrock is offline   Reply With Quote
Old 12-19-2018, 01:31 AM   #4
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,901
Default

@dysrock


You dont have to loop in markers for that there is a get marker by ID function API natvely.
X-Raym is offline   Reply With Quote
Old 12-19-2018, 03:48 AM   #5
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 565
Default

Quote:
Originally Posted by X-Raym View Post
@dysrock


You dont have to loop in markers for that there is a get marker by ID function API natvely.
Really? Which API can do that? I checked that API list again and still confusing
dsyrock is offline   Reply With Quote
Old 12-19-2018, 04:29 AM   #6
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,458
Default

There is DeleteProjectMarkerByIndex and SetProjectMarkerByIndex, but there is not a Get one, AFAIK
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 12-19-2018, 06:45 AM   #7
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,901
Default

Hmmm you are right, maybe it was a custom function I made.


I would say that if you have to build your own Get project Marker by Index, first loop on all markers, store them in table with key as idx, and then just access the key, it will be far more efficient than having the markers loop called each time you need to access the function.


Note: reaper.GoToMarker( proj, marker_index, use_timeline_order ) take idx apparently.
X-Raym is offline   Reply With Quote
Old 12-19-2018, 07:11 AM   #8
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,458
Default

Code:
local mrk_cnt = reaper.CountProjectMarkers(0)
local markers, regions = {}, {}
for i=0, mrk_cnt-1 do
  local _, isrgn, pos, rgnend, name, index = reaper.EnumProjectMarkers( i )
  if isrgn then
    regions[index] = {Start = pos, End = rgnend, Name = name}
  else
    markers[index] = {Pos = pos, Name = name}
  end
end

-- EXAMPLES
-- Get time of marker with markrgnidx 2
time = markers[2].Pos
-- Get name of region with index 1
name = regions[1].Name
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 12-19-2018, 07:12 AM   #9
tXShooter
Human being with feelings
 
tXShooter's Avatar
 
Join Date: Aug 2017
Posts: 336
Default

I think this will work...

Code:
function MarkerTime() -- Define 'num' if calling with a known markerindex number: MarkerTime(num)
	local num = reaper.CountProjectMarkers(0) -- delete if using MarkerTime(num)
	local MarkerTime
	local _1, _2, MarkerTime, _3, _4, index=reaper.EnumProjectMarkers(num-1)
	MarkerTime = reaper.format_timestr(MarkerTime, "")
	-- reaper.ShowConsoleMsg("The Marker Time is: "..tostring(MarkerTime) .. "\n")
	return MarkerTime
end
If I understand how things work... I'm not having to set the markerindex prior to calling because in my use I set the marker just prior to calling this, so by default it's the last marker in the index.

My next question about this is: While recording, if I wanted to include in the text of the Marker what its time is, would there be a way of grabbing the time just prior to reaper.AddProjectMarker(0,0, reaper.GetPlayPosition(),0,MarkerText,-1)?
__________________
"But be ye doers of the word, and not hearers only, deceiving your own selves."
tXShooter is offline   Reply With Quote
Old 12-19-2018, 07:28 AM   #10
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,458
Default

Quote:
Originally Posted by tXShooter View Post
I think this will work...
My next question about this is: While recording, if I wanted to include in the text of the Marker what its time is, would there be a way of grabbing the time just prior to reaper.AddProjectMarker(0,0, reaper.GetPlayPosition(),0,MarkerText,-1)?

Code:
local playpos = reaper.GetPlayPosition()
local Name = "Seconds" -- or whatever name you wish
reaper.AddProjectMarker( 0, false, playpos, 0, Name .. " " .. math.floor(playpos*100+0.5)/100, -1)

This gives the time in seconds and two decimal places. Do you want it in another format?
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)

Last edited by amagalma; 12-19-2018 at 07:34 AM.
amagalma is offline   Reply With Quote
Old 12-19-2018, 09:38 AM   #11
tXShooter
Human being with feelings
 
tXShooter's Avatar
 
Join Date: Aug 2017
Posts: 336
Default

Quote:
Originally Posted by amagalma View Post
Code:
local playpos = reaper.GetPlayPosition()
local Name = "Seconds" -- or whatever name you wish
reaper.AddProjectMarker( 0, false, playpos, 0, Name .. " " .. math.floor(playpos*100+0.5)/100, -1)

This gives the time in seconds and two decimal places. Do you want it in another format?
Thank you, amagalma.

I used your information to formulate:
Code:
function GetPlayPosition()
	local playpos = reaper.GetPlayPosition()
	playpos = reaper.format_timestr(playpos, "")
	return playpos
end
I had done something similar to this before but had forgotten it. It sucks getting old.
__________________
"But be ye doers of the word, and not hearers only, deceiving your own selves."
tXShooter 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 08:34 AM.


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