|
|
|
12-18-2018, 06:50 PM
|
#1
|
Human being with feelings
Join Date: Aug 2017
Posts: 336
|
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."
|
|
|
12-18-2018, 06:57 PM
|
#2
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,970
|
With EnumProjectMarkers.
|
|
|
12-18-2018, 10:58 PM
|
#3
|
Human being with feelings
Join Date: Sep 2018
Location: China
Posts: 565
|
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
|
|
|
12-19-2018, 01:31 AM
|
#4
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,901
|
@dysrock
You dont have to loop in markers for that there is a get marker by ID function API natvely.
|
|
|
12-19-2018, 03:48 AM
|
#5
|
Human being with feelings
Join Date: Sep 2018
Location: China
Posts: 565
|
Quote:
Originally Posted by X-Raym
@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
|
|
|
12-19-2018, 04:29 AM
|
#6
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
There is DeleteProjectMarkerByIndex and SetProjectMarkerByIndex, but there is not a Get one, AFAIK
|
|
|
12-19-2018, 06:45 AM
|
#7
|
Human being with feelings
Join Date: Apr 2013
Location: France
Posts: 9,901
|
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.
|
|
|
12-19-2018, 07:11 AM
|
#8
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
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
|
|
|
12-19-2018, 07:12 AM
|
#9
|
Human being with feelings
Join Date: Aug 2017
Posts: 336
|
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."
|
|
|
12-19-2018, 07:28 AM
|
#10
|
Human being with feelings
Join Date: Apr 2011
Posts: 3,458
|
Quote:
Originally Posted by tXShooter
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?
Last edited by amagalma; 12-19-2018 at 07:34 AM.
|
|
|
12-19-2018, 09:38 AM
|
#11
|
Human being with feelings
Join Date: Aug 2017
Posts: 336
|
Quote:
Originally Posted by amagalma
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."
|
|
|
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 08:34 AM.
|