/
TJF fucking last touched envelope visible toggle.lua
209 lines (156 loc) · 8.39 KB
/
TJF fucking last touched envelope visible toggle.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
--@description TJF Toggle Last Touched FX Envelope Visible and Hide all Others
--@version 1.6
--@author Tim Farrell
--
--@about
-- # TJF Toggle Last Touched FX Envelope Visible and Hide all Others
-- Will the the Envelope for your last touched parameter
-- Does not stipulate between Take or Track FX
-- Will Hide All other Visible Envelopes on the Track/Take for clarity.
-- TakeFX will update if you adjust the Parameter
--
--@changelog
-- v1.0 - nothing to report
-- v1.1 - removed BR_Env functions for all Native Reaper API
-- v1.2 - Added Ability to update value after adjusting TAKEFX - Track FX depends on automation mode
-- v1.3 - updated SetEnvelopeVis() function to prevent future breaking
-- v1.4 - Sets Last Touched Envelope as Selected when adjusting parameter
-- Take FX - Will also select all points also (for easy clear/deletion)
-- v1.4.1 Script maintainance (removed unused functions)
-- v1.5 - added support for folder trim automation visibility
-- v1.6 - added X,Y,Z support for ReaSurround2
local EnableZ = true
function Msg(param) reaper.ShowConsoleMsg(tostring(param).."\n") end
function round(number, decimals)
local power = 10^decimals
return math.floor(number * power) / power
end
function GetEnvelopeVis(envelope)
Msg("envelope:")
Msg(envelope)
local retval, str = reaper.GetEnvelopeStateChunk( envelope, "", false )
if retval then
str = string.match(str, "\nVIS %d")
str = string.match(str, "%d")
if str=="1" then return true else return false end
end
--reaper.SetEnvelopeStateChunk( envelope, str, true )
end--EnvelopeVis()
function SetEnvelopeVis(envelope, bool)
local retval, str = reaper.GetEnvelopeStateChunk( envelope, "VIS", false )
if retval then
if bool
then str = string.gsub(str, "\nVIS %d", "\nVIS 1")
else str = string.gsub(str, "\nVIS %d", "\nVIS 0")
end
end
reaper.SetEnvelopeStateChunk( envelope, str, true )
end--EnvelopeVis()
function ReaSurround2(CurrentEnv, MasterEnvelope, speakers)
if speakers=="" then speakers = 0 end
speakers = tonumber(string.match(speakers, "%d+"))
local _, MasterName = reaper.GetEnvelopeName( MasterEnvelope )
if string.find(MasterName, "ReaSurround2" )
then
local channel = string.match(MasterName, "%d+")
if channel
then
local _, CurrentName = reaper.GetEnvelopeName( CurrentEnv )
if string.find(CurrentName, "in "..channel.." X ") or string.find(CurrentName, "in "..channel.." Y ")
then return true
elseif EnableZ and speakers > 8 and string.find(CurrentName, "in "..channel.." Z ")
then return true
end
end
end
return false
end
function TrackFXLastTouched(tracknumber, fxnumber, paramnumber)
local track = reaper.CSurf_TrackFromID(tracknumber, false)
fxvalue, minval, maxval = reaper.TrackFX_GetParam( track, fxnumber, paramnumber )
fxvalue = round(fxvalue,7)
envelope = reaper.GetFXEnvelope( track, fxnumber, paramnumber, false )
if not reaper.ValidatePtr2(0, envelope, "TrackEnvelope*") or not envelope then
envelope = reaper.GetFXEnvelope( track, fxnumber, paramnumber, true )
created = true
end
local visible = not GetEnvelopeVis(envelope)
--retval, name = reaper.TrackFX_GetFXName( track, fxnumber, "" )
local _, speakers = reaper.TrackFX_GetNamedConfigParm( track, fxnumber, "NUMSPEAKERS" )
--[[ ---------ADJUST VALUE
if reaper.CountEnvelopePoints( envelope ) < 2 then
if reaper.CountEnvelopePoints(envelope) < 1
then reaper.InsertEnvelopePointEx( envelope, -1, 0, fxvalue, 0, 0, 1, 0 )
end
retval, time, value, shape, tension, selected = reaper.GetEnvelopePoint( envelope, 0 )
value = round(value,7)
if value ~= fxvalue then visible = true end
reaper.SetEnvelopePoint( envelope, 0, time, fxvalue, shape, tension, selected, false )
end--if
]]--
----------SET VISIBILITY
for i=0, reaper.CountTrackEnvelopes( track ) - 1 do
local env = reaper.GetTrackEnvelope( track, i )
local _, name = reaper.GetEnvelopeName( env )
local _, trackname = reaper.GetTrackName(track)
if (name == "Trim Volume" and reaper.GetMediaTrackInfo_Value(track, "I_FOLDERDEPTH" ) == 1 and trackname ~= "PIX" )
then SetEnvelopeVis(env, true)
elseif ReaSurround2(env, envelope, speakers) then SetEnvelopeVis(env, visible)
elseif env~=envelope then SetEnvelopeVis(env, false)
elseif created then SetEnvelopeVis(env, true)
else SetEnvelopeVis(env, visible)
end
end--for
reaper.SetCursorContext( 2, envelope ) -- selects envelope
--reaper.Main_OnCommand(40332,0) -- Envelope: Select all points
end--TrackFXLastTouched
function TakeFXLastTouched(tracknumber, fxnumber, paramnumber)
local track = reaper.CSurf_TrackFromID((tracknumber & 0xFFFF), false)
local takenumber = (fxnumber >> 16)
fxnumber = (fxnumber & 0xFFFF)
local item_index = (tracknumber >> 16)-1
local item = reaper.GetTrackMediaItem(track, item_index)
local take = reaper.GetTake(item, takenumber)
fxvalue, minval, maxval = reaper.TakeFX_GetParam( take, fxnumber, paramnumber )
fxvalue = round(fxvalue,7)
local envelope = reaper.TakeFX_GetEnvelope( take, fxnumber, paramnumber, false )
if envelope == nil then
envelope = reaper.TakeFX_GetEnvelope( take, fxnumber, paramnumber, true )
created = true
end
local visible = not GetEnvelopeVis(envelope)
local _, speakers = reaper.TakeFX_GetNamedConfigParm( take, fxnumber, "NUMSPEAKERS" )
---------ADJUST VALUE
if reaper.CountEnvelopePoints( envelope ) < 2 then
if reaper.CountEnvelopePoints(envelope) < 1
then reaper.InsertEnvelopePointEx( envelope, -1, 0, fxvalue, 0, 0, 1, 0 )
end
retval, time, value, shape, tension, selected = reaper.GetEnvelopePoint( envelope, 0 )
value = round(value,7)
if value ~= fxvalue then visible = true end
reaper.SetEnvelopePoint( envelope, 0, time, fxvalue, shape, tension, selected, false )
end--if
----------SET VISIBILITY
for i=0, reaper.CountTakeEnvelopes( take ) - 1 do
local env = reaper.GetTakeEnvelope( take, i )
if ReaSurround2(env, envelope, speakers) then SetEnvelopeVis(env, visible)
elseif env~=envelope then SetEnvelopeVis(env, false)
elseif created then --SetEnvelopeVis(env, true)
else SetEnvelopeVis(env, visible)
end
end--for
reaper.SetCursorContext( 2, envelope ) -- selects envelope
reaper.Main_OnCommand(40332,0) -- Envelope: Select all points
end--TakeFXLastTouched
function Main()
local retval, tracknumber, fxnumber, paramnumber = reaper.GetLastTouchedFX()
if retval then
if (tracknumber >> 16) == 0 then TrackFXLastTouched(tracknumber, fxnumber, paramnumber) -- Track FX or Input FX
else TakeFXLastTouched(tracknumber, fxnumber, paramnumber) -- ITEM FX >>>>>
end
end
end--Main()
Main()
reaper.UpdateArrange()
reaper.TrackList_AdjustWindows(false)
reaper.defer(function() end) --prevent Undo