- API -
dofile(reaper.AZ_GetLuaInitPath())
allCount = reaper.AZ_GetMediaTypeCount(0,"")
mediaList = {}
mediaInterval = 1
setMediaTime = 0
for i = 1,allCount do
mediaList[i] = {}
mediaList[i]["name"]= reaper.AZ_GetMediaName(0,i-1)
mediaList[i]["media"]= reaper.AZ_GetMediaItemSelect(0,i-1,0)
mediaList[i]["length"]= reaper.AZ_GetMediaLength(0,i-1)
end
table.sort(mediaList,function(a,b) return (a.name < b.name)end)
for index, value in pairs(mediaList) do
if index == 1 then
reaper.AZ_SetMediaItemStartTimeSeconds(mediaList[index].media,setMediaTime)
setMediaTime = setMediaTime+mediaList[index].length+mediaInterval
else
reaper.AZ_SetMediaItemStartTimeSeconds(mediaList[index].media,setMediaTime)
setMediaTime = setMediaTime+mediaList[index].length+mediaInterval
end
end
- API Detail-
Multiple media in a project
- SCRIPT -
dofile(reaper.AZ_GetLuaInitPath())
allCount = reaper.AZ_GetMediaTypeCount(0,"")
Get the total number of media (allCount)
mediaList = {}
Define the array (medialist)
mediaInterval = 1
Prepare media interval value as a variable
setMediaTime = 0
Prepare the media start position as a variable
for i = 1,allCount do
*1
Loop from 1 to the variable (allCount)
mediaList[i] = {}
*2
Define an array {} inside the array (mediaList[i]).
mediaList[i]["name"]= reaper.AZ_GetMediaName(0,i-1)
Get the name of the media and save it in ["name"] of mediaList[i]
mediaList[i]["media"]= reaper.AZ_GetMediaItemSelect(0,i-1,0)
Get MediaItem and save it in ["media"] of mediaList[i]
mediaList[i]["length"]= reaper.AZ_GetMediaLength(0,i-1)
Get the length of the media and save it in ["length"] of mediaList[i]
end
table.sort(mediaList,function(a,b) return (a.name < b.name)end)
*3
Sort the array using ["name"] of the array (mediaList).
By sorting the names, the "media" and "length" enclosed with the same ID in the array will also be swapped.
for index, value in pairs(mediaList) do
Repeat for the number of elements in the array (mediaList)
if index == 1 then
*4
If the variable (index) is 1, it continues below.
reaper.AZ_SetMediaItemStartTimeSeconds(mediaList[index].media,setMediaTime)
Set the media in the array (mediaList[index]) to setMediaTime (0 seconds position).
setMediaTime = setMediaTime+mediaList[index].length+mediaInterval
Output the second starting point
Media start position variable (setMediaTime) + media length + media interval value (1 second)
else
If statement Check the contents of the variable (index)
If not the first one, continue below
reaper.AZ_SetMediaItemStartTimeSeconds(mediaList[index].media,setMediaTime)
Set the media in the array mediaList[index] to setMediaTime (second or later position).
setMediaTime = setMediaTime+mediaList[index].length+mediaInterval
Output the third and subsequent start points
Media start position variable (setMediaTime) + media length + media interval value (1 second)
end
Repeat for the number of arrays (mediaList)
end
All media placed in the project is sorted in ascending order.
=References===