/
TJF SCRIPT START EMPTY TEMPLATE.lua
156 lines (120 loc) · 5.09 KB
/
TJF SCRIPT START EMPTY TEMPLATE.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
--@noindex
-- NoIndex: true
--@description TJF Script Name
--@version 1.0
--@author Tim Farrell
--@links
-- TJF Reapack https://github.com/sonictim/TJF-Scripts/raw/master/index.xml
--
--@about
-- # TJF Script Name
--
-- Information about the script
--
--
-- DISCLAIMER:
-- This script was written for my own personal use and therefore I offer no support of any kind.
-- Any feature requests/bug reports will be ignored entirely, unless of course they interest me and I want to pursue them.
-- I strongly recommend never to run this or any other script I've written for any reason what so ever.
-- Ignore this advice at your own peril!
--
--
--@changelog
-- v1.0 - nothing to report
--[[------------------------------[[---
DEBUG
---]]------------------------------]]--
reaper.ClearConsole()
function Msg(param) reaper.ShowConsoleMsg(tostring(param).."\n") end
--[[------------------------------[[---
GLOBAL VARIABLES
---]]------------------------------]]--
local item = {}
local itemcount = reaper.CountSelectedMediaItems(0)
for i = 1, itemcount do item[i] = reaper.GetSelectedMediaItem(0, i-1) end -- FILL ITEM ARRAY
local track = {}
local trackcount = reaper.CountSelectedTracks(0)
for i = 1, trackcount do track[i] = reaper.GetSelectedTrack(0, i-1) end -- FILL TRACK ARRAY
start_time, end_time = reaper.GetSet_LoopTimeRange2(0, false, false, 0, 0, false) -- Get start and end time selection value in seconds
--second false chooses time or loop points
local curpos = reaper.GetCursorPosition() --Get current cursor position
function take(param) return reaper.GetActiveTake(item[param]) end --can call take function to match take to item
--[[------------------------------[[---
FUNCTIONS
---]]------------------------------]]--
function RazorEditSelectionExists()
for i=0, reaper.CountTracks(0)-1 do
local retval, x = reaper.GetSetMediaTrackInfo_String(reaper.GetTrack(0,i), "P_RAZOREDITS", "string", false)
if x ~= "" then return true end
end
return false
end--RazorEditSelectionExists()
function GetRazorEdits() -- Function Written by BirdBird on reaper forums
local trackCount = reaper.CountTracks(0)
local areaMap = {}
for i = 0, trackCount - 1 do
local track = reaper.GetTrack(0, i)
local ret, area = reaper.GetSetMediaTrackInfo_String(track, 'P_RAZOREDITS', '', false)
if area ~= '' then
--PARSE STRING
local str = {}
for j in string.gmatch(area, "%S+") do
table.insert(str, j)
end
--FILL AREA DATA
local j = 1
while j <= #str do
--area data
local areaStart = tonumber(str[j])
local areaEnd = tonumber(str[j+1])
local GUID = str[j+2]
local isEnvelope = GUID ~= '""'
--get item data
local items = {}
if not isEnvelope then
local itemCount = reaper.CountTrackMediaItems(track)
for k = 0, itemCount - 1 do
local item = reaper.GetTrackMediaItem(track, k)
local pos = reaper.GetMediaItemInfo_Value(item, "D_POSITION")
local length = reaper.GetMediaItemInfo_Value(item, "D_LENGTH")
local itemEndPos = pos+length
--check if item is in area bounds
if (itemEndPos > areaStart and itemEndPos <= areaEnd) or
(pos >= areaStart and pos < areaEnd) or
(pos <= areaStart and itemEndPos >= areaEnd) then
table.insert(items,item)
end
end
end
local areaData = {
areaStart = areaStart,
areaEnd = areaEnd,
track = track,
items = items,
isEnvelope = isEnvelope,
GUID = GUID
}
table.insert(areaMap, areaData)
j = j + 3
end
end
end
return areaMap
end
--[[------------------------------[[---
MAIN
---]]------------------------------]]--
function Main()
end--Main()
--[[------------------------------[[---
CALL THE SCRIPT
---]]------------------------------]]--
reaper.Undo_BeginBlock()
--reaper.PreventUIRefresh(1) -- uncomment only once script works
Main()
--reaper.PreventUIRefresh(-1) -- uncomment only once script works
reaper.UpdateArrange()
--reaper.UpdateTimeline()
--reaper.TrackList_AdjustWindows(0) -- Updates the window view (used when resizing tracks)
reaper.Undo_EndBlock("TJF Script Name", -1)
--reaper.defer(function() end) --prevent Undo