/
TJF Copy Test.lua
155 lines (97 loc) · 4.57 KB
/
TJF Copy Test.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
--@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()
local function Msg(param) reaper.ShowConsoleMsg(tostring(param).."\n") end
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()
local function ClearSection(section)
reaper.DeleteExtState( section, "Razor Edits", true )
local key = 1
local loop = reaper.HasExtState(section, "Item" .. key)
while loop == true do
reaper.DeleteExtState( section, "Item" .. key, true )
key = key + 1
loop = reaper.HasExtState(section, "Item" .. key)
end
end
local function GetTrackSelectedMediaItems(track)
local items = {}
for i=1, reaper.CountTrackMediaItems(track) do
local item = reaper.GetTrackMediaItem(track, i-1)
if reaper.IsMediaItemSelected(item) then table.insert(items, item) end
end
if #items > 0 then return items end
return false
end
--[[------------------------------[[---
MAIN
---]]------------------------------]]--
local function Main()
if reaper.CountSelectedMediaItems(0) < 1 and not RazorEditSelectionExists() then return end
local starttime, endtime = nil, nil
for t=1, reaper.CountTracks()
do
ClearSection("Track"..t)
local track = reaper.GetTrack(0,t-1)
local _, area = reaper.GetSetMediaTrackInfo_String( track, "P_RAZOREDITS", "", false )
reaper.SetExtState( "Track" .. t, "Razor Edits", area, false )
local items = GetTrackSelectedMediaItems(track)
if items then
for i = 1, #items do
local itemstart = reaper.GetMediaItemInfo_Value( items[i], "D_POSITION" )
local itemend = itemstart + reaper.GetMediaItemInfo_Value( items[i], "D_LENGTH" )
if starttime == nil or itemstart < starttime then starttime = itemstart end
if endtime == nil or itemend > endtime then endtime = itemend end
local _, str = reaper.GetItemStateChunk( items[i], "", false )
str = string.gsub(str, "GUID .-\n", "GUID " .. reaper.genGuid("") .. "\n" )
reaper.SetExtState( "Track" .. t, "Item"..i, str, false )
end
else
reaper.SetExtState( "Track" .. t, "Item1", "nil", false )
end
end
ClearSection("Track"..reaper.CountTracks()+1)
reaper.SetExtState( "TJF Copy", "StartTime", starttime, false )
reaper.SetExtState( "TJF Copy", "EndTime", endtime, false )
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